Mercurial > louis > kiibohd-controller
comparison Scan/UARTConnect/connect_scan.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 | e7a3be42ae1e |
children | 077a1dfd8529 |
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 * This file is free software: you can redistribute it and/or modify | 3 * This file is free software: you can redistribute it and/or modify |
4 * it under the terms of the GNU General Public License as published by | 4 * it under the terms of the GNU General Public License as published by |
5 * the Free Software Foundation, either version 3 of the License, or | 5 * the Free Software Foundation, either version 3 of the License, or |
6 * (at your option) any later version. | 6 * (at your option) any later version. |
468 Connect_cableOkSlave = 0; | 468 Connect_cableOkSlave = 0; |
469 print(" Slave "); | 469 print(" Slave "); |
470 } | 470 } |
471 else | 471 else |
472 { | 472 { |
473 // Lower current requirement during errors | |
474 // USB minimum | |
475 // Only if this is not the master node | |
476 if ( Connect_id != 0 ) | |
477 { | |
478 Output_update_external_current( 100 ); | |
479 } | |
480 | |
473 Connect_cableFaultsMaster++; | 481 Connect_cableFaultsMaster++; |
474 Connect_cableOkMaster = 0; | 482 Connect_cableOkMaster = 0; |
475 print(" Master "); | 483 print(" Master "); |
476 } | 484 } |
477 printHex( byte ); | 485 printHex( byte ); |
487 { | 495 { |
488 Connect_cableChecksSlave++; | 496 Connect_cableChecksSlave++; |
489 } | 497 } |
490 else | 498 else |
491 { | 499 { |
500 // If we already have an Id, then set max current again | |
501 if ( Connect_id != 255 && Connect_id != 0 ) | |
502 { | |
503 // TODO reset to original negotiated current | |
504 Output_update_external_current( 500 ); | |
505 } | |
492 Connect_cableChecksMaster++; | 506 Connect_cableChecksMaster++; |
493 } | 507 } |
494 } | 508 } |
495 } | 509 } |
496 | 510 |
557 // Set the device id | 571 // Set the device id |
558 Connect_id = id; | 572 Connect_id = id; |
559 | 573 |
560 // Send reponse back to master | 574 // Send reponse back to master |
561 Connect_send_IdReport( id ); | 575 Connect_send_IdReport( id ); |
576 | |
577 // Node now enumerated, set external power to USB Max | |
578 // Only set if this is not the master node | |
579 // TODO Determine power slice for each node as part of protocol | |
580 if ( Connect_id != 0 ) | |
581 { | |
582 Output_update_external_current( 500 ); | |
583 } | |
562 | 584 |
563 // Propogate next Id if the connection is ok | 585 // Propogate next Id if the connection is ok |
564 if ( Connect_cableOkSlave ) | 586 if ( Connect_cableOkSlave ) |
565 { | 587 { |
566 Connect_send_IdEnumeration( id + 1 ); | 588 Connect_send_IdEnumeration( id + 1 ); |
1172 | 1194 |
1173 // Process Rx Buffers | 1195 // Process Rx Buffers |
1174 Connect_rx_process( 0 ); | 1196 Connect_rx_process( 0 ); |
1175 Connect_rx_process( 1 ); | 1197 Connect_rx_process( 1 ); |
1176 } | 1198 } |
1199 } | |
1200 | |
1201 | |
1202 // Called by parent Scan module whenever the available current changes | |
1203 void Connect_currentChange( unsigned int current ) | |
1204 { | |
1205 // TODO - Any potential power saving here? | |
1177 } | 1206 } |
1178 | 1207 |
1179 | 1208 |
1180 | 1209 |
1181 // ----- CLI Command Functions ----- | 1210 // ----- CLI Command Functions ----- |