Skip to content

Commit 7a05cb1

Browse files
authored
Merge pull request #74 from Rajssss/master
st7735s: Added brightness control though LED pin
2 parents a68ce89 + 4006495 commit 7a05cb1

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ if(CONFIG_LV_TOUCH_CONTROLLER)
7979
endif()
8080
endif()
8181

82+
# Add backlight control to compilation only if it is selected in menuconfig
83+
if(CONFIG_LV_ENABLE_BACKLIGHT_CONTROL)
84+
list(APPEND SOURCES "lvgl_tft/esp_lcd_backlight.c")
85+
endif()
86+
8287
if(CONFIG_LV_I2C)
8388
list(APPEND SOURCES "lvgl_i2c/i2c_manager.c")
8489
endif()

lvgl_helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ extern "C" {
1616

1717
#include "lvgl_spi_conf.h"
1818
#include "lvgl_tft/disp_driver.h"
19+
#include "lvgl_tft/esp_lcd_backlight.h"
1920
#include "lvgl_touch/touch_driver.h"
2021

2122
/*********************

lvgl_tft/esp_lcd_backlight.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @file esp_lcd_backlight.c
3+
*
4+
*/
5+
6+
/*********************
7+
* INCLUDES
8+
*********************/
9+
#include "esp_lcd_backlight.h"
10+
#include "driver/ledc.h"
11+
#include "esp_log.h"
12+
13+
static const char *TAG = "disp_brightness";
14+
15+
void disp_brightness_control_enable(void)
16+
{
17+
/*
18+
Configure LED (Backlight) pin as PWM for Brightness control.
19+
*/
20+
ledc_channel_config_t LCD_backlight_channel = {
21+
.gpio_num = DISP_PIN_BCKL,
22+
.speed_mode = LEDC_LOW_SPEED_MODE,
23+
.channel = LEDC_CHANNEL_0,
24+
.intr_type = LEDC_INTR_DISABLE,
25+
.timer_sel = LEDC_TIMER_0,
26+
.duty = 0,
27+
.hpoint = 0,
28+
.flags.output_invert = 0
29+
};
30+
ledc_timer_config_t LCD_backlight_timer = {
31+
.speed_mode = LEDC_LOW_SPEED_MODE,
32+
.bit_num = LEDC_TIMER_10_BIT,
33+
.timer_num = LEDC_TIMER_0,
34+
.freq_hz = 5000,
35+
.clk_cfg = LEDC_AUTO_CLK
36+
};
37+
38+
ESP_ERROR_CHECK( ledc_timer_config(&LCD_backlight_timer) );
39+
ESP_ERROR_CHECK( ledc_channel_config(&LCD_backlight_channel) );
40+
41+
}
42+
43+
void disp_set_brightness(uint16_t brightness)
44+
{
45+
/*
46+
Set brightness.
47+
0 -> Display off
48+
100 -> Full brightness
49+
NOTE: brightness value must be between 0 - 100
50+
*/
51+
if(brightness > 100)
52+
{
53+
ESP_LOGE(TAG, "Brightness value must be between 0 - 100");
54+
return;
55+
}
56+
ESP_ERROR_CHECK( ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, brightness*10) );
57+
ESP_ERROR_CHECK( ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0) );
58+
}

lvgl_tft/esp_lcd_backlight.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @file esp_lcd_backlight.h
3+
*/
4+
5+
#ifndef ESP_LCD_BACKLIGHT_H
6+
#define ESP_LCD_BACKLIGHT_H
7+
8+
/*********************
9+
* INCLUDES
10+
*********************/
11+
#include <stdbool.h>
12+
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
13+
#include "lvgl.h"
14+
#else
15+
#include "lvgl/lvgl.h"
16+
#endif
17+
18+
19+
/*********************
20+
* DEFINES
21+
*********************/
22+
#if CONFIG_LV_ENABLE_BACKLIGHT_CONTROL
23+
#define DISP_PIN_BCKL CONFIG_LV_DISP_PIN_BCKL
24+
#endif
25+
26+
/**********************
27+
* GLOBAL PROTOTYPES
28+
**********************/
29+
void disp_brightness_control_enable(void);
30+
void disp_set_brightness(uint16_t brightness);
31+
32+
33+
#ifdef __cplusplus
34+
} /* extern "C" */
35+
#endif
36+
37+
#endif /*ESP_LCD_BACKLIGHT_H*/

0 commit comments

Comments
 (0)