Browse Source

lcd led key lvgl init finished.

master
pomin-163 5 months ago
parent
commit
fa57fabd71
  1. 6
      .gitmodules
  2. 2
      CMakeLists.txt
  3. 6
      Proj.code-workspace
  4. 1
      components/esp-dl
  5. 1
      components/esp-sr
  6. 116
      components/myui/guider/generated/events_init.c
  7. 1
      components/myui/guider/generated/events_init.h
  8. 3
      components/myui/guider/generated/gui_guider.h
  9. 179
      components/myui/guider/generated/gui_guider.py
  10. 79
      components/myui/guider/generated/setup_scr_screen.c
  11. 2
      main/CMakeLists.txt
  12. 200
      main/Kconfig.projbuild
  13. 25
      main/app.h
  14. 146
      main/btns.c
  15. 38
      main/init/app_init.h
  16. 158
      main/init/btns_init.c
  17. 161
      main/init/led_init.c
  18. 76
      main/init/lvgl_init.c
  19. 183
      main/main.c
  20. 41
      main/main.cpp
  21. 1678
      main/sdkconfig
  22. 5
      partitions.csv
  23. 155
      sdkconfig
  24. 233
      sdkconfig.old

6
.gitmodules

@ -1,3 +1,9 @@
[submodule "components/esp32-camera"]
path = components/esp32-camera
url = https://github.com/espressif/esp32-camera.git
[submodule "components/esp-dl"]
path = components/esp-dl
url = https://github.com/espressif/esp-dl.git
[submodule "components/esp-sr"]
path = components/esp-sr
url = https://github.com/espressif/esp-sr.git

2
CMakeLists.txt

@ -6,6 +6,8 @@ set(EXTRA_COMPONENT_DIRS "components/board"
"components/esp32-camera"
"components/lcd"
"components/led_strip"
"components/modules"
"components/myui"
)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

6
Proj.code-workspace

@ -76,6 +76,7 @@
"C_Cpp.default.forcedInclude": [
],
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json",
"files.associations": {
"*.cjson": "jsonc",
@ -91,7 +92,10 @@
"lv_demo_keypad_encoder.h": "c",
"esp_freertos_hooks.h": "c",
"gui_guider.h": "c",
"app.h": "c"
"app.h": "c",
"app_init.h": "c",
"freertos.h": "c",
"led_strip.h": "c"
},
},
}

1
components/esp-dl

@ -0,0 +1 @@
Subproject commit d9493506707c0b68fa10447ec24380af6f19bb32

1
components/esp-sr

@ -0,0 +1 @@
Subproject commit 4a87107f006b4c8770441b2c0b3dc1d6a01cb433

116
components/myui/guider/generated/events_init.c

@ -11,119 +11,3 @@
void events_init(lv_ui *ui)
{
}
static void screen_btnm_1_event_handler(lv_event_t *e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_anim_t screen_btn_1_anim_x;
lv_anim_t screen_btn_1_anim_y;
lv_anim_t screen_btnm_1_anim_x;
lv_anim_t screen_btnm_1_anim_y;
switch (code)
{
case LV_EVENT_CLICKED:
{
//Write animation: screen_btn_1move in x direction
lv_anim_init(&screen_btn_1_anim_x);
lv_anim_set_var(&screen_btn_1_anim_x, guider_ui.screen_btn_1);
lv_anim_set_time(&screen_btn_1_anim_x, 200);
lv_anim_set_exec_cb(&screen_btn_1_anim_x, (lv_anim_exec_xcb_t)lv_obj_set_x);
lv_anim_set_values(&screen_btn_1_anim_x, lv_obj_get_x(guider_ui.screen_btn_1), 315);
lv_anim_set_path_cb(&screen_btn_1_anim_x, &lv_anim_path_bounce);
lv_anim_start(&screen_btn_1_anim_x);
//Write animation: screen_btn_1move in y direction
lv_anim_init(&screen_btn_1_anim_y);
lv_anim_set_var(&screen_btn_1_anim_y, guider_ui.screen_btn_1);
lv_anim_set_time(&screen_btn_1_anim_y, 200);
lv_anim_set_exec_cb(&screen_btn_1_anim_y, (lv_anim_exec_xcb_t)lv_obj_set_y);
lv_anim_set_values(&screen_btn_1_anim_y, lv_obj_get_y(guider_ui.screen_btn_1), 0);
lv_anim_set_path_cb(&screen_btn_1_anim_y, &lv_anim_path_bounce);
lv_anim_start(&screen_btn_1_anim_y);
//Write animation: screen_btnm_1move in x direction
lv_anim_init(&screen_btnm_1_anim_x);
lv_anim_set_var(&screen_btnm_1_anim_x, guider_ui.screen_btnm_1);
lv_anim_set_time(&screen_btnm_1_anim_x, 200);
lv_anim_set_exec_cb(&screen_btnm_1_anim_x, (lv_anim_exec_xcb_t)lv_obj_set_x);
lv_anim_set_values(&screen_btnm_1_anim_x, lv_obj_get_x(guider_ui.screen_btnm_1), 320);
lv_anim_set_path_cb(&screen_btnm_1_anim_x, &lv_anim_path_linear);
lv_anim_start(&screen_btnm_1_anim_x);
//Write animation: screen_btnm_1move in y direction
lv_anim_init(&screen_btnm_1_anim_y);
lv_anim_set_var(&screen_btnm_1_anim_y, guider_ui.screen_btnm_1);
lv_anim_set_time(&screen_btnm_1_anim_y, 200);
lv_anim_set_exec_cb(&screen_btnm_1_anim_y, (lv_anim_exec_xcb_t)lv_obj_set_y);
lv_anim_set_values(&screen_btnm_1_anim_y, lv_obj_get_y(guider_ui.screen_btnm_1), 0);
lv_anim_set_path_cb(&screen_btnm_1_anim_y, &lv_anim_path_linear);
lv_anim_start(&screen_btnm_1_anim_y);
lv_obj_set_width(guider_ui.screen_tabview_1, 315);
}
break;
default:
break;
}
}
static void screen_btn_1_event_handler(lv_event_t *e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_anim_t screen_btnm_1_anim_x;
lv_anim_t screen_btnm_1_anim_y;
lv_anim_t screen_btn_1_anim_x;
lv_anim_t screen_btn_1_anim_y;
switch (code)
{
case LV_EVENT_CLICKED:
{
//Write animation: screen_btnm_1move in x direction
lv_anim_init(&screen_btnm_1_anim_x);
lv_anim_set_var(&screen_btnm_1_anim_x, guider_ui.screen_btnm_1);
lv_anim_set_time(&screen_btnm_1_anim_x, 200);
lv_anim_set_exec_cb(&screen_btnm_1_anim_x, (lv_anim_exec_xcb_t)lv_obj_set_x);
lv_anim_set_values(&screen_btnm_1_anim_x, lv_obj_get_x(guider_ui.screen_btnm_1), 288);
lv_anim_set_path_cb(&screen_btnm_1_anim_x, &lv_anim_path_linear);
lv_anim_start(&screen_btnm_1_anim_x);
//Write animation: screen_btnm_1move in y direction
lv_anim_init(&screen_btnm_1_anim_y);
lv_anim_set_var(&screen_btnm_1_anim_y, guider_ui.screen_btnm_1);
lv_anim_set_time(&screen_btnm_1_anim_y, 200);
lv_anim_set_exec_cb(&screen_btnm_1_anim_y, (lv_anim_exec_xcb_t)lv_obj_set_y);
lv_anim_set_values(&screen_btnm_1_anim_y, lv_obj_get_y(guider_ui.screen_btnm_1), 0);
lv_anim_set_path_cb(&screen_btnm_1_anim_y, &lv_anim_path_linear);
lv_anim_start(&screen_btnm_1_anim_y);
//Write animation: screen_btn_1move in x direction
lv_anim_init(&screen_btn_1_anim_x);
lv_anim_set_var(&screen_btn_1_anim_x, guider_ui.screen_btn_1);
lv_anim_set_time(&screen_btn_1_anim_x, 200);
lv_anim_set_exec_cb(&screen_btn_1_anim_x, (lv_anim_exec_xcb_t)lv_obj_set_x);
lv_anim_set_values(&screen_btn_1_anim_x, lv_obj_get_x(guider_ui.screen_btn_1), 320);
lv_anim_set_path_cb(&screen_btn_1_anim_x, &lv_anim_path_linear);
lv_anim_start(&screen_btn_1_anim_x);
//Write animation: screen_btn_1move in y direction
lv_anim_init(&screen_btn_1_anim_y);
lv_anim_set_var(&screen_btn_1_anim_y, guider_ui.screen_btn_1);
lv_anim_set_time(&screen_btn_1_anim_y, 200);
lv_anim_set_exec_cb(&screen_btn_1_anim_y, (lv_anim_exec_xcb_t)lv_obj_set_y);
lv_anim_set_values(&screen_btn_1_anim_y, lv_obj_get_y(guider_ui.screen_btn_1), 0);
lv_anim_set_path_cb(&screen_btn_1_anim_y, &lv_anim_path_linear);
lv_anim_start(&screen_btn_1_anim_y);
lv_obj_set_width(guider_ui.screen_tabview_1, 288);
}
break;
default:
break;
}
}
void events_init_screen(lv_ui *ui)
{
lv_obj_add_event_cb(ui->screen_btnm_1, screen_btnm_1_event_handler, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui->screen_btn_1, screen_btn_1_event_handler, LV_EVENT_ALL, NULL);
}

1
components/myui/guider/generated/events_init.h

@ -14,7 +14,6 @@ extern "C" {
#include "gui_guider.h"
void events_init(lv_ui *ui);
void events_init_screen(lv_ui *ui);
#ifdef __cplusplus
}

3
components/myui/guider/generated/gui_guider.h

@ -25,8 +25,7 @@ typedef struct
lv_obj_t *screen_tabview_1_Sensor;
lv_obj_t *screen_tabview_1_ToDo;
lv_obj_t *screen_btnm_1;
lv_obj_t *screen_btn_1;
lv_obj_t *screen_btn_1_label;
lv_obj_t *screen_label_3;
}lv_ui;
void setup_ui(lv_ui *ui);

179
components/myui/guider/generated/gui_guider.py

@ -334,7 +334,7 @@ screen_label_1.add_style(style_screen_label_1_main_main_default, lv.PART.MAIN|lv
screen_tabview_1_Sensor = screen_tabview_1.add_tab("Sensor")
screen_tabview_1_ToDo = screen_tabview_1.add_tab("ToDo")
screen_tabview_1.set_pos(0,0)
screen_tabview_1.set_size(314,240)
screen_tabview_1.set_size(290,240)
# create style style_screen_tabview_1_main_main_default
style_screen_tabview_1_main_main_default = lv.style_t()
style_screen_tabview_1_main_main_default.init()
@ -360,27 +360,8 @@ style_screen_tabview_1_main_main_default.set_text_line_space(16)
screen_tabview_1.add_style(style_screen_tabview_1_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)
screen_btnm_1 = lv.btnmatrix(screen)
screen_btnm_1.set_pos(288,0)
screen_btnm_1.set_size(32,240)
screen_btnm_1.update_layout()
screen_btnm_1_anim_move_x = lv.anim_t()
screen_btnm_1_anim_move_x.init()
screen_btnm_1_anim_move_x.set_var(screen_btnm_1)
screen_btnm_1_anim_move_x.set_values(screen_btnm_1.get_x(), 320)
screen_btnm_1_anim_move_x.set_time(500)
screen_btnm_1_anim_move_x.set_path_cb(lv.anim_t.path_bounce)
screen_btnm_1_anim_move_x.set_custom_exec_cb(lambda a,val: anim_x_cb(screen_btnm_1,val))
lv.anim_t.start(screen_btnm_1_anim_move_x)
screen_btnm_1_anim_move_y = lv.anim_t()
screen_btnm_1_anim_move_y.init()
screen_btnm_1_anim_move_y.set_var(screen_btnm_1)
screen_btnm_1_anim_move_y.set_values(screen_btnm_1.get_x(), 0)
screen_btnm_1_anim_move_y.set_time(500)
screen_btnm_1_anim_move_y.set_path_cb(lv.anim_t.path_bounce)
screen_btnm_1_anim_move_y.set_custom_exec_cb(lambda a,val: anim_y_cb(screen_btnm_1,val))
lv.anim_t.start(screen_btnm_1_anim_move_y)
screen_btnm_1.set_pos(292,0)
screen_btnm_1.set_size(28,240)
btnm_map = [
"1",
"\n",
@ -401,7 +382,7 @@ style_screen_btnm_1_main_main_default = lv.style_t()
style_screen_btnm_1_main_main_default.init()
style_screen_btnm_1_main_main_default.set_radius(4)
style_screen_btnm_1_main_main_default.set_bg_color(lv.color_make(0xff,0xff,0xff))
style_screen_btnm_1_main_main_default.set_bg_grad_color(lv.color_make(0xff,0xff,0xff))
style_screen_btnm_1_main_main_default.set_bg_grad_color(lv.color_make(0xf0,0xf0,0xf0))
style_screen_btnm_1_main_main_default.set_bg_grad_dir(lv.GRAD_DIR.HOR)
style_screen_btnm_1_main_main_default.set_bg_opa(255)
style_screen_btnm_1_main_main_default.set_border_color(lv.color_make(0xff,0xff,0xff))
@ -420,7 +401,7 @@ screen_btnm_1.add_style(style_screen_btnm_1_main_main_default, lv.PART.MAIN|lv.S
style_screen_btnm_1_main_items_default = lv.style_t()
style_screen_btnm_1_main_items_default.init()
style_screen_btnm_1_main_items_default.set_radius(4)
style_screen_btnm_1_main_items_default.set_bg_color(lv.color_make(0xe6,0xe6,0xe6))
style_screen_btnm_1_main_items_default.set_bg_color(lv.color_make(0xff,0xff,0xff))
style_screen_btnm_1_main_items_default.set_bg_grad_color(lv.color_make(0xe6,0xe6,0xe6))
style_screen_btnm_1_main_items_default.set_bg_grad_dir(lv.GRAD_DIR.VER)
style_screen_btnm_1_main_items_default.set_bg_opa(255)
@ -438,129 +419,37 @@ except AttributeError:
# add style for screen_btnm_1
screen_btnm_1.add_style(style_screen_btnm_1_main_items_default, lv.PART.ITEMS|lv.STATE.DEFAULT)
screen_btn_1 = lv.btn(screen)
screen_btn_1.set_pos(315,0)
screen_btn_1.set_size(5,240)
screen_btn_1.add_flag(lv.obj.FLAG.CHECKABLE)
# create style style_screen_btn_1_main_main_default
style_screen_btn_1_main_main_default = lv.style_t()
style_screen_btn_1_main_main_default.init()
style_screen_btn_1_main_main_default.set_radius(5)
style_screen_btn_1_main_main_default.set_bg_color(lv.color_make(0x21,0x95,0xf6))
style_screen_btn_1_main_main_default.set_bg_grad_color(lv.color_make(0x21,0x95,0xf6))
style_screen_btn_1_main_main_default.set_bg_grad_dir(lv.GRAD_DIR.VER)
style_screen_btn_1_main_main_default.set_bg_opa(255)
style_screen_btn_1_main_main_default.set_shadow_color(lv.color_make(0x21,0x95,0xf6))
style_screen_btn_1_main_main_default.set_shadow_opa(255)
style_screen_btn_1_main_main_default.set_border_color(lv.color_make(0x21,0x95,0xf6))
style_screen_btn_1_main_main_default.set_border_width(0)
style_screen_btn_1_main_main_default.set_border_opa(255)
# add style for screen_btn_1
screen_btn_1.add_style(style_screen_btn_1_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)
def screen_btnm_1_clicked_1_event_cb(e,screen_btn_1):
src = e.get_target()
code = e.get_code()
screen_btn_1_event_move_x = lv.anim_t()
screen_btn_1_event_move_x.init()
screen_btn_1_event_move_x.set_var(screen_btn_1)
screen_btn_1_event_move_x.set_values(screen_btn_1.get_x(), 315)
screen_btn_1_event_move_x.set_time(200)
screen_btn_1_event_move_x.set_path_cb(lv.anim_t.path_bounce)
screen_btn_1_event_move_x.set_custom_exec_cb(lambda a,val: anim_x_cb(screen_btn_1,val))
lv.anim_t.start(screen_btn_1_event_move_x)
screen_btn_1_event_move_y = lv.anim_t()
screen_btn_1_event_move_y.init()
screen_btn_1_event_move_y.set_var(screen_btn_1)
screen_btn_1_event_move_y.set_values(screen_btn_1.get_y(), 0)
screen_btn_1_event_move_y.set_time(200)
screen_btn_1_event_move_y.set_path_cb(lv.anim_t.path_bounce)
screen_btn_1_event_move_y.set_custom_exec_cb(lambda a,val: anim_y_cb(screen_btn_1,val))
lv.anim_t.start(screen_btn_1_event_move_y)
screen_btnm_1.add_event_cb(lambda e: screen_btnm_1_clicked_1_event_cb(e,screen_btn_1), lv.EVENT.CLICKED, None)
def screen_btnm_1_clicked_2_event_cb(e,screen_btnm_1):
src = e.get_target()
code = e.get_code()
screen_btnm_1_event_move_x = lv.anim_t()
screen_btnm_1_event_move_x.init()
screen_btnm_1_event_move_x.set_var(screen_btnm_1)
screen_btnm_1_event_move_x.set_values(screen_btnm_1.get_x(), 320)
screen_btnm_1_event_move_x.set_time(200)
screen_btnm_1_event_move_x.set_path_cb(lv.anim_t.path_linear)
screen_btnm_1_event_move_x.set_custom_exec_cb(lambda a,val: anim_x_cb(screen_btnm_1,val))
lv.anim_t.start(screen_btnm_1_event_move_x)
screen_btnm_1_event_move_y = lv.anim_t()
screen_btnm_1_event_move_y.init()
screen_btnm_1_event_move_y.set_var(screen_btnm_1)
screen_btnm_1_event_move_y.set_values(screen_btnm_1.get_y(), 0)
screen_btnm_1_event_move_y.set_time(200)
screen_btnm_1_event_move_y.set_path_cb(lv.anim_t.path_linear)
screen_btnm_1_event_move_y.set_custom_exec_cb(lambda a,val: anim_y_cb(screen_btnm_1,val))
lv.anim_t.start(screen_btnm_1_event_move_y)
screen_btnm_1.add_event_cb(lambda e: screen_btnm_1_clicked_2_event_cb(e,screen_btnm_1), lv.EVENT.CLICKED, None)
def screen_btnm_1_clicked_3_event_cb(e,screen_tabview_1):
src = e.get_target()
code = e.get_code()
screen_tabview_1.set_width(315)
screen_btnm_1.add_event_cb(lambda e: screen_btnm_1_clicked_3_event_cb(e,screen_tabview_1), lv.EVENT.CLICKED, None)
screen_label_3 = lv.label(screen)
screen_label_3.set_pos(290,0)
screen_label_3.set_size(4,240)
screen_label_3.set_text(" ")
screen_label_3.set_long_mode(lv.label.LONG.WRAP)
screen_label_3.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
# create style style_screen_label_3_main_main_default
style_screen_label_3_main_main_default = lv.style_t()
style_screen_label_3_main_main_default.init()
style_screen_label_3_main_main_default.set_radius(0)
style_screen_label_3_main_main_default.set_bg_color(lv.color_make(0x21,0x95,0xf6))
style_screen_label_3_main_main_default.set_bg_grad_color(lv.color_make(0x21,0x95,0xf6))
style_screen_label_3_main_main_default.set_bg_grad_dir(lv.GRAD_DIR.VER)
style_screen_label_3_main_main_default.set_bg_opa(255)
style_screen_label_3_main_main_default.set_text_color(lv.color_make(0x00,0x00,0x00))
try:
style_screen_label_3_main_main_default.set_text_font(lv.font_simsun_12)
except AttributeError:
try:
style_screen_label_3_main_main_default.set_text_font(lv.font_montserrat_12)
except AttributeError:
style_screen_label_3_main_main_default.set_text_font(lv.font_montserrat_16)
style_screen_label_3_main_main_default.set_text_letter_space(2)
style_screen_label_3_main_main_default.set_pad_left(0)
style_screen_label_3_main_main_default.set_pad_right(0)
style_screen_label_3_main_main_default.set_pad_top(0)
style_screen_label_3_main_main_default.set_pad_bottom(0)
# add style for screen_label_3
screen_label_3.add_style(style_screen_label_3_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)
def screen_btn_1_clicked_1_event_cb(e,screen_btnm_1):
src = e.get_target()
code = e.get_code()
screen_btnm_1_event_move_x = lv.anim_t()
screen_btnm_1_event_move_x.init()
screen_btnm_1_event_move_x.set_var(screen_btnm_1)
screen_btnm_1_event_move_x.set_values(screen_btnm_1.get_x(), 288)
screen_btnm_1_event_move_x.set_time(200)
screen_btnm_1_event_move_x.set_path_cb(lv.anim_t.path_linear)
screen_btnm_1_event_move_x.set_custom_exec_cb(lambda a,val: anim_x_cb(screen_btnm_1,val))
lv.anim_t.start(screen_btnm_1_event_move_x)
screen_btnm_1_event_move_y = lv.anim_t()
screen_btnm_1_event_move_y.init()
screen_btnm_1_event_move_y.set_var(screen_btnm_1)
screen_btnm_1_event_move_y.set_values(screen_btnm_1.get_y(), 0)
screen_btnm_1_event_move_y.set_time(200)
screen_btnm_1_event_move_y.set_path_cb(lv.anim_t.path_linear)
screen_btnm_1_event_move_y.set_custom_exec_cb(lambda a,val: anim_y_cb(screen_btnm_1,val))
lv.anim_t.start(screen_btnm_1_event_move_y)
screen_btn_1.add_event_cb(lambda e: screen_btn_1_clicked_1_event_cb(e,screen_btnm_1), lv.EVENT.CLICKED, None)
def screen_btn_1_clicked_2_event_cb(e,screen_btn_1):
src = e.get_target()
code = e.get_code()
screen_btn_1_event_move_x = lv.anim_t()
screen_btn_1_event_move_x.init()
screen_btn_1_event_move_x.set_var(screen_btn_1)
screen_btn_1_event_move_x.set_values(screen_btn_1.get_x(), 320)
screen_btn_1_event_move_x.set_time(200)
screen_btn_1_event_move_x.set_path_cb(lv.anim_t.path_linear)
screen_btn_1_event_move_x.set_custom_exec_cb(lambda a,val: anim_x_cb(screen_btn_1,val))
lv.anim_t.start(screen_btn_1_event_move_x)
screen_btn_1_event_move_y = lv.anim_t()
screen_btn_1_event_move_y.init()
screen_btn_1_event_move_y.set_var(screen_btn_1)
screen_btn_1_event_move_y.set_values(screen_btn_1.get_y(), 0)
screen_btn_1_event_move_y.set_time(200)
screen_btn_1_event_move_y.set_path_cb(lv.anim_t.path_linear)
screen_btn_1_event_move_y.set_custom_exec_cb(lambda a,val: anim_y_cb(screen_btn_1,val))
lv.anim_t.start(screen_btn_1_event_move_y)
screen_btn_1.add_event_cb(lambda e: screen_btn_1_clicked_2_event_cb(e,screen_btn_1), lv.EVENT.CLICKED, None)
def screen_btn_1_clicked_3_event_cb(e,screen_tabview_1):
src = e.get_target()
code = e.get_code()
screen_tabview_1.set_width(288)
screen_btn_1.add_event_cb(lambda e: screen_btn_1_clicked_3_event_cb(e,screen_tabview_1), lv.EVENT.CLICKED, None)

79
components/myui/guider/generated/setup_scr_screen.c

@ -29,7 +29,7 @@ void setup_scr_screen(lv_ui *ui){
//Write codes screen_tabview_1
ui->screen_tabview_1 = lv_tabview_create(ui->screen, LV_DIR_TOP, 30);
lv_obj_set_pos(ui->screen_tabview_1, 0, 0);
lv_obj_set_size(ui->screen_tabview_1, 314, 240);
lv_obj_set_size(ui->screen_tabview_1, 290, 240);
//Home
ui->screen_tabview_1_Home = lv_tabview_add_tab(ui->screen_tabview_1,"Home");
@ -229,8 +229,8 @@ void setup_scr_screen(lv_ui *ui){
//Write codes screen_btnm_1
ui->screen_btnm_1 = lv_btnmatrix_create(ui->screen);
lv_obj_set_pos(ui->screen_btnm_1, 288, 0);
lv_obj_set_size(ui->screen_btnm_1, 32, 240);
lv_obj_set_pos(ui->screen_btnm_1, 292, 0);
lv_obj_set_size(ui->screen_btnm_1, 28, 240);
static const char *screen_btnm_1_text_map[] = {
"1","\n","2","\n",
"3","\n","4","\n",
@ -246,7 +246,7 @@ void setup_scr_screen(lv_ui *ui){
lv_style_init(&style_screen_btnm_1_main_main_default);
lv_style_set_radius(&style_screen_btnm_1_main_main_default, 4);
lv_style_set_bg_color(&style_screen_btnm_1_main_main_default, lv_color_make(0xff, 0xff, 0xff));
lv_style_set_bg_grad_color(&style_screen_btnm_1_main_main_default, lv_color_make(0xff, 0xff, 0xff));
lv_style_set_bg_grad_color(&style_screen_btnm_1_main_main_default, lv_color_make(0xf0, 0xf0, 0xf0));
lv_style_set_bg_grad_dir(&style_screen_btnm_1_main_main_default, LV_GRAD_DIR_HOR);
lv_style_set_bg_opa(&style_screen_btnm_1_main_main_default, 255);
lv_style_set_border_color(&style_screen_btnm_1_main_main_default, lv_color_make(0xff, 0xff, 0xff));
@ -266,7 +266,7 @@ void setup_scr_screen(lv_ui *ui){
else
lv_style_init(&style_screen_btnm_1_main_items_default);
lv_style_set_radius(&style_screen_btnm_1_main_items_default, 4);
lv_style_set_bg_color(&style_screen_btnm_1_main_items_default, lv_color_make(0xe6, 0xe6, 0xe6));
lv_style_set_bg_color(&style_screen_btnm_1_main_items_default, lv_color_make(0xff, 0xff, 0xff));
lv_style_set_bg_grad_color(&style_screen_btnm_1_main_items_default, lv_color_make(0xe6, 0xe6, 0xe6));
lv_style_set_bg_grad_dir(&style_screen_btnm_1_main_items_default, LV_GRAD_DIR_VER);
lv_style_set_bg_opa(&style_screen_btnm_1_main_items_default, 255);
@ -276,48 +276,31 @@ void setup_scr_screen(lv_ui *ui){
lv_style_set_text_font(&style_screen_btnm_1_main_items_default, &lv_font_simsun_12);
lv_obj_add_style(ui->screen_btnm_1, &style_screen_btnm_1_main_items_default, LV_PART_ITEMS|LV_STATE_DEFAULT);
//Update pos for widget screen_btnm_1
lv_obj_update_layout(ui->screen_btnm_1);
//Write animation: screen_btnm_1move in x direction
lv_anim_t screen_btnm_1_x;
lv_anim_init(&screen_btnm_1_x);
lv_anim_set_var(&screen_btnm_1_x, ui->screen_btnm_1);
lv_anim_set_time(&screen_btnm_1_x, 500);
lv_anim_set_exec_cb(&screen_btnm_1_x, (lv_anim_exec_xcb_t)lv_obj_set_x);
lv_anim_set_values(&screen_btnm_1_x, lv_obj_get_x(ui->screen_btnm_1), 320);
lv_anim_set_path_cb(&screen_btnm_1_x, lv_anim_path_bounce);
lv_anim_start(&screen_btnm_1_x);
//Write codes screen_btn_1
ui->screen_btn_1 = lv_btn_create(ui->screen);
lv_obj_set_pos(ui->screen_btn_1, 315, 0);
lv_obj_set_size(ui->screen_btn_1, 5, 240);
//Write style state: LV_STATE_DEFAULT for style_screen_btn_1_main_main_default
static lv_style_t style_screen_btn_1_main_main_default;
if (style_screen_btn_1_main_main_default.prop_cnt > 1)
lv_style_reset(&style_screen_btn_1_main_main_default);
//Write codes screen_label_3
ui->screen_label_3 = lv_label_create(ui->screen);
lv_obj_set_pos(ui->screen_label_3, 290, 0);
lv_obj_set_size(ui->screen_label_3, 4, 240);
lv_label_set_text(ui->screen_label_3, " ");
lv_label_set_long_mode(ui->screen_label_3, LV_LABEL_LONG_WRAP);
lv_obj_set_style_text_align(ui->screen_label_3, LV_TEXT_ALIGN_CENTER, 0);
//Write style state: LV_STATE_DEFAULT for style_screen_label_3_main_main_default
static lv_style_t style_screen_label_3_main_main_default;
if (style_screen_label_3_main_main_default.prop_cnt > 1)
lv_style_reset(&style_screen_label_3_main_main_default);
else
lv_style_init(&style_screen_btn_1_main_main_default);
lv_style_set_radius(&style_screen_btn_1_main_main_default, 5);
lv_style_set_bg_color(&style_screen_btn_1_main_main_default, lv_color_make(0x21, 0x95, 0xf6));
lv_style_set_bg_grad_color(&style_screen_btn_1_main_main_default, lv_color_make(0x21, 0x95, 0xf6));
lv_style_set_bg_grad_dir(&style_screen_btn_1_main_main_default, LV_GRAD_DIR_VER);
lv_style_set_bg_opa(&style_screen_btn_1_main_main_default, 255);
lv_style_set_shadow_color(&style_screen_btn_1_main_main_default, lv_color_make(0x21, 0x95, 0xf6));
lv_style_set_shadow_opa(&style_screen_btn_1_main_main_default, 255);
lv_style_set_border_color(&style_screen_btn_1_main_main_default, lv_color_make(0x21, 0x95, 0xf6));
lv_style_set_border_width(&style_screen_btn_1_main_main_default, 0);
lv_style_set_border_opa(&style_screen_btn_1_main_main_default, 255);
lv_obj_add_style(ui->screen_btn_1, &style_screen_btn_1_main_main_default, LV_PART_MAIN|LV_STATE_DEFAULT);
lv_obj_add_flag(ui->screen_btn_1, LV_OBJ_FLAG_CHECKABLE);
ui->screen_btn_1_label = lv_label_create(ui->screen_btn_1);
lv_label_set_text(ui->screen_btn_1_label, "");
lv_obj_set_style_text_color(ui->screen_btn_1_label, lv_color_make(0x00, 0x00, 0x00), LV_STATE_DEFAULT);
lv_obj_set_style_pad_all(ui->screen_btn_1, 0, LV_STATE_DEFAULT);
lv_obj_align(ui->screen_btn_1_label, LV_ALIGN_CENTER, 0, 0);
//Init events for screen
events_init_screen(ui);
lv_style_init(&style_screen_label_3_main_main_default);
lv_style_set_radius(&style_screen_label_3_main_main_default, 0);
lv_style_set_bg_color(&style_screen_label_3_main_main_default, lv_color_make(0x21, 0x95, 0xf6));
lv_style_set_bg_grad_color(&style_screen_label_3_main_main_default, lv_color_make(0x21, 0x95, 0xf6));
lv_style_set_bg_grad_dir(&style_screen_label_3_main_main_default, LV_GRAD_DIR_VER);
lv_style_set_bg_opa(&style_screen_label_3_main_main_default, 255);
lv_style_set_text_color(&style_screen_label_3_main_main_default, lv_color_make(0x00, 0x00, 0x00));
lv_style_set_text_font(&style_screen_label_3_main_main_default, &lv_font_simsun_12);
lv_style_set_text_letter_space(&style_screen_label_3_main_main_default, 2);
lv_style_set_pad_left(&style_screen_label_3_main_main_default, 0);
lv_style_set_pad_right(&style_screen_label_3_main_main_default, 0);
lv_style_set_pad_top(&style_screen_label_3_main_main_default, 0);
lv_style_set_pad_bottom(&style_screen_label_3_main_main_default, 0);
lv_obj_add_style(ui->screen_label_3, &style_screen_label_3_main_main_default, LV_PART_MAIN|LV_STATE_DEFAULT);
}

2
main/CMakeLists.txt

@ -1,4 +1,4 @@
file(GLOB_RECURSE SOURCES ./*.c)
file(GLOB_RECURSE SOURCES ./*.c ./*.cpp ./init/*.c)
set(COMPONENT_SRCS ${SOURCES})
register_component()

200
main/Kconfig.projbuild

@ -1,105 +1,111 @@
menu "My Configuration"
menu "camera"
choice CAMERA_PAD_TYPE
prompt "camera pad type"
default CAMERA_PAD_ESP32_S2_KALUGA_V1_3
config CAMERA_PAD_ESP32_S2_KALUGA_V1_3
bool "ESP32-S2-KALUGA_V1.3"
config CAMERA_PAD_ESP32_S2_KALUGA_V1_2
bool "ESP32-S2-KALUGA_V1.2"
config CAMERA_PAD_ESP32_S2_KALUGA_V1_1
bool "ESP32-S2-KALUGA_V1.1"
endchoice
config CAMERA_JPEG_MODE
bool "jpeg mode"
endmenu
choice CAMERA_PAD_TYPE
prompt "camera pad type"
default CAMERA_PAD_ESP32_S2_KALUGA_V1_3
config CAMERA_PAD_ESP32_S2_KALUGA_V1_3
bool "ESP32-S2-KALUGA_V1.3"
config CAMERA_PAD_ESP32_S2_KALUGA_V1_2
bool "ESP32-S2-KALUGA_V1.2"
config CAMERA_PAD_ESP32_S2_KALUGA_V1_1
bool "ESP32-S2-KALUGA_V1.1"
endchoice
config CAMERA_JPEG_MODE
bool "jpeg mode"
choice LCD_PAD_TYPE
prompt "LCD pad type"
default LCD_PAD_ESP32_S2_KALUGA_V1_3
config LCD_PAD_ESP32_S2_KALUGA_V1_3
bool "ESP32-S2-KALUGA_V1.3"
config LCD_PAD_ESP32_S2_KALUGA_V1_2
bool "ESP32-S2-KALUGA_V1.2"
config LCD_PAD_ESP32_S2_KALUGA_V1_1
bool "ESP32-S2-KALUGA_V1.1"
endchoice
choice AUDIO_PAD_TYPE
prompt "audio pad type"
default AUDIO_PAD_ESP32_S2_KALUGA_V1_2
config AUDIO_PAD_ESP32_S2_KALUGA_V1_3
bool "ESP32-S2-KALUGA_V1.3"
config AUDIO_PAD_ESP32_S2_KALUGA_V1_2
bool "ESP32-S2-KALUGA_V1.2"
config AUDIO_PAD_ESP32_S2_KALUGA_V1_1
bool "ESP32-S2-KALUGA_V1.1"
help
Set the GPIO number used for transmitting the RMT signal.
endchoice
choice LCD_VERSION
prompt "LCD version"
default LCD_ST7789
config LCD_ST7789
bool "ST7789"
config LCD_ILI9341
bool "ILI9341"
help
Set LCD version
endchoice
config EXAMPLE_RMT_TX_GPIO
int "WS2812 GPIO"
default 45
help
Set the GPIO number used for transmitting the RMT signal.
config EXAMPLE_STRIP_LED_NUMBER
int "Number of LEDS in a strip"
default 1
help
A single RGB strip contains several LEDs.
menu "WiFi Settings"
config ESP_WIFI_SSID
string "WiFi STA SSID"
default ""
help
WiFi SSID (network name) to connect to or empty for Off.
config ESP_WIFI_PASSWORD
string "WiFi STA Password"
default ""
help
WiFi Password if WEP/WPA/WPA2 or empty if Open.
config ESP_WIFI_AP_SSID
string "WiFi AP SSID"
default "ESP32-Camera"
help
AP SSID (network name) to create or empty for Off.
menu "lcd"
choice LCD_PAD_TYPE
prompt "LCD pad type"
default LCD_PAD_ESP32_S2_KALUGA_V1_3
config LCD_PAD_ESP32_S2_KALUGA_V1_3
bool "ESP32-S2-KALUGA_V1.3"
config LCD_PAD_ESP32_S2_KALUGA_V1_2
bool "ESP32-S2-KALUGA_V1.2"
config LCD_PAD_ESP32_S2_KALUGA_V1_1
bool "ESP32-S2-KALUGA_V1.1"
endchoice
choice LCD_VERSION
prompt "LCD version"
default LCD_ST7789
config LCD_ST7789
bool "ST7789"
config LCD_ILI9341
bool "ILI9341"
help
Set LCD version
endchoice
endmenu
config ESP_WIFI_AP_PASSWORD
string "WiFi AP Password"
default ""
help
AP password for WPA2 or empty for Open.
menu "audio"
choice AUDIO_PAD_TYPE
prompt "audio pad type"
default AUDIO_PAD_ESP32_S2_KALUGA_V1_2
config AUDIO_PAD_ESP32_S2_KALUGA_V1_3
bool "ESP32-S2-KALUGA_V1.3"
config AUDIO_PAD_ESP32_S2_KALUGA_V1_2
bool "ESP32-S2-KALUGA_V1.2"
config AUDIO_PAD_ESP32_S2_KALUGA_V1_1
bool "ESP32-S2-KALUGA_V1.1"
help
Set the GPIO number used for transmitting the RMT signal.
endchoice
endmenu
config SERVER_IP
string "WiFi AP IP Address"
default "192.168.4.1"
help
IP address that the ESP will assign to it's AP interface. You can use this IP to connect to the camera after flashing.
menu "led"
config RMT_TX_GPIO
int "WS2812 GPIO"
default 45
help
Set the GPIO number used for transmitting the RMT signal.
config STRIP_LED_NUMBER
int "Number of LEDS in a strip"
default 1
help
A single RGB strip contains several LEDs.
endmenu
config ESP_MAXIMUM_RETRY
int "Maximum retry"
default 5
help
Set the Maximum retry to avoid station reconnecting to the AP unlimited when the AP is really inexistent.
menu "wifi"
config ESP_WIFI_SSID
string "WiFi STA SSID"
default ""
help
WiFi SSID (network name) to connect to or empty for Off.
config ESP_WIFI_PASSWORD
string "WiFi STA Password"
default ""
help
WiFi Password if WEP/WPA/WPA2 or empty if Open.
config ESP_WIFI_AP_SSID
string "WiFi AP SSID"
default "ESP32-Camera"
help
AP SSID (network name) to create or empty for Off.
config ESP_WIFI_AP_PASSWORD
string "WiFi AP Password"
default ""
help
AP password for WPA2 or empty for Open.
config SERVER_IP
string "WiFi AP IP Address"
default "192.168.4.1"
help
IP address that the ESP will assign to it's AP interface. You can use this IP to connect to the camera after flashing.
config ESP_MAXIMUM_RETRY
int "Maximum retry"
default 5
help
Set the Maximum retry to avoid station reconnecting to the AP unlimited when the AP is really inexistent.
endmenu
endmenu

25
main/app.h

@ -1,3 +1,10 @@
/**
* @author: Pomin
* @date: 2022-08-27 22:33:59
* @github: https://github.com/POMIN-163
* @lastedit: 2022-08-27 22:33:59
* @description:
**/
#ifndef _APP_H
#define _APP_H
@ -5,23 +12,7 @@
extern "C"{
#endif
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_event.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_heap_caps.h"
#include "esp_log.h"
#include "driver/gpio.h"
#include "driver/adc.h"
#include "driver/rmt.h"
#include "led_strip.h"
void btns_init(void);
#include "init/app_init.h"
#ifdef __cplusplus
}

146
main/btns.c

@ -1,146 +0,0 @@
#include "app.h"
#define DEFAULT_VREF \
1100 /*!< Use adc2_vref_to_gpio() to obtain a better estimate */
#define NO_OF_SAMPLES 64
#define SAMPLE_TIME 200 /*!< Sampling time(ms) */
static const adc_channel_t channel =
ADC_CHANNEL_5; /*!< PIO7 if ADC1, GPIO17 if ADC2 */
static const adc_bits_width_t width = ADC_WIDTH_BIT_13;
static const adc_atten_t atten = ADC_ATTEN_DB_11;
static const adc_unit_t unit = ADC_UNIT_1;
static xQueueHandle adc_queue = NULL;
led_strip_t *strip;
#define DEVIATION 0.1
const char *TAG = "main";
double adc_voltage_conversion(uint32_t adc_reading) {
double voltage = 0;
voltage = (2.60 * adc_reading) / 8191;
return voltage;
}
void button_task(void *arg) {
/*!<Continuously sample ADC1*/
while (1) {
uint32_t adc_reading = 0;
double voltage = 0;
/*!< Multisampling */
for (int i = 0; i < NO_OF_SAMPLES; i++) {
if (unit == ADC_UNIT_1) {
adc_reading += adc1_get_raw((adc1_channel_t)channel);
} else {
int raw;
adc2_get_raw((adc2_channel_t)channel, width, &raw);
adc_reading += raw;
}
}
adc_reading /= NO_OF_SAMPLES;
voltage = adc_voltage_conversion(adc_reading);
ESP_LOGD(TAG, "ADC%d CH%d Raw: %d ; Voltage: %0.2lfV", unit, channel,
adc_reading, voltage);
xQueueSend(adc_queue, (double *)&voltage, 0);
vTaskDelay(pdMS_TO_TICKS(SAMPLE_TIME));
}
vTaskDelete(NULL);
}
void led_task(void *arg) {
double voltage = 0;
while (1) {
xQueueReceive(adc_queue, &voltage, portMAX_DELAY);
if (voltage > 2.6) {
continue;
} else if (voltage > 2.41 - DEVIATION && voltage <= 2.41 + DEVIATION) {
ESP_LOGI(TAG, "rec(K1) -> red");
ESP_ERROR_CHECK(strip->set_pixel(strip, 0, 255, 0, 0));
ESP_ERROR_CHECK(strip->refresh(strip, 0));
} else if (voltage > 1.98 - DEVIATION && voltage <= 1.98 + DEVIATION) {
ESP_LOGI(TAG, "mode(K2) -> green");
ESP_ERROR_CHECK(strip->set_pixel(strip, 0, 0, 255, 0));
ESP_ERROR_CHECK(strip->refresh(strip, 0));
} else if (voltage > 1.65 - DEVIATION && voltage <= 1.65 + DEVIATION) {
ESP_LOGI(TAG, "play(K3) -> blue");
ESP_ERROR_CHECK(strip->set_pixel(strip, 0, 0, 0, 255));
ESP_ERROR_CHECK(strip->refresh(strip, 0));
} else if (voltage > 1.11 - DEVIATION && voltage <= 1.11 + DEVIATION) {
ESP_LOGI(TAG, "set(K4) -> yellow");
ESP_ERROR_CHECK(strip->set_pixel(strip, 0, 255, 255, 0));
ESP_ERROR_CHECK(strip->refresh(strip, 0));
} else if (voltage > 0.82 - DEVIATION && voltage <= 0.82 + DEVIATION) {
ESP_LOGI(TAG, "vol(K5) -> purple");
ESP_ERROR_CHECK(strip->set_pixel(strip, 0, 255, 0, 255));
ESP_ERROR_CHECK(strip->refresh(strip, 0));
} else if (voltage > 0.38 - DEVIATION && voltage <= 0.38 + DEVIATION) {
ESP_LOGI(TAG, "vol+(K6) -> write");
ESP_ERROR_CHECK(strip->set_pixel(strip, 0, 255, 255, 255));
ESP_ERROR_CHECK(strip->refresh(strip, 0));
}
}
vTaskDelete(NULL);
}
void adc_init(void) {
if (unit == ADC_UNIT_1) {
adc1_config_width(width);
adc1_config_channel_atten(channel, atten);
} else {
adc2_config_channel_atten((adc2_channel_t)channel, atten);
}
}
esp_err_t example_rmt_init(uint8_t gpio_num, int led_number,
uint8_t rmt_channel) {
ESP_LOGI(TAG, "Initializing WS2812");
rmt_config_t config = RMT_DEFAULT_CONFIG_TX(gpio_num, rmt_channel);
/*!< set counter clock to 40MHz */
config.clk_div = 2;
ESP_ERROR_CHECK(rmt_config(&config));
ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0));
led_strip_config_t strip_config =
LED_STRIP_DEFAULT_CONFIG(led_number, (led_strip_dev_t)config.channel);
strip = led_strip_new_rmt_ws2812(&strip_config);
if (!strip) {
ESP_LOGE(TAG, "install WS2812 driver failed");
return ESP_FAIL;
}
/*!< Clear LED strip (turn off all LEDs) */
ESP_ERROR_CHECK(strip->clear(strip, 100));
/*!< Show simple rainbow chasing pattern */
return ESP_OK;
}
void btns_init(void) {
/*!< WS2812 init*/
ESP_ERROR_CHECK(example_rmt_init(CONFIG_EXAMPLE_RMT_TX_GPIO,
CONFIG_EXAMPLE_STRIP_LED_NUMBER,
RMT_CHANNEL_0));
adc_queue = xQueueCreate(1, sizeof(double));
adc_init();
xTaskCreatePinnedToCore(&button_task, "button_task", 3 * 1024, NULL, 5,
NULL, 0);
xTaskCreatePinnedToCore(&led_task, "led_task", 3 * 1024, NULL, 5, NULL, 0);
}

38
main/init/app_init.h

@ -0,0 +1,38 @@
/**
* @author: Pomin
* @date: 2022-08-27 22:34:01
* @github: https://github.com/POMIN-163
* @lastedit: 2022-08-28 22:25:31
* @description:
**/
#ifndef _APP_INIT_H
#define _APP_INIT_H
#ifdef __cplusplus
extern "C"{
#endif
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_event.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_heap_caps.h"
#include "esp_log.h"
#include "driver/gpio.h"
#include "driver/adc.h"
int lvgl_init(void);
void lv_port_indev_init(void);
void led_init(void);
void btns_init(void);
#ifdef __cplusplus
}
#endif
#endif // _APP_INIT_H

158
main/init/btns_init.c

@ -0,0 +1,158 @@
/**
* @author: Pomin
* @date: 2022-08-27 22:33:46
* @github: https://github.com/POMIN-163
* @lastedit: 2022-08-28 22:26:31
* @description: ADC
**/
#include "app_init.h"
#include "gui_guider.h"
#include "lvgl_helpers.h"
#define NO_OF_SAMPLES 64
#define SAMPLE_TIME 200
static const adc_channel_t channel = ADC_CHANNEL_5;
static const adc_bits_width_t width = ADC_WIDTH_BIT_13;
static const adc_atten_t atten = ADC_ATTEN_DB_11;
static const adc_unit_t unit = ADC_UNIT_1;
static uint8_t key_status;
/* 门限 */
#define DEVIATION 0.1
#define TAG "btns"
/**
* @brief ADC
*
* @param adc_reading
* @return double
**/
double adc_voltage_conversion(uint32_t adc_reading) {
double voltage = 0;
voltage = (2.60 * adc_reading) / 8191;
return voltage;
}
void button_task(void *arg) {
while (1) {
uint32_t adc_reading = 0;
double voltage = 0;
for (int i = 0; i < NO_OF_SAMPLES; i++) {
if (unit == ADC_UNIT_1) {
adc_reading += adc1_get_raw((adc1_channel_t)channel);
} else {
int raw;
adc2_get_raw((adc2_channel_t)channel, width, &raw);
adc_reading += raw;
}
}
adc_reading /= NO_OF_SAMPLES;
voltage = adc_voltage_conversion(adc_reading);
key_status = 0;
if (voltage > 2.6) {
continue;
} else if (voltage > 2.41 - DEVIATION && voltage <= 2.41 + DEVIATION) {
key_status = 1;
} else if (voltage > 1.98 - DEVIATION && voltage <= 1.98 + DEVIATION) {
key_status = 2;
} else if (voltage > 1.65 - DEVIATION && voltage <= 1.65 + DEVIATION) {
key_status = 3;
} else if (voltage > 1.11 - DEVIATION && voltage <= 1.11 + DEVIATION) {
key_status = 4;
} else if (voltage > 0.82 - DEVIATION && voltage <= 0.82 + DEVIATION) {
key_status = 5;
} else if (voltage > 0.38 - DEVIATION && voltage <= 0.38 + DEVIATION) {
key_status = 6;
}
vTaskDelay(pdMS_TO_TICKS(SAMPLE_TIME));
}
vTaskDelete(NULL);
}
/**
* @brief ADC
*
**/
void adc_init(void) {
if (unit == ADC_UNIT_1) {
adc1_config_width(width);
adc1_config_channel_atten(channel, atten);
} else {
adc2_config_channel_atten((adc2_channel_t)channel, atten);
}
}
/**
* @brief
*
**/
void btns_init(void) {
adc_init();
BaseType_t res = xTaskCreatePinnedToCore(&button_task, "button_task", 4 * 1024, NULL, 5, NULL, 0);
if (res == pdPASS) {
ESP_LOGI(TAG, "successed init.");
} else {
ESP_LOGE(TAG, "failed init.");
}
}
/* * * lvgl 驱动支持 * * */
static void button_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data);
static int8_t button_get_pressed_id(void);
lv_indev_t *indev_button;
void lv_port_indev_init(void) {
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_BUTTON;
indev_drv.read_cb = button_read;
indev_button = lv_indev_drv_register(&indev_drv);
static const lv_point_t btn_points[6] = {
{ 300, 20 }, /* Button 0 */
{ 300, 60 }, /* Button 1 */
{ 300, 100 }, /* Button 2 */
{ 300, 140 }, /* Button 3 */
{ 300, 180 }, /* Button 4 */
{ 300, 220 }, /* Button 5 */
};
lv_indev_set_button_points(indev_button, btn_points);
}
static void button_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data) {
static uint8_t last_btn = 0;
int8_t btn_act = button_get_pressed_id();
if (btn_act >= 0) {
data->state = LV_INDEV_STATE_PR;
last_btn = btn_act;
} else {
data->state = LV_INDEV_STATE_REL;
}
data->btn_id = last_btn;
}
static int8_t button_get_pressed_id(void) {
for (uint8_t i = 0; i < 6; i++) {
if (key_status - 1 == i) {
return i;
}
}
return -1;
}

161
main/init/led_init.c

@ -0,0 +1,161 @@
/**
* @author: Pomin
* @date: 2022-08-27 22:33:39
* @github: https://github.com/POMIN-163
* @lastedit: 2022-08-28 22:35:55
* @description: led
**/
#include "app_init.h"
#include "driver/rmt.h"
#include "led_strip.h"
led_strip_t* strip;
#define TAG "led"
/**
* @brief WS2812
*
* @param gpio_num
* @param led_number
* @param rmt_channel
* @return esp_err_t
**/
esp_err_t rmt_init(uint8_t gpio_num, int led_number, uint8_t rmt_channel) {
ESP_LOGI(TAG, "Initializing WS2812");
rmt_config_t config = RMT_DEFAULT_CONFIG_TX(gpio_num, rmt_channel);
config.clk_div = 2;
ESP_ERROR_CHECK(rmt_config(&config));
ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0));
led_strip_config_t strip_config =
LED_STRIP_DEFAULT_CONFIG(led_number, (led_strip_dev_t)config.channel);
strip = led_strip_new_rmt_ws2812(&strip_config);
if (!strip) {
ESP_LOGE(TAG, "install WS2812 driver failed");
return ESP_FAIL;
}
ESP_ERROR_CHECK(strip->clear(strip, 100));
return ESP_OK;
}
/* hsv 色彩空间 */
typedef struct chsv {
uint16_t h;
uint16_t s;
uint16_t v;
} chsv;
/* rgb 色彩 */
typedef struct crgb {
uint8_t r;
uint8_t g;
uint8_t b;
} crgb;
/**
* @brief hsv rgb
*
* @param rgb
* @param hsv
**/
void HSVtoRGB(crgb* rgb, chsv* hsv) {
// R,G,B from 0-255, H from 0-360, S,V from 0-100
uint16_t rgb_max = (uint16_t)(hsv->v * 2.55f);
uint16_t rgb_min = (uint16_t)(rgb_max * (100 - hsv->s) / 100.0f);
int i = hsv->h / 60;
int difs = hsv->h % 60; // factorial part of h
// rgb adjustment amount by hue
uint16_t rgb_Adj = (rgb_max - rgb_min) * difs / 60.0f;
switch (i) {
case 0:
rgb->r = (uint8_t)rgb_max;
rgb->g = (uint8_t)(rgb_min + rgb_Adj);
rgb->b = (uint8_t)rgb_min;
break;
case 1:
rgb->r = (uint8_t)(rgb_max - rgb_Adj);
rgb->g = (uint8_t)rgb_max;
rgb->b = (uint8_t)rgb_min;
break;
case 2:
rgb->r = (uint8_t)rgb_min;
rgb->g = (uint8_t)rgb_max;
rgb->b = (uint8_t)(rgb_min + rgb_Adj);
break;
case 3:
rgb->r = (uint8_t)rgb_min;
rgb->g = (uint8_t)(rgb_max - rgb_Adj);
rgb->b = (uint8_t)rgb_max;
break;
case 4:
rgb->r = (uint8_t)(rgb_min + rgb_Adj);
rgb->g = (uint8_t)rgb_min;
rgb->b = (uint8_t)rgb_max;
break;
default: // case 5:
rgb->r = (uint8_t)rgb_max;
rgb->g = (uint8_t)rgb_min;
rgb->b = (uint8_t)(rgb_max - rgb_Adj);
break;
}
}
/**
* @brief
*
**/
crgb* rgb_brilliant(void) {
static crgb rgb = {0};
static int step = 1;
static chsv hsv = {
.h = 0, // 0 ~ 360
.s = 100, // 0 ~ 100
.v = 20 // 0 ~ 100
};
hsv.h += step;
if (hsv.h == 358) {
step = -1;
} else if (hsv.h == 0) {
step = 1;
}
HSVtoRGB(&rgb, &hsv);
return &rgb;
}
void led_task(void* arg) {
crgb * rgb;
while (1) {
vTaskDelay(10);
rgb = rgb_brilliant();
strip->set_pixel(strip, 0, rgb->r, rgb->g, rgb->b);
strip->refresh(strip, 0);
}
vTaskDelete(NULL);
}
/**
* @brief led
*
**/
void led_init(void) {
ESP_ERROR_CHECK(
rmt_init(CONFIG_RMT_TX_GPIO, CONFIG_STRIP_LED_NUMBER, RMT_CHANNEL_0));
BaseType_t res = xTaskCreatePinnedToCore(&led_task, "led_task", 1 * 1024,
NULL, 5, NULL, 0);
if (res == pdPASS) {
ESP_LOGI(TAG, "successed init.");
} else {
ESP_LOGE(TAG, "failed init.");
}
}

76
main/init/lvgl_init.c

@ -0,0 +1,76 @@
/**
* @author: Pomin
* @date: 2022-08-27 22:33:56
* @github: https://github.com/POMIN-163
* @lastedit: 2022-08-28 22:15:27
* @description: lvgl
**/
#include "app_init.h"
#include "custom.h"
#include "esp_freertos_hooks.h"
#include "events_init.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
#include "gui_guider.h"
#include "lvgl_helpers.h"
// #include "lv_examples/src/lv_demo_benchmark/lv_demo_benchmark.h"
// #include "lv_examples/src/lv_demo_music/lv_demo_music.h"
// #include "lv_examples/src/lv_demo_widgets/lv_demo_widgets.h"
static void lv_tick_task(void *arg) {
(void)arg;
lv_tick_inc(portTICK_PERIOD_MS);
}
SemaphoreHandle_t xGuiSemaphore;
lv_ui guider_ui;
void gui_task(void *arg) {
xGuiSemaphore = xSemaphoreCreateMutex();
lv_init();
lvgl_driver_init();
static lv_disp_draw_buf_t draw_buf;
lv_color_t *buf1 = (lv_color_t *)heap_caps_malloc(
DLV_HOR_RES_MAX * DLV_VER_RES_MAX * sizeof(lv_color_t), MALLOC_CAP_DMA);
lv_color_t *buf2 = (lv_color_t *)heap_caps_malloc(
DLV_HOR_RES_MAX * DLV_VER_RES_MAX * sizeof(lv_color_t), MALLOC_CAP_DMA);
lv_disp_draw_buf_init(&draw_buf, buf1, buf2,
DLV_HOR_RES_MAX * DLV_VER_RES_MAX);
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.draw_buf = &draw_buf;
disp_drv.flush_cb = disp_driver_flush;
disp_drv.hor_res = 320;
disp_drv.ver_res = 240;
lv_disp_drv_register(&disp_drv);
esp_register_freertos_tick_hook((esp_freertos_tick_cb_t)lv_tick_task);
// lv_demo_widgets();
// lv_demo_music();
// lv_demo_benchmark();
setup_ui(&guider_ui);
events_init(&guider_ui);
// custom_init(&guider_ui);
lv_port_indev_init();
while (1) {
vTaskDelay(pdMS_TO_TICKS(10));
if (pdTRUE == xSemaphoreTake(xGuiSemaphore, portMAX_DELAY)) {
lv_timer_handler();
xSemaphoreGive(xGuiSemaphore);
}
}
}
int lvgl_init(void) {
xTaskCreatePinnedToCore(gui_task, "gui task", 1024 * 4, NULL, 6, NULL, 0);
return 0;
}

183
main/main.c

@ -1,183 +0,0 @@
#include <stdio.h>
#include "esp_freertos_hooks.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
// #include "lv_examples/src/lv_demo_benchmark/lv_demo_benchmark.h"
// #include "lv_examples/src/lv_demo_music/lv_demo_music.h"
// #include "lv_examples/src/lv_demo_widgets/lv_demo_widgets.h"
#include "app.h"
#include "custom.h"
#include "events_init.h"
#include "gui_guider.h"
#include "lvgl_helpers.h"
static void lv_tick_task(void *arg) {
(void)arg;
lv_tick_inc(portTICK_PERIOD_MS);
}
SemaphoreHandle_t xGuiSemaphore;
lv_ui guider_ui;
static void gui_task(void *arg) {
xGuiSemaphore = xSemaphoreCreateMutex();
lv_init();
lvgl_driver_init();
/* double buff create */
static lv_disp_draw_buf_t draw_buf;
lv_color_t *buf1 = heap_caps_malloc(
DLV_HOR_RES_MAX * DLV_VER_RES_MAX * sizeof(lv_color_t), MALLOC_CAP_DMA);
lv_color_t *buf2 = heap_caps_malloc(
DLV_HOR_RES_MAX * DLV_VER_RES_MAX * sizeof(lv_color_t), MALLOC_CAP_DMA);
lv_disp_draw_buf_init(
&draw_buf, buf1, buf2,
DLV_HOR_RES_MAX * DLV_VER_RES_MAX); /*Initialize the display buffer*/
static lv_disp_drv_t
disp_drv; /*A variable to hold the drivers. Must be static or global.*/
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
disp_drv.draw_buf = &draw_buf; /*Set an initialized buffer*/
disp_drv.flush_cb =
disp_driver_flush; /*Set a flush callback to draw to the display*/
disp_drv.hor_res = 320; /*Set the horizontal resolution in pixels*/
disp_drv.ver_res = 240; /*Set the vertical resolution in pixels*/
lv_disp_drv_register(
&disp_drv); /*Register the driver and save the created display objects*/
esp_register_freertos_tick_hook(lv_tick_task);
// lv_demo_widgets();
// lv_demo_music();
// lv_demo_benchmark();
setup_ui(&guider_ui);
events_init(&guider_ui);
custom_init(&guider_ui);
while (1) {
/* Delay 1 tick (assumes FreeRTOS tick is 10ms */
vTaskDelay(pdMS_TO_TICKS(10));
/* Try to take the semaphore, call lvgl related function on success */
if (pdTRUE == xSemaphoreTake(xGuiSemaphore, portMAX_DELAY)) {
lv_timer_handler();
xSemaphoreGive(xGuiSemaphore);
}
}
}
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "esp_camera.h"
#include "lcd.h"
#include "board.h"
static const char *TAG = "main";
void app_main()
{
// xTaskCreatePinnedToCore(gui_task, "gui task", 1024 * 4, NULL, 1, NULL, 0);
btns_init();
lcd_config_t lcd_config = {
.clk_fre = 40 * 1000 * 1000,
.pin_clk = LCD_CLK,
.pin_mosi = LCD_MOSI,
.pin_dc = LCD_DC,
.pin_cs = LCD_CS,
.pin_rst = LCD_RST,
.pin_bk = LCD_BK,
.max_buffer_size = 2 * 1024,
.horizontal = 2, /*!< 2: UP, 3: DOWN */
#ifdef CONFIG_CAMERA_JPEG_MODE
.swap_data = 1,
#else
.swap_data = 0,
#endif
};
lcd_init(&lcd_config);
camera_config_t camera_config = {
.pin_pwdn = -1,
.pin_reset = -1,
.pin_xclk = CAM_XCLK,
.pin_sscb_sda = CAM_SDA,
.pin_sscb_scl = CAM_SCL,
.pin_d7 = CAM_D7,
.pin_d6 = CAM_D6,
.pin_d5 = CAM_D5,
.pin_d4 = CAM_D4,
.pin_d3 = CAM_D3,
.pin_d2 = CAM_D2,
.pin_d1 = CAM_D1,
.pin_d0 = CAM_D0,
.pin_vsync = CAM_VSYNC,
.pin_href = CAM_HSYNC,
.pin_pclk = CAM_PCLK,
//XCLK 20MHz or 10MHz for OV2640 double FPS (Experimental)
.xclk_freq_hz = 20000000,
.ledc_timer = LEDC_TIMER_0,
.ledc_channel = LEDC_CHANNEL_0,
#ifdef CONFIG_CAMERA_JPEG_MODE
.pixel_format = PIXFORMAT_JPEG, //YUV422,GRAYSCALE,RGB565,JPEG
#else
.pixel_format = PIXFORMAT_RGB565,
#endif
.frame_size = FRAMESIZE_QVGA, //QQVGA-UXGA Do not use sizes above QVGA when not JPEG
.jpeg_quality = 12, //0-63 lower number means higher quality
.fb_count = 2 //if more than one, i2s runs in continuous mode. Use only with JPEG
};
//initialize the camera
esp_err_t err = esp_camera_init(&camera_config);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Camera Init Failed");
return;
}
sensor_t *s = esp_camera_sensor_get();
s->set_vflip(s, 1);//flip it back
//initial sensors are flipped vertically and colors are a bit saturated
if (s->id.PID == OV3660_PID) {
s->set_brightness(s, 1);//up the blightness just a bit
s->set_saturation(s, -2);//lower the saturation
}
//drop down frame size for higher initial frame rate
s->set_framesize(s, FRAMESIZE_QVGA);
ESP_LOGI(TAG, "Camera Init done");
#ifdef CONFIG_CAMERA_JPEG_MODE
ESP_LOGI(TAG, "Camera jpeg mode");
uint8_t *rgb565 = malloc(240 * 320 * 2);
if (NULL == rgb565) {
ESP_LOGE(TAG, "can't alloc memory for rgb565 buffer");
return;
}
#endif
while (1) {
camera_fb_t *pic = esp_camera_fb_get();
if (pic) {
ESP_LOGI(TAG, "picture: %d x %d %dbyte", pic->width, pic->height, pic->