Mercurial > louis > kiibohd-controller
comparison Scan/MatrixARM/matrix_scan.c @ 436:ac7a07c54b70
Revert "Fixed ghosting matrix check (did send bad keys on release), now using…"
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Fri, 13 May 2016 14:38:05 -0700 |
parents | eae9fd6acc9a |
children | 94ef7b561d7d |
comparison
equal
deleted
inserted
replaced
435:d4388d80d651 | 436:ac7a07c54b70 |
---|---|
78 #ifdef GHOSTING_MATRIX | 78 #ifdef GHOSTING_MATRIX |
79 KeyGhost Matrix_ghostArray[ Matrix_colsNum * Matrix_rowsNum ]; | 79 KeyGhost Matrix_ghostArray[ Matrix_colsNum * Matrix_rowsNum ]; |
80 | 80 |
81 uint8_t col_use[Matrix_colsNum], row_use[Matrix_rowsNum]; // used count | 81 uint8_t col_use[Matrix_colsNum], row_use[Matrix_rowsNum]; // used count |
82 uint8_t col_ghost[Matrix_colsNum], row_ghost[Matrix_rowsNum]; // marked as having ghost if 1 | 82 uint8_t col_ghost[Matrix_colsNum], row_ghost[Matrix_rowsNum]; // marked as having ghost if 1 |
83 uint8_t col_ghost_old[Matrix_colsNum], row_ghost_old[Matrix_rowsNum]; // old ghost state | |
84 #endif | 83 #endif |
85 | 84 |
86 | 85 |
87 // Matrix debug flag - If set to 1, for each keypress the scan code is displayed in hex | 86 // Matrix debug flag - If set to 1, for each keypress the scan code is displayed in hex |
88 // If set to 2, for each key state change, the scan code is displayed along with the state | 87 // If set to 2, for each key state change, the scan code is displayed along with the state |
210 | 209 |
211 // Setup Strobe Pins | 210 // Setup Strobe Pins |
212 for ( uint8_t pin = 0; pin < Matrix_colsNum; pin++ ) | 211 for ( uint8_t pin = 0; pin < Matrix_colsNum; pin++ ) |
213 { | 212 { |
214 Matrix_pin( Matrix_cols[ pin ], Type_StrobeSetup ); | 213 Matrix_pin( Matrix_cols[ pin ], Type_StrobeSetup ); |
215 col_use[pin] = 0; | |
216 col_ghost[pin] = 0; | |
217 col_ghost_old[pin] = 0; | |
218 } | 214 } |
219 | 215 |
220 // Setup Sense Pins | 216 // Setup Sense Pins |
221 for ( uint8_t pin = 0; pin < Matrix_rowsNum; pin++ ) | 217 for ( uint8_t pin = 0; pin < Matrix_rowsNum; pin++ ) |
222 { | 218 { |
223 Matrix_pin( Matrix_rows[ pin ], Type_SenseSetup ); | 219 Matrix_pin( Matrix_rows[ pin ], Type_SenseSetup ); |
224 row_use[pin] = 0; | |
225 row_ghost[pin] = 0; | |
226 row_ghost_old[pin] = 0; | |
227 } | 220 } |
228 | 221 |
229 // Clear out Debounce Array | 222 // Clear out Debounce Array |
230 for ( uint8_t item = 0; item < Matrix_maxKeys; item++ ) | 223 for ( uint8_t item = 0; item < Matrix_maxKeys; item++ ) |
231 { | 224 { |
453 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | 446 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . |
454 #ifdef GHOSTING_MATRIX | 447 #ifdef GHOSTING_MATRIX |
455 // strobe = column, sense = row | 448 // strobe = column, sense = row |
456 | 449 |
457 // Count (rows) use for columns | 450 // Count (rows) use for columns |
451 //print("C "); | |
458 for ( uint8_t col = 0; col < Matrix_colsNum; col++ ) | 452 for ( uint8_t col = 0; col < Matrix_colsNum; col++ ) |
459 { | 453 { |
460 uint8_t used = 0; | 454 uint8_t used = 0; |
461 for ( uint8_t row = 0; row < Matrix_rowsNum; row++ ) | 455 for ( uint8_t row = 0; row < Matrix_rowsNum; row++ ) |
462 { | 456 { |
463 uint8_t key = Matrix_colsNum * row + col; | 457 uint8_t key = Matrix_colsNum * row + col; |
464 KeyState *state = &Matrix_scanArray[ key ]; | 458 KeyState *state = &Matrix_scanArray[ key ]; |
465 if ( keyOn(state->curState) ) | 459 if ( keyOn(state->curState) ) |
466 used++; | 460 used++; |
467 } | 461 } |
462 //printInt8(used); | |
468 col_use[col] = used; | 463 col_use[col] = used; |
469 col_ghost_old[col] = col_ghost[col]; | |
470 col_ghost[col] = 0; // clear | 464 col_ghost[col] = 0; // clear |
471 } | 465 } |
472 | 466 |
473 // Count (columns) use for rows | 467 // Count (columns) use for rows |
468 //print(" R "); | |
474 for ( uint8_t row = 0; row < Matrix_rowsNum; row++ ) | 469 for ( uint8_t row = 0; row < Matrix_rowsNum; row++ ) |
475 { | 470 { |
476 uint8_t used = 0; | 471 uint8_t used = 0; |
477 for ( uint8_t col = 0; col < Matrix_colsNum; col++ ) | 472 for ( uint8_t col = 0; col < Matrix_colsNum; col++ ) |
478 { | 473 { |
479 uint8_t key = Matrix_colsNum * row + col; | 474 uint8_t key = Matrix_colsNum * row + col; |
480 KeyState *state = &Matrix_scanArray[ key ]; | 475 KeyState *state = &Matrix_scanArray[ key ]; |
481 if ( keyOn(state->curState) ) | 476 if ( keyOn(state->curState) ) |
482 used++; | 477 used++; |
483 } | 478 } |
479 //printInt8(used); | |
484 row_use[row] = used; | 480 row_use[row] = used; |
485 row_ghost_old[row] = row_ghost[row]; | |
486 row_ghost[row] = 0; // clear | 481 row_ghost[row] = 0; // clear |
487 } | 482 } |
488 | 483 |
489 // Check if matrix has ghost | 484 // Check if matrix has ghost |
490 // Happens when key is pressed and some other key is pressed in same row and another in same column | 485 // Happens when key is pressed and some other key is pressed in same row and another in same column |
486 //print(" G "); | |
491 for ( uint8_t col = 0; col < Matrix_colsNum; col++ ) | 487 for ( uint8_t col = 0; col < Matrix_colsNum; col++ ) |
492 { | 488 { |
493 for ( uint8_t row = 0; row < Matrix_rowsNum; row++ ) | 489 for ( uint8_t row = 0; row < Matrix_rowsNum; row++ ) |
494 { | 490 { |
495 uint8_t key = Matrix_colsNum * row + col; | 491 uint8_t key = Matrix_colsNum * row + col; |
497 if ( keyOn(state->curState) && col_use[col] >= 2 && row_use[row] >= 2 ) | 493 if ( keyOn(state->curState) && col_use[col] >= 2 && row_use[row] >= 2 ) |
498 { | 494 { |
499 // mark col and row as having ghost | 495 // mark col and row as having ghost |
500 col_ghost[col] = 1; | 496 col_ghost[col] = 1; |
501 row_ghost[row] = 1; | 497 row_ghost[row] = 1; |
498 //print(" "); printInt8(col); print(","); printInt8(row); | |
502 } | 499 } |
503 } | 500 } |
504 } | 501 } |
502 //print( NL ); | |
505 | 503 |
506 // Send keys | 504 // Send keys |
507 for ( uint8_t col = 0; col < Matrix_colsNum; col++ ) | 505 for ( uint8_t col = 0; col < Matrix_colsNum; col++ ) |
508 { | 506 { |
509 for ( uint8_t row = 0; row < Matrix_rowsNum; row++ ) | 507 for ( uint8_t row = 0; row < Matrix_rowsNum; row++ ) |
512 KeyState *state = &Matrix_scanArray[ key ]; | 510 KeyState *state = &Matrix_scanArray[ key ]; |
513 KeyGhost *st = &Matrix_ghostArray[ key ]; | 511 KeyGhost *st = &Matrix_ghostArray[ key ]; |
514 | 512 |
515 // col or row is ghosting (crossed) | 513 // col or row is ghosting (crossed) |
516 uint8_t ghost = (col_ghost[col] > 0 || row_ghost[row] > 0) ? 1 : 0; | 514 uint8_t ghost = (col_ghost[col] > 0 || row_ghost[row] > 0) ? 1 : 0; |
517 uint8_t ghost_old = (col_ghost_old[col] > 0 || row_ghost_old[row] > 0) ? 1 : 0; | |
518 ghost = ghost || ghost_old ? 1 : 0; | |
519 | 515 |
520 st->prev = st->cur; // previous | 516 st->prev = st->cur; // previous |
521 // save state if no ghost or outside ghosted area | 517 // save state if no ghost or outside ghosted area |
522 if ( ghost == 0 ) | 518 if ( ghost == 0 ) |
523 st->saved = state->curState; // save state if no ghost | 519 st->saved = state->curState; // save state if no ghost |