今天我们要对P8口的GPIO1_12进行操作。3V3和GND也是板子提供的。
注意:
为了在linux下操作某一引脚, 引脚值通常为 通道号x32+该通道上的引脚编号。
这里GPIO1_12为例,就是 1x32+12 =44.
关于GPIO,大家可以参考Linux的gpio接口手册。也就是说Linux下基本上也是差不多这么操作GPIO口的,就像下面这些代码(摘自Linux gpio.txt)。
/sys/class/gpio/
"export" ... Userspace may ask the kernel to export control of
a GPIO to userspace by writing its number to this file.
Example: "echo 19 > export" will create a "gpio19" node
for GPIO #19, if that's not requested by kernel code.
"unexport" ... Reverses the effect of exporting to userspace.
Example: "echo 19 > unexport" will remove a "gpio19"
node exported using the "export" file.
相关操作函数
/* export the GPIO to userspace */
int gpio_export(unsigned gpio, bool direction_may_change);
/* reverse gpio_export() */
void gpio_unexport();
/* create a sysfs link to an exported GPIO node */
int gpio_export_link(struct device *dev, const char *name,
unsigned gpio);
/* change the polarity of a GPIO node in sysfs */
int gpio_sysfs_set_active_low(unsigned gpio, int value);