Android uses gpio as the PWM output to control the LED Backlight

Source: Internet
Author: User
Reprinted please indicate the source and author of the article Source: http://blog.csdn.net/lbmygf

1. In the board-Level Initialization File mx53_smd_c, configure the gpio1-1 to the PWM mode:

/* Gpio1 for PWM */
Mx53_pad_gpio_1108pwm2_pwmo, 2. kernel_imx/ARCH/ARM/Plat-mxc/PWM. c In the PWM driver, we can see export_symbol (pwm_request); export_symbol (pwm_enable); export_symbol (pwm_config); it exports all the functions globally. So, it can be used directly in the Backlight Drive. 3. Let's take a look at the backlight DRIVER: kernel_imx/Drivers/Video/backlight/da9052_bl.c. In this da9052_bl.c, the original backlight is adjusted. You can keep it and handle it by yourself, the key is how your hardware works. You need to use the brightness parameter to adjust the duty cycle of PWM Based on this value. Define a global pwm_device pointer: struct pwm_device * PWM in the front part of da9052_bl.c; Add the following information to the da9052_backlight_probe probe function: int ret;
PWM = pwm_request (1, "Backlight"); If (is_err (PWM )){
Dev_err (& pdev-> Dev, "unable to request PWM for Backlight \ n ");
Ret = ptr_err (PWM );
Goto err_bl;
} Else
Dev_dbg (& pdev-> Dev, "Got PWM for Backlight \ n"); the first parameter of pwm_request is the ID of the PWM device, here, you can confirm that the PWM you used is the one. I have two in this system. I use pwm2 and will traverse the PWM device when pwm_request () is called, find the one with ID 1. Mxc_pwm2_device definition in kernel/ARCH/ARM/mach-mx5/devices. C, id = 1 struct platform_device mxc_pwm2_device = {
. Name = "mxc_pwm ",
. ID = 1,
. Num_resources = array_size (pwm2_resources ),
. Resource = pwm2_resources,
}; 4. Finally, you can find a function with the brightness parameter to implement your own control. My control is as follows: Unsigned int period = 50000; // 78770;
Unsigned int max = 255; If (brightness = 0 ){
Pwm_config (PWM, 0, period );
Pwm_disable (PWM );
} Else {
Pwm_config (PWM, brightness * period/max, period );
Pwm_enable (PWM );
}

This is almost the case.

Related Article

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.