Kickpi-Book
  • KICKPI Document
  • K5/K5C(A133)
    • A133中文文档
      • 01-主板介绍
        • 01-KICKPI-K5硬件介绍
        • 02-KICKPI-K5C硬件介绍
      • 02-入门必读
        • 01-网盘目录说明
        • 02-快速使用
        • 03-功能测试
        • 04-扩展引脚
      • 03-镜像烧录
        • 01-获取镜像文件
        • 02-SD卡烧录
        • 02-USB线烧录
      • 04-SDK编译
        • 01-编译环境搭建
        • 02-LINUX_SDK源码编译
        • 03-ANDROID_SDK源码编译
      • 05-外设驱动
        • LCD功能调试
        • LRADC按键配置
      • 06-ANDROID系统定制
        • 01-Android常用系统定制
      • 07-LINUX系统定制
        • 02-Linux常用系统定制
      • 08-进阶
        • K5C主板供电
        • 安卓休眠唤醒
        • 13-硬件工厂测试
    • en
      • 01-Development_board_Introduction
        • 01-KICKPI-K5_Hardware_Introduction
        • 02-KICKPI-K5C_Hardware_Introduction
      • 02-Getting_Started_Guide
        • 01-KICKPI_Cloud_Storage_Introduction
        • 02-Quick_Start_Guide
        • 03-Functional_Testing
        • 04-Expansion_Pins_Testing
      • 03-Image_Flashing_Guide
        • 01-How_to_Get_Image_File
        • 02-SD Card Burning
        • 03-USB_Cable_Flashing
      • 04-SDK_Compilation_Guide
        • 01-Compilation_Environment_Setup
        • 02-Linux_SDK_Compilation
        • 03-Android_SDK_Compilation
      • 06-Android_System_Customization
        • 01-Android_Common_System_Customization
      • 07-Linux_System_Customization
        • ADB_Tutorial
  • K2B/K2C(H618)
    • en
      • 01-Development_board_Introduction
        • 01-KICKPI-K2B_Hardware_Introduction
        • 02-KICKPI-K2B_Hardware_Introduction
      • 02-Getting_Started_Guide
        • 01-KICKPI_Cloud_Storage_Introduction
        • 02-Quick_Start_Guide
        • 03-Functional_Testing
        • 04-Expansion_Pins_Testing
      • 03-Image_Flashing_Guide
        • 01-SD_Card_Flashing
        • 02-USB_Cable_Flashing
      • 04-SDK_Compilation_Guide
        • 01-Compilation_Environment_Setup
        • 02-Linux_SDK_Compilation
        • 03-Android_SDK_Compilation
      • 05-Drivers_Development
        • RTC
      • 06-Android_System_Customization
        • 01-Android_Common_System_Customization
      • 07-Linux_System_Customization
        • 01-Linux_Common_System_Customization
      • 08-Advanced_Topics
        • Hardware_Factory_Testing
        • Keybox
    • zh
      • 01-主板介绍
        • 01-KICKPI-K2B硬件介绍
        • 02-KICKPI-K2C硬件介绍
      • 02-入门必读
        • 01-网盘目录说明
        • 02-快速使用
        • 03-功能测试
        • 04-扩展引脚
      • 03-镜像烧录
        • 01-SD卡烧录
        • 02-USB线烧录
      • 04-SDK编译
        • 01-编译环境搭建
        • 02-LINUX_SDK源码编译
        • 2. Android SDK编译
      • 05-外设驱动
        • RTC
      • 06-Android系统定制
        • Android常用系统定制
      • 07-Linux系统定制
        • 01-Linux常用系统定制
        • 02-Linux_QT开发环境搭建
      • 08-进阶
        • Keybox
        • Secure Boot
        • Windows_QT开发环境搭建
        • 扩展引脚功能定制
        • 硬件工厂测试
  • K1/K1B/K3/K8(RK356x-RK3588)
    • en
      • 01-Development_board_Introduction
        • 01-RK_Chip_Comparison_Introduction
        • 02-KICKPI-K1_Hardware_Introduction
        • 03-KICKPI-K1B_Hardware_Introduction
        • 04-KICKPI-K3_Hardware_Introduction
        • 05-KICKPI-K8_Hardware_Introduction
      • 02-Getting_Started_Guide
        • 01-Cloud_Storage_Directory_Description
        • 02-K1-Quick_Start_Guide
        • 02-K1B-Quick_Start_Guide
        • 02-K3-Quick_Start_Guide
        • 02-K8-Quick_Start_Guide
        • 03-Functional_Testing
        • 04-Expansion_Pins
      • 03-Image_Flashing_Guide
        • 01-USB_Cable_Flashing
      • 04-SDK_Compilation_Guide
        • 01-Compilation_Environment_Setup
        • 02-LINUX_SDK_Compilation
        • 03-ANDROID_SDK_Compilation
      • 05-Drivers_Development
        • GPIO
        • Kernel
        • LCD
        • PWM
        • RTC
      • 06-Android_System_Customization
        • 01-Common_Android_System_Customizations
        • 01-Common_Android_System_Customizations
      • 07-Linux_System_Customization
        • 01-Common_Linux_System_Customization
        • 02-Installing_VNC_on_Linux
        • 03-Linux_Docker
        • 04-Linux_QT_Environment_Setup
        • 05-Linux_NPU_YOLOV5S_object_detection
      • 08-Advanced_Topics
        • 01-Hardware_Factory_Test
        • 02-Hardware_Aging_Test
        • 03-Firmware_Unpacking_and_Packing
    • zh
      • 01-主板介绍
        • 01-RK芯片对比介绍
        • 02-KICKPI-K1硬件介绍
        • 03-KICKPI-K1B硬件介绍
        • 04-KICKPI-K3硬件介绍
        • 05-KICKPI-K8硬件介绍
      • 02-入门必读
        • 01-网盘目录说明
        • 02-K1-快速使用
        • 02-K1B-快速使用
        • 02-K3-快速使用
        • 02-K8-快速使用
        • 03-功能测试
        • 04-拓展引脚
      • 03-镜像烧录
        • 01-获取镜像文件
        • 02-USB线烧录
      • 04-SDK编译
        • 01-编译环境搭建
        • 02-LINUX_SDK编译
        • 03-ANDROID_SDK编译
      • 05-外设驱动
        • GPIO
        • Kernel
        • LCD
        • PWM
        • RTC
      • 06-ANDROID系统定制
        • 01-Android常用系统定制
        • 07-Android NPU YOLOV5 目标检测
      • 07-LINUX系统定制
        • 01-Linux常用系统定制
        • 02-Linux安装VNC
        • 03-Linux Docker环境搭建
        • 04-Linux QT环境搭建
        • 05-Linux NPU YOLOV5S 目标检测
      • 08-进阶
        • 01-硬件工厂测试
        • 02-硬件老化测试
        • 03-固件解包和打包
  • K7(RK3576)
    • en
      • 01-Development_board_Introduction
        • 01-KICKPI-K7_Hardware_Introduction
      • 02-Getting_Started_Guide
        • 01-KICKPI_Cloud_Storage_Introduction
        • 02-Quick_Start_Guide
        • 03-Functional_Testing
        • 04-Expansion_Pins_Testing
      • 03-Image_Flashing_Guide
        • 01-How_to_Get_Image_File
        • 02-USB_Cable_Flashing
      • 04-SDK_Compilation_Guide
        • 01-Compilation_Environment_Setup
        • 02-Linux_SDK_Compilation
        • 03-Android_SDK_Compilation
      • 05-Drivers_Development
        • ADC
        • PWM
      • 06-Android_System_Customization
        • 01-Android_Common_System_Customization
      • 07-Linux_System_Customization
        • 01-Linux_Common_System_Customization
        • 02-Linux_Docker_Environment_Setup
        • 03-Linux_NPU_YOLOv5s_Object_Detection
        • 04-Linux_DeepSeek_Large_Model
        • 05-Linux_VNC_Remote_Control
      • 08-Advanced_Topics
        • Advanced_Testing
    • zh
      • 01-主板介绍
        • 01-KICKPI-K7硬件介绍
      • 02-入门必读
        • 01-网盘目录说明
        • 02-快速使用
        • 03-功能测试
        • 04-拓展引脚
      • 03-镜像烧录
        • 01-获取镜像文件
        • 02-USB线烧录
      • 04-SDK编译
        • 01-编译环境搭建
        • 02-Linux_SDK编译
        • 03-Android_SDK编译
      • 05-外设驱动
        • ADC
        • PWM
      • 06-ANDROID系统定制
        • 01-Android常用系统定制
      • 07-LINUX系统定制
        • 01-Linux常用系统定制
        • 02-Linux Docker环境搭建
        • 03-Linux NPU YOLOV5S 目标检测
        • 04-Linux_Deepseek大模型
        • 05-Linux_VNC远程控制
      • 08-进阶
        • 进阶测试
  • K4B(T113-S3)
    • T113-S3中文文档
      • 01-KICKPI-K4B硬件介绍
      • 10-系统镜像烧录
      • 11-SDK源码编译
      • 12-硬件功能测试
      • 13-硬件工厂测试
      • LCD功能调试
      • 20-Ubuntu20.04系统定制
      • Buildroot_QT5配置
      • Buildroot系统定制
  • common
    • en
      • adb
        • ADB_Tutorial
      • allwinner_burnning
        • SD_Card_Flashing
        • USB_Cable_Flashing
      • debug
        • 01 - Log Collection
      • display
        • FPC_Interface_Introduction
      • linux
        • SSH
    • zh
      • adb
        • ADB教程
      • android
        • qt
      • debug
        • 01-日志抓取
        • 常见问题
      • display
        • FPC接口介绍
      • linux
        • SSH
        • VNC
        • qt
      • 全志烧录
        • SD卡烧录
        • USB线烧录
Powered by GitBook
On this page
  • LED配置
  • gpio-key配置
  • sys gpio控制
  1. K1/K1B/K3/K8(RK356x-RK3588)
  2. zh
  3. 05-外设驱动

GPIO

GPIO常用配置一般是配成LED输出或者key输入,下面是对设备树这部分修改的示例,供参考修改

注意:任何IO都只能配置一种功能,如果要修改已经有使用的IO需要找到对应位置注释掉原本的使用

LED配置

例如:将K1拓展引脚上的GPIO1_D4配置成LED,可以参考下面的修改

--- a/kernel/arch/arm64/boot/dts/rockchip/rk3568-kickpi-extend-40pin.dtsi
+++ b/kernel/arch/arm64/boot/dts/rockchip/rk3568-kickpi-extend-40pin.dtsi
@@ -29,10 +29,10 @@ gpio1d0 {
         gpios = <&gpio1 RK_PD0 GPIO_ACTIVE_HIGH>;
         default-state = "off";
     };
+    gpio1d4 {
+        gpios = <&gpio1 RK_PD4 GPIO_ACTIVE_HIGH>;
+        default-state = "off";
+    };
     gpio3b5 {
         gpios = <&gpio3 RK_PB5 GPIO_ACTIVE_HIGH>;
         default-state = "off";

测试

  • 查看GPIO注册列表

$ ls /sys/class/leds/

gpio1b0/ gpio1b2/ gpio1d4/ gpio3b6/ 
gpio1a4/ gpio1b1/ gpio1d0/ gpio3b5/ gpio4c4/
  • 命令行控制GPIO

$ echo 1 > /sys/class/leds/gpio1d4/brightness
$ echo 0 > /sys/class/leds/gpio1d4/brightness

gpio-key配置

例如:将K1拓展引脚上的GPIO1_D4配置成KEY_1,可以参考下面的修改

--- a/kernel/arch/arm64/boot/dts/rockchip/rk3568-kickpi-extend-40pin.dtsi
+++ b/kernel/arch/arm64/boot/dts/rockchip/rk3568-kickpi-extend-40pin.dtsi
@@ -29,10 +29,10 @@ gpio1d0 {
         gpios = <&gpio1 RK_PD0 GPIO_ACTIVE_HIGH>;
         default-state = "off";
     };
-    gpio1d4 {
-        gpios = <&gpio1 RK_PD4 GPIO_ACTIVE_HIGH>;
-        default-state = "off";
-    };
+    // gpio1d4 {
+    //     gpios = <&gpio1 RK_PD4 GPIO_ACTIVE_HIGH>;
+    //     default-state = "off";
+    // };
     gpio3b5 {
         gpios = <&gpio3 RK_PB5 GPIO_ACTIVE_HIGH>;
         default-state = "off";

--- a/kernel/arch/arm64/boot/dts/rockchip/rk3568-kickpi-k1.dtsi
+++ b/kernel/arch/arm64/boot/dts/rockchip/rk3568-kickpi-k1.dtsi
@@ -76,6 +76,21 @@ fan0: gpio-fan {
                status = "okay";
        };
        */
+
+       
+       gpio-keys {
+               compatible = "gpio-keys";
+               autorepeat;
+           status = "okay";
+       
+               key_1D4 {
+                       label = "GPIO_KEY_1D4";
+                       linux,code = <KEY_1>;
+                       gpios = <&gpio1 RK_PD4 GPIO_ACTIVE_LOW>;
+                       debounce-interval = <100>;
+               };
+       };
+
 };
 
 &leds {
(END)

其中code值可以参考驱动中的宏定义

rk356x-linux\kernel\include\uapi\linux\input-event-codes.h

测试

  • Android测试使用命令getevent:

console:/ # getevent
add device 1: /dev/input/event3
  name:     "sunxi-ir-uinput"
add device 2: /dev/input/event2
  name:     "gt9xxnew_ts"
add device 3: /dev/input/event0
  name:     "sunxi-ir"
add device 4: /dev/input/event1
  name:     "gpio-keys"
/dev/input/event2: 0001 014a 00000001
/dev/input/event2: 0003 0035 00000247
/dev/input/event2: 0003 0036 000001c3
/dev/input/event2: 0003 0030 0000001e
/dev/input/event2: 0003 0032 0000001e
  • Linux测试使用evtest:

root@ubuntu2004:~# evtest 
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0:      fe6e0030.pwm
/dev/input/event1:      rk805 pwrkey
/dev/input/event2:      rockchip-rk809 Headset
/dev/input/event3:      hdmi_cec_key
/dev/input/event4:      adc-keys
/dev/input/event5:      gpio-keys
Select the device event number [0-5]: 5
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "gpio-keys"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 2 (KEY_1)
Key repeat handling:
  Repeat type 20 (EV_REP)
    Repeat code 0 (REP_DELAY)
      Value    250
    Repeat code 1 (REP_PERIOD)
      Value     33
Properties:
Testing ... (interrupt to exit)
Event: time 1699275783.300685, type 1 (EV_KEY), code 2 (KEY_1), value 1
Event: time 1699275783.300685, -------------- SYN_REPORT ------------
Event: time 1699275783.573759, type 1 (EV_KEY), code 2 (KEY_1), value 2
Event: time 1699275783.573759, -------------- SYN_REPORT ------------
Event: time 1699275783.610429, type 1 (EV_KEY), code 2 (KEY_1), value 2
Event: time 1699275783.610429, -------------- SYN_REPORT ------------
Event: time 1699275783.647094, type 1 (EV_KEY), code 2 (KEY_1), value 2
Event: time 1699275783.647094, -------------- SYN_REPORT ------------
Event: time 1699275783.647094, type 1 (EV_KEY), code 2 (KEY_1), value 0
Event: time 1699275783.647094, -------------- SYN_REPORT ------------

sys gpio控制

当GPIO没有任何使用时,可以通过 /sys/class/gpio 进行控制

PIN 脚计算

GPIO1-D0 (gpio1-24)为例:

每组GPIO有32位:0-32
A(0-7)B(8-15)C(16-23)D(24-31)
GPIO1-D0  计算 Pin num = 32 * 1 + 24 = 56

步骤一 确保GPIO没有任何使用

先将对应GPIO引脚注释,/sys/class/gpio/export 只能导入未注册的 gpio,将设备树对应IO取消使能

步骤二 编译镜像,重新烧录

步骤三 确认gpio未被注册

cat /sys/kernel/debug/pinctrl/pinctrl-rockchip-pinctrl/pinmux-pins

未注册如下:pin 56 (gpio1-24): (MUX UNCLAIMED) (GPIO UNCLAIMED)

步骤四 对IO口进行控制

通过 /sys/class/gpio/export 注册 56并进行控制

注册

root@kickpi:~# echo  56 > /sys/class/gpio/export

查看是否生成

root@kickpi:~# ls /sys/class/gpio/
export  gpio56  gpiochip0  gpiochip352  unexport

注册后的结点内容

root@kickpi:~# ls /sys/class/gpio/gpio56
active_low  device  direction  edge  power  subsystem  uevent  value
root@kickpi:~#

通过结点下的内容控制 gpio , 常用如下

GPIO 模式

direction
	in / out
	echo in > /sys/class/gpio/gpio56/direction
	echo out > /sys/class/gpio/gpio56/direction

in:输入

out:输出

GPIO读取及高低控制

value
	0 / 1
	cat /sys/class/gpio/gpio56/value 		
	echo 1 > /sys/class/gpio/gpio56/value
	echo 0 > /sys/class/gpio/gpio56/value

0:低

1:高

Last updated 2 days ago