"Android" Deep Exploration of the seventh chapter experience

Source: Internet
Author: User

The seventh chapter outlines another driver: LED light control

1. Create an LED-driven device file:

1th Step: Initialize the Cdev with the Cdev_init function;

2nd step: Specify the number of the device, divided into two specified methods

3rd Step: Use the Cdev_add function to add the character device to the character device array in the kernel;

4th Step: Use Class_create macro to create struct class;

5th step: Create a device file using the Device_create function.

2. Uninstalling the LED-driven device files

Key code:

void Device_destory (Sruct class *class,dev_t devt)

void Clss_dsetroy (struct class *class)

void Unregister_chrdex_region (dev_t from,unsigned count)

1. The control led,led driver can control the LEDs in two ways, string and I/O commands.

LEDs have two pins: GPB0 and GPB1. One of the pins is connected to the ARM processor's GPI0 port, and the other pin is connected to the power supply via a current-limiting resistor. The control LEDs need to be completed by 3 registers, Gpmcon, Gpmdat, Gpmpud, respectively. Each register can use 4 bytes. Use the low 16 bits of the Gpmcon register to set the LED two port property to OUTPT. The low 4-bit control using the Gpmdat register controls the light and off of 4 LEDs.

Working with hardware, you need to write the program to I/O memory, and I/O memory is responsible for interacting with each of the host's hardware. In LED drivers, direct write string data and I/O control commands can be used to interact with device files.

"Android" Deep Exploration of the seventh chapter experience

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.