Mercurial > louis > kiibohd-controller
comparison Output/usbMuxUart/output_com.c @ 347:136e47478441
UARTConnect enumeration working!
- Fixed cli reflash mode set
- Cleaned up debugging code
- 4 500 000 baud seems to be reliable
- Fixed master selection (assumes slave node unless USB enumerates)
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Sat, 18 Jul 2015 18:53:21 -0700 |
parents | e8841d3c6db5 |
children | 39e338a6733d |
comparison
equal
deleted
inserted
replaced
346:1beec5f17e64 | 347:136e47478441 |
---|---|
59 | 59 |
60 | 60 |
61 // ----- Function Declarations ----- | 61 // ----- Function Declarations ----- |
62 | 62 |
63 void cliFunc_kbdProtocol( char* args ); | 63 void cliFunc_kbdProtocol( char* args ); |
64 void cliFunc_outputDebug( char* args ); | |
64 void cliFunc_readLEDs ( char* args ); | 65 void cliFunc_readLEDs ( char* args ); |
65 void cliFunc_readUART ( char* args ); | 66 void cliFunc_readUART ( char* args ); |
66 void cliFunc_sendKeys ( char* args ); | 67 void cliFunc_sendKeys ( char* args ); |
67 void cliFunc_sendUART ( char* args ); | 68 void cliFunc_sendUART ( char* args ); |
68 void cliFunc_setKeys ( char* args ); | 69 void cliFunc_setKeys ( char* args ); |
72 | 73 |
73 // ----- Variables ----- | 74 // ----- Variables ----- |
74 | 75 |
75 // Output Module command dictionary | 76 // Output Module command dictionary |
76 CLIDict_Entry( kbdProtocol, "Keyboard Protocol Mode: 0 - Boot, 1 - OS/NKRO Mode" ); | 77 CLIDict_Entry( kbdProtocol, "Keyboard Protocol Mode: 0 - Boot, 1 - OS/NKRO Mode" ); |
78 CLIDict_Entry( outputDebug, "Toggle Output Debug mode." ); | |
77 CLIDict_Entry( readLEDs, "Read LED byte:" NL "\t\t1 NumLck, 2 CapsLck, 4 ScrlLck, 16 Kana, etc." ); | 79 CLIDict_Entry( readLEDs, "Read LED byte:" NL "\t\t1 NumLck, 2 CapsLck, 4 ScrlLck, 16 Kana, etc." ); |
78 CLIDict_Entry( readUART, "Read UART buffer until empty." ); | 80 CLIDict_Entry( readUART, "Read UART buffer until empty." ); |
79 CLIDict_Entry( sendKeys, "Send the prepared list of USB codes and modifier byte." ); | 81 CLIDict_Entry( sendKeys, "Send the prepared list of USB codes and modifier byte." ); |
80 CLIDict_Entry( sendUART, "Send characters over UART0." ); | 82 CLIDict_Entry( sendUART, "Send characters over UART0." ); |
81 CLIDict_Entry( setKeys, "Prepare a space separated list of USB codes (decimal). Waits until \033[35msendKeys\033[0m." ); | 83 CLIDict_Entry( setKeys, "Prepare a space separated list of USB codes (decimal). Waits until \033[35msendKeys\033[0m." ); |
82 CLIDict_Entry( setMod, "Set the modfier byte:" NL "\t\t1 LCtrl, 2 LShft, 4 LAlt, 8 LGUI, 16 RCtrl, 32 RShft, 64 RAlt, 128 RGUI" ); | 84 CLIDict_Entry( setMod, "Set the modfier byte:" NL "\t\t1 LCtrl, 2 LShft, 4 LAlt, 8 LGUI, 16 RCtrl, 32 RShft, 64 RAlt, 128 RGUI" ); |
83 | 85 |
84 CLIDict_Def( outputCLIDict, "USB Module Commands" ) = { | 86 CLIDict_Def( outputCLIDict, "USB Module Commands" ) = { |
85 CLIDict_Item( kbdProtocol ), | 87 CLIDict_Item( kbdProtocol ), |
88 CLIDict_Item( outputDebug ), | |
86 CLIDict_Item( readLEDs ), | 89 CLIDict_Item( readLEDs ), |
87 CLIDict_Item( readUART ), | 90 CLIDict_Item( readUART ), |
88 CLIDict_Item( sendKeys ), | 91 CLIDict_Item( sendKeys ), |
89 CLIDict_Item( sendUART ), | 92 CLIDict_Item( sendUART ), |
90 CLIDict_Item( setKeys ), | 93 CLIDict_Item( setKeys ), |
94 | 97 |
95 | 98 |
96 // Which modifier keys are currently pressed | 99 // Which modifier keys are currently pressed |
97 // 1=left ctrl, 2=left shift, 4=left alt, 8=left gui | 100 // 1=left ctrl, 2=left shift, 4=left alt, 8=left gui |
98 // 16=right ctrl, 32=right shift, 64=right alt, 128=right gui | 101 // 16=right ctrl, 32=right shift, 64=right alt, 128=right gui |
99 uint8_t USBKeys_Modifiers = 0; | 102 uint8_t USBKeys_Modifiers = 0; |
100 uint8_t USBKeys_ModifiersCLI = 0; // Separate CLI send buffer | 103 uint8_t USBKeys_ModifiersCLI = 0; // Separate CLI send buffer |
101 | 104 |
102 // Currently pressed keys, max is defined by USB_MAX_KEY_SEND | 105 // Currently pressed keys, max is defined by USB_MAX_KEY_SEND |
103 uint8_t USBKeys_Keys [USB_NKRO_BITFIELD_SIZE_KEYS]; | 106 uint8_t USBKeys_Keys [USB_NKRO_BITFIELD_SIZE_KEYS]; |
104 uint8_t USBKeys_KeysCLI[USB_NKRO_BITFIELD_SIZE_KEYS]; // Separate CLI send buffer | 107 uint8_t USBKeys_KeysCLI[USB_NKRO_BITFIELD_SIZE_KEYS]; // Separate CLI send buffer |
105 | 108 |
106 // System Control and Consumer Control 1KRO containers | 109 // System Control and Consumer Control 1KRO containers |
107 uint8_t USBKeys_SysCtrl; | 110 uint8_t USBKeys_SysCtrl; |
108 uint16_t USBKeys_ConsCtrl; | 111 uint16_t USBKeys_ConsCtrl; |
109 | 112 |
110 // The number of keys sent to the usb in the array | 113 // The number of keys sent to the usb in the array |
111 uint8_t USBKeys_Sent = 0; | 114 uint8_t USBKeys_Sent = 0; |
112 uint8_t USBKeys_SentCLI = 0; | 115 uint8_t USBKeys_SentCLI = 0; |
113 | 116 |
114 // 1=num lock, 2=caps lock, 4=scroll lock, 8=compose, 16=kana | 117 // 1=num lock, 2=caps lock, 4=scroll lock, 8=compose, 16=kana |
115 volatile uint8_t USBKeys_LEDs = 0; | 118 volatile uint8_t USBKeys_LEDs = 0; |
116 | 119 |
117 // Protocol setting from the host. | 120 // Protocol setting from the host. |
118 // 0 - Boot Mode | 121 // 0 - Boot Mode |
119 // 1 - NKRO Mode (Default, unless set by a BIOS or boot interface) | 122 // 1 - NKRO Mode (Default, unless set by a BIOS or boot interface) |
120 volatile uint8_t USBKeys_Protocol = 0; | 123 volatile uint8_t USBKeys_Protocol = 1; |
121 | 124 |
122 // Indicate if USB should send update | 125 // Indicate if USB should send update |
123 // OS only needs update if there has been a change in state | 126 // OS only needs update if there has been a change in state |
124 USBKeyChangeState USBKeys_Changed = USBKeyChangeState_None; | 127 USBKeyChangeState USBKeys_Changed = USBKeyChangeState_None; |
125 | 128 |
126 // the idle configuration, how often we send the report to the | 129 // the idle configuration, how often we send the report to the |
127 // host (ms * 4) even when it hasn't changed | 130 // host (ms * 4) even when it hasn't changed |
128 uint8_t USBKeys_Idle_Config = 125; | 131 uint8_t USBKeys_Idle_Config = 125; |
129 | 132 |
130 // count until idle timeout | 133 // count until idle timeout |
131 uint8_t USBKeys_Idle_Count = 0; | 134 uint8_t USBKeys_Idle_Count = 0; |
132 | 135 |
133 // Indicates whether the Output module is fully functional | 136 // Indicates whether the Output module is fully functional |
134 // 0 - Not fully functional, 1 - Fully functional | 137 // 0 - Not fully functional, 1 - Fully functional |
135 // 0 is often used to show that a USB cable is not plugged in (but has power) | 138 // 0 is often used to show that a USB cable is not plugged in (but has power) |
136 uint8_t Output_Available = 0; | 139 volatile uint8_t Output_Available = 0; |
137 | 140 |
138 // Debug control variable for Output modules | 141 // Debug control variable for Output modules |
139 // 0 - Debug disabled (default) | 142 // 0 - Debug disabled (default) |
140 // 1 - Debug enabled | 143 // 1 - Debug enabled |
141 uint8_t Output_DebugMode = 0; | 144 uint8_t Output_DebugMode = 0; |
142 | 145 |
143 | 146 |
144 | 147 |
145 // ----- Capabilities ----- | 148 // ----- Capabilities ----- |
146 | 149 |
220 if ( state == 0x01 || state == 0x03 ) | 223 if ( state == 0x01 || state == 0x03 ) |
221 USBKeys_Changed |= USBKeyChangeState_Consumer; | 224 USBKeys_Changed |= USBKeyChangeState_Consumer; |
222 | 225 |
223 // Only send keypresses if press or hold state | 226 // Only send keypresses if press or hold state |
224 if ( stateType == 0x00 && state == 0x03 ) // Release state | 227 if ( stateType == 0x00 && state == 0x03 ) // Release state |
225 return; | 228 { |
229 USBKeys_ConsCtrl = 0; | |
230 return; | |
231 } | |
226 | 232 |
227 // Set consumer control code | 233 // Set consumer control code |
228 USBKeys_ConsCtrl = *(uint16_t*)(&args[0]); | 234 USBKeys_ConsCtrl = *(uint16_t*)(&args[0]); |
229 } | 235 } |
230 | 236 |
266 if ( state == 0x01 || state == 0x03 ) | 272 if ( state == 0x01 || state == 0x03 ) |
267 USBKeys_Changed |= USBKeyChangeState_System; | 273 USBKeys_Changed |= USBKeyChangeState_System; |
268 | 274 |
269 // Only send keypresses if press or hold state | 275 // Only send keypresses if press or hold state |
270 if ( stateType == 0x00 && state == 0x03 ) // Release state | 276 if ( stateType == 0x00 && state == 0x03 ) // Release state |
271 return; | 277 { |
278 USBKeys_SysCtrl = 0; | |
279 return; | |
280 } | |
272 | 281 |
273 // Set system control code | 282 // Set system control code |
274 USBKeys_SysCtrl = args[0]; | 283 USBKeys_SysCtrl = args[0]; |
275 } | 284 } |
276 | 285 |
315 uint8_t key = args[0]; | 324 uint8_t key = args[0]; |
316 | 325 |
317 // Depending on which mode the keyboard is in, USBKeys_Keys array is used differently | 326 // Depending on which mode the keyboard is in, USBKeys_Keys array is used differently |
318 // Boot mode - Maximum of 6 byte codes | 327 // Boot mode - Maximum of 6 byte codes |
319 // NKRO mode - Each bit of the 26 byte corresponds to a key | 328 // NKRO mode - Each bit of the 26 byte corresponds to a key |
320 // Bits 0 - 160 (first 20 bytes) correspond to USB Codes 4 - 164 | 329 // Bits 0 - 45 (bytes 0 - 5) correspond to USB Codes 4 - 49 (Main) |
321 // Bits 161 - 205 (last 6 bytes) correspond to USB Codes 176 - 221 | 330 // Bits 48 - 161 (bytes 6 - 20) correspond to USB Codes 51 - 164 (Secondary) |
322 // Bits 206 - 208 (last byte) correspond to the 3 padded bits in USB (unused) | 331 // Bits 168 - 213 (bytes 21 - 26) correspond to USB Codes 176 - 221 (Tertiary) |
332 // Bits 214 - 216 unused | |
323 uint8_t bytePosition = 0; | 333 uint8_t bytePosition = 0; |
324 uint8_t byteShift = 0; | 334 uint8_t byteShift = 0; |
325 switch ( USBKeys_Protocol ) | 335 switch ( USBKeys_Protocol ) |
326 { | 336 { |
327 case 0: // Boot Mode | 337 case 0: // Boot Mode |
369 } | 379 } |
370 | 380 |
371 USBKeys_Changed |= USBKeyChangeState_Modifiers; | 381 USBKeys_Changed |= USBKeyChangeState_Modifiers; |
372 break; | 382 break; |
373 } | 383 } |
374 // First 20 bytes | 384 // First 6 bytes |
375 else if ( key >= 4 && key <= 164 ) | 385 else if ( key >= 4 && key <= 49 ) |
376 { | 386 { |
377 // Lookup (otherwise division or multiple checks are needed to do alignment) | 387 // Lookup (otherwise division or multiple checks are needed to do alignment) |
378 uint8_t keyPos = key - 4; // Starting position in array | 388 // Starting at 0th position, each byte has 8 bits, starting at 4th bit |
389 uint8_t keyPos = key + (0 * 8 - 4); // Starting position in array, Ignoring 4 keys | |
379 switch ( keyPos ) | 390 switch ( keyPos ) |
380 { | 391 { |
381 byteLookup( 0 ); | 392 byteLookup( 0 ); |
382 byteLookup( 1 ); | 393 byteLookup( 1 ); |
383 byteLookup( 2 ); | 394 byteLookup( 2 ); |
384 byteLookup( 3 ); | 395 byteLookup( 3 ); |
385 byteLookup( 4 ); | 396 byteLookup( 4 ); |
386 byteLookup( 5 ); | 397 byteLookup( 5 ); |
398 } | |
399 | |
400 USBKeys_Changed |= USBKeyChangeState_MainKeys; | |
401 } | |
402 // Next 14 bytes | |
403 else if ( key >= 51 && key <= 155 ) | |
404 { | |
405 // Lookup (otherwise division or multiple checks are needed to do alignment) | |
406 // Starting at 6th byte position, each byte has 8 bits, starting at 51st bit | |
407 uint8_t keyPos = key + (6 * 8 - 51); // Starting position in array | |
408 switch ( keyPos ) | |
409 { | |
387 byteLookup( 6 ); | 410 byteLookup( 6 ); |
388 byteLookup( 7 ); | 411 byteLookup( 7 ); |
389 byteLookup( 8 ); | 412 byteLookup( 8 ); |
390 byteLookup( 9 ); | 413 byteLookup( 9 ); |
391 byteLookup( 10 ); | 414 byteLookup( 10 ); |
398 byteLookup( 17 ); | 421 byteLookup( 17 ); |
399 byteLookup( 18 ); | 422 byteLookup( 18 ); |
400 byteLookup( 19 ); | 423 byteLookup( 19 ); |
401 } | 424 } |
402 | 425 |
403 USBKeys_Changed |= USBKeyChangeState_MainKeys; | 426 USBKeys_Changed |= USBKeyChangeState_SecondaryKeys; |
427 } | |
428 // Next byte | |
429 else if ( key >= 157 && key <= 164 ) | |
430 { | |
431 // Lookup (otherwise division or multiple checks are needed to do alignment) | |
432 uint8_t keyPos = key + (20 * 8 - 157); // Starting position in array, Ignoring 6 keys | |
433 switch ( keyPos ) | |
434 { | |
435 byteLookup( 20 ); | |
436 } | |
437 | |
438 USBKeys_Changed |= USBKeyChangeState_TertiaryKeys; | |
404 } | 439 } |
405 // Last 6 bytes | 440 // Last 6 bytes |
406 else if ( key >= 176 && key <= 221 ) | 441 else if ( key >= 176 && key <= 221 ) |
407 { | 442 { |
408 // Lookup (otherwise division or multiple checks are needed to do alignment) | 443 // Lookup (otherwise division or multiple checks are needed to do alignment) |
409 uint8_t keyPos = key - 176; // Starting position in array | 444 uint8_t keyPos = key + (21 * 8 - 176); // Starting position in array |
410 switch ( keyPos ) | 445 switch ( keyPos ) |
411 { | 446 { |
412 byteLookup( 20 ); | |
413 byteLookup( 21 ); | 447 byteLookup( 21 ); |
414 byteLookup( 22 ); | 448 byteLookup( 22 ); |
415 byteLookup( 23 ); | 449 byteLookup( 23 ); |
416 byteLookup( 24 ); | 450 byteLookup( 24 ); |
417 byteLookup( 25 ); | 451 byteLookup( 25 ); |
418 } | 452 byteLookup( 26 ); |
419 | 453 } |
420 USBKeys_Changed |= USBKeyChangeState_SecondaryKeys; | 454 |
455 USBKeys_Changed |= USBKeyChangeState_QuartiaryKeys; | |
456 } | |
457 // Received 0x00 | |
458 // This is a special USB Code that internally indicates a "break" | |
459 // It is used to send "nothing" in order to break up sequences of USB Codes | |
460 else if ( key == 0x00 ) | |
461 { | |
462 USBKeys_Changed |= USBKeyChangeState_MainKeys; | |
463 | |
464 // Also flush out buffers just in case | |
465 Output_flushBuffers(); | |
466 break; | |
421 } | 467 } |
422 // Invalid key | 468 // Invalid key |
423 else | 469 else |
424 { | 470 { |
425 warn_msg("USB Code not within 4-164 (0x4-0xA4) or 176-221 (0xB0-0xDD) NKRO Mode: "); | 471 warn_msg("USB Code not within 4-49 (0x4-0x31), 51-155 (0x33-0x9B), 157-164 (0x9D-0xA4), 176-221 (0xB0-0xDD) or 224-231 (0xE0-0xE7) NKRO Mode: "); |
426 printHex( key ); | 472 printHex( key ); |
427 print( NL ); | 473 print( NL ); |
428 break; | 474 break; |
429 } | 475 } |
430 | 476 |
465 // USB Module Setup | 511 // USB Module Setup |
466 inline void Output_setup() | 512 inline void Output_setup() |
467 { | 513 { |
468 // Setup UART | 514 // Setup UART |
469 uart_serial_setup(); | 515 uart_serial_setup(); |
470 print("\033[2J"); // Clear screen | 516 |
471 | 517 // Initialize the USB |
472 // Initialize the USB, and then wait for the host to set configuration. | 518 // If a USB connection does not exist, just ignore it |
473 // This will hang forever if USB does not initialize | 519 // All usb related functions will non-fatally fail if called |
520 // If the USB initialization is delayed, then functionality will just be delayed | |
474 usb_init(); | 521 usb_init(); |
475 | |
476 while ( !usb_configured() ); | |
477 | 522 |
478 // Register USB Output CLI dictionary | 523 // Register USB Output CLI dictionary |
479 CLI_registerDictionary( outputCLIDict, outputCLIDictName ); | 524 CLI_registerDictionary( outputCLIDict, outputCLIDictName ); |
480 | 525 |
481 // Zero out USBKeys_Keys array | 526 // Flush key buffers |
482 for ( uint8_t c = 0; c < USB_NKRO_BITFIELD_SIZE_KEYS; c++ ) | 527 Output_flushBuffers(); |
483 USBKeys_Keys[ c ] = 0; | |
484 } | 528 } |
485 | 529 |
486 | 530 |
487 // USB Data Send | 531 // USB Data Send |
488 inline void Output_send() | 532 inline void Output_send() |
494 | 538 |
495 // Send keypresses while there are pending changes | 539 // Send keypresses while there are pending changes |
496 while ( USBKeys_Changed ) | 540 while ( USBKeys_Changed ) |
497 usb_keyboard_send(); | 541 usb_keyboard_send(); |
498 | 542 |
499 // Clear modifiers and keys | 543 // Clear keys sent |
500 USBKeys_Modifiers = 0; | 544 USBKeys_Sent = 0; |
501 USBKeys_Sent = 0; | |
502 | 545 |
503 // Signal Scan Module we are finished | 546 // Signal Scan Module we are finished |
504 switch ( USBKeys_Protocol ) | 547 switch ( USBKeys_Protocol ) |
505 { | 548 { |
506 case 0: // Boot Mode | 549 case 0: // Boot Mode |
550 // Clear modifiers only in boot mode | |
551 USBKeys_Modifiers = 0; | |
507 Scan_finishedWithOutput( USBKeys_Sent <= USB_BOOT_MAX_KEYS ? USBKeys_Sent : USB_BOOT_MAX_KEYS ); | 552 Scan_finishedWithOutput( USBKeys_Sent <= USB_BOOT_MAX_KEYS ? USBKeys_Sent : USB_BOOT_MAX_KEYS ); |
508 break; | 553 break; |
509 case 1: // NKRO Mode | 554 case 1: // NKRO Mode |
510 Scan_finishedWithOutput( USBKeys_Sent ); | 555 Scan_finishedWithOutput( USBKeys_Sent ); |
511 break; | 556 break; |
512 } | 557 } |
513 } | 558 } |
514 | 559 |
515 | 560 |
516 // Sets the device into firmware reload mode | 561 // Sets the device into firmware reload mode |
517 inline void Output_firmwareReload() | 562 void Output_firmwareReload() |
518 { | 563 { |
519 uart_device_reload(); | 564 usb_device_reload(); |
520 } | 565 } |
521 | 566 |
522 | 567 |
523 // USB Input buffer available | 568 // USB Input buffer available |
524 inline unsigned int Output_availablechar() | 569 inline unsigned int Output_availablechar() |
591 info_msg("Keyboard Protocol: "); | 636 info_msg("Keyboard Protocol: "); |
592 printInt8( USBKeys_Protocol ); | 637 printInt8( USBKeys_Protocol ); |
593 } | 638 } |
594 | 639 |
595 | 640 |
596 void cliFunc_readLEDs( char* args ) | 641 void cliFunc_outputDebug( char* args ) |
597 { | |
598 print( NL ); | |
599 info_msg("LED State: "); | |
600 printInt8( USBKeys_LEDs ); | |
601 } | |
602 | |
603 | |
604 void cliFunc_readUART( char* args ) | |
605 { | |
606 print( NL ); | |
607 | |
608 // Read UART buffer until empty | |
609 while ( uart_serial_available() > 0 ) | |
610 { | |
611 char out[] = { (char)uart_serial_getchar(), '\0' }; | |
612 dPrint( out ); | |
613 } | |
614 } | |
615 | |
616 | |
617 void cliFunc_sendKeys( char* args ) | |
618 { | |
619 // Copy USBKeys_KeysCLI to USBKeys_Keys | |
620 for ( uint8_t key = 0; key < USBKeys_SentCLI; ++key ) | |
621 { | |
622 // TODO | |
623 //USBKeys_Keys[key] = USBKeys_KeysCLI[key]; | |
624 } | |
625 USBKeys_Sent = USBKeys_SentCLI; | |
626 | |
627 // Set modifier byte | |
628 USBKeys_Modifiers = USBKeys_ModifiersCLI; | |
629 } | |
630 | |
631 | |
632 void cliFunc_sendUART( char* args ) | |
633 { | |
634 // Write all args to UART | |
635 uart_serial_write( args, lenStr( args ) ); | |
636 } | |
637 | |
638 | |
639 void cliFunc_setKeys( char* args ) | |
640 { | |
641 char* curArgs; | |
642 char* arg1Ptr; | |
643 char* arg2Ptr = args; | |
644 | |
645 // Parse up to USBKeys_MaxSize args (whichever is least) | |
646 for ( USBKeys_SentCLI = 0; USBKeys_SentCLI < USB_BOOT_MAX_KEYS; ++USBKeys_SentCLI ) | |
647 { | |
648 curArgs = arg2Ptr; | |
649 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); | |
650 | |
651 // Stop processing args if no more are found | |
652 if ( *arg1Ptr == '\0' ) | |
653 break; | |
654 | |
655 // Add the USB code to be sent | |
656 // TODO | |
657 //USBKeys_KeysCLI[USBKeys_SentCLI] = numToInt( arg1Ptr ); | |
658 } | |
659 } | |
660 | |
661 | |
662 void cliFunc_setMod( char* args ) | |
663 { | 642 { |
664 // Parse number from argument | 643 // Parse number from argument |
665 // NOTE: Only first argument is used | 644 // NOTE: Only first argument is used |
666 char* arg1Ptr; | 645 char* arg1Ptr; |
667 char* arg2Ptr; | 646 char* arg2Ptr; |
668 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); | 647 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); |
669 | 648 |
649 // Default to 1 if no argument is given | |
650 Output_DebugMode = 1; | |
651 | |
652 if ( arg1Ptr[0] != '\0' ) | |
653 { | |
654 Output_DebugMode = (uint16_t)numToInt( arg1Ptr ); | |
655 } | |
656 } | |
657 | |
658 | |
659 void cliFunc_readLEDs( char* args ) | |
660 { | |
661 print( NL ); | |
662 info_msg("LED State: "); | |
663 printInt8( USBKeys_LEDs ); | |
664 } | |
665 | |
666 | |
667 void cliFunc_readUART( char* args ) | |
668 { | |
669 print( NL ); | |
670 | |
671 // Read UART buffer until empty | |
672 while ( uart_serial_available() > 0 ) | |
673 { | |
674 char out[] = { (char)uart_serial_getchar(), '\0' }; | |
675 dPrint( out ); | |
676 } | |
677 } | |
678 | |
679 | |
680 void cliFunc_sendKeys( char* args ) | |
681 { | |
682 // Copy USBKeys_KeysCLI to USBKeys_Keys | |
683 for ( uint8_t key = 0; key < USBKeys_SentCLI; ++key ) | |
684 { | |
685 // TODO | |
686 //USBKeys_Keys[key] = USBKeys_KeysCLI[key]; | |
687 } | |
688 USBKeys_Sent = USBKeys_SentCLI; | |
689 | |
690 // Set modifier byte | |
691 USBKeys_Modifiers = USBKeys_ModifiersCLI; | |
692 } | |
693 | |
694 | |
695 void cliFunc_sendUART( char* args ) | |
696 { | |
697 // Write all args to UART | |
698 uart_serial_write( args, lenStr( args ) ); | |
699 } | |
700 | |
701 | |
702 void cliFunc_setKeys( char* args ) | |
703 { | |
704 char* curArgs; | |
705 char* arg1Ptr; | |
706 char* arg2Ptr = args; | |
707 | |
708 // Parse up to USBKeys_MaxSize args (whichever is least) | |
709 for ( USBKeys_SentCLI = 0; USBKeys_SentCLI < USB_BOOT_MAX_KEYS; ++USBKeys_SentCLI ) | |
710 { | |
711 curArgs = arg2Ptr; | |
712 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); | |
713 | |
714 // Stop processing args if no more are found | |
715 if ( *arg1Ptr == '\0' ) | |
716 break; | |
717 | |
718 // Add the USB code to be sent | |
719 // TODO | |
720 //USBKeys_KeysCLI[USBKeys_SentCLI] = numToInt( arg1Ptr ); | |
721 } | |
722 } | |
723 | |
724 | |
725 void cliFunc_setMod( char* args ) | |
726 { | |
727 // Parse number from argument | |
728 // NOTE: Only first argument is used | |
729 char* arg1Ptr; | |
730 char* arg2Ptr; | |
731 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); | |
732 | |
670 USBKeys_ModifiersCLI = numToInt( arg1Ptr ); | 733 USBKeys_ModifiersCLI = numToInt( arg1Ptr ); |
671 } | 734 } |
672 | 735 |