2026-04-15 09:30:40 +08:00
|
|
|
#include <caf/events/module_state_event.h>
|
|
|
|
|
|
|
|
|
|
#include "usb_state_event.h"
|
|
|
|
|
|
2026-04-15 15:13:44 +08:00
|
|
|
static const char *usb_state_name(enum usb_state state)
|
2026-04-15 09:30:40 +08:00
|
|
|
{
|
2026-04-15 15:13:44 +08:00
|
|
|
switch (state) {
|
|
|
|
|
case USB_STATE_DISABLED:
|
|
|
|
|
return "disabled";
|
|
|
|
|
case USB_STATE_DISCONNECTED:
|
|
|
|
|
return "disconnected";
|
|
|
|
|
case USB_STATE_POWERED:
|
|
|
|
|
return "powered";
|
|
|
|
|
case USB_STATE_ACTIVE:
|
|
|
|
|
return "active";
|
|
|
|
|
case USB_STATE_SUSPENDED:
|
|
|
|
|
return "suspended";
|
2026-04-15 09:30:40 +08:00
|
|
|
default:
|
|
|
|
|
return "?";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void log_usb_state_event(const struct app_event_header *aeh)
|
|
|
|
|
{
|
|
|
|
|
const struct usb_state_event *event = cast_usb_state_event(aeh);
|
|
|
|
|
|
2026-04-15 15:13:44 +08:00
|
|
|
APP_EVENT_MANAGER_LOG(aeh, "state:%s", usb_state_name(event->state));
|
2026-04-15 09:30:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void profile_usb_state_event(struct log_event_buf *buf,
|
|
|
|
|
const struct app_event_header *aeh)
|
|
|
|
|
{
|
|
|
|
|
const struct usb_state_event *event = cast_usb_state_event(aeh);
|
|
|
|
|
|
2026-04-15 15:13:44 +08:00
|
|
|
nrf_profiler_log_encode_uint8(buf, event->state);
|
2026-04-15 09:30:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APP_EVENT_INFO_DEFINE(usb_state_event,
|
2026-04-15 15:13:44 +08:00
|
|
|
ENCODE(NRF_PROFILER_ARG_U8),
|
|
|
|
|
ENCODE("state"),
|
2026-04-15 09:30:40 +08:00
|
|
|
profile_usb_state_event);
|
|
|
|
|
|
|
|
|
|
APP_EVENT_TYPE_DEFINE(usb_state_event,
|
|
|
|
|
log_usb_state_event,
|
|
|
|
|
&usb_state_event_info,
|
|
|
|
|
APP_EVENT_FLAGS_CREATE(
|
|
|
|
|
APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE));
|