Android Deep Explore seventh chapter

Source: Internet
Author: User

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

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.