Added button driver.
This commit is contained in:
parent
535e24ec9d
commit
01221fa28f
|
@ -5,6 +5,7 @@ idf_component_register(SRCS
|
|||
"assets/fonts/material_webfont/material_webfont_32.c"
|
||||
"main.c"
|
||||
"helper/helper_wifi.c"
|
||||
"impl/impl_btn.c"
|
||||
"impl/impl_epd.c"
|
||||
"impl/impl_lvgl.c"
|
||||
"interface/if_standby.c"
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
#include "impl_btn.h"
|
||||
|
||||
#include "driver/gpio.h"
|
||||
|
||||
#define BTN_GPIO_1 GPIO_NUM_46
|
||||
#define BTN_GPIO_2 GPIO_NUM_45
|
||||
#define BTN_GPIO_3 GPIO_NUM_42
|
||||
#define BTN_GPIO_4 GPIO_NUM_41
|
||||
|
||||
static void impl_btn_setup_pin(gpio_num_t pin) {
|
||||
gpio_reset_pin(pin);
|
||||
gpio_set_direction(pin, GPIO_MODE_INPUT);
|
||||
gpio_pullup_en(pin);
|
||||
}
|
||||
|
||||
esp_err_t impl_btn_init(void) {
|
||||
impl_btn_setup_pin(BTN_GPIO_1);
|
||||
impl_btn_setup_pin(BTN_GPIO_2);
|
||||
impl_btn_setup_pin(BTN_GPIO_3);
|
||||
impl_btn_setup_pin(BTN_GPIO_4);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t impl_btn_read(uint8_t *btn_status) {
|
||||
*btn_status = 0U;
|
||||
|
||||
/* Bug workaround: GPIO46 cannot pull up. */
|
||||
//if (gpio_get_level(BTN_GPIO_1) == 0) *btn_status |= 0x01U;
|
||||
if (gpio_get_level(BTN_GPIO_2) == 0) *btn_status |= (0x01U << 1U);
|
||||
if (gpio_get_level(BTN_GPIO_3) == 0) *btn_status |= (0x01U << 2U);
|
||||
if (gpio_get_level(BTN_GPIO_4) == 0) *btn_status |= (0x01U << 3U);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef IMPL_BTN_H
|
||||
#define IMPL_BTN_H
|
||||
|
||||
#include "esp_system.h"
|
||||
|
||||
esp_err_t impl_btn_init(void);
|
||||
esp_err_t impl_btn_read(uint8_t *btn_status);
|
||||
|
||||
#endif
|
|
@ -1,6 +1,7 @@
|
|||
#include "impl_lvgl.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "impl_btn.h"
|
||||
#include "impl_epd.h"
|
||||
|
||||
#define LOG_TAG "IMPL_LVGL"
|
||||
|
@ -9,7 +10,7 @@
|
|||
#define EPD_DISPLAY_FRAME_SIZE (EPD_DISPLAY_PIXEL_COUNT * 2 / 8)
|
||||
|
||||
#define EPD_DISPLAY_GS 0
|
||||
#define EPD_DISPLAY_MAX_PARTIAL 6
|
||||
#define EPD_DISPLAY_MAX_PARTIAL 12
|
||||
|
||||
static impl_epd_handle_t s_epd_impl;
|
||||
|
||||
|
@ -34,9 +35,12 @@ static epd_gdew042t2_t s_gd_epd = {
|
|||
static uint8_t s_epd_partial_counter = 0;
|
||||
#endif
|
||||
|
||||
static uint32_t s_last_key = 0;
|
||||
|
||||
static lv_disp_draw_buf_t s_disp_buf;
|
||||
static lv_color_t s_disp_store[EPD_DISPLAY_FRAME_SIZE];
|
||||
static lv_disp_drv_t s_disp_drv;
|
||||
static lv_indev_drv_t s_indev_drv;
|
||||
|
||||
static TaskHandle_t s_lv_tick_handle;
|
||||
static TaskHandle_t s_lv_task_handle;
|
||||
|
@ -118,6 +122,34 @@ static void impl_lvgl_epd_rounder_cb(lv_disp_drv_t *disp_drv, lv_area_t *area) {
|
|||
area->x2 = 399;
|
||||
}
|
||||
|
||||
static void impl_lvgl_button_read(lv_indev_drv_t *drv, lv_indev_data_t *data) {
|
||||
uint8_t btn = 0U;
|
||||
impl_btn_read(&btn);
|
||||
|
||||
if (btn != 0) {
|
||||
switch (btn) {
|
||||
case 0x02:
|
||||
data->key = LV_KEY_ENTER;
|
||||
break;
|
||||
case 0x04:
|
||||
data->key = LV_KEY_NEXT;
|
||||
break;
|
||||
case 0x08:
|
||||
data->key = LV_KEY_PREV;
|
||||
break;
|
||||
}
|
||||
|
||||
data->state = LV_INDEV_STATE_PRESSED;
|
||||
s_last_key = data->key;
|
||||
}
|
||||
|
||||
else {
|
||||
data->key = s_last_key;
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
s_last_key = 0U;
|
||||
}
|
||||
}
|
||||
|
||||
static void impl_lvgl_log_cb(const char *buf) {
|
||||
// Log to console.
|
||||
ESP_LOGI("LVGL", "%s", buf);
|
||||
|
@ -179,6 +211,22 @@ esp_err_t impl_lvgl_init(void) {
|
|||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
impl_btn_init();
|
||||
|
||||
lv_indev_drv_init(&s_indev_drv);
|
||||
s_indev_drv.type = LV_INDEV_TYPE_KEYPAD;
|
||||
s_indev_drv.read_cb = impl_lvgl_button_read;
|
||||
|
||||
lv_indev_t *indev = lv_indev_drv_register(&s_indev_drv);
|
||||
if(indev == NULL) {
|
||||
ESP_LOGE(LOG_TAG, "LVGL indev register failed.");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
lv_group_t *indev_group = lv_group_create();
|
||||
lv_group_set_default(indev_group);
|
||||
lv_indev_set_group(indev, indev_group);
|
||||
|
||||
lv_theme_t *default_theme = lv_theme_mono_init(disp, false, &lv_font_unscii_16);
|
||||
lv_disp_set_theme(disp, default_theme);
|
||||
|
||||
|
@ -190,7 +238,7 @@ esp_err_t impl_lvgl_init(void) {
|
|||
|
||||
xSemaphoreGive(s_lv_semphr_handle);
|
||||
|
||||
if (xTaskCreate(impl_lvgl_tick_task, "LV_TICK", 1024, NULL, 5, &s_lv_tick_handle) != pdPASS) {
|
||||
if (xTaskCreate(impl_lvgl_tick_task, "LV_TICK", 4096, NULL, 5, &s_lv_tick_handle) != pdPASS) {
|
||||
ESP_LOGE(LOG_TAG, "LVGL tick task creation failed.");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
|
|
@ -16,17 +16,27 @@ lv_obj_t *g_standby_screen;
|
|||
void if_standby_task(void *pvParameters) {
|
||||
impl_lvgl_lock();
|
||||
|
||||
// Custom style.
|
||||
lv_style_t container_style;
|
||||
lv_style_init(&container_style);
|
||||
lv_style_set_border_color(&container_style, lv_color_white());
|
||||
lv_style_set_border_width(&container_style, 0);
|
||||
lv_style_set_outline_width(&container_style, 0);
|
||||
lv_style_set_pad_all(&container_style, 0);
|
||||
|
||||
// 1st line
|
||||
lv_obj_t *top_container = lv_obj_create(g_standby_screen);
|
||||
|
||||
lv_obj_set_size(top_container, 400, 60);
|
||||
lv_obj_add_style(top_container, &container_style, 0);
|
||||
|
||||
lv_obj_set_size(top_container, 400, 50);
|
||||
lv_obj_align(top_container, LV_ALIGN_TOP_MID, 0, 0);
|
||||
lv_obj_set_flex_flow(top_container, LV_FLEX_FLOW_ROW);
|
||||
|
||||
lv_obj_t *network_status_obj = lv_obj_create(top_container);
|
||||
lv_obj_t *network_status_obj = lv_btn_create(top_container);
|
||||
lv_obj_t *weekday_obj = lv_obj_create(top_container);
|
||||
lv_obj_t *date_obj = lv_obj_create(top_container);
|
||||
lv_obj_t *battery_obj = lv_obj_create(top_container);
|
||||
lv_obj_t *battery_obj = lv_btn_create(top_container);
|
||||
|
||||
lv_obj_set_size(network_status_obj, 50, 50);
|
||||
lv_obj_set_size(battery_obj, 50, 50);
|
||||
|
@ -40,19 +50,23 @@ void if_standby_task(void *pvParameters) {
|
|||
// 2nd line
|
||||
lv_obj_t *main_container = lv_obj_create(g_standby_screen);
|
||||
|
||||
lv_obj_set_size(main_container, 400, 235);
|
||||
lv_obj_add_style(main_container, &container_style, 0);
|
||||
|
||||
lv_obj_set_size(main_container, 400, 245);
|
||||
lv_obj_align_to(main_container, top_container, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
|
||||
lv_obj_set_flex_flow(main_container, LV_FLEX_FLOW_ROW);
|
||||
|
||||
lv_obj_t *time_obj = lv_obj_create(main_container);
|
||||
|
||||
lv_obj_set_height(time_obj, 225);
|
||||
lv_obj_set_height(time_obj, 245);
|
||||
lv_obj_set_flex_grow(time_obj, 1);
|
||||
|
||||
// 2nd line, DHT column
|
||||
lv_obj_t *dht_container = lv_obj_create(main_container);
|
||||
|
||||
lv_obj_set_size(dht_container, 110, 225);
|
||||
lv_obj_add_style(dht_container, &container_style, 0);
|
||||
|
||||
lv_obj_set_size(dht_container, 100, 245);
|
||||
lv_obj_set_flex_flow(dht_container, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
lv_obj_t *temp_obj = lv_obj_create(dht_container);
|
||||
|
@ -85,7 +99,6 @@ void if_standby_task(void *pvParameters) {
|
|||
lv_obj_set_style_text_font(humid_icon_label, &material_webfont_32, 0);
|
||||
lv_obj_set_style_text_font(humid_label, &bebas_neue_32, 0);
|
||||
|
||||
|
||||
lv_label_set_text(network_status_label, "\U000F092D");
|
||||
lv_label_set_text(battery_label, "\U000F007A");
|
||||
lv_label_set_text(weekday_label, "SUN");
|
||||
|
@ -108,13 +121,11 @@ void if_standby_task(void *pvParameters) {
|
|||
|
||||
impl_lvgl_unlock();
|
||||
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
ESP_LOGI(LOG_TAG, "Standby screen created.");
|
||||
|
||||
for (;;) {
|
||||
gettimeofday(&tv, &tz);
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
// Wait for notifications.
|
||||
vTaskSuspend(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,7 +135,7 @@ esp_err_t if_standby_init(void) {
|
|||
lv_disp_load_scr(g_standby_screen);
|
||||
impl_lvgl_unlock();
|
||||
|
||||
if (xTaskCreate(if_standby_task, "STBY_TASK", 1024, NULL, 6, &s_if_standby_handle) != pdPASS) {
|
||||
if (xTaskCreate(if_standby_task, "STBY_TASK", 4096, NULL, 6, &s_if_standby_handle) != pdPASS) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
|
|
|
@ -181,7 +181,7 @@ e.g. "stm32f769xx.h" or "stm32f429xx.h"*/
|
|||
*LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail
|
||||
*LV_LOG_LEVEL_USER Only logs added by the user
|
||||
*LV_LOG_LEVEL_NONE Do not log anything*/
|
||||
# define LV_LOG_LEVEL LV_LOG_LEVEL_WARN
|
||||
# define LV_LOG_LEVEL LV_LOG_LEVEL_INFO
|
||||
|
||||
/*1: Print the log with 'printf';
|
||||
*0: User need to register a callback with `lv_log_register_print_cb()`*/
|
||||
|
|
|
@ -36,6 +36,6 @@ void app_main(void) {
|
|||
|
||||
/* Dead loop */
|
||||
for (;;) {
|
||||
vTaskDelay(pdMS_TO_TICKS(60000));
|
||||
vTaskSuspend(NULL);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue