The implementation principle of LED driver:
The Linux kernel provides several functions that interact with I/O memory, and the kernel management module for Linux is responsible for the data in the I/O memory and hardware.
Every hardware that connects to Linux has a mapped address in memory, and the LEDs on the board have their first address.
Steps to create a device file:
The first step uses the Cdev_init function to initialize the Cdev
The second step specifies the device number
The third step uses the Cdev_add function to add the character device to the character device array in the kernel
Fourth step create a struct class using the Class_create macro
The fifth step is to create a device file using the Device_create function.
LED drivers can control LEDs in two ways:
(1) control led via string
(2) led control via LED
Here are a few things to keep in mind when writing code:
(1) The status of 4 LEDs (light and off) is stored with a char array of length 4,
(2) If the written string length is less than equal to 4, write these strings directly if the string length is greater than four write the first 4 characters.
(3) Since the prior mem array has been zeroed, if the length of the written string is less than 4, then the equivalent of the subsequent character is 0.
(4) It is better to read the current value of the Gpmdat register before Gpmdat register to write the data, and to retain the value unrelated to this operation by bitwise AND, bit or etc.
Seventh Reading notes