Reworked the way the pwm brightness works

This commit is contained in:
Th3maz1ng 2023-01-01 18:59:27 +01:00
parent 0138b7d152
commit f4a2c59ab2

View File

@ -78,7 +78,7 @@ const uint8_t gc9a01_init_seq[] = {
0x02, 0, 0x8E, 0xFF,
0x02, 0, 0x8F, 0xFF,
0x03, 0, 0xB6, 0x00, 0x00,
0x02, 0, 0x36, 0x48,
0x02, 0, 0x36, 0x88,
0x02, 0, 0x3A, 0x55,
0x05, 0, 0x90, 0x08, 0x08, 0x08, 0x08,
0x02, 0, 0xBD, 0x06,
@ -298,10 +298,6 @@ void lcd_register_draw_finished_cb(LCDConfig_t * const LCDConfig, DrawFinishedCb
void lcd_init(LCDConfig_t * const LCDConfig)
{
if(!LCDConfig) return;
// Backlight is controlled using PWM
wm_pwm4_config(LCDConfig->LCDPWMBacklightPin);
tls_pwm_init(4, 10000, 0, 0);
//tls_gpio_cfg(LCDConfig->LCDPWMBacklightPin, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
tls_gpio_cfg(LCDConfig->LCDChipSelectPin, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
@ -421,7 +417,23 @@ void lcd_set_backlight(LCDConfig_t * const LCDConfig, uint8_t brightness)
{
if(!LCDConfig) return;
tls_pwm_duty_set(4, brightness);
if(brightness)
{
// Backlight is controlled using PWM
wm_pwm4_config(LCDConfig->LCDPWMBacklightPin);
// Set pwm to 10kHz
tls_pwm_init(4, 10000, 0, 0);
// Set brightness
tls_pwm_duty_set(4, brightness);
}
else
{
// We stop the pwm
tls_pwm_stop(4);
tls_gpio_cfg(LCDConfig->LCDPWMBacklightPin, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_FLOATING);
tls_gpio_write(LCDConfig->LCDPWMBacklightPin, 0);
}
}
void lcd_hardware_reset(LCDConfig_t * const LCDConfig)