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 17KB

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