Seventh chapter LED will blink for me: Control the Light emitting diode

Source: Internet
Author: User

Seventh chapter LED will blink for me: Control the Light emitting diode


7.1 LED Driver Implementation principle

7.2 Writing LED drivers

7.2.1 Experience the magic of LED drivers
Before you test the LED driver, you need to s3c the development Board with a USB data cable, and then open the power switch on the S3C Development Board. After successful startup, execute the build.sh script file to compile and install the LED driver. If all goes well, the build.sh script file automatically uploads the S3c6410_leds.ko file to the S3C Development Board and installs it.

7.2.2 creating LED-driven device files
Steps to create a device file:
First step: Initialize the Cdev with the Cdev_init function
Step Two: Specify the device number
Step three: Use the Cdev_add function to add a character device to the character device array in the kernel
Fourth step: Create a struct class using the Class_create macro
Fifth step: Create a device file using the Device_create function


7.2.3 uninstalling LED-driven device files
Uninstalling a Linux-powered device file requires calling the Device_destroy, Class_destroy, and Unregister_chrdev_region methods in turn.
The Leds_destroy_device function is used to unload the LED-driven device file, and the Leds_exit function is the LED-driven unload function. The Leds_exit function works by invoking the Leds_destroy_device function to unload the LED driver files.
Code: Book P118

7.2.4 setting register and initializing led driver
Need to know:
LEDs have two pins: GPB0 and GPB1.
Control LEDs require three registers to complete.
Each register can use 4 bytes, which is the space occupied by an int type of data.
Use the low 16 bits of the Gpmcon register to set the two port properties of the LEDs to output.
The low four-bit control using the Gpmdat register controls the light-off of 4 LEDs. Each bit controls an LED. The lowest bit controls the LEDs closest to the battery. 0,1, respectively, represent light and extinguish.
Use the low 8 bits of the GPMPUD register to open the 4 led pull-up circuit respectively. Each of the two controls an LED pull-up circuit.

7.2.5 Control LED
LED drivers can control LEDs in two ways:
1. Control led via string
2. Control led via I/o command

7.2.6 module parameters for LED driver
Book P123
Note: There can be no spaces between parameter names, parameter values, and equals signs when you make module parameters.

7.2.7 full code for LED driver
LED driver's complete code: Book p125~p129

7.3 Test LED Driver

7.3.1 General Program for writing test I/O control commands
LED drivers have 2 ways to interact with device files: write directly to string devices and I/O control commands. Writing data directly to a device file can be done using the command line, or through the write function. But I/O control commands can only be emitted through the IOCTL function.

7.3.2 using NDK to test LED drivers
Source code for NDK program: Book p132~p133
Java code calling the NDK function: Book p133~p135

7.3.3 using Java test LED driver
Because the JDK does not provide an API for sending I/O commands, using Java can only test the LED driver by sending a control string.
Test the LED driver Java code: Book p135~p136

7.4 LED-driven porting
The simplest porting of LED drivers is to compile them on different versions of the Linux kernel.
If the API that happens to be used by Linux drives does not change in the migrated target Linux kernel, simply recompiling the Linux-powered source code makes it easy to port the Linux driver from one Linux kernel to another Linux kernel. But most of the cases are not so simple.

    • Blog: http://www.cnblogs.com/zhanglu19940601/


Seventh chapter LED will blink for me: Control the Light emitting diode

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.