Best way to adjust the USB ConfigDescriptor bMaxPower in 1.0.1 on a Leonardo?

Hi all,
I've been playing with what is ostensibly a Leonardo clone - the Freetronics LeoStick. I've compiled the new Arduino 1.0.1 Caterina bootloader and using the new 1.0.1 USBCore.cpp/.h files etc.

The current USB_CONFIG_POWER_MA Macro used as part of the D_CONFIG macro called out of USBCore.cpp is hardcoded at 500ma.
This can cause errors to appear when plugging the device into many Keyboard based USB Ports or Hubs. I'm lead to believe particularly on MacOSX ?

So I've tried to hack in, unfortunately (I hate modifying core code :frowning: ) the ability to alter this in a sketch, so you can set it in the setup() function. Is this the best way to do this?
This works, and allows you to set any arbitrary integer value to be used for the negotiation of the sketch comport.

Edit USBCore.cpp . Around line 47 or so, you'll see

extern const DeviceDescriptor USB_DeviceDescriptorA PROGMEM;

Add the line

int usbMaxPower = 500;

Edit USBCore.h. Edit the D_CONFIG define around line 284 to be:

#define D_CONFIG(_totalLength,_interfaces) \
   { 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED, USB_CONFIG_POWER_MA(usbMaxPower) }

By default, it will now negotiate 500ma. However in your sketch, at the top, define

extern int usbMaxPower

Then you can do in setup(), before calling any USB descriptors (i.e, one of the first things)

usbMaxPower = 100;

Voila! Script defineable usbMaxPower values... albeit very klunky and involving hacks to the USBCore.cpp/USBCore.h - which I was trying to avoid.

Is this the best way to accomplish this for now with 1.0.1 ?

Adrian

No comments ? Or is this in the wrong Forum ?

No comments ?

How many people do you suppose have Leonardos already?

PaulS:
How many people do you suppose have Leonardos already?

I was asking broadly - Theres still a general programming question though ? Anyway.. no worries..