Seventh Chapter Impressions

Source: Internet
Author: User

This chapter learns to control light emitting diodes by interacting directly with the hardware and controlling four small lights on the Development Board.

LED the implementation principle of the drive can start writing led driven, similar to the previous chapter step, implemented by command and read-write files. First create the led Drive device files, you can use cdev_init,register_chrdev_region,cdev_add and so on to establish the main device number of the device file. The steps are as follows:1 initializing cdev2 with cdev_init specifying the device number 3 Use the Cdev_add function to add a character device to a character device group in the kernel 4 using class_creat Macros Create a struct class5 use the device_creat function to create a device file

and then uninstall led device files for drives

{Device_destroy (leds_class,dev_number);

If (Leds_class)

Class_destroy (Leds_class);

Unregister_chrdev_region (Dev_number,device_number);

Return;}

Static void Leds_exit (void)

{

Leds_destroy_device ();

PRINTK (device_name "\text!\n");

}

Module_exit (Leds_exit);

then set the register and initialize theledDrive,ArmThe processor has multiple registers, by setting the values of different registers, setting theledpin status, open or disable pull-up circuitry, and controlledlight and extinguish. LedThere are two pins,GPB0and theGPB1Controlledneed to be completed with three registersEach register can be used4of bytesUseGpmconRegister is low -Bit willledthe two port properties are set toOutput. UseGpmdatRegister is low4bit Control4aledthe light off. UseGpmpudlow eight bits of register open four respectivelyledpull-up circuit. Thenafter that, it's more important control.led, to complete this process,ledthe driver must accept the corresponding data. If you are using string control, you need to useFile_operations.write. If you passI/OCommand Controlled, you need to useFile_operations.ioctlfunction. There are a few things to know when writing:4aledstate with a length of4of theChararray Storage. if the length of the written string is less than4, directly written, if greater than4, write only before4A. Asthe string that is written is less than4, which is the equivalent of all the following. toGpnmdatThe register is best read before writing the dataGpmdatThe current value. the final TestledThere are several ways to drive:General procedures for writing control commands:leddrivers have two ways of interacting with device files: writing string data directly andI/Ocontrol commands. UseNDKTestledDrive,UseJavaTestledDrive. LedThe driver is the first to really deal with hardwareLinuxDrive, although this drive is not complicated, it just controls the4aled, but it has includedLinuxdrive all the necessary parts.

have a positive attitude to study Android Software, we will find the joy of learning and the driving force of progress.

Seventh Chapter Impressions

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.