Control Light Emitting Diodes
Creating LED-driven device files
1. Initialize the Cdev with the Cdev_init function
Cdev Structural Body
struct cdev{
struct Kobject kobj;
struct module *owner;
const struct File_operations *ops;
struct List_head list;
dev_t Dev;
unsigned int count;
}
2. Specify the device number
Specify directly in code: use Mkdev macros to combine primary and secondary device numbers into device numbers, use major and minor macros to get primary and secondary device numbers from the device number
Dynamic allocation: alloc_chrdev_region function
3. Use the Cdev_add function to add a character device to a character device array in the kernel
Specifies the device file pointer, device number, and number of device files. Call the Cdev_add function
4. Create a struct class using the Class_creat macro
5. Create a device file using the Device_creat function
Uninstalling LED-driven device files
Call the Device_destroy,class_destroy and Unregister_chrdev_region methods in turn
Set register and initialize led driver
Control LED
1, through the string control led 2, through the I/O command control LED
Android Deep Explore seventh chapter