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.

matrix_scan.c 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /* Copyright (C) 2014-2016 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 <kll_defs.h>
  27. #include <led.h>
  28. #include <print.h>
  29. #include <macro.h>
  30. #include <Lib/delay.h>
  31. // Local Includes
  32. #include "matrix_scan.h"
  33. // Matrix Configuration
  34. #include <matrix.h>
  35. // ----- Defines -----
  36. #if ( DebounceThrottleDiv_define > 0 )
  37. nat_ptr_t Matrix_divCounter = 0;
  38. #endif
  39. // ----- Function Declarations -----
  40. // CLI Functions
  41. void cliFunc_matrixDebug( char* args );
  42. void cliFunc_matrixInfo( char* args );
  43. void cliFunc_matrixState( char* args );
  44. // ----- Variables -----
  45. // Scan Module command dictionary
  46. CLIDict_Entry( matrixDebug, "Enables matrix debug mode, prints out each scan code." NL "\t\tIf argument \033[35mT\033[0m is given, prints out each scan code state transition." );
  47. CLIDict_Entry( matrixInfo, "Print info about the configured matrix." );
  48. CLIDict_Entry( matrixState, "Prints out the current scan table N times." NL "\t\t \033[1mO\033[0m - Off, \033[1;33mP\033[0m - Press, \033[1;32mH\033[0m - Hold, \033[1;35mR\033[0m - Release, \033[1;31mI\033[0m - Invalid" );
  49. CLIDict_Def( matrixCLIDict, "Matrix Module Commands" ) = {
  50. CLIDict_Item( matrixDebug ),
  51. CLIDict_Item( matrixInfo ),
  52. CLIDict_Item( matrixState ),
  53. { 0, 0, 0 } // Null entry for dictionary end
  54. };
  55. // Debounce Array
  56. KeyState Matrix_scanArray[ Matrix_colsNum * Matrix_rowsNum ];
  57. // Ghost Arrays
  58. #ifdef GHOSTING_MATRIX
  59. KeyGhost Matrix_ghostArray[ Matrix_colsNum * Matrix_rowsNum ];
  60. uint8_t col_use[Matrix_colsNum], row_use[Matrix_rowsNum]; // used count
  61. uint8_t col_ghost[Matrix_colsNum], row_ghost[Matrix_rowsNum]; // marked as having ghost if 1
  62. uint8_t col_ghost_old[Matrix_colsNum], row_ghost_old[Matrix_rowsNum]; // old ghost state
  63. #endif
  64. // Matrix debug flag - If set to 1, for each keypress the scan code is displayed in hex
  65. // If set to 2, for each key state change, the scan code is displayed along with the state
  66. uint8_t matrixDebugMode = 0;
  67. // Matrix State Table Debug Counter - If non-zero display state table after every matrix scan
  68. uint16_t matrixDebugStateCounter = 0;
  69. // Matrix Scan Counters
  70. uint16_t matrixMaxScans = 0;
  71. uint16_t matrixCurScans = 0;
  72. uint16_t matrixPrevScans = 0;
  73. // System Timer used for delaying debounce decisions
  74. extern volatile uint32_t systick_millis_count;
  75. // ----- Functions -----
  76. // Pin action (Strobe, Sense, Strobe Setup, Sense Setup)
  77. // NOTE: This function is highly dependent upon the organization of the register map
  78. // Only guaranteed to work with Freescale MK20 series uCs
  79. uint8_t Matrix_pin( GPIO_Pin gpio, Type type )
  80. {
  81. // Register width is defined as size of a pointer
  82. unsigned int gpio_offset = gpio.port * 0x40 / sizeof(unsigned int*);
  83. unsigned int port_offset = gpio.port * 0x1000 / sizeof(unsigned int*) + gpio.pin;
  84. // Assumes 0x40 between GPIO Port registers and 0x1000 between PORT pin registers
  85. // See Lib/mk20dx.h
  86. volatile unsigned int *GPIO_PDDR = (unsigned int*)(&GPIOA_PDDR) + gpio_offset;
  87. #ifndef GHOSTING_MATRIX
  88. volatile unsigned int *GPIO_PSOR = (unsigned int*)(&GPIOA_PSOR) + gpio_offset;
  89. #endif
  90. volatile unsigned int *GPIO_PCOR = (unsigned int*)(&GPIOA_PCOR) + gpio_offset;
  91. volatile unsigned int *GPIO_PDIR = (unsigned int*)(&GPIOA_PDIR) + gpio_offset;
  92. volatile unsigned int *PORT_PCR = (unsigned int*)(&PORTA_PCR0) + port_offset;
  93. // Operation depends on Type
  94. switch ( type )
  95. {
  96. case Type_StrobeOn:
  97. #ifdef GHOSTING_MATRIX
  98. *GPIO_PCOR |= (1 << gpio.pin);
  99. *GPIO_PDDR |= (1 << gpio.pin); // output, low
  100. #else
  101. *GPIO_PSOR |= (1 << gpio.pin);
  102. #endif
  103. break;
  104. case Type_StrobeOff:
  105. #ifdef GHOSTING_MATRIX
  106. // Ghosting martix needs to put not used (off) strobes in high impedance state
  107. *GPIO_PDDR &= ~(1 << gpio.pin); // input, high Z state
  108. #endif
  109. *GPIO_PCOR |= (1 << gpio.pin);
  110. break;
  111. case Type_StrobeSetup:
  112. #ifdef GHOSTING_MATRIX
  113. *GPIO_PDDR &= ~(1 << gpio.pin); // input, high Z state
  114. *GPIO_PCOR |= (1 << gpio.pin);
  115. #else
  116. // Set as output pin
  117. *GPIO_PDDR |= (1 << gpio.pin);
  118. #endif
  119. // Configure pin with slow slew, high drive strength and GPIO mux
  120. *PORT_PCR = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
  121. // Enabling open-drain if specified
  122. switch ( Matrix_type )
  123. {
  124. case Config_Opendrain:
  125. *PORT_PCR |= PORT_PCR_ODE;
  126. break;
  127. // Do nothing otherwise
  128. default:
  129. break;
  130. }
  131. break;
  132. case Type_Sense:
  133. #ifdef GHOSTING_MATRIX // inverted
  134. return *GPIO_PDIR & (1 << gpio.pin) ? 0 : 1;
  135. #else
  136. return *GPIO_PDIR & (1 << gpio.pin) ? 1 : 0;
  137. #endif
  138. case Type_SenseSetup:
  139. // Set as input pin
  140. *GPIO_PDDR &= ~(1 << gpio.pin);
  141. // Configure pin with passive filter and GPIO mux
  142. *PORT_PCR = PORT_PCR_PFE | PORT_PCR_MUX(1);
  143. // Pull resistor config
  144. switch ( Matrix_type )
  145. {
  146. case Config_Pullup:
  147. *PORT_PCR |= PORT_PCR_PE | PORT_PCR_PS;
  148. break;
  149. case Config_Pulldown:
  150. *PORT_PCR |= PORT_PCR_PE;
  151. break;
  152. // Do nothing otherwise
  153. default:
  154. break;
  155. }
  156. break;
  157. }
  158. return 0;
  159. }
  160. // Setup GPIO pins for matrix scanning
  161. void Matrix_setup()
  162. {
  163. // Register Matrix CLI dictionary
  164. CLI_registerDictionary( matrixCLIDict, matrixCLIDictName );
  165. // Setup Strobe Pins
  166. for ( uint8_t pin = 0; pin < Matrix_colsNum; pin++ )
  167. {
  168. Matrix_pin( Matrix_cols[ pin ], Type_StrobeSetup );
  169. #ifdef GHOSTING_MATRIX
  170. col_use[pin] = 0;
  171. col_ghost[pin] = 0;
  172. col_ghost_old[pin] = 0;
  173. #endif
  174. }
  175. // Setup Sense Pins
  176. for ( uint8_t pin = 0; pin < Matrix_rowsNum; pin++ )
  177. {
  178. Matrix_pin( Matrix_rows[ pin ], Type_SenseSetup );
  179. #ifdef GHOSTING_MATRIX
  180. row_use[pin] = 0;
  181. row_ghost[pin] = 0;
  182. row_ghost_old[pin] = 0;
  183. #endif
  184. }
  185. // Clear out Debounce Array
  186. for ( uint8_t item = 0; item < Matrix_maxKeys; item++ )
  187. {
  188. Matrix_scanArray[ item ].prevState = KeyState_Off;
  189. Matrix_scanArray[ item ].curState = KeyState_Off;
  190. Matrix_scanArray[ item ].activeCount = 0;
  191. Matrix_scanArray[ item ].inactiveCount = DebounceDivThreshold_define; // Start at 'off' steady state
  192. Matrix_scanArray[ item ].prevDecisionTime = 0;
  193. #ifdef GHOSTING_MATRIX
  194. Matrix_ghostArray[ item ].prev = KeyState_Off;
  195. Matrix_ghostArray[ item ].cur = KeyState_Off;
  196. Matrix_ghostArray[ item ].saved = KeyState_Off;
  197. #endif
  198. }
  199. // Clear scan stats counters
  200. matrixMaxScans = 0;
  201. matrixPrevScans = 0;
  202. }
  203. void Matrix_keyPositionDebug( KeyPosition pos )
  204. {
  205. // Depending on the state, use a different flag + color
  206. switch ( pos )
  207. {
  208. case KeyState_Off:
  209. print("\033[1mO\033[0m");
  210. break;
  211. case KeyState_Press:
  212. print("\033[1;33mP\033[0m");
  213. break;
  214. case KeyState_Hold:
  215. print("\033[1;32mH\033[0m");
  216. break;
  217. case KeyState_Release:
  218. print("\033[1;35mR\033[0m");
  219. break;
  220. case KeyState_Invalid:
  221. default:
  222. print("\033[1;31mI\033[0m");
  223. break;
  224. }
  225. }
  226. // Scan the matrix for keypresses
  227. // NOTE: scanNum should be reset to 0 after a USB send (to reset all the counters)
  228. void Matrix_scan( uint16_t scanNum )
  229. {
  230. #if ( DebounceThrottleDiv_define > 0 )
  231. // Scan-rate throttling
  232. // By scanning using a divider, the scan rate slowed down
  233. // DebounceThrottleDiv_define == 1 means -> /2 or half scan rate
  234. // This helps with bouncy switches on fast uCs
  235. if ( !( Matrix_divCounter++ & (1 << ( DebounceThrottleDiv_define - 1 )) ) )
  236. return;
  237. #endif
  238. // Increment stats counters
  239. if ( scanNum > matrixMaxScans ) matrixMaxScans = scanNum;
  240. if ( scanNum == 0 )
  241. {
  242. matrixPrevScans = matrixCurScans;
  243. matrixCurScans = 0;
  244. }
  245. else
  246. {
  247. matrixCurScans++;
  248. }
  249. // Read systick for event scheduling
  250. uint8_t currentTime = (uint8_t)systick_millis_count;
  251. // For each strobe, scan each of the sense pins
  252. for ( uint8_t strobe = 0; strobe < Matrix_colsNum; strobe++ )
  253. {
  254. #ifdef STROBE_DELAY
  255. uint32_t start = micros();
  256. while ((micros() - start) < STROBE_DELAY);
  257. #endif
  258. // Strobe Pin
  259. Matrix_pin( Matrix_cols[ strobe ], Type_StrobeOn );
  260. #ifdef STROBE_DELAY
  261. start = micros();
  262. while ((micros() - start) < STROBE_DELAY);
  263. #endif
  264. // Scan each of the sense pins
  265. for ( uint8_t sense = 0; sense < Matrix_rowsNum; sense++ )
  266. {
  267. // Key position
  268. uint8_t key = Matrix_colsNum * sense + strobe;
  269. KeyState *state = &Matrix_scanArray[ key ];
  270. // If first scan, reset state
  271. if ( scanNum == 0 )
  272. {
  273. // Set previous state, and reset current state
  274. state->prevState = state->curState;
  275. state->curState = KeyState_Invalid;
  276. }
  277. // Signal Detected
  278. // Increment count and right shift opposing count
  279. // This means there is a maximum of scan 13 cycles on a perfect off to on transition
  280. // (coming from a steady state 0xFFFF off scans)
  281. // Somewhat longer with switch bounciness
  282. // The advantage of this is that the count is ongoing and never needs to be reset
  283. // State still needs to be kept track of to deal with what to send to the Macro module
  284. if ( Matrix_pin( Matrix_rows[ sense ], Type_Sense ) )
  285. {
  286. // Only update if not going to wrap around
  287. if ( state->activeCount < DebounceDivThreshold_define ) state->activeCount += 1;
  288. state->inactiveCount >>= 1;
  289. }
  290. // Signal Not Detected
  291. else
  292. {
  293. // Only update if not going to wrap around
  294. if ( state->inactiveCount < DebounceDivThreshold_define ) state->inactiveCount += 1;
  295. state->activeCount >>= 1;
  296. }
  297. // Check for state change if it hasn't been set
  298. // But only if enough time has passed since last state change
  299. // Only check if the minimum number of scans has been met
  300. // the current state is invalid
  301. // and either active or inactive count is over the debounce threshold
  302. if ( state->curState == KeyState_Invalid )
  303. {
  304. // Determine time since last decision
  305. uint8_t lastTransition = currentTime - state->prevDecisionTime;
  306. // Attempt state transition
  307. switch ( state->prevState )
  308. {
  309. case KeyState_Press:
  310. case KeyState_Hold:
  311. if ( state->activeCount > state->inactiveCount )
  312. {
  313. state->curState = KeyState_Hold;
  314. }
  315. else
  316. {
  317. // If not enough time has passed since Hold
  318. // Keep previous state
  319. if ( lastTransition < MinDebounceTime_define )
  320. {
  321. //warn_print("FAST Release stopped");
  322. state->curState = state->prevState;
  323. continue;
  324. }
  325. state->curState = KeyState_Release;
  326. }
  327. break;
  328. case KeyState_Release:
  329. case KeyState_Off:
  330. if ( state->activeCount > state->inactiveCount )
  331. {
  332. // If not enough time has passed since Hold
  333. // Keep previous state
  334. if ( lastTransition < MinDebounceTime_define )
  335. {
  336. //warn_print("FAST Press stopped");
  337. state->curState = state->prevState;
  338. continue;
  339. }
  340. state->curState = KeyState_Press;
  341. }
  342. else
  343. {
  344. state->curState = KeyState_Off;
  345. }
  346. break;
  347. case KeyState_Invalid:
  348. default:
  349. erro_print("Matrix scan bug!! Report me!");
  350. break;
  351. }
  352. // Update decision time
  353. state->prevDecisionTime = currentTime;
  354. // Send keystate to macro module
  355. #ifndef GHOSTING_MATRIX
  356. Macro_keyState( key, state->curState );
  357. #endif
  358. // Matrix Debug, only if there is a state change
  359. if ( matrixDebugMode && state->curState != state->prevState )
  360. {
  361. // Basic debug output
  362. if ( matrixDebugMode == 1 && state->curState == KeyState_Press )
  363. {
  364. printHex( key );
  365. print(" ");
  366. }
  367. // State transition debug output
  368. else if ( matrixDebugMode == 2 )
  369. {
  370. printHex( key );
  371. Matrix_keyPositionDebug( state->curState );
  372. print(" ");
  373. }
  374. }
  375. }
  376. }
  377. // Unstrobe Pin
  378. Matrix_pin( Matrix_cols[ strobe ], Type_StrobeOff );
  379. }
  380. // Matrix ghosting check and elimination
  381. // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  382. #ifdef GHOSTING_MATRIX
  383. // strobe = column, sense = row
  384. // Count (rows) use for columns
  385. for ( uint8_t col = 0; col < Matrix_colsNum; col++ )
  386. {
  387. uint8_t used = 0;
  388. for ( uint8_t row = 0; row < Matrix_rowsNum; row++ )
  389. {
  390. uint8_t key = Matrix_colsNum * row + col;
  391. KeyState *state = &Matrix_scanArray[ key ];
  392. if ( keyOn(state->curState) )
  393. used++;
  394. }
  395. col_use[col] = used;
  396. col_ghost_old[col] = col_ghost[col];
  397. col_ghost[col] = 0; // clear
  398. }
  399. // Count (columns) use for rows
  400. for ( uint8_t row = 0; row < Matrix_rowsNum; row++ )
  401. {
  402. uint8_t used = 0;
  403. for ( uint8_t col = 0; col < Matrix_colsNum; col++ )
  404. {
  405. uint8_t key = Matrix_colsNum * row + col;
  406. KeyState *state = &Matrix_scanArray[ key ];
  407. if ( keyOn(state->curState) )
  408. used++;
  409. }
  410. row_use[row] = used;
  411. row_ghost_old[row] = row_ghost[row];
  412. row_ghost[row] = 0; // clear
  413. }
  414. // Check if matrix has ghost
  415. // Happens when key is pressed and some other key is pressed in same row and another in same column
  416. for ( uint8_t col = 0; col < Matrix_colsNum; col++ )
  417. {
  418. for ( uint8_t row = 0; row < Matrix_rowsNum; row++ )
  419. {
  420. uint8_t key = Matrix_colsNum * row + col;
  421. KeyState *state = &Matrix_scanArray[ key ];
  422. if ( keyOn(state->curState) && col_use[col] >= 2 && row_use[row] >= 2 )
  423. {
  424. // mark col and row as having ghost
  425. col_ghost[col] = 1;
  426. row_ghost[row] = 1;
  427. }
  428. }
  429. }
  430. // Send keys
  431. for ( uint8_t col = 0; col < Matrix_colsNum; col++ )
  432. {
  433. for ( uint8_t row = 0; row < Matrix_rowsNum; row++ )
  434. {
  435. uint8_t key = Matrix_colsNum * row + col;
  436. KeyState *state = &Matrix_scanArray[ key ];
  437. KeyGhost *st = &Matrix_ghostArray[ key ];
  438. // col or row is ghosting (crossed)
  439. uint8_t ghost = (col_ghost[col] > 0 || row_ghost[row] > 0) ? 1 : 0;
  440. uint8_t ghost_old = (col_ghost_old[col] > 0 || row_ghost_old[row] > 0) ? 1 : 0;
  441. ghost = ghost || ghost_old ? 1 : 0;
  442. st->prev = st->cur; // previous
  443. // save state if no ghost or outside ghosted area
  444. if ( ghost == 0 )
  445. st->saved = state->curState; // save state if no ghost
  446. // final
  447. // use saved state if ghosting, or current if not
  448. st->cur = ghost > 0 ? st->saved : state->curState;
  449. // Send keystate to macro module
  450. KeyPosition k = !st->cur
  451. ? (!st->prev ? KeyState_Off : KeyState_Release)
  452. : ( st->prev ? KeyState_Hold : KeyState_Press);
  453. Macro_keyState( key, k );
  454. }
  455. }
  456. #endif
  457. // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  458. // State Table Output Debug
  459. if ( matrixDebugStateCounter > 0 )
  460. {
  461. // Decrement counter
  462. matrixDebugStateCounter--;
  463. // Output stats on number of scans being done per USB send
  464. print( NL );
  465. info_msg("Max scans: ");
  466. printHex( matrixMaxScans );
  467. print( NL );
  468. info_msg("Previous scans: ");
  469. printHex( matrixPrevScans );
  470. print( NL );
  471. // Output current scan number
  472. info_msg("Scan Number: ");
  473. printHex( scanNum );
  474. print( NL );
  475. // Display the state info for each key
  476. print("<key>:<previous state><current state> <active count> <inactive count>");
  477. for ( uint8_t key = 0; key < Matrix_maxKeys; key++ )
  478. {
  479. // Every 4 keys, put a newline
  480. if ( key % 4 == 0 )
  481. print( NL );
  482. print("\033[1m0x");
  483. printHex_op( key, 2 );
  484. print("\033[0m");
  485. print(":");
  486. Matrix_keyPositionDebug( Matrix_scanArray[ key ].prevState );
  487. Matrix_keyPositionDebug( Matrix_scanArray[ key ].curState );
  488. print(" 0x");
  489. printHex_op( Matrix_scanArray[ key ].activeCount, 4 );
  490. print(" 0x");
  491. printHex_op( Matrix_scanArray[ key ].inactiveCount, 4 );
  492. print(" ");
  493. }
  494. print( NL );
  495. }
  496. }
  497. // Called by parent scan module whenever the available current changes
  498. // current - mA
  499. void Matrix_currentChange( unsigned int current )
  500. {
  501. // TODO - Any potential power savings?
  502. }
  503. // ----- CLI Command Functions -----
  504. void cliFunc_matrixInfo( char* args )
  505. {
  506. print( NL );
  507. info_msg("Columns: ");
  508. printHex( Matrix_colsNum );
  509. print( NL );
  510. info_msg("Rows: ");
  511. printHex( Matrix_rowsNum );
  512. print( NL );
  513. info_msg("Max Keys: ");
  514. printHex( Matrix_maxKeys );
  515. }
  516. void cliFunc_matrixDebug( char* args )
  517. {
  518. // Parse number from argument
  519. // NOTE: Only first argument is used
  520. char* arg1Ptr;
  521. char* arg2Ptr;
  522. CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
  523. // Set the matrix debug flag depending on the argument
  524. // If no argument, set to scan code only
  525. // If set to T, set to state transition
  526. switch ( arg1Ptr[0] )
  527. {
  528. // T as argument
  529. case 'T':
  530. case 't':
  531. matrixDebugMode = matrixDebugMode != 2 ? 2 : 0;
  532. break;
  533. // No argument
  534. case '\0':
  535. matrixDebugMode = matrixDebugMode != 1 ? 1 : 0;
  536. break;
  537. // Invalid argument
  538. default:
  539. return;
  540. }
  541. print( NL );
  542. info_msg("Matrix Debug Mode: ");
  543. printInt8( matrixDebugMode );
  544. }
  545. void cliFunc_matrixState( char* args )
  546. {
  547. // Parse number from argument
  548. // NOTE: Only first argument is used
  549. char* arg1Ptr;
  550. char* arg2Ptr;
  551. CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
  552. // Default to 1 if no argument is given
  553. matrixDebugStateCounter = 1;
  554. if ( arg1Ptr[0] != '\0' )
  555. {
  556. matrixDebugStateCounter = (uint16_t)numToInt( arg1Ptr );
  557. }
  558. }