GPIO

Common GPIO configurations are typically set as LED outputs or key inputs. The following are examples of modifying this part of the device tree for reference.

Note: Any IO can only be configured with one function. If you need to modify an already used IO, you need to find the corresponding position and comment out the original usage.

LED Configuration

For example, to configure GPIO1_D4 on the K1 expansion pin as an LED, you can refer to the following modifications.

--- 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";

Testing

  • View the GPIO registration list

  • Control the GPIO from the command line

gpio-key Configuration

For example, to configure GPIO1_D4 on the K1 expansion pin as KEY_1, you can refer to the following modifications.

The code values can be referred to in the macro definitions in the driver.

Testing

  • Use the command getevent for Android testing:

  • Use evtest for Linux testing:

sys GPIO Control

When a GPIO is not in use, it can be controlled through /sys/class/gpio.

PIN Calculation

Take GPIO1-D0 (gpio1-24) as an example:

Step 1: Ensure the GPIO is not in use

First, comment out the corresponding GPIO pin. /sys/class/gpio/export can only import unregistered GPIOs. Disable the corresponding IO in the device tree.

Step 2: Compile the image and re-flash

Step 3: Confirm the GPIO is not registered

If not registered, it will be as follows: pin 56 (gpio1-24): (MUX UNCLAIMED) (GPIO UNCLAIMED)

Step 4: Control the IO port

Register 56 through /sys/class/gpio/export and control it.

Control the GPIO through the contents under the node. Commonly used ones are as follows:

Last updated