First of all, the implementation of the LED driver principle, the Linux driver is not directly to the memory of the hardware to write data, but with the native I/O memory interaction, each of the hardware connected to Linux in I/O memory will have a map of the first address.
To write the driver, first create the LED-driven device file:
1. Initialize the Cdev with the Cdev_init function
Describing the device file requires a CDEV structure, cdev Most of the member variables do not require us to initialize, as long as the Cdev_init function can be called to initialize the majority of the Cdev member variables
2. Specify the device number
The file number of the Linux device is the main device number and this device number, the device number is specified in two ways: directly in the code, and dynamically assigned.
3. Use the Cdev_add function to add a character device to the character device array in the kernel, and call the Cdev_add function to specify the device file pointer, device number, and number of device files.
4. Create a struct class using the Class_create macro
5. Create a device file using the Device_create function
Uninstalling the LED driver's file requires calling the Device_destroy, Class_destroy, and Unregister_chrdev_region methods in turn.
You must know how to set the register before controlling the LED light on or off.
LED drivers can use two ways to control LED lights:
1. Control the LEDs via a string;
2. Control the LEDs with the I/O command.
Test LED Driver:
1. Test led driver with NDK
2. Test LED driver using Java
The drive to control LED lights is the first and hardware-bound driver of this book, although the program is not complex, but includes all the necessary parts of Linux drivers.
The seventh chapter is mainly about the control of light emitting diode driver, used to control the Development Board of the 4 LED lights