Adding dynamic USB power support

- Each scan module now has a current change callback which passes the available current as a parameter
- No longer attempts to use the max 500 mA immediately, starts with 100 mA then goes to 500 mA after enumeration
- If enumeration fails due to bMaxPower of 500 mA, then attempt again at 100 mA (might also be possible to go even lower to 20 mA in certain cases)
- Now working with the Apple Ipad (no over-power messages)
- Fixed Wake-up behaviour on Apple Ipad (and likely other iOS devices)
- More effecient set_feature/clear_feature handling (device handler)
- Initial power handling via Interconnect (still needs work to get it more dynamic)
This commit is contained in:
Jacob Alexander 2016-02-21 19:56:52 -08:00
parent 62ba0c558b
commit aaae9bc0f2
29 changed files with 503 additions and 48 deletions

View file

@ -1,5 +1,5 @@
// Originally Generated from MCHCK Toolkit
/* Copyright (c) Jacob Alexander 2014-2015 <haata@kiibohd.com>
/* Copyright (c) Jacob Alexander 2014-2016 <haata@kiibohd.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -38,7 +38,7 @@ static const struct usb_config_1 usb_config_1 = {
.bConfigurationValue = 1,
.iConfiguration = 0,
.one = 1,
.bMaxPower = 100
.bMaxPower = 50
},
.usb_function_0 = {
.iface = {

View file

@ -1,5 +1,5 @@
/* Copyright (c) 2011,2012 Simon Schubert <2@0x2c.org>.
* Modifications by Jacob Alexander 2014-2015 <haata@kiibohd.com>
* Modifications by Jacob Alexander 2014-2016 <haata@kiibohd.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -241,8 +241,11 @@ void main()
GPIOA_PCOR |= (1<<13);
#define USBPortSwapDelay_ms 1000
#define USBPortSwapIncrement_ms 100
// For keyboards with dual usb ports, doesn't do anything on keyboards without them
// If a USB connection is not detected in 2 seconds, switch to the other port to see if it's plugged in there
// If a USB connection is not detected in 1 second, switch to the other port to see if it's plugged in there
// Incremement the delay by 100 ms each attempt, just in case the device is slow
uint32_t attempt = 0;
uint32_t last_ms = systick_millis_count;
for (;;)
{
@ -250,7 +253,7 @@ void main()
// Only check for swapping after delay
uint32_t wait_ms = systick_millis_count - last_ms;
if ( wait_ms < USBPortSwapDelay_ms )
if ( wait_ms < USBPortSwapDelay_ms + attempt * USBPortSwapIncrement_ms )
{
continue;
}
@ -262,6 +265,7 @@ void main()
{
print("USB not initializing, port swapping (if supported)");
GPIOA_PTOR |= (1<<13);
attempt++;
}
}
#else