20250529 同步自原始工程:

优化 CMakeLists.txt,增加 lib-out 目录的包含;修改 app_config.c 中的 LED 灯带开关变量名;更新 app_config.h,增加新的灯效模式和方向控制;更新 SBDEMO.h 中的默认设备名称;在 msc_host.c 中添加 USB 设备连接类型的处理;在 usbport.c 中增加 USB 连接类型的状态管理;更新 Kconfig,增加 LED 灯带的最大图层数和竞速模式选项;新增 spbelib_interface.h 文件,定义无线调参功能接口;删除不再使用的 components/CMakeLists.txt 文件;更新 misc.h,添加读取 MCU 身份信息的 MD5 值的函数声明;修改 tim.h 中的 drv_pwm_init 函数参数;更新 kk.h,增加默认工作队列的创建宏;优化 sh.c 中的命令行插入字符串逻辑;更新 sdkconfig 默认配置文件,升级 ESP-IDF 版本和调整蓝牙默认发射功率。
This commit is contained in:
LokLiang
2025-05-29 18:05:20 +08:00
parent 499994b239
commit 176b2c49f6
17 changed files with 451 additions and 77 deletions

View File

@@ -18,6 +18,8 @@
#include "errno.h"
#include "esp_vfs.h"
#include "spbelib_interface.h"
#include "config/hardware_define.h"
// #include "usb/cdc_acm_host.h"
@@ -58,7 +60,7 @@ typedef struct
} __usb_data_t;
static QueueHandle_t app_queue;
static SemaphoreHandle_t ready_to_uninstall_usb;
// static SemaphoreHandle_t ready_to_uninstall_usb;
static msc_host_vfs_handle_t vfs_handle;
static usbport_status_e g_usb_status = USBPORT_STATUS_NO_CONNECTION;
@@ -89,6 +91,7 @@ static SemaphoreHandle_t s_usb_write_mux = NULL;
static portMUX_TYPE s_out_ringbuf_mux = portMUX_INITIALIZER_UNLOCKED;
volatile static int s_in_buffered_data_len = 0;
volatile static int s_out_buffered_data_len = 0;
volatile static usb_connect_type_t s_usb_connect_type = USB_CONNECTED_UNKNOWN;
//////////// End CDC 全局变量 ////////////
@@ -100,27 +103,41 @@ static uint16_t g_msc_file_count = 0;
//////////// End MSC 全局变量 ////////////
static TaskHandle_t s_usb_task_handle, s_device_task_handle; //, workthread_handle;
static void usb_device_event_cb(const msc_host_event_t *event, void *arg)
{
switch (event->event)
{
case MSC_DEVICE_CONNECTED:
s_usb_connect_type = USB_CONNECTED_MSC;
SYS_LOG_INF("MSC device connected");
sblib_send_event(LIB_EVENT_USBH_MSC, 0, NULL);
break;
case MSC_DEVICE_DISCONNECTED:
s_usb_connect_type = USB_CONNECTED_UNKNOWN;
SYS_LOG_INF("MSC device disconnected");
sblib_send_event(LIB_EVENT_USBH_UNKNOW_DEVICE, 0, NULL);
break;
case CDC_DEVICE_CONNECTED:
s_usb_connect_type = USB_CONNECTED_CDC;
SYS_LOG_INF("CDC device connected");
sblib_send_event(LIB_EVENT_USBH_CDC, 0, NULL);
break;
case CDC_DEVICE_DISCONNECTED:
s_usb_connect_type = USB_CONNECTED_UNKNOWN;
SYS_LOG_INF("CDC device disconnected");
sblib_send_event(LIB_EVENT_USBH_UNKNOW_DEVICE, 0, NULL);
break;
case DFU_DEVICE_CONNECTED:
s_usb_connect_type = USB_CONNECTED_DFU;
SYS_LOG_INF("DFU device connected");
sblib_send_event(LIB_EVENT_USBH_DFU, 0, NULL);
break;
case DFU_DEVICE_DISCONNECTED:
s_usb_connect_type = USB_CONNECTED_UNKNOWN;
SYS_LOG_INF("DFU device disconnected");
sblib_send_event(LIB_EVENT_USBH_UNKNOW_DEVICE, 0, NULL);
break;
}
@@ -133,20 +150,26 @@ static void handle_usb_events(void *args)
while (1)
{
uint32_t event_flags;
SYS_LOG_INF("usb_host_lib_handle_events(portMAX_DELAY, &event_flags);");
usb_host_lib_handle_events(portMAX_DELAY, &event_flags);
// Release devices once all clients has deregistered
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_NO_CLIENTS)
{
SYS_LOG_INF("usb_host_device_free_all();");
usb_host_device_free_all();
// SYS_LOG_INF("xSemaphoreGive(ready_to_uninstall_usb);");
// xSemaphoreGive(ready_to_uninstall_usb);
break;
}
// Give ready_to_uninstall_usb semaphore to indicate that USB Host library
// can be deinitialized, and terminate this task.
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_ALL_FREE)
{
xSemaphoreGive(ready_to_uninstall_usb);
}
// if (event_flags & USB_HOST_LIB_EVENT_FLAGS_ALL_FREE)
// {
// SYS_LOG_INF("xSemaphoreGive(ready_to_uninstall_usb);");
// xSemaphoreGive(ready_to_uninstall_usb);
// }
}
s_usb_task_handle = NULL;
vTaskDelete(NULL);
}
@@ -308,6 +331,7 @@ static void handle_device_events(void *args)
msc_host_event_t app_event;
while (1)
{
SYS_LOG_INF("xQueueReceive(app_queue, &app_event, portMAX_DELAY);");
xQueueReceive(app_queue, &app_event, portMAX_DELAY);
switch (app_event.event)
@@ -501,19 +525,22 @@ static int _usbhost_port_read(sb_data_port_t *port, void *buffer, uint32_t lengt
}
}
static bool s_is_started = false;
static int _usbhost_start(sb_data_port_t *port)
{
s_is_started = true;
return 0;
}
static int _usbhost_stop(sb_data_port_t *port)
{
s_is_started = false;
return 0;
}
static bool _usbhost_is_started(sb_data_port_t *port)
{
return true;
return s_is_started;
}
static uint32_t _usbhost_get_rx_length(sb_data_port_t *port)
@@ -705,8 +732,11 @@ static sb_data_port_vtable_t const usbhost_port_vtable = {
//////////// STM32固件升级相关的函数结束 //////////////
// static TaskHandle_t s_usb_task_handle, s_device_task_handle; //, workthread_handle;
int usbport_init(void)
{
SYS_LOG_INF("usbport_init");
if (s_port.vtable)
{
SYS_LOG_WRN("repeated initialize");
@@ -716,26 +746,33 @@ int usbport_init(void)
s_port.vtable = &usbhost_port_vtable;
s_port.data = &s_usb_data;
TaskHandle_t usb_task_handle, device_task_handle; //, workthread_handle;
memset(&s_usb_data, 0, sizeof(__usb_data_t));
os_pipe_create(&s_usb_data.pipe_obj, 1024 * 2);
ready_to_uninstall_usb = xSemaphoreCreateBinary();
// if (ready_to_uninstall_usb == NULL)
// {
// ready_to_uninstall_usb = xSemaphoreCreateBinary();
// }
app_queue = xQueueCreate(3, sizeof(msc_host_event_t));
assert(app_queue);
static usb_host_config_t const host_config = {
// .skip_phy_setup = false,
.skip_phy_setup = false,
.intr_flags = ESP_INTR_FLAG_LEVEL1,
};
ESP_ERROR_CHECK(usb_host_install(&host_config));
xTaskCreatePinnedToCore(handle_usb_events, "usb_events", 4096, NULL, SBTASK_PRIORITY_USB_HOST, &usb_task_handle, SBTASK_CORE_INDEX_USB_HOST);
assert(usb_task_handle);
xTaskCreatePinnedToCore(handle_device_events, "device_events", 4096, NULL, SBTASK_PRIORITY_USB_DEVICE, &device_task_handle, SBTASK_CORE_INDEX_USB_DEVICE);
assert(device_task_handle);
if (s_usb_task_handle == NULL)
{
xTaskCreatePinnedToCore(handle_usb_events, "usb_events", 4096, NULL, SBTASK_PRIORITY_USB_HOST, &s_usb_task_handle, SBTASK_CORE_INDEX_USB_HOST);
assert(s_usb_task_handle);
}
if (s_device_task_handle == NULL)
{
xTaskCreatePinnedToCore(handle_device_events, "device_events", 4096, NULL, SBTASK_PRIORITY_USB_DEVICE, &s_device_task_handle, SBTASK_CORE_INDEX_USB_DEVICE);
assert(s_device_task_handle);
}
const msc_host_driver_config_t msc_config = {
.create_backround_task = true,
@@ -748,6 +785,70 @@ int usbport_init(void)
return 0;
}
void usbport_deinit(void)
{
SYS_LOG_INF("usbport_deinit");
if (s_port.vtable == NULL)
{
SYS_LOG_WRN("usb host not initialized");
return;
}
if (g_connected_usb_device)
{
if (vfs_handle)
{
msc_host_vfs_unregister(vfs_handle);
vfs_handle = NULL;
}
msc_host_uninstall_device(g_connected_usb_device);
g_connected_usb_device = NULL;
}
if (g_cdc_dev)
{
cdc_host_close(g_cdc_dev);
g_cdc_dev = NULL;
}
ESP_ERROR_CHECK(msc_host_uninstall());
vTaskDelay(pdMS_TO_TICKS(100));
// if (s_device_task_handle)
// {
// vTaskDelete(s_device_task_handle);
// s_device_task_handle = NULL;
// }
// if (s_usb_task_handle)
// {
// vTaskDelete(s_usb_task_handle);
// s_usb_task_handle = NULL;
// }
ESP_ERROR_CHECK(usb_host_uninstall());
if (app_queue)
{
vQueueDelete(app_queue);
app_queue = NULL;
}
// if (ready_to_uninstall_usb)
// {
// vSemaphoreDelete(ready_to_uninstall_usb);
// ready_to_uninstall_usb = NULL;
// }
if (os_pipe_is_valid(&s_usb_data.pipe_obj))
{
os_pipe_delete(&s_usb_data.pipe_obj);
}
s_port.vtable = NULL;
}
sb_data_port_t *usbport_bind(os_work_t *rx_resume_work)
{
if (s_port.data == NULL)
@@ -764,6 +865,21 @@ sb_data_port_t *usbport_bind(os_work_t *rx_resume_work)
return &s_port;
}
void usbport_unbind(sb_data_port_t *port)
{
if (port == NULL)
{
SYS_LOG_WRN("usb host not initialized");
return;
}
__usb_data_t *usb_data = port->data;
os_pipe_unregist(&usb_data->pipe_obj);
usb_data->rx_resume_work = NULL;
}
usbport_status_e usbport_get_state(void)
{
return g_usb_status;
@@ -785,3 +901,8 @@ msc_file_info *msc_get_cached_file_list(uint16_t *out_file_count)
}
return g_msc_file_lists;
}
usb_connect_type_t usbport_get_usb_type(void)
{
return s_usb_connect_type;
}