新增PWM调光部分
This commit is contained in:
parent
dd4f44f9eb
commit
86ffd82ffe
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -13,5 +13,8 @@
|
|||||||
"board/esp32s3-builtin.cfg"
|
"board/esp32s3-builtin.cfg"
|
||||||
],
|
],
|
||||||
"idf.portWin": "COM6",
|
"idf.portWin": "COM6",
|
||||||
"idf.flashType": "UART"
|
"idf.flashType": "UART",
|
||||||
|
"files.associations": {
|
||||||
|
"ledc.h": "c"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,7 @@
|
|||||||
"uiExportFolderPath": "D:\\yuwell_workspace\\FluxDC\\SquareLineProj\\Export",
|
"uiExportFolderPath": "D:\\yuwell_workspace\\FluxDC\\SquareLineProj\\Export",
|
||||||
"projectExportFolderPath": "D:\\yuwell_workspace\\FluxDC\\SquareLineProj\\Export",
|
"projectExportFolderPath": "D:\\yuwell_workspace\\FluxDC\\SquareLineProj\\Export",
|
||||||
"custom_variable_prefix": "uic",
|
"custom_variable_prefix": "uic",
|
||||||
"backup_cnt": 220,
|
"backup_cnt": 221,
|
||||||
"autosave_cnt": 0,
|
"autosave_cnt": 0,
|
||||||
"group_color_cnt": 0,
|
"group_color_cnt": 0,
|
||||||
"lvgl_version": "8.3.6",
|
"lvgl_version": "8.3.6",
|
||||||
|
|||||||
@ -7306,7 +7306,7 @@
|
|||||||
"strtype": "SLIDER/Range",
|
"strtype": "SLIDER/Range",
|
||||||
"intarray": [
|
"intarray": [
|
||||||
0,
|
0,
|
||||||
100
|
8192
|
||||||
],
|
],
|
||||||
"InheritedType": 7
|
"InheritedType": 7
|
||||||
},
|
},
|
||||||
@ -16317,7 +16317,7 @@
|
|||||||
"uiExportFolderPath": "D:\\yuwell_workspace\\FluxDC\\SquareLineProj\\Export",
|
"uiExportFolderPath": "D:\\yuwell_workspace\\FluxDC\\SquareLineProj\\Export",
|
||||||
"projectExportFolderPath": "D:\\yuwell_workspace\\FluxDC\\SquareLineProj\\Export",
|
"projectExportFolderPath": "D:\\yuwell_workspace\\FluxDC\\SquareLineProj\\Export",
|
||||||
"custom_variable_prefix": "uic",
|
"custom_variable_prefix": "uic",
|
||||||
"backup_cnt": 219,
|
"backup_cnt": 220,
|
||||||
"autosave_cnt": 0,
|
"autosave_cnt": 0,
|
||||||
"group_color_cnt": 0,
|
"group_color_cnt": 0,
|
||||||
"lvgl_version": "8.3.6",
|
"lvgl_version": "8.3.6",
|
||||||
|
|||||||
Binary file not shown.
@ -4,6 +4,9 @@
|
|||||||
// Project name: ESP32S3_UI
|
// Project name: ESP32S3_UI
|
||||||
|
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
#include "driver/ledc.h"
|
||||||
|
#include "esp_err.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
void ReadSdCallFunc(lv_event_t * e)
|
void ReadSdCallFunc(lv_event_t * e)
|
||||||
{
|
{
|
||||||
@ -29,9 +32,12 @@ void F3callbackFunc(lv_event_t * e)
|
|||||||
void lightSliderCallback(lv_event_t * e)
|
void lightSliderCallback(lv_event_t * e)
|
||||||
{
|
{
|
||||||
// Your code here
|
// Your code here
|
||||||
|
uint32_t value = lv_slider_get_value(e->target);
|
||||||
lv_obj_t * slider = lv_event_get_target(e);
|
//ESP_LOGI("lightSliderCallback", "value = %u", value);
|
||||||
|
printf("value = %lu\n", value);
|
||||||
lv_slider_get_value(slider);
|
// Set duty to 50%
|
||||||
|
ESP_ERROR_CHECK(ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, value));
|
||||||
|
// Update duty to apply the new value
|
||||||
|
ESP_ERROR_CHECK(ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
#include "esp_lcd_panel_ops.h"
|
#include "esp_lcd_panel_ops.h"
|
||||||
#include "esp_spiffs.h"
|
#include "esp_spiffs.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
|
#include "driver/ledc.h"
|
||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
|
|
||||||
/*导入Modbus控制头文件*/
|
/*导入Modbus控制头文件*/
|
||||||
@ -87,6 +88,41 @@ static SemaphoreHandle_t lvgl_mux = NULL;
|
|||||||
|
|
||||||
extern void example_lvgl_demo_ui(lv_disp_t *disp);
|
extern void example_lvgl_demo_ui(lv_disp_t *disp);
|
||||||
|
|
||||||
|
/*利用 PWM进行背光亮度调节*/
|
||||||
|
#define LEDC_TIMER LEDC_TIMER_0
|
||||||
|
#define LEDC_MODE LEDC_LOW_SPEED_MODE
|
||||||
|
#define LEDC_OUTPUT_IO (EXAMPLE_PIN_NUM_BK_LIGHT) // Define the output GPIO
|
||||||
|
#define LEDC_CHANNEL LEDC_CHANNEL_0
|
||||||
|
#define LEDC_DUTY_RES LEDC_TIMER_13_BIT // Set duty resolution to 13 bits
|
||||||
|
#define LEDC_DUTY (4096) // Set duty to 50%. (2 ** 13) * 50% = 4096
|
||||||
|
#define LEDC_FREQUENCY (4000) // Frequency in Hertz. Set frequency at 4 kHz
|
||||||
|
|
||||||
|
static void example_ledc_init(void)
|
||||||
|
{
|
||||||
|
// Prepare and then apply the LEDC PWM timer configuration
|
||||||
|
ledc_timer_config_t ledc_timer = {
|
||||||
|
.speed_mode = LEDC_MODE,
|
||||||
|
.duty_resolution = LEDC_DUTY_RES,
|
||||||
|
.timer_num = LEDC_TIMER,
|
||||||
|
.freq_hz = LEDC_FREQUENCY, // Set output frequency at 4 kHz
|
||||||
|
.clk_cfg = LEDC_AUTO_CLK
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
|
||||||
|
|
||||||
|
// Prepare and then apply the LEDC PWM channel configuration
|
||||||
|
ledc_channel_config_t ledc_channel = {
|
||||||
|
.speed_mode = LEDC_MODE,
|
||||||
|
.channel = LEDC_CHANNEL,
|
||||||
|
.timer_sel = LEDC_TIMER,
|
||||||
|
.intr_type = LEDC_INTR_DISABLE,
|
||||||
|
.gpio_num = LEDC_OUTPUT_IO,
|
||||||
|
.duty = 0, // Set duty to 0%
|
||||||
|
.hpoint = 0
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool example_notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx)
|
static bool example_notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx)
|
||||||
{
|
{
|
||||||
lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx;
|
lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx;
|
||||||
@ -410,6 +446,9 @@ void app_main(void)
|
|||||||
ESP_LOGI(TAG, "Display LVGL animation");
|
ESP_LOGI(TAG, "Display LVGL animation");
|
||||||
|
|
||||||
/*测试git*/
|
/*测试git*/
|
||||||
|
/*配置LEDC进行背光亮度调节 */
|
||||||
|
example_ledc_init();
|
||||||
|
|
||||||
|
|
||||||
// Lock the mutex due to the LVGL APIs are not thread-safe
|
// Lock the mutex due to the LVGL APIs are not thread-safe
|
||||||
if (example_lvgl_lock(-1)) {
|
if (example_lvgl_lock(-1)) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user