Skip to content

Commit a17a77b

Browse files
committed
st7735s: Added brightness control though LED pin
-> Uses LED(Backlight) Pin as PWM to control the brightness Signed-off-by: Rajssss <sssraj.sssraj@gmail.com>
1 parent cccb932 commit a17a77b

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

lvgl_tft/st7735s.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "disp_spi.h"
1111
#include "driver/i2c.h"
1212
#include "driver/gpio.h"
13+
#include "driver/ledc.h"
1314
#include "esp_log.h"
1415
#include "freertos/FreeRTOS.h"
1516
#include "freertos/task.h"
@@ -172,6 +173,51 @@ void st7735s_sleep_out()
172173
st7735s_send_cmd(0x11);
173174
}
174175

176+
void st7735s_brightness_control_enable(void)
177+
{
178+
/*
179+
Configure LED (Backlight) pin as PWM for Brightness control.
180+
*/
181+
ledc_channel_config_t LCD_backlight_channel = {
182+
.gpio_num = ST7735S_BCKL,
183+
.speed_mode = LEDC_LOW_SPEED_MODE,
184+
.channel = LEDC_CHANNEL_0,
185+
.intr_type = LEDC_INTR_DISABLE,
186+
.timer_sel = LEDC_TIMER_0,
187+
.duty = 0,
188+
.hpoint = 0,
189+
.flags.output_invert = 0
190+
};
191+
ledc_timer_config_t LCD_backlight_timer = {
192+
.speed_mode = LEDC_LOW_SPEED_MODE,
193+
.bit_num = LEDC_TIMER_10_BIT,
194+
.timer_num = LEDC_TIMER_0,
195+
.freq_hz = 5000,
196+
.clk_cfg = LEDC_AUTO_CLK
197+
};
198+
199+
ESP_ERROR_CHECK( ledc_timer_config(&LCD_backlight_timer) );
200+
ESP_ERROR_CHECK( ledc_channel_config(&LCD_backlight_channel) );
201+
202+
}
203+
204+
void st7735s_set_brightness(uint16_t brightness)
205+
{
206+
/*
207+
Set brightness.
208+
0 -> Display off
209+
100 -> Full brightness
210+
NOTE: brightness value must be between 0 - 100
211+
*/
212+
if(brightness > 100)
213+
{
214+
ESP_LOGE(TAG, "Brightness value must be between 0 - 100");
215+
return;
216+
}
217+
ESP_ERROR_CHECK( ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, brightness*10) );
218+
ESP_ERROR_CHECK( ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0) );
219+
}
220+
175221
/**********************
176222
* STATIC FUNCTIONS
177223
**********************/

lvgl_tft/st7735s.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extern "C" {
2626
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
2727

2828
#define ST7735S_DC CONFIG_LV_DISP_PIN_DC
29+
#define ST7735S_BCKL CONFIG_LV_DISP_PIN_BCKL
2930
#define ST7735S_RST CONFIG_LV_DISP_PIN_RST
3031
#define ST7735S_USE_RST CONFIG_LV_DISP_USE_RST
3132

@@ -137,6 +138,8 @@ void st7735s_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * col
137138
void st7735s_enable_backlight(bool backlight);
138139
void st7735s_sleep_in(void);
139140
void st7735s_sleep_out(void);
141+
void st7735s_brightness_control_enable(void);
142+
void st7735s_set_brightness(uint16_t brightness);
140143

141144
/**********************
142145
* MACROS

0 commit comments

Comments
 (0)