[stm32 pandora] support backlight with brightness adjustable (#5691)

This commit is contained in:
Man, Jianting (Meco) 2022-03-20 03:47:57 -04:00 committed by GitHub
parent 9ee5940f25
commit bb4fc9cb3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 9 deletions

View File

@ -57,6 +57,9 @@ menu "Onboard Peripheral Drivers"
select BSP_USING_SPI
select BSP_USING_SPI3
select BSP_SPI3_TX_USING_DMA
select BSP_USING_PWM
select BSP_USING_PWM4
select BSP_USING_PWM4_CH2
default n
config BSP_USING_LCD_SAMPLE

View File

@ -24,7 +24,6 @@
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
#define LCD_PWR_PIN GET_PIN(B, 7)
#define LCD_DC_PIN GET_PIN(B, 4)
#define LCD_RES_PIN GET_PIN(B, 6)
@ -120,9 +119,6 @@ static void lcd_gpio_init(void)
rt_pin_mode(LCD_DC_PIN, PIN_MODE_OUTPUT);
rt_pin_mode(LCD_RES_PIN, PIN_MODE_OUTPUT);
rt_pin_mode(LCD_PWR_PIN, PIN_MODE_OUTPUT);
rt_pin_write(LCD_PWR_PIN, PIN_LOW);
rt_pin_write(LCD_RES_PIN, PIN_LOW);
//wait at least 100ms for reset
@ -133,8 +129,10 @@ static void lcd_gpio_init(void)
static int rt_hw_lcd_init(void)
{
__HAL_RCC_GPIOD_CLK_ENABLE();
rt_hw_spi_device_attach("spi3", "spi30", GPIOD, GPIO_PIN_7);
lcd_gpio_init();
/* Memory Data Access Control */
lcd_write_cmd(0x36);
lcd_write_data(0x00);
@ -213,7 +211,7 @@ static int rt_hw_lcd_init(void)
rt_thread_mdelay(100);
/* display on */
rt_pin_write(LCD_PWR_PIN, PIN_HIGH);
lcd_display_on();
lcd_write_cmd(0x29);
return RT_EOK;
@ -236,27 +234,39 @@ void lcd_set_color(rt_uint16_t back, rt_uint16_t fore)
}
#endif /* BSP_USING_LVGL */
void lcd_display_brightness(rt_uint8_t percent)
{
struct rt_device_pwm *pwm_dev;
pwm_dev = (struct rt_device_pwm*)rt_device_find("pwm4");
if(pwm_dev != RT_NULL)
{
rt_pwm_set(pwm_dev, 2, 1000000, percent*10000); /* PWM4 CH2 with 1000Hz */
rt_pwm_enable(pwm_dev, 2);
}
}
void lcd_display_on(void)
{
rt_pin_write(LCD_PWR_PIN, PIN_HIGH);
lcd_display_brightness(100);
}
void lcd_display_off(void)
{
rt_pin_write(LCD_PWR_PIN, PIN_LOW);
lcd_display_brightness(0);
}
/* lcd enter the minimum power consumption mode and backlight off. */
void lcd_enter_sleep(void)
{
rt_pin_write(LCD_PWR_PIN, PIN_LOW);
lcd_display_off();
rt_thread_mdelay(5);
lcd_write_cmd(0x10);
}
/* lcd turn off sleep mode and backlight on. */
void lcd_exit_sleep(void)
{
rt_pin_write(LCD_PWR_PIN, PIN_HIGH);
lcd_display_on();
rt_thread_mdelay(5);
lcd_write_cmd(0x11);
rt_thread_mdelay(120);

View File

@ -55,6 +55,7 @@ void lcd_enter_sleep(void);
void lcd_exit_sleep(void);
void lcd_display_on(void);
void lcd_display_off(void);
void lcd_display_brightness(rt_uint8_t percent);
void lcd_address_set(rt_uint16_t x1, rt_uint16_t y1, rt_uint16_t x2, rt_uint16_t y2);
void lcd_fill_array(rt_uint16_t x_start, rt_uint16_t y_start, rt_uint16_t x_end, rt_uint16_t y_end, void *pcolor);