2026-04-10 13:46:50 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
#include "hid_tx_report_event.h"
|
|
|
|
|
|
|
|
|
|
#define HID_TX_REPORT_EVENT_LOG_BUF_LEN 192
|
|
|
|
|
|
2026-04-15 15:47:14 +08:00
|
|
|
static const char *channel_name(enum hid_send_channel channel)
|
2026-04-10 13:46:50 +08:00
|
|
|
{
|
2026-04-15 15:47:14 +08:00
|
|
|
switch (channel) {
|
|
|
|
|
case HID_SEND_CH_USB_KEYS:
|
|
|
|
|
return "usb_keys";
|
|
|
|
|
case HID_SEND_CH_USB_CONSUMER:
|
|
|
|
|
return "usb_consumer";
|
|
|
|
|
case HID_SEND_CH_BLE_SHARED:
|
|
|
|
|
return "ble_shared";
|
2026-04-10 13:46:50 +08:00
|
|
|
default:
|
|
|
|
|
return "?";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *report_type_name(enum keyboard_report_type report_type)
|
|
|
|
|
{
|
|
|
|
|
switch (report_type) {
|
|
|
|
|
case KEYBOARD_REPORT_TYPE_KEYS:
|
|
|
|
|
return "keys";
|
|
|
|
|
case KEYBOARD_REPORT_TYPE_CONSUMER:
|
|
|
|
|
return "consumer";
|
|
|
|
|
default:
|
|
|
|
|
return "?";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *protocol_mode_name(enum keyboard_protocol_mode protocol_mode)
|
|
|
|
|
{
|
|
|
|
|
switch (protocol_mode) {
|
|
|
|
|
case KEYBOARD_PROTOCOL_MODE_BOOT:
|
|
|
|
|
return "boot";
|
|
|
|
|
case KEYBOARD_PROTOCOL_MODE_REPORT:
|
|
|
|
|
return "report";
|
|
|
|
|
default:
|
|
|
|
|
return "?";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void log_hid_tx_report_event(const struct app_event_header *aeh)
|
|
|
|
|
{
|
|
|
|
|
const struct hid_tx_report_event *event = cast_hid_tx_report_event(aeh);
|
|
|
|
|
char log_buf[HID_TX_REPORT_EVENT_LOG_BUF_LEN];
|
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
|
|
pos = snprintf(log_buf, sizeof(log_buf),
|
2026-04-15 15:47:14 +08:00
|
|
|
"channel:%s type:%s protocol:%s seq:%u len:%zu",
|
|
|
|
|
channel_name(event->channel),
|
2026-04-10 13:46:50 +08:00
|
|
|
report_type_name(event->report_type),
|
|
|
|
|
protocol_mode_name(event->protocol_mode),
|
|
|
|
|
event->sequence,
|
|
|
|
|
event->dyndata.size);
|
|
|
|
|
if ((pos > 0) && (pos < sizeof(log_buf))) {
|
|
|
|
|
for (size_t i = 0; i < event->dyndata.size; i++) {
|
|
|
|
|
int tmp = snprintf(&log_buf[pos], sizeof(log_buf) - pos,
|
|
|
|
|
" %02x", event->dyndata.data[i]);
|
|
|
|
|
|
|
|
|
|
if (tmp < 0) {
|
|
|
|
|
log_buf[sizeof(log_buf) - 2] = '~';
|
|
|
|
|
pos = tmp;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pos += tmp;
|
|
|
|
|
if (pos >= sizeof(log_buf)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pos < 0) {
|
|
|
|
|
APP_EVENT_MANAGER_LOG(aeh, "log message preparation failure");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APP_EVENT_MANAGER_LOG(aeh, "%s", log_buf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void profile_hid_tx_report_event(struct log_event_buf *buf,
|
|
|
|
|
const struct app_event_header *aeh)
|
|
|
|
|
{
|
|
|
|
|
const struct hid_tx_report_event *event = cast_hid_tx_report_event(aeh);
|
|
|
|
|
|
2026-04-15 15:47:14 +08:00
|
|
|
nrf_profiler_log_encode_uint8(buf, event->channel);
|
2026-04-10 13:46:50 +08:00
|
|
|
nrf_profiler_log_encode_uint8(buf, event->report_type);
|
|
|
|
|
nrf_profiler_log_encode_uint8(buf, event->protocol_mode);
|
|
|
|
|
nrf_profiler_log_encode_uint16(buf, event->sequence);
|
|
|
|
|
nrf_profiler_log_encode_uint8(buf, (uint8_t)event->dyndata.size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APP_EVENT_INFO_DEFINE(hid_tx_report_event,
|
|
|
|
|
ENCODE(NRF_PROFILER_ARG_U8,
|
|
|
|
|
NRF_PROFILER_ARG_U8,
|
|
|
|
|
NRF_PROFILER_ARG_U8,
|
|
|
|
|
NRF_PROFILER_ARG_U16,
|
|
|
|
|
NRF_PROFILER_ARG_U8),
|
2026-04-15 15:47:14 +08:00
|
|
|
ENCODE("channel", "report_type", "protocol_mode", "sequence", "len"),
|
2026-04-10 13:46:50 +08:00
|
|
|
profile_hid_tx_report_event);
|
|
|
|
|
|
|
|
|
|
APP_EVENT_TYPE_DEFINE(hid_tx_report_event,
|
|
|
|
|
log_hid_tx_report_event,
|
|
|
|
|
&hid_tx_report_event_info,
|
|
|
|
|
APP_EVENT_FLAGS_CREATE(
|
|
|
|
|
APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE));
|