在linux下控制gpio可以先用简单的命令行去控制下看看,
1. devmem 0x41200000 32
0x00000005
2.devicetree的结构如下
dip0: gpio_dip_sw@41200000 {
compatible = "generic-uio","uio";
reg =<0x41200000 0x1000>;
text_data = "GPIO_DIP_SWITCH"; //for test
bin_data=; //for test
};
需要注意的点是 reg=后面的一个参数必须要大于等于0x1000 ;
3. c语言源码
fd_led=open(filename,O_RDONLY);
if(fd_led<0)
return 1;
base_address = mmap(NULL, 0x10, PROT_READ | PROT_WRITE, MAP_SHARED, fd_led, 0);
if(base_address==MAP_FAILED)
{perror("mmap");
}
总结一下:
下面是完整的API函数
#include
#include
#include
// The specific GPIO being used must be setup and replaced thru
// this code. The GPIO of 240 is in the path of most the sys