add Adafruit_USBD_Device::setConfigurationMaxPower() and setConfigurationAttribute

This commit is contained in:
hathach 2025-05-22 11:01:23 +07:00
parent cdc07c1d96
commit 60fb663caa
No known key found for this signature in database
GPG key ID: 26FAB84F615C3C52
2 changed files with 16 additions and 1 deletions

View file

@ -46,7 +46,7 @@ body:
- type: input
attributes:
label: TinyUSB Library version
placeholder: "Release version or github latest"
placeholder: "Release version or commit SHA"
validations:
required: true

View file

@ -80,6 +80,21 @@ public:
// Clear/Reset configuration descriptor
void clearConfiguration(void);
// Set configuration attribute
void setConfigurationAttribute(uint8_t attribute) {
_desc_cfg[offsetof(tusb_desc_configuration_t, bmAttributes)] = attribute;
}
// Set max power consumption in mA (absolute max is 510ma)
bool setConfigurationMaxPower(uint16_t power_ma) {
if (power_ma > 255 * 2u) {
return false;
}
_desc_cfg[offsetof(tusb_desc_configuration_t, bMaxPower)] =
(uint8_t)(power_ma / 2);
return true;
}
// Provide user buffer for configuration descriptor, if total length > 256
void setConfigurationBuffer(uint8_t *buf, uint32_t buflen);