comparison Output/pjrcUSB/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 970dab727f47
comparison
equal deleted inserted replaced
419:910be0f02758 420:23a1868b4ac2
1 /* Copyright (C) 2011-2015 by Jacob Alexander 1 /* Copyright (C) 2011-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
135 // Debug control variable for Output modules 135 // Debug control variable for Output modules
136 // 0 - Debug disabled (default) 136 // 0 - Debug disabled (default)
137 // 1 - Debug enabled 137 // 1 - Debug enabled
138 uint8_t Output_DebugMode = 0; 138 uint8_t Output_DebugMode = 0;
139 139
140 // mA - Set by outside module if not using USB (i.e. Interconnect)
141 // Generally set to 100 mA (low power) or 500 mA (high power)
142 uint16_t Output_ExtCurrent_Available = 0;
143
144 // mA - Set by USB module (if exists)
145 // Initially 100 mA, but may be negotiated higher (e.g. 500 mA)
146 uint16_t Output_USBCurrent_Available = 0;
147
140 148
141 149
142 // ----- Capabilities ----- 150 // ----- Capabilities -----
143 151
144 // Set Boot Keyboard Protocol 152 // Set Boot Keyboard Protocol
533 541
534 542
535 // USB Data Send 543 // USB Data Send
536 inline void Output_send() 544 inline void Output_send()
537 { 545 {
546 // USB status checks
547 // Non-standard USB state manipulation, usually does nothing
548 usb_device_check();
549
538 // Boot Mode Only, unset stale keys 550 // Boot Mode Only, unset stale keys
539 if ( USBKeys_Protocol == 0 ) 551 if ( USBKeys_Protocol == 0 )
540 for ( uint8_t c = USBKeys_Sent; c < USB_BOOT_MAX_KEYS; c++ ) 552 for ( uint8_t c = USBKeys_Sent; c < USB_BOOT_MAX_KEYS; c++ )
541 USBKeys_Keys[c] = 0; 553 USBKeys_Keys[c] = 0;
542 554
612 { 624 {
613 usb_device_software_reset(); 625 usb_device_software_reset();
614 } 626 }
615 627
616 628
629 // Update USB current (mA)
630 // Triggers power change event
631 void Output_update_usb_current( unsigned int current )
632 {
633 // Only signal if changed
634 if ( current == Output_USBCurrent_Available )
635 return;
636
637 // Update USB current
638 Output_USBCurrent_Available = current;
639
640 unsigned int total_current = Output_current_available();
641 info_msg("USB Available Current Changed. Total Available: ");
642 printInt32( total_current );
643 print(" mA" NL);
644
645 // Send new total current to the Scan Modules
646 Scan_currentChange( Output_current_available() );
647 }
648
649
650 // Update external current (mA)
651 // Triggers power change event
652 void Output_update_external_current( unsigned int current )
653 {
654 // Only signal if changed
655 if ( current == Output_ExtCurrent_Available )
656 return;
657
658 // Update external current
659 Output_ExtCurrent_Available = current;
660
661 unsigned int total_current = Output_current_available();
662 info_msg("External Available Current Changed. Total Available: ");
663 printInt32( total_current );
664 print(" mA" NL);
665
666 // Send new total current to the Scan Modules
667 Scan_currentChange( Output_current_available() );
668 }
669
670
671 // Power/Current Available
672 unsigned int Output_current_available()
673 {
674 unsigned int total_current = 0;
675
676 // Check for USB current source
677 total_current += Output_USBCurrent_Available;
678
679 // Check for external current source
680 total_current += Output_ExtCurrent_Available;
681
682 // XXX If the total available current is still 0
683 // Set to 100 mA, which is generally a safe assumption at startup
684 // before we've been able to determine actual available current
685 if ( total_current == 0 )
686 {
687 total_current = 100;
688 }
689
690 return total_current;
691 }
692
693
694
617 // ----- CLI Command Functions ----- 695 // ----- CLI Command Functions -----
618 696
619 void cliFunc_kbdProtocol( char* args ) 697 void cliFunc_kbdProtocol( char* args )
620 { 698 {
621 print( NL ); 699 print( NL );