假设给GPIO0~GPIO7命名分别为“test0...test7”,需要在ma35d1.dtsi配置,相关配置如下: gpioa: gpioa@40040000 { reg = <0x0 0x40040000 0 0x40>, <0x0 0x40040800 0 0x40>; interrupts = <GIC_SPI 14 IRQ_TYPE_LEVEL_HIGH>; clocks = <&clk GPA_GATE>; gpio-controller; #gpio-cells = <2>; interrupt-controller; #interrupt-cells = <2>; gpio-line-names = "test0", "test1", "test2", "test3", "test4", "test5", "test6", "test7","","","","","","","",""; }; 编译后用工具gpioinfo可以查询GPIO的信息如下: # ./gpioinfo gpiochip0 - 16 lines: line 0: "test0" unused input active-high line 1: "test1" unused input active-high line 2: "test2" unused input active-high line 3: "test3" unused input active-high line 4: "test4" unused input active-high line 5: "test5" unused input active-high line 6: "test6" unused input active-high line 7: "test7" unused input active-high line 8: unnamed unused input active-high line 9: unnamed unused input active-high line 10: unnamed unused input active-high line 11: unnamed unused input active-high line 12: unnamed unused input active-high line 13: unnamed unused input active-high line 14: unnamed unused input active-high line 15: unnamed unused input active-high ...... 第一列是GPIO的编号,第二列是line-name,在dts里面通过配置gpio-line-names来配置,第三列是被使用者名字,第四列是方向,最后一列是激活状态
控制GPiO时就不用管在哪个端口哪个pin了,直接给名字就可以调用 类似,比如上面定义了一个IO叫test0,用libgpiod自带的控制程序可以这样控制:
gpiofind test0,这个程序会输出对应的gpiochip和offset # ./gpiofind test0 gpiochip0 0
再用gpioset gpiochipXX offset=1来控制输出高电平 # ./gpioget gpiochip0 0 0 # ./gpioset gpiochip0 0=1 # ./gpioget gpiochip0 0 1 #
|