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