Test Commands
All command operations in this chapter are run in the board's terminal.
1 A first look at /sys
Like the /proc directory, the files and folders under /sys provide information about devices, kernel modules, filesystems, and other kernel components. For example, the block subdirectory holds all block devices; the bus subdirectory holds all bus types in the system (i2c, usb, sdio, pci, etc.); and the class subdirectory categorizes devices by type, such as leds, lcd, mtd, and pwm.
Try running the following commands in the board's terminal to view the directory contents at each level of sys:
#在板卡上的终端执行以下命令查看
ls /sys
ls /sys/class
ls /sys/class/leds
ls /sys/class/leds/work
As you can see, this board's /sys/class/leds directory contains: work, the green heartbeat LED on the development board.
Taking the /sys/class/leds/work directory as an example, it in turn contains files such as brightness, device, max_brightness, power, subsystem, trigger, and uevent. Among them, brightness indicates the LED brightness and trigger indicates the LED trigger mode. We can use commands such as echo and cat to modify or view these files, thereby controlling the LED. The following examples walk through this.
2 Control the heartbeat LED
Before controlling the heartbeat LED, you need to switch to the root user.
Before controlling it, we can first look at the heartbeat LED's trigger mode.
cat /sys/class/leds/work/triggerYou can see that heartbeat is the currently selected state.

The brightness file under the LED device represents its brightness value. In the kernel driver shipped with this board, the heartbeat LED is driven directly by IO; its brightness range is 1 and 0 for on and off.
#灭了心跳灯,心脏毁灭
echo 0 > /sys/class/leds/work/brightness
#亮了心跳灯,心脏永恒
echo 1 > /sys/class/leds/work/brightness
After this operation, you can check the heartbeat LED's current trigger mode — it is now in the uncontrolled (none) state.
If you want to switch the LED back to heartbeat mode, run the following; afterwards the heartbeat LED re-enters the heartbeat state.
#在root权限下进行下列操作
echo heartbeat > /sys/class/leds/work/trigger3 A first look at /dev
Besides the /proc and /sys directories, the /dev directory also contains a wealth of device information. It holds all the external devices used by the Linux system — for example /dev/tty for serial-port devices and /dev/ram for memory. Through these device files we can also access the corresponding hardware.
Try viewing the contents of the dev directory with:
ls /dev
ls /dev/input
Taking the contents of the /dev/input directory above as an example, event0 is the event-file interface for an input device, through which you can learn the input events reported by the device. The number after event is not bound to a specific device; you can check the file /proc/bus/input/devices to see what each of them represents.
Run the following command in the board's terminal:
cat /proc/bus/input/devices
As shown above, the current board contains several input devices; on a specific board the results may differ:
- event0: named
rk805 pwrkey, corresponds to the power on/off key, input0. Some boards do not have this feature. - event1: named
goodix-ts, corresponds to the gt9xx touchscreen, input1. Some boards do not have this feature. - event2: named
hdmi_cec_key, receives and handles HDMI CEC key events, input2. Some boards do not have this feature. - event3: named
adc-keys, corresponds to the Recovery key, input3. Some boards do not have this feature. - event4: named
rk-headset, corresponds to headphone-insertion detection, input4. Some boards do not have this feature.
Tips
The Recovery key's flashing function only takes effect during kernel boot; once the system has booted, the key loses that function. We can, however, still operate the key — the example below uses this key.
4 Detecting keys
On the board, we can use the evtest tool to more conveniently view the currently connected input devices and detect them in real time.
Install evtest via apt:
sudo apt install evtestNote: before using apt install for the first time, run the following to refresh the package index:
sudo apt updateUsing the evtest tool:
sudo evtestAfter running the command, it scans the event input-event files under /dev/input and lists them in the terminal.

It prompts us to select a device by number for testing; choose according to your own board's output.
We select "adc-keys", i.e. press '3' and press Enter to confirm. You can press "Ctrl"+"c" to exit.

adc-keys corresponds to the Recovery key. After we perform one press-and-release, the result is as shown below.

