07 Test Command
The command operations in this chapter are all executed in the terminal of the board
1 A preliminary exploration of the /sys directory
Similar to the /proc directory, the files/folders under the /sys directory provide users with some information about devices, kernel modules, file systems, and other kernel components. For example, the subdirectory block stores all block devices; the subdirectory bus stores all bus types in the system, including i2c, usb, sdio, pci, etc.; the subdirectory class classifies devices by type, such as leds, lcd, mtd, pwm, etc.
Try to execute the following command in the terminal of the board to view the directory contents of each level of sys:
#在板卡上的终端执行以下命令查看
ls /sys
ls /sys/class
ls /sys/class/leds
ls /sys/class/leds/work

As you can see, the /sys/class/leds directory of this board contains: work, the green light on the development board that beats like a heart
Take the /sys/class/leds/work directory as an example, it contains files such as brightness, device, max_brightness, power, subsystem, trigger, uevent, etc. Brightness indicates the brightness of the LED light, and trigger indicates the triggering method of the LED light. We can modify or view these files through commands such as echo and cat to achieve the purpose of controlling the LED light. The following is an example to explain.
2. Control the heartbeat light
Before controlling the heartbeat light, you need to switch to the root user
Before controlling the heartbeat light, let's take a look at how the heartbeat light is triggered.
cat /sys/class/leds/work/trigger
As you can see, the selected state is heartbeat.

The brightness file under the LED light device indicates its brightness value. In the kernel driver provided by this board, the heartbeat light is directly controlled by IO, and its brightness range is 1 and 0, indicating on and off;
#灭了心跳灯,心脏毁灭
echo 0 > /sys/class/leds/work/brightness
#亮了心跳灯,心脏永恒
echo 1 > /sys/class/leds/work/brightness
当我们完成这操作后,可以查看心跳灯现在的触发方式,现在处于无控制状态

If you want to switch the light to heartbeat mode, after execution, the heartbeat light will re-enter the heartbeat state
#在root权限下进行下列操作
echo heartbeat > /sys/class/leds/work/trigger
3 A preliminary look at the /dev directory
In addition to the /proc and /sys directories, the /dev directory also contains a wealth of device information. This directory contains all external devices used in the Linux system, such as /dev/tty for serial port devices and /dev/ram for memory. Through these device files, we can also access the corresponding hardware devices.
Try viewing the contents of the dev directory using the following command:
ls /dev
ls /dev/input

Take the contents of the /dev/input directory in the figure above as an example. Event0 is the event file interface of the input device, through which you can get the input events reported by the device. The numbers after event are not bound to the device. You can check the file /proc/bus/input/devices to understand what they represent.
Execute the following command in the terminal of the board:
cat /proc/bus/input/devices

As shown in the figure above, you can see that the current board contains multiple input devices, which may be different on the specific board:
event0: The name is rk805 pwrkey, which corresponds to the power button on/off, input0. Some boards may not have this function.
event1: The name is goodix-ts, it corresponds to the gt9xx touch screen, input1, some boards may not have this function.
event2: The name is hdmi_cec_key, which corresponds to receiving and processing HDMI CEC key events, input2. Some boards may not have this function.
event3: The name is adc-keys, which corresponds to the Recovery key, input3. Some boards may not have this function.
event4: The name is rk-headset, which corresponds to the headphone insertion detection, input4. Some boards may not have this function.
Tips
The recovery key's flashing function only works when the kernel is started. After entering the system, the key loses its function. We can operate the key. The following takes this key as an example
4 Detection button
In the board, we can use the evtest tool to more conveniently view the input devices currently connected to the hardware and perform real-time testing on them.
apt install evtest tool
sudo apt install evtest
Note: Before using the apt install command for the first time, you need to execute the following to refresh the mirror source
sudo apt update
Use the evtest tool:
sudo evtest
After sudo evtest executes the command, it scans the event device input event files in the /dev/input directory and lists them to the terminal.

It prompts us to select the corresponding device for testing by number. Please make the selection according to the output on your board.
We select "adc-keys", press '3' and then press Enter to confirm, and you can execute "Ctrl" + "c" to exit

adc-keys corresponds to the Recovery button. When I press and release it, it looks like the following figure:
