LED

Intruduction

There are tow LED lights on the ROC-3399-PC-PLUS development board, as shown in the following table:

LED    | GPIO ref | GPIO number
    ---|---    ---|---
Blue   | gpio2_D3 | 91  
Red    | GPIO0_B5 | 12

Controlling the LED in a device way can be controlled by using the LED device subsystem or directly operating GPIO. Standard Linux defines the LED subsystem specifically for LED devices. Both LEDS in the ROC-3399-PC-PLUS development board are defined as devices. Users can control the two leds through the directory /sys/class/leds/.

The default state of LED on the development board is:

  • Green: Turn on when the system is powered on.

  • Yellow:User-defined.

  • Red : User-defined.

Users can control each LED by entering commands to its brightness properties via echo:

root@roc_3399_pc:~ # echo 0 >/sys/class/leds/firefly:green:power/brightness  //Green LED OFF
root@roc_3399_pc:~ # echo 1 >/sys/class/leds/firefly:green:power/brightness  //Green LED ON

Trigger mode is used to control LED

Trigger contains multiple ways to control LED. Here are two examples :

  • Simple trigger LED

  • Complex trigger LED

For more details, please refer to leds-class.txt

First we need to know how many leds to define and what the corresponding LED properties are.

The LED node is defined in the kernel/arch/arm64/boot/dts/rockchip/rk3399-roc-pc-plus.dts as follows:

 &firefly_leds {
   power_led: power {
       label = "firefly:green:power";
       linux,default-trigger = "ir-power-click";
       default-state = "on";
       gpios = <&gpio2 27 GPIO_ACTIVE_HIGH>;
       pinctrl-names = "default";
       pinctrl-0 = <&led_power>;
   };
   user_led: user {
       label = "firefly:red:user";
       linux,default-trigger = "ir-user-click";
       default-state = "off";
       gpios = <&gpio0 13 GPIO_ACTIVE_HIGH>;
       pinctrl-names = "default";
       pinctrl-0 = <&led_user>;
   };
   user_led1: user1 {
       label = "firefly:yellow:user";
       linux,default-trigger = "ir-user-click";
       default-state = "off";
       gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
       pinctrl-names = "default";
       pinctrl-0 = <&led_user>;
   };
};

Note: the values of compatible should be consistent with the values of . compatible in drivers/leds/ leus-gpio.c.

Simple trigger LED

According to the name is to see is a simple way to trigger the control LED, as follows, on the default to turn on the green light, the green light turns on when you turn ROC-3399-PC-plus on.

(1). Define LED triggers, which are added as follows in the kernel/drivers/leds/trigger/led-firefly-demo.c :

DEFINE_LED_TRIGGER(ledtrig_default_control);

(2). Register the trigger :

led_trigger_register_simple("ir-user-click", &ledtrig_default_control);

(3). Control the LED ON.

led_trigger_event(ledtrig_default_control, LED_FULL);   //yellow led on

(4). Open LED demo

led-firefly-demo is not opened by default. If necessary, the demo driver can be opened with the following patch :

--- a/kernel/arch/arm64/boot/dts/rockchip/rk3399-firefly-demo.dtsi
+++ b/kernel/arch/arm64/boot/dts/rockchip/rk3399-firefly-demo.dtsi
@@ -52,7 +52,7 @@
            led_demo: led_demo { 
-                status = "disabled";
+                status = "okay"; 
                 compatible = "firefly,rk3399-led"; 
                 };

Complex trigger LED

The following is a more complicated example of controlling the LED with trigger mode. Timer trigger is to make the LED achieve the effect of constantly on and off.

We need to configure the timer trigger on the kernel.

In the kernel directory using make menuconfig, and the timer trigger driver is selected as follows :

Device Drivers
--->LED Support
   --->LED Trigger support 
      --->LED Timer Trigger

Save the configuration and compile the kernel, upgrade kernel.img to AIO-3399C, we can use the serial port to input the command, you can see the blue light flickering at intervals :

echo "timer" > sys/class/leds/firefly\:green\:power/trigger

Users can also use the cat command to get the available value of the trigger:

root@rk3399_firefly_box:/ # cat sys/class/leds/firefly\:blue\:power/trigger    
none rc-feedback test_ac-online test_battery-charging-or-full test_battery-charging 
test_battery-full test_battery-charging-blink-full-solid test_usb-online mmc0 mmc1 
ir-user-click [timer] heartbeat backlight default-on rfkill0 mmc2 rfkill1 rfkill2