驱动需要包含 #include
判断一个IO是否合法:int
gpio_is_valid(int number);
设置GPIO的方向,如果是输出同时设置电平:
- /* set as input or output, returning 0 or negative errno */
- int gpio_direction_input(unsigned gpio);
- int gpio_direction_output(unsigned gpio, int value);
获取输入引脚的电平:- /* GPIO INPUT: return zero or nonzero */
- int gpio_get_value(unsigned gpio);
- /* GPIO OUTPUT */
- void gpio_set_value(unsigned gpio, int value);
- int gpio_cansleep(unsigned gpio);
To
access such GPIOs, a different set of accessors is defined:
- /* GPIO INPUT: return zero or nonzero, might sleep */
- int gpio_get_value_cansleep(unsigned gpio);
- /* GPIO OUTPUT, might sleep */
- void gpio_set_value_cansleep(unsigned gpio, int value);获取一个GPIO并声明标签:
- /* request GPIO, returning 0 or negative errno.
- * non-null labels may be useful for diagnostics.
- */
- int gpio_request(unsigned gpio, const char *label);
- /* release previously-claimed GPIO */
- void gpio_free(unsigned gpio);
将GPIO映射为IRQ中断:- /* map GPIO numbers to IRQ numbers */
- int gpio_to_irq(unsigned gpio);
- /* map IRQ numbers to GPIO numbers (avoid using this) */
- int irq_to_gpio(unsigned irq);
设置GPIO
IRQ中断类型:
- if (!sw->both_edges) {
- if (gpio_get_value(sw->gpio))
- set_irq_type(gpio_to_irq(sw->gpio), IRQ_TYPE_EDGE_FALLING);
- else
- set_irq_type(gpio_to_irq(sw->gpio), IRQ_TYPE_EDGE_RISING);
- }
在驱动中使用延时函数mdelay,需要包含文件。
阅读(3135) | 评论(0) | 转发(0) |