feat(keyboard): 添加蓝牙HID支持和电池状态事件

- 添加BLE相关模块:ble_adv_ctrl_module、ble_adv_uuid16、ble_bas_module、
  ble_hid_module
- 新增电池状态事件(bat_state_event)用于监控电池电量、充电状态
- 在多个事件中添加HID_TRANSPORT_BLE支持,包括hid_led_event、
  set_protocol_event等
- 更新配置文件prj.conf以启用蓝牙功能、HID服务和设置系统
- 修改电池模块以计算并报告电池SOC百分比
- 集成CAF设置加载器以管理蓝牙配对信息
This commit is contained in:
2026-04-10 19:28:20 +08:00
parent b9b7d342f5
commit 39d2962258
21 changed files with 1186 additions and 60 deletions

View File

@@ -0,0 +1,32 @@
#include "bat_state_event.h"
static void log_bat_state_event(const struct app_event_header *aeh)
{
const struct bat_state_event *event = cast_bat_state_event(aeh);
APP_EVENT_MANAGER_LOG(aeh, "soc:%u charging:%u full:%u",
event->soc, event->charging, event->full);
}
static void profile_bat_state_event(struct log_event_buf *buf,
const struct app_event_header *aeh)
{
const struct bat_state_event *event = cast_bat_state_event(aeh);
nrf_profiler_log_encode_uint8(buf, event->soc);
nrf_profiler_log_encode_uint8(buf, event->charging);
nrf_profiler_log_encode_uint8(buf, event->full);
}
APP_EVENT_INFO_DEFINE(bat_state_event,
ENCODE(NRF_PROFILER_ARG_U8,
NRF_PROFILER_ARG_U8,
NRF_PROFILER_ARG_U8),
ENCODE("soc", "charging", "full"),
profile_bat_state_event);
APP_EVENT_TYPE_DEFINE(bat_state_event,
log_bat_state_event,
&bat_state_event_info,
APP_EVENT_FLAGS_CREATE(
APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE));

View File

@@ -1,10 +1,23 @@
#include "hid_led_event.h"
static const char *transport_name(enum hid_transport transport)
{
switch (transport) {
case HID_TRANSPORT_USB:
return "USB";
case HID_TRANSPORT_BLE:
return "BLE";
default:
return "?";
}
}
static void log_hid_led_event(const struct app_event_header *aeh)
{
const struct hid_led_event *event = cast_hid_led_event(aeh);
APP_EVENT_MANAGER_LOG(aeh, "led_bm:0x%02x", event->led_bm);
APP_EVENT_MANAGER_LOG(aeh, "transport:%s led_bm:0x%02x",
transport_name(event->transport), event->led_bm);
}
static void profile_hid_led_event(struct log_event_buf *buf,
@@ -12,12 +25,13 @@ static void profile_hid_led_event(struct log_event_buf *buf,
{
const struct hid_led_event *event = cast_hid_led_event(aeh);
nrf_profiler_log_encode_uint8(buf, event->transport);
nrf_profiler_log_encode_uint8(buf, event->led_bm);
}
APP_EVENT_INFO_DEFINE(hid_led_event,
ENCODE(NRF_PROFILER_ARG_U8),
ENCODE("led_bm"),
ENCODE(NRF_PROFILER_ARG_U8, NRF_PROFILER_ARG_U8),
ENCODE("transport", "led_bm"),
profile_hid_led_event);
APP_EVENT_TYPE_DEFINE(hid_led_event,

View File

@@ -5,6 +5,8 @@ static const char *transport_name(enum hid_transport transport)
switch (transport) {
case HID_TRANSPORT_USB:
return "USB";
case HID_TRANSPORT_BLE:
return "BLE";
default:
return "?";
}

View File

@@ -5,6 +5,8 @@ static const char *transport_name(enum hid_transport transport)
switch (transport) {
case HID_TRANSPORT_USB:
return "USB";
case HID_TRANSPORT_BLE:
return "BLE";
default:
return "?";
}

View File

@@ -9,6 +9,8 @@ static const char *transport_name(enum hid_transport transport)
switch (transport) {
case HID_TRANSPORT_USB:
return "USB";
case HID_TRANSPORT_BLE:
return "BLE";
default:
return "?";
}

View File

@@ -1,5 +1,17 @@
#include "set_protocol_event.h"
static const char *transport_name(enum hid_transport transport)
{
switch (transport) {
case HID_TRANSPORT_USB:
return "USB";
case HID_TRANSPORT_BLE:
return "BLE";
default:
return "?";
}
}
static const char *protocol_mode_name(enum keyboard_protocol_mode protocol_mode)
{
switch (protocol_mode) {
@@ -16,7 +28,8 @@ static void log_set_protocol_event(const struct app_event_header *aeh)
{
const struct set_protocol_event *event = cast_set_protocol_event(aeh);
APP_EVENT_MANAGER_LOG(aeh, "protocol:%s",
APP_EVENT_MANAGER_LOG(aeh, "transport:%s protocol:%s",
transport_name(event->transport),
protocol_mode_name(event->protocol_mode));
}
@@ -25,12 +38,13 @@ static void profile_set_protocol_event(struct log_event_buf *buf,
{
const struct set_protocol_event *event = cast_set_protocol_event(aeh);
nrf_profiler_log_encode_uint8(buf, event->transport);
nrf_profiler_log_encode_uint8(buf, event->protocol_mode);
}
APP_EVENT_INFO_DEFINE(set_protocol_event,
ENCODE(NRF_PROFILER_ARG_U8),
ENCODE("protocol_mode"),
ENCODE(NRF_PROFILER_ARG_U8, NRF_PROFILER_ARG_U8),
ENCODE("transport", "protocol_mode"),
profile_set_protocol_event);
APP_EVENT_TYPE_DEFINE(set_protocol_event,