Kiibohd Controller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* Copyright (C) 2014 by Jacob Alexander
  2. *
  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
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. */
  21. // ----- Includes -----
  22. // Compiler Includes
  23. #include <Lib/ScanLib.h>
  24. // Project Includes
  25. #include <cli.h>
  26. #include <led.h>
  27. #include <print.h>
  28. // Local Includes
  29. #include "scan_loop.h"
  30. // ----- Defines -----
  31. // ----- Macros -----
  32. // ----- Function Declarations -----
  33. void cliFunc_dac ( char* args );
  34. void cliFunc_dacVref( char* args );
  35. void cliFunc_echo ( char* args );
  36. // ----- Variables -----
  37. // Buffer used to inform the macro processing module which keys have been detected as pressed
  38. volatile uint8_t KeyIndex_Buffer[KEYBOARD_BUFFER];
  39. volatile uint8_t KeyIndex_BufferUsed;
  40. // Scan Module command dictionary
  41. char* scanCLIDictName = "ADC Test Module Commands";
  42. CLIDictItem scanCLIDict[] = {
  43. #if defined(_mk20dx256_) // DAC is only supported on Teensy 3.1
  44. { "dac", "Set DAC output value, from 0 to 4095 (1/4096 Vref to Vref).", cliFunc_dac },
  45. { "dacVref", "Set DAC Vref. 0 is 1.2V. 1 is 3.3V.", cliFunc_dacVref },
  46. #endif
  47. { "echo", "Example command, echos the arguments.", cliFunc_echo },
  48. { 0, 0, 0 } // Null entry for dictionary end
  49. };
  50. // ----- Functions -----
  51. // Setup
  52. inline void Scan_setup()
  53. #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
  54. {
  55. // Register Scan CLI dictionary
  56. CLI_registerDictionary( scanCLIDict, scanCLIDictName );
  57. }
  58. #elif defined(_mk20dx128_) || defined(_mk20dx256_) // ARM
  59. {
  60. // Register Scan CLI dictionary
  61. CLI_registerDictionary( scanCLIDict, scanCLIDictName );
  62. #if defined(_mk20dx256_) // DAC is only supported on Teensy 3.1
  63. // DAC Setup
  64. SIM_SCGC2 |= SIM_SCGC2_DAC0;
  65. DAC0_C0 = DAC_C0_DACEN | DAC_C0_DACRFS; // 3.3V VDDA is DACREF_2
  66. #endif
  67. }
  68. #endif
  69. // Main Detection Loop
  70. inline uint8_t Scan_loop()
  71. {
  72. return 0;
  73. }
  74. // Signal KeyIndex_Buffer that it has been properly read
  75. void Scan_finishedWithBuffer( uint8_t sentKeys )
  76. {
  77. }
  78. // Signal that the keys have been properly sent over USB
  79. void Scan_finishedWithUSBBuffer( uint8_t sentKeys )
  80. {
  81. }
  82. // Reset Keyboard
  83. void Scan_resetKeyboard()
  84. {
  85. }
  86. // ----- CLI Command Functions -----
  87. // XXX Just an example command showing how to parse arguments (more complex than generally needed)
  88. void cliFunc_echo( char* args )
  89. {
  90. char* curArgs;
  91. char* arg1Ptr;
  92. char* arg2Ptr = args;
  93. print( NL ); // No \n by default after the command is entered
  94. // Parse args until a \0 is found
  95. while ( 1 )
  96. {
  97. curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list
  98. CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
  99. // Stop processing args if no more are found
  100. if ( *arg1Ptr == '\0' )
  101. break;
  102. // Print out the arg
  103. dPrint( arg1Ptr );
  104. }
  105. }
  106. void cliFunc_dac( char* args )
  107. {
  108. #if defined(_mk20dx256_) // DAC is only supported on Teensy 3.1
  109. // Parse code from argument
  110. // NOTE: Only first argument is used
  111. char* arg1Ptr;
  112. char* arg2Ptr;
  113. CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
  114. int dacOut = decToInt( arg1Ptr );
  115. // Make sure the value is between 0 and 4096, otherwise ignore
  116. if ( dacOut >= 0 && dacOut <= 4095 )
  117. {
  118. *(int16_t *) &(DAC0_DAT0L) = dacOut;
  119. }
  120. #endif
  121. }
  122. void cliFunc_dacVref( char* args )
  123. {
  124. #if defined(_mk20dx256_) // DAC is only supported on Teensy 3.1
  125. // Parse code from argument
  126. // NOTE: Only first argument is used
  127. char* arg1Ptr;
  128. char* arg2Ptr;
  129. CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
  130. switch ( decToInt( arg1Ptr ) )
  131. {
  132. case 0:
  133. // XXX Doesn't seem to work...
  134. DAC0_C0 = DAC_C0_DACEN; // 1.2V ref is DACREF_1
  135. break;
  136. case 1:
  137. DAC0_C0 = DAC_C0_DACEN | DAC_C0_DACRFS; // 3.3V VDDA is DACREF_2
  138. break;
  139. }
  140. #endif
  141. }