2024-03-28 12:19:52 +08:00
|
|
|
#include "app_main.h"
|
|
|
|
|
|
|
|
|
|
/* 标准库 */
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
/* 配置 */
|
|
|
|
|
#include "config/board_config.h"
|
2025-02-21 10:30:22 +08:00
|
|
|
#include "config/app_config.h"
|
2024-03-28 12:19:52 +08:00
|
|
|
|
|
|
|
|
/* SDK */
|
|
|
|
|
#include "esp_err.h"
|
2025-02-21 10:30:22 +08:00
|
|
|
#include "hal/spi_types.h"
|
|
|
|
|
|
|
|
|
|
/* 驱动 */
|
|
|
|
|
#include "drivers/ws2812_spi/ws2812_spi.h"
|
|
|
|
|
#include "drivers/ws2812_spi/ws2812_spi_shell.h"
|
2024-03-28 12:19:52 +08:00
|
|
|
|
|
|
|
|
/* 通用模块 */
|
2025-02-18 17:41:45 +08:00
|
|
|
#include "button/button.h"
|
2024-03-28 12:19:52 +08:00
|
|
|
|
|
|
|
|
/* 应用模块 */
|
|
|
|
|
|
|
|
|
|
/* 自定义框架抽象层 */
|
|
|
|
|
#include "os/os.h"
|
|
|
|
|
#include "os/os_common.h"
|
|
|
|
|
#include "console.h"
|
|
|
|
|
#include "shell/sh_vset.h"
|
|
|
|
|
|
2025-02-21 10:30:22 +08:00
|
|
|
#define CONFIG_SYS_LOG_LEVEL SYS_LOG_LEVEL_INF
|
2024-03-28 12:19:52 +08:00
|
|
|
#define SYS_LOG_DOMAIN "MAIN"
|
|
|
|
|
#include "sys_log.h"
|
|
|
|
|
|
|
|
|
|
nvs_handle g_nvs_hdl; // nvs 句柄
|
|
|
|
|
os_work_q_t g_work_q_hdl_low; // 低于 default_os_work_q_hdl 优先级的工作队列
|
|
|
|
|
|
|
|
|
|
static void _init_nvs(void);
|
2025-02-21 10:30:22 +08:00
|
|
|
static void _init_work_q(void);
|
|
|
|
|
static void _init_ws2812(void);
|
2025-02-18 17:41:45 +08:00
|
|
|
static void _change_mode_event_button(button_hdl_t *handle, press_event_t event);
|
2024-03-28 12:19:52 +08:00
|
|
|
static void _vset_cb(sh_t *sh_hdl);
|
|
|
|
|
|
|
|
|
|
void work_app_main(void *arg)
|
|
|
|
|
{
|
|
|
|
|
/* 初始化 SDK 的 nvs 模块 */
|
|
|
|
|
_init_nvs();
|
|
|
|
|
|
2025-02-21 10:30:22 +08:00
|
|
|
/* 初始化配置 */
|
|
|
|
|
board_cfg_init(); // 板级配置
|
|
|
|
|
app_cfg_init(); // 应用配置
|
|
|
|
|
|
|
|
|
|
/* 初始化其他优先级的工作队列 */
|
|
|
|
|
_init_work_q();
|
|
|
|
|
|
2024-03-28 12:19:52 +08:00
|
|
|
/* 初始化按键检测和控制 */
|
2025-02-21 10:30:22 +08:00
|
|
|
btn_attach(&g_cfg_board->key_reset, _change_mode_event_button, EVENT_PRESS_UP | EVENT_PRESS_DOWN | EVENT_LONG_PRESS_HOLD);
|
|
|
|
|
|
|
|
|
|
/* 初始化 ws2812 */
|
|
|
|
|
_init_ws2812();
|
|
|
|
|
ws2812_spi_shell_register(); // 用于测试 ws2812 的 shell 命令
|
2024-03-28 12:19:52 +08:00
|
|
|
|
|
|
|
|
/* 启动 shell */
|
|
|
|
|
os_thread_sleep(100);
|
2025-02-21 10:30:22 +08:00
|
|
|
shell_start(_vset_cb);
|
|
|
|
|
SYS_LOG_DBG("app start");
|
2024-03-28 12:19:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void _init_nvs(void)
|
|
|
|
|
{
|
|
|
|
|
#define _NVS_NAME "nvs-app"
|
|
|
|
|
if (g_nvs_hdl == 0)
|
|
|
|
|
{
|
|
|
|
|
ESP_ERROR_CHECK(nvs_open(_NVS_NAME, NVS_READWRITE, &g_nvs_hdl));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-21 10:30:22 +08:00
|
|
|
static void _init_work_q(void)
|
|
|
|
|
{
|
|
|
|
|
/* 不使用以节省内存 */
|
|
|
|
|
// os_work_q_create(&g_work_q_hdl_low,
|
|
|
|
|
// "app-work_q-low",
|
|
|
|
|
// 0x2000,
|
|
|
|
|
// OS_PRIORITY_LOW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void _init_ws2812(void)
|
|
|
|
|
{
|
|
|
|
|
#if (CONFIG_LED_STRIP_MAX_LEDS)
|
|
|
|
|
ws2812_spi_led_strip_init(SPI2_HOST, CONFIG_LED_STRIP_MAX_LEDS);
|
|
|
|
|
#else
|
|
|
|
|
ws2812_spi_led_strip_init(SPI2_HOST, 10);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void _vset_cb(sh_t *sh_hdl)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-18 17:41:45 +08:00
|
|
|
static void _change_mode_event_button(button_hdl_t *handle, press_event_t event)
|
2024-03-28 12:19:52 +08:00
|
|
|
{
|
|
|
|
|
static const char *const stat_tab[] = {
|
2025-02-18 17:41:45 +08:00
|
|
|
[PRESS_UP] = "up",
|
|
|
|
|
[PRESS_DOWN] = "down",
|
|
|
|
|
[LONG_PRESS_HOLD] = "held",
|
2024-03-28 12:19:52 +08:00
|
|
|
};
|
2025-02-18 17:41:45 +08:00
|
|
|
if (event < __ARRAY_SIZE(stat_tab) && stat_tab[event])
|
2024-03-28 12:19:52 +08:00
|
|
|
{
|
2025-02-18 17:41:45 +08:00
|
|
|
SYS_LOG_DBG("button stat: %s", stat_tab[event]);
|
2024-03-28 12:19:52 +08:00
|
|
|
}
|
|
|
|
|
}
|