- 在CMakeLists.txt中添加usb_cdc_module、usb_cdc_test_module和 usb_device_module源文件 - 添加usb_cdc_rx_event、usb_cdc_tx_event、usb_device_state_event、 usb_function_ready_event和usb_prepare_event事件定义 - 实现USB CDC串口通信功能,包括接收和发送数据处理 - 添加USB设备状态管理,支持连接、断开、激活等状态变化 - 配置设备树中的USB端点数量以支持CDC ACM功能 - 创建USB设备模块用于管理USB堆栈初始化和状态监控 - 添加USB功能就绪事件以协调不同USB功能的准备状态
43 lines
1.1 KiB
C
43 lines
1.1 KiB
C
#include "usb_function_ready_event.h"
|
|
|
|
static const char *usb_function_name(uint8_t function_mask)
|
|
{
|
|
switch (function_mask) {
|
|
case USB_FUNCTION_HID:
|
|
return "hid";
|
|
case USB_FUNCTION_CDC_ACM:
|
|
return "cdc_acm";
|
|
default:
|
|
return "?";
|
|
}
|
|
}
|
|
|
|
static void log_usb_function_ready_event(const struct app_event_header *aeh)
|
|
{
|
|
const struct usb_function_ready_event *event =
|
|
cast_usb_function_ready_event(aeh);
|
|
|
|
APP_EVENT_MANAGER_LOG(aeh, "function:%s",
|
|
usb_function_name(event->function_mask));
|
|
}
|
|
|
|
static void profile_usb_function_ready_event(struct log_event_buf *buf,
|
|
const struct app_event_header *aeh)
|
|
{
|
|
const struct usb_function_ready_event *event =
|
|
cast_usb_function_ready_event(aeh);
|
|
|
|
nrf_profiler_log_encode_uint8(buf, event->function_mask);
|
|
}
|
|
|
|
APP_EVENT_INFO_DEFINE(usb_function_ready_event,
|
|
ENCODE(NRF_PROFILER_ARG_U8),
|
|
ENCODE("function_mask"),
|
|
profile_usb_function_ready_event);
|
|
|
|
APP_EVENT_TYPE_DEFINE(usb_function_ready_event,
|
|
log_usb_function_ready_event,
|
|
&usb_function_ready_event_info,
|
|
APP_EVENT_FLAGS_CREATE(
|
|
APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE));
|