In the previous section, we learned that Linux drivers can control hardware and software, and can interact between hardware and software. In this chapter we learn the principle of LED driver implementation. The Linux kernel provides multiple functions that interact with I/O memory to implement control hardware.
Write led driver, led driver will build a/dev/s3c6410_leds device file, the Linux driver can control 4 LEDs, close to the battery led number 1, and so on, the other 1 means open, 0 means off. Next, create the LED-driven device files: First step: Initialize Cdev with the Cdev_init function, step two: Specify the device number, step three: Use the Cdev_add function to add the character device to the character device array in the kernel; Fourth step: Use Class_ Create macro creates a struct class; Fifth step: Create a device file using the Device_create function.
It then introduces the device files for uninstalling LED drivers, requiring one call to the Device_destroy, Class_destroy, and Unregister_chrdev_region methods.
Set the register with the initialize LED driver and control the LEDs. LED drivers can control the led:1 in the following two ways. Control the LEDs with a string. 2. Controlling LEDs with I/O commands
Using NDK to test led drivers, NDK program testing and executable program testing is almost the most straightforward way to test Linux drivers in an Android application is to use DNK.
Using Java test LED drivers, the JDK is used to provide APIs for sending I/O commands, so using Java can only test led drivers by sending a control string.
The LED driver is the first of the book to interact between hardware and software. Although not complex, its implementation includes all the necessary parts of Linux drivers.
Seventh: LED will blink for me: Control Light Emitting diode