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>
This commit is contained in:
parent
cccb932d3c
commit
a17a77b923
|
@ -10,6 +10,7 @@
|
||||||
#include "disp_spi.h"
|
#include "disp_spi.h"
|
||||||
#include "driver/i2c.h"
|
#include "driver/i2c.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
|
#include "driver/ledc.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
|
@ -172,6 +173,51 @@ void st7735s_sleep_out()
|
||||||
st7735s_send_cmd(0x11);
|
st7735s_send_cmd(0x11);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void st7735s_brightness_control_enable(void)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Configure LED (Backlight) pin as PWM for Brightness control.
|
||||||
|
*/
|
||||||
|
ledc_channel_config_t LCD_backlight_channel = {
|
||||||
|
.gpio_num = ST7735S_BCKL,
|
||||||
|
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||||
|
.channel = LEDC_CHANNEL_0,
|
||||||
|
.intr_type = LEDC_INTR_DISABLE,
|
||||||
|
.timer_sel = LEDC_TIMER_0,
|
||||||
|
.duty = 0,
|
||||||
|
.hpoint = 0,
|
||||||
|
.flags.output_invert = 0
|
||||||
|
};
|
||||||
|
ledc_timer_config_t LCD_backlight_timer = {
|
||||||
|
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||||
|
.bit_num = LEDC_TIMER_10_BIT,
|
||||||
|
.timer_num = LEDC_TIMER_0,
|
||||||
|
.freq_hz = 5000,
|
||||||
|
.clk_cfg = LEDC_AUTO_CLK
|
||||||
|
};
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK( ledc_timer_config(&LCD_backlight_timer) );
|
||||||
|
ESP_ERROR_CHECK( ledc_channel_config(&LCD_backlight_channel) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void st7735s_set_brightness(uint16_t brightness)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Set brightness.
|
||||||
|
0 -> Display off
|
||||||
|
100 -> Full brightness
|
||||||
|
NOTE: brightness value must be between 0 - 100
|
||||||
|
*/
|
||||||
|
if(brightness > 100)
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "Brightness value must be between 0 - 100");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ESP_ERROR_CHECK( ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, brightness*10) );
|
||||||
|
ESP_ERROR_CHECK( ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0) );
|
||||||
|
}
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
|
@ -26,6 +26,7 @@ extern "C" {
|
||||||
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
|
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * 40)
|
||||||
|
|
||||||
#define ST7735S_DC CONFIG_LV_DISP_PIN_DC
|
#define ST7735S_DC CONFIG_LV_DISP_PIN_DC
|
||||||
|
#define ST7735S_BCKL CONFIG_LV_DISP_PIN_BCKL
|
||||||
#define ST7735S_RST CONFIG_LV_DISP_PIN_RST
|
#define ST7735S_RST CONFIG_LV_DISP_PIN_RST
|
||||||
#define ST7735S_USE_RST CONFIG_LV_DISP_USE_RST
|
#define ST7735S_USE_RST CONFIG_LV_DISP_USE_RST
|
||||||
|
|
||||||
|
@ -137,6 +138,8 @@ void st7735s_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * col
|
||||||
void st7735s_enable_backlight(bool backlight);
|
void st7735s_enable_backlight(bool backlight);
|
||||||
void st7735s_sleep_in(void);
|
void st7735s_sleep_in(void);
|
||||||
void st7735s_sleep_out(void);
|
void st7735s_sleep_out(void);
|
||||||
|
void st7735s_brightness_control_enable(void);
|
||||||
|
void st7735s_set_brightness(uint16_t brightness);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
|
|
Loading…
Reference in a new issue