Mercurial > louis > kiibohd-controller
comparison 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 |
comparison
equal
deleted
inserted
replaced
419:910be0f02758 | 420:23a1868b4ac2 |
---|---|
1 /* Copyright (C) 2014-2015 by Jacob Alexander | 1 /* Copyright (C) 2014-2016 by Jacob Alexander |
2 * | 2 * |
3 * Permission is hereby granted, free of charge, to any person obtaining a copy | 3 * Permission is hereby granted, free of charge, to any person obtaining a copy |
4 * of this software and associated documentation files (the "Software"), to deal | 4 * of this software and associated documentation files (the "Software"), to deal |
5 * in the Software without restriction, including without limitation the rights | 5 * in the Software without restriction, including without limitation the rights |
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
140 | 140 |
141 // Debug control variable for Output modules | 141 // Debug control variable for Output modules |
142 // 0 - Debug disabled (default) | 142 // 0 - Debug disabled (default) |
143 // 1 - Debug enabled | 143 // 1 - Debug enabled |
144 uint8_t Output_DebugMode = 0; | 144 uint8_t Output_DebugMode = 0; |
145 | |
146 // mA - Set by outside module if not using USB (i.e. Interconnect) | |
147 // Generally set to 100 mA (low power) or 500 mA (high power) | |
148 uint16_t Output_ExtCurrent_Available = 0; | |
149 | |
150 // mA - Set by USB module (if exists) | |
151 // Initially 100 mA, but may be negotiated higher (e.g. 500 mA) | |
152 uint16_t Output_USBCurrent_Available = 0; | |
145 | 153 |
146 | 154 |
147 | 155 |
148 // ----- Capabilities ----- | 156 // ----- Capabilities ----- |
149 | 157 |
542 | 550 |
543 | 551 |
544 // USB Data Send | 552 // USB Data Send |
545 inline void Output_send() | 553 inline void Output_send() |
546 { | 554 { |
555 // USB status checks | |
556 // Non-standard USB state manipulation, usually does nothing | |
557 usb_device_check(); | |
558 | |
547 // Boot Mode Only, unset stale keys | 559 // Boot Mode Only, unset stale keys |
548 if ( USBKeys_Protocol == 0 ) | 560 if ( USBKeys_Protocol == 0 ) |
549 for ( uint8_t c = USBKeys_Sent; c < USB_BOOT_MAX_KEYS; c++ ) | 561 for ( uint8_t c = USBKeys_Sent; c < USB_BOOT_MAX_KEYS; c++ ) |
550 USBKeys_Keys[c] = 0; | 562 USBKeys_Keys[c] = 0; |
551 | 563 |
639 { | 651 { |
640 usb_device_software_reset(); | 652 usb_device_software_reset(); |
641 } | 653 } |
642 | 654 |
643 | 655 |
656 // Update USB current (mA) | |
657 // Triggers power change event | |
658 void Output_update_usb_current( unsigned int current ) | |
659 { | |
660 // Only signal if changed | |
661 if ( current == Output_USBCurrent_Available ) | |
662 return; | |
663 | |
664 // Update USB current | |
665 Output_USBCurrent_Available = current; | |
666 | |
667 unsigned int total_current = Output_current_available(); | |
668 info_msg("USB Available Current Changed. Total Available: "); | |
669 printInt32( total_current ); | |
670 print(" mA" NL); | |
671 | |
672 // Send new total current to the Scan Modules | |
673 Scan_currentChange( Output_current_available() ); | |
674 } | |
675 | |
676 | |
677 // Update external current (mA) | |
678 // Triggers power change event | |
679 void Output_update_external_current( unsigned int current ) | |
680 { | |
681 // Only signal if changed | |
682 if ( current == Output_ExtCurrent_Available ) | |
683 return; | |
684 | |
685 // Update external current | |
686 Output_ExtCurrent_Available = current; | |
687 | |
688 unsigned int total_current = Output_current_available(); | |
689 info_msg("External Available Current Changed. Total Available: "); | |
690 printInt32( total_current ); | |
691 print(" mA" NL); | |
692 | |
693 // Send new total current to the Scan Modules | |
694 Scan_currentChange( Output_current_available() ); | |
695 } | |
696 | |
697 | |
698 // Power/Current Available | |
699 unsigned int Output_current_available() | |
700 { | |
701 unsigned int total_current = 0; | |
702 | |
703 // Check for USB current source | |
704 total_current += Output_USBCurrent_Available; | |
705 | |
706 // Check for external current source | |
707 total_current += Output_ExtCurrent_Available; | |
708 | |
709 // XXX If the total available current is still 0 | |
710 // Set to 100 mA, which is generally a safe assumption at startup | |
711 // before we've been able to determine actual available current | |
712 if ( total_current == 0 ) | |
713 { | |
714 total_current = 100; | |
715 } | |
716 | |
717 return total_current; | |
718 } | |
719 | |
720 | |
721 | |
644 // ----- CLI Command Functions ----- | 722 // ----- CLI Command Functions ----- |
645 | 723 |
646 void cliFunc_kbdProtocol( char* args ) | 724 void cliFunc_kbdProtocol( char* args ) |
647 { | 725 { |
648 print( NL ); | 726 print( NL ); |