Merge pull request #74 from Rajssss/master

st7735s: Added brightness control though LED pin
This commit is contained in:
Carlos Diaz 2021-07-29 18:27:59 -05:00 committed by GitHub
commit 7a05cb17bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 101 additions and 0 deletions

View file

@ -79,6 +79,11 @@ if(CONFIG_LV_TOUCH_CONTROLLER)
endif()
endif()
# Add backlight control to compilation only if it is selected in menuconfig
if(CONFIG_LV_ENABLE_BACKLIGHT_CONTROL)
list(APPEND SOURCES "lvgl_tft/esp_lcd_backlight.c")
endif()
if(CONFIG_LV_I2C)
list(APPEND SOURCES "lvgl_i2c/i2c_manager.c")
endif()

View file

@ -16,6 +16,7 @@ extern "C" {
#include "lvgl_spi_conf.h"
#include "lvgl_tft/disp_driver.h"
#include "lvgl_tft/esp_lcd_backlight.h"
#include "lvgl_touch/touch_driver.h"
/*********************

View file

@ -0,0 +1,58 @@
/**
* @file esp_lcd_backlight.c
*
*/
/*********************
* INCLUDES
*********************/
#include "esp_lcd_backlight.h"
#include "driver/ledc.h"
#include "esp_log.h"
static const char *TAG = "disp_brightness";
void disp_brightness_control_enable(void)
{
/*
Configure LED (Backlight) pin as PWM for Brightness control.
*/
ledc_channel_config_t LCD_backlight_channel = {
.gpio_num = DISP_PIN_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 disp_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) );
}

View file

@ -0,0 +1,37 @@
/**
* @file esp_lcd_backlight.h
*/
#ifndef ESP_LCD_BACKLIGHT_H
#define ESP_LCD_BACKLIGHT_H
/*********************
* INCLUDES
*********************/
#include <stdbool.h>
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
/*********************
* DEFINES
*********************/
#if CONFIG_LV_ENABLE_BACKLIGHT_CONTROL
#define DISP_PIN_BCKL CONFIG_LV_DISP_PIN_BCKL
#endif
/**********************
* GLOBAL PROTOTYPES
**********************/
void disp_brightness_control_enable(void);
void disp_set_brightness(uint16_t brightness);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*ESP_LCD_BACKLIGHT_H*/