Android Deep Explore (Vol. 1) Hal with Driver Development Learning notes (7)

Source: Internet
Author: User

Android Deep Explore ( vol. 1) HAL with Driver Development Learning notes (7)

The seventh chapter controls the light emitting diode

    1. LED Driver Implementation principle

2. writing LED Drivers

* Create LED -driven device files

• Initialize cdev with the cdev_init function

• Specify the device number

• Use the cdev_add function to add a character device to a character device group in the kernel

• Create stuct class with class_creat macros

• Create a device file using device_creat

    1. Uninstalling LED -driven device files

Call device_destory,class_destory,unregister_chrdev_region prototype as follows

void Device_destory (struct class *class,dev_t devt)

void Class_destroy (struct class *cls)

Void unregister_chrdev_region (dev_t from,unsigned count)

    1. Set register and initialize LED driver

* LEDThere are two ofPin:Gpboand theGPBI. One of the pins is connected to theARMProcessor'sG P I Oport, and the other pin is connected to the power supply via a current-limiting resistor:VCC3on. WhenG P I OWhen the port is low,LEDthe voltage difference is generated at both ends,LEDThe current passes and glows, whereas whenGPIOWhen the port is high,LEDno current is passed in theLEDwill go off. Switching between high and low levels is very fast, soLEDthere must be a-a delay between the lights, otherwise the human eye cannot captureLEDthe changes.

* Control of L E D requires 3 registers. The completion of these 3 registers is G P M C O N(Port configuration register ) Gpmdat(port data register) and gpmpud (Port pull-up circuit register).

* UseGpmconRegister is low1 6Bit willLEDof two ports (Gpboand theGPBL) is set to the property of theO U t p u t. Every4bit to set aLED,Total 4aL E D. O u t p u tthe value is0 0 0 1(binary), if the hexadecimal number meansGpmconRegister is low1 6the value of the bit is0x 1111.

* 4 LEDs are illuminated and extinguished using the low 4 bits of the Gpmdat register . Each bit controls an LED. The lowest bit controls the LEDs that are closest to the battery . 0 indicates bright,l is off .

* UseGpmpudDepositThe Low8bits Open separately4 xLEDThe Pull (p u l l-u p) circuit. Two people control aLEDpull-up circuit. 1 0CBinary ) for opening the upper circuit. If you use a 16-digit number,GpmpudRegister is low8bit isOxaaTo open at the same time4aLEDpull-up circuit.

    1. Control LED

* by String

* via I/o command

    1. Test LED driver

* General program for writing test i/ control commands

* use NDK to test LED driver

    1. LED -driven porting

Android Deep Explore (Vol. 1) Hal with Driver Development Learning notes (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.