20 uint16_t (*
onGetReport)(uint8_t report_id, uint8_t report_type,
21 uint8_t* buffer, uint16_t reqlen) =
nullptr;
23 uint8_t
const* buffer, uint16_t bufsize) =
nullptr;
29 const char*
name =
nullptr;
56 const char*
getName()
const override {
return "UsbManager"; }
59 bool start()
override;
94 bool hidSlotsFull()
const {
return activeHidCount() >= MAX_ACTIVE_HID; }
105 return !wasNeededBefore && needsReplug_;
109 struct InterfaceEntry {
111 const char* owner =
nullptr;
115 uint8_t activeHidCount()
const;
119 uint8_t endpointsInUse()
const;
120 static uint8_t interfaceEndpoints(
const UsbInterfaceSpec& def);
122 static constexpr uint8_t MAX_ACTIVE_HID = 2;
125 static constexpr uint8_t MAX_ENDPOINTS = 8;
126 static constexpr uint8_t CDC_ENDPOINTS = 3;
127 static constexpr uint8_t MSC_ENDPOINTS = 2;
130 uint8_t activeMask_ = 0;
131 bool needsReplug_ =
false;
132 bool mscActive_ =
false;
133 const char* mscOwner_ =
nullptr;
134 InterfaceEntry entries_[3] = {};
bool init() override
Initializes USB manager service state.
bool registerMassStorage(const char *owner)
Registers the single USB Mass Storage LUN and re-enumerates.
bool registerInterface(UsbHidInterface type, const char *moduleName, const UsbInterfaceSpec &def)
Registers a HID interface request from a module.
const char * getName() const override
bool hidSlotsFull() const
Reports whether the HID interface budget is exhausted.
ServiceState getState() const override
bool newlyRequiresReplug(bool wasNeededBefore) const
Tests whether a toggle newly introduced a replug requirement.
bool start() override
Starts USB manager service state.
bool massStorageActive() const
Reports whether the MSC LUN is currently active.
void unregisterMassStorage(const char *owner)
Unregisters the MSC LUN and re-enumerates (drive disappears).
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.
uint8_t activeInterfaceMask() const
bool applyConfiguration()
Applies current interface set to USB HID stack.
void(* onReportComplete)(uint8_t const *report, uint16_t len)
void(* onSetReport)(uint8_t report_id, uint8_t report_type, uint8_t const *buffer, uint16_t bufsize)
uint16_t(* onGetReport)(uint8_t report_id, uint8_t report_type, uint8_t *buffer, uint16_t reqlen)
const uint8_t * reportDesc
UsbHidCallbacks callbacks