Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting of USB Power parameter #421

Open
DisasterAreaDesigns opened this issue May 26, 2024 · 0 comments
Open

Allow setting of USB Power parameter #421

DisasterAreaDesigns opened this issue May 26, 2024 · 0 comments
Labels
Feature New feature or request

Comments

@DisasterAreaDesigns
Copy link

Many USB hosts have power limits and will refuse to connect if a device reports a power requirement higher than this limit. For example, the Apple Camera Connection kit will report an error if the user attempts to connect a device that reports a 100mA requirement, but will succeed on a 20mA device.

This parameter appears to be set in Adafruit_USBD_Device.cpp:

// Config number, interface count, string index, total length, // attribute (bit 7 set to 1), power in mA. // Note: Total Length Interface Number will be updated later uint8_t const dev_cfg[sizeof(tusb_desc_configuration_t)] = { TUD_CONFIG_DESCRIPTOR(1, 0, 0, sizeof(tusb_desc_configuration_t), TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP | TU_BIT(7), 100), };

The 100mA power value is thus fixed in the library and can't be changed without editing the .cpp file here. That also means that any changes made to the file are replaced by library updates.

There is a define in the file, USB_CONFIG_POWER which defaults to 100. I think the idea would be to allow this to be editable in the variant file for your particular board, which makes it a lot less dangerous since it will rarely be changed.

Thus, I propose this change:

// Config number, interface count, string index, total length, // attribute (bit 7 set to 1), power in mA. // Note: Total Length Interface Number will be updated later uint8_t const dev_cfg[sizeof(tusb_desc_configuration_t)] = { TUD_CONFIG_DESCRIPTOR(1, 0, 0, sizeof(tusb_desc_configuration_t), TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP | TU_BIT(7), USB_CONFIG_POWER), };

... which would then allow a user to use:

#define USB_CONFIG_POWER <myVal>

... to change the power reporting. Note that this has nothing to do with the actual power the board requires, just like the current value of 100mA is not rooted in reality! But it's useful for setting this value for picky hosts.

I suspect most users are fine with the 100mA limitation but my application requires a device that can report a lower power requirement.

@DisasterAreaDesigns DisasterAreaDesigns added the Feature New feature or request label May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant