Mercurial > louis > kiibohd-controller
diff Output/usbMuxUart/output_com.c @ 420:23a1868b4ac2
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)
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Sun, 21 Feb 2016 19:56:52 -0800 |
parents | d8f61e15aca1 |
children | f10c2dad7f55 |
line wrap: on
line diff
--- a/Output/usbMuxUart/output_com.c Sun Feb 21 14:19:52 2016 -0800 +++ b/Output/usbMuxUart/output_com.c Sun Feb 21 19:56:52 2016 -0800 @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2015 by Jacob Alexander +/* Copyright (C) 2014-2016 by Jacob Alexander * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -143,6 +143,14 @@ // 1 - Debug enabled uint8_t Output_DebugMode = 0; +// mA - Set by outside module if not using USB (i.e. Interconnect) +// Generally set to 100 mA (low power) or 500 mA (high power) +uint16_t Output_ExtCurrent_Available = 0; + +// mA - Set by USB module (if exists) +// Initially 100 mA, but may be negotiated higher (e.g. 500 mA) +uint16_t Output_USBCurrent_Available = 0; + // ----- Capabilities ----- @@ -544,6 +552,10 @@ // USB Data Send inline void Output_send() { + // USB status checks + // Non-standard USB state manipulation, usually does nothing + usb_device_check(); + // Boot Mode Only, unset stale keys if ( USBKeys_Protocol == 0 ) for ( uint8_t c = USBKeys_Sent; c < USB_BOOT_MAX_KEYS; c++ ) @@ -641,6 +653,72 @@ } +// Update USB current (mA) +// Triggers power change event +void Output_update_usb_current( unsigned int current ) +{ + // Only signal if changed + if ( current == Output_USBCurrent_Available ) + return; + + // Update USB current + Output_USBCurrent_Available = current; + + unsigned int total_current = Output_current_available(); + info_msg("USB Available Current Changed. Total Available: "); + printInt32( total_current ); + print(" mA" NL); + + // Send new total current to the Scan Modules + Scan_currentChange( Output_current_available() ); +} + + +// Update external current (mA) +// Triggers power change event +void Output_update_external_current( unsigned int current ) +{ + // Only signal if changed + if ( current == Output_ExtCurrent_Available ) + return; + + // Update external current + Output_ExtCurrent_Available = current; + + unsigned int total_current = Output_current_available(); + info_msg("External Available Current Changed. Total Available: "); + printInt32( total_current ); + print(" mA" NL); + + // Send new total current to the Scan Modules + Scan_currentChange( Output_current_available() ); +} + + +// Power/Current Available +unsigned int Output_current_available() +{ + unsigned int total_current = 0; + + // Check for USB current source + total_current += Output_USBCurrent_Available; + + // Check for external current source + total_current += Output_ExtCurrent_Available; + + // XXX If the total available current is still 0 + // Set to 100 mA, which is generally a safe assumption at startup + // before we've been able to determine actual available current + if ( total_current == 0 ) + { + total_current = 100; + } + + return total_current; +} + + + // ----- CLI Command Functions ----- void cliFunc_kbdProtocol( char* args )