The LED will blink for me: control Light Emitting diodes
I. Writing LED drivers
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
Notice: LED has two pins GPB0 and GPB1;
Control LEDs need to be completed by 3 registers;
Each register can use 4 bytes;
Use the low 16 bits of the Gpmcon register to set the two port properties of the LEDs to output;
Low 4-bit control LED is illuminated using the GPMDAT register;
Use the low 8 bits of the GPMPUD register to turn on the LED light's pull-up circuit respectively.
Control LED
Controlling LEDs by string: Using the command line or through the Write function
Control led via I/O command: via the IOCTL function
Module parameters for LED driver
Note: The data of the pointer type is used when specifying the array length by the third parameter of the Module_param_array macro;
If the Linux driver contains multiple module parameters, the parameters are enclosed in single or double quotation marks;
When specifying parameter values for an array type, there can be no spaces before and after commas
Android Deep Explore (Vol. 1) HAL and Driver development reading experience 7