Android Deep Explore (Vol. 1) HAL and Driver development reading experience 7

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.