Snapshot of JC3636W518EN kit before demo folder cleanup

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patriandClaude Opus 5.5 committed 2026-10-22 23:56:18 +02:00
commit 9ee85bfd86
1862 files changed
+668877

No files matched your search

@@ -0,0 +1,117 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "ESP_PanelLog.h"
#include "ESP_PanelBacklight.h"
static const char *TAG = "ESP_PanelBacklight";
ESP_PanelBacklight::ESP_PanelBacklight(int io_num, bool light_up_level, bool use_pwm):
_is_initialized(false),
_use_pwm(use_pwm),
_light_up_level(light_up_level),
_io_num(io_num),
_timer_config(ESP_PANEL_BACKLIGHT_LEDC_TIMER_CONFIG_DEFAULT()),
_channel_config(ESP_PANEL_BACKLIGHT_LEDC_CHANNEL_CONFIG_DEFAULT(io_num, light_up_level))
{
}
ESP_PanelBacklight::ESP_PanelBacklight(const ledc_timer_config_t &timer_config, const ledc_channel_config_t &channel_config):
_is_initialized(false),
_use_pwm(true),
_timer_config(timer_config),
_channel_config(channel_config)
{
}
ESP_PanelBacklight::~ESP_PanelBacklight()
{
ESP_PANEL_ENABLE_TAG_DEBUG_LOG();
if (!_is_initialized && !del()) {
ESP_LOGE(TAG, "Delete device failed");
}
ESP_LOGD(TAG, "Destroyed");
}
bool ESP_PanelBacklight::begin(void)
{
ESP_PANEL_CHECK_FALSE_RET(_io_num >= 0, false, "Invalid IO number");
ESP_PANEL_ENABLE_TAG_DEBUG_LOG();
ESP_LOGD(TAG, "begin start");
if (_use_pwm) {
ESP_LOGD(TAG, "Use PWM(LEDC) to control");
ESP_PANEL_CHECK_ERR_RET(ledc_timer_config(&_timer_config), false, "LEDC timer config failed");
ESP_PANEL_CHECK_ERR_RET(ledc_channel_config(&_channel_config), false, "LEDC channel config failed");
} else {
ESP_LOGD(TAG, "Use GPIO to control");
gpio_config_t io_config = ESP_PANEL_BACKLIGHT_GPIO_CONFIG_DEFAULT(_io_num);
ESP_PANEL_CHECK_ERR_RET(gpio_config(&io_config), false, "GPIO config failed");
ESP_PANEL_CHECK_ERR_RET(gpio_set_level((gpio_num_t)_io_num, _light_up_level), false, "GPIO set level failed");
}
_is_initialized = true;
ESP_LOGD(TAG, "begin end");
return true;
}
bool ESP_PanelBacklight::setBrightness(uint8_t percent)
{
ESP_PANEL_CHECK_FALSE_RET(_is_initialized, false, "Device has not been initialized");
ESP_LOGD(TAG, "Set brightness to %d%%", percent);
percent = percent > 100 ? 100 : percent;
if (_use_pwm) {
uint32_t duty_cycle = (BIT(_timer_config.duty_resolution) * percent) / 100;
ledc_channel_t channel = _channel_config.channel;
ledc_mode_t mode = _channel_config.speed_mode;
ESP_PANEL_CHECK_ERR_RET(ledc_set_duty(mode, channel, duty_cycle), false, "LEDC set duty failed");
ESP_PANEL_CHECK_ERR_RET(ledc_update_duty(mode, channel), false, "LEDC update duty failed");
} else {
bool level = (percent > 0) ? _light_up_level : !_light_up_level;
ESP_PANEL_CHECK_ERR_RET(gpio_set_level((gpio_num_t)_io_num, level), false, "GPIO set level failed");
}
return true;
}
bool ESP_PanelBacklight::on(void)
{
return setBrightness(100);
}
bool ESP_PanelBacklight::off(void)
{
return setBrightness(0);
}
bool ESP_PanelBacklight::del(void)
{
ESP_PANEL_CHECK_FALSE_RET(_is_initialized, false, "Device has not been initialized");
if (_use_pwm) {
ledc_mode_t mode = _channel_config.speed_mode;
ledc_channel_t channel = _channel_config.channel;
ESP_PANEL_CHECK_ERR_RET(ledc_stop(mode, channel, _light_up_level), false, "LEDC stop failed");
} else {
gpio_reset_pin((gpio_num_t)_io_num);
}
_is_initialized = false;
ESP_LOGD(TAG, "Delete device");
return true;
}
@@ -0,0 +1,139 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include "driver/ledc.h"
/**
* @brief Backlight LEDC default configuration macros
*
*/
#define ESP_PANEL_BACKLIGHT_LEDC_TIMER_CONFIG_DEFAULT() \
{ \
.speed_mode = LEDC_LOW_SPEED_MODE, \
.duty_resolution = LEDC_TIMER_10_BIT, \
.timer_num = LEDC_TIMER_0, \
.freq_hz = 5000, \
.clk_cfg = LEDC_AUTO_CLK, \
}
#define ESP_PANEL_BACKLIGHT_LEDC_CHANNEL_CONFIG_DEFAULT(io_num, on_level) \
{ \
.gpio_num = io_num, \
.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 = !on_level, \
}, \
}
/**
* @brief Backlight GPIO default configuration macro
*
*/
#define ESP_PANEL_BACKLIGHT_GPIO_CONFIG_DEFAULT(io_num) \
{ \
.pin_bit_mask = BIT64(io_num), \
.mode = GPIO_MODE_OUTPUT, \
.pull_up_en = GPIO_PULLUP_DISABLE, \
.pull_down_en = GPIO_PULLDOWN_DISABLE, \
.intr_type = GPIO_INTR_DISABLE, \
}
/**
* @brief The backlight device class
*
*/
class ESP_PanelBacklight {
public:
/**
* @brief Construct a new backlight device in a simple way, the `begin()` function should be called after this
*
* @note This function uses some default values to config the backlight device, please use `config*()` functions to
* change them
*
* @param io_num GPIO number
* @param light_up_level Level when light up
* @param use_pwm Use PWM(LEDC) if set to true
*/
ESP_PanelBacklight(int io_num, bool light_up_level, bool use_pwm);
/**
* @brief Construct a new backlight device with using PWM(LEDC) in a complex way, the `begin()` function should be
* called after this
*
* @param timer_config LEDC timer configuration
* @param channel_config LEDC channel configuration
*/
ESP_PanelBacklight(const ledc_timer_config_t &timer_config, const ledc_channel_config_t &channel_config);
/**
* @brief Destroy the backlight device
*
*/
~ESP_PanelBacklight();
/**
* @brief Startup the backlight device
*
* @return true if success, otherwise false
*/
bool begin(void);
/**
* @brief Set the brightness of the backlight by percent
*
* @note This function should be called after `begin()`
* @note When not using PWM, calling this function only controls the backlight switch and cannot adjust
* the brightness
*
* @param percent The brightness percent, 0-100
*
* @return true if success, otherwise false
*/
bool setBrightness(uint8_t percent);
/**
* @brief Turn on the backlight
*
* @note This function should be called after `begin()`
* @note This function is same as `setBrightness(100)`
*
* @return true if success, otherwise false
*/
bool on(void);
/**
* @brief Turn off the backlight
*
* @note This function should be called after `begin()`
* @note This function is same as `setBrightness(0)`
*
* @return true if success, otherwise false
*/
bool off(void);
/**
* @brief Delete the backlight device, release the resources
*
* @note This function should be called after `begin()`
*
* @return true if success, otherwise false
*/
bool del(void);
private:
bool _is_initialized;
bool _use_pwm;
bool _light_up_level;
uint8_t _io_num;
ledc_timer_config_t _timer_config;
ledc_channel_config_t _channel_config;
};