6static const char*
TAG =
"UsbManager";
48uint8_t UsbManager::activeHidCount()
const {
50 for (
const auto& entry : entries_) {
51 if (entry.active) count++;
63 return activeHidCount() < MAX_ACTIVE_HID;
75 const uint8_t idx =
static_cast<uint8_t
>(type);
76 if (idx >= (
sizeof(entries_) /
sizeof(entries_[0])))
return false;
78 auto& entry = entries_[idx];
80 if (entry.owner && moduleName && strcmp(entry.owner, moduleName) == 0) {
83 LOG_W(
TAG,
"Interface %d already owned by %s", idx, entry.owner ? entry.owner :
"?");
87 if (!canActivate(type)) {
88 LOG_W(
TAG,
"HID interface limit reached (max %d)", MAX_ACTIVE_HID);
93 entry.owner = moduleName;
95 activeMask_ |= (1u << idx);
96 LOG_I(
TAG,
"Registered HID interface %d for %s", idx, moduleName ? moduleName :
"?");
107 const uint8_t idx =
static_cast<uint8_t
>(type);
108 if (idx >= (
sizeof(entries_) /
sizeof(entries_[0])))
return;
110 auto& entry = entries_[idx];
111 if (!entry.active)
return;
112 if (entry.owner && moduleName && strcmp(entry.owner, moduleName) != 0) {
113 LOG_W(
TAG,
"Interface %d owned by %s, not %s", idx,
114 entry.owner ? entry.owner :
"?", moduleName ? moduleName :
"?");
118 entry.active =
false;
119 entry.owner =
nullptr;
121 activeMask_ &= ~(1u << idx);
122 LOG_I(
TAG,
"Unregistered HID interface %d", idx);
131 needsReplug_ =
false;
136 const auto& entry = entries_[
static_cast<uint8_t
>(type)];
137 if (!entry.active)
return;
138 defs[count++] = entry.def;
145 bool replug_needed =
false;
147 if (!ok || replug_needed) {
CDC Log: logging over TinyUSB CDC and UART.
#define LOG_W(tag, fmt,...)
#define LOG_I(tag, fmt,...)
bool init() override
Initializes USB manager service state.
bool registerInterface(UsbHidInterface type, const char *moduleName, const UsbInterfaceSpec &def)
Registers a HID interface request from a module.
bool start() override
Starts USB manager service state.
static UsbManager & instance()
Returns singleton USB manager instance.
void unregisterInterface(UsbHidInterface type, const char *moduleName)
Unregisters a previously registered HID interface.
void stop() override
Stops USB manager service state.
bool applyConfiguration()
Applies current interface set to USB HID stack.
bool usb_hid_apply_config(const UsbInterfaceDef *defs, size_t count, bool *needs_replug)
Applies the runtime interface configuration and optionally triggers re-enumeration.