feat: 添加模式切换模块支持USB/2.4G/BLE模式检测

- 在CMakeLists.txt中添加新的包含目录inc/events和源文件
  mode_switch_module.c、mode_switch_event.c
- 在设备树文件中添加模式切换ADC配置节点和通道设置
- 新增mode_switch_event.h头文件定义模式切换事件结构
- 实现mode_switch_event.c事件处理和日志记录功能
- 创建mode_switch_module.c核心模块实现ADC采样、
  模式检测和事件发布逻辑
- 支持三种模式:USB、2.4G、BLE的电压阈值判断
- 集成CAF事件系统,支持电源管理和状态转换
This commit is contained in:
2026-04-08 14:28:05 +08:00
parent e4c824d657
commit 6610b3471d
5 changed files with 312 additions and 1 deletions

View File

@@ -0,0 +1,45 @@
#include <inttypes.h>
#include "mode_switch_event.h"
static const char *mode_name(enum mode_switch_mode mode)
{
switch (mode) {
case MODE_SWITCH_USB:
return "USB";
case MODE_SWITCH_24G:
return "2.4G";
case MODE_SWITCH_BLE:
return "BLE";
default:
return "?";
}
}
static void log_mode_switch_event(const struct app_event_header *aeh)
{
const struct mode_switch_event *event = cast_mode_switch_event(aeh);
APP_EVENT_MANAGER_LOG(aeh, "mode:%s voltage:%" PRIu16 "mV",
mode_name(event->mode), event->voltage_mv);
}
static void profile_mode_switch_event(struct log_event_buf *buf,
const struct app_event_header *aeh)
{
const struct mode_switch_event *event = cast_mode_switch_event(aeh);
nrf_profiler_log_encode_uint8(buf, event->mode);
nrf_profiler_log_encode_uint16(buf, event->voltage_mv);
}
APP_EVENT_INFO_DEFINE(mode_switch_event,
ENCODE(NRF_PROFILER_ARG_U8, NRF_PROFILER_ARG_U16),
ENCODE("mode", "voltage_mv"),
profile_mode_switch_event);
APP_EVENT_TYPE_DEFINE(mode_switch_event,
log_mode_switch_event,
&mode_switch_event_info,
APP_EVENT_FLAGS_CREATE(
APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE));