@ -46,12 +46,15 @@ uint16_t Atreus::masks_[ROWS];
uint8_t Atreus : : debounce_matrix_ [ ROWS ] [ COLS ] ;
uint8_t Atreus : : debounce_matrix_ [ ROWS ] [ COLS ] ;
uint8_t Atreus : : debounce = 3 ;
uint8_t Atreus : : debounce = 3 ;
constexpr uint8_t Atreus : : row_pins [ 4 ] ;
void Atreus : : setup ( void ) {
void Atreus : : setup ( void ) {
wdt_disable ( ) ;
wdt_disable ( ) ;
delay ( 100 ) ;
delay ( 100 ) ;
for ( uint8_t i = 0 ; i < ROWS ; i + + ) {
for ( uint8_t i = 0 ; i < ROWS ; i + + ) {
unselectRow ( i ) ;
DDRD | = _BV ( row_pins [ i ] ) ;
PORTD | = _BV ( row_pins [ i ] ) ;
keyState_ [ i ] = previousKeyState_ [ i ] = 0 ;
keyState_ [ i ] = previousKeyState_ [ i ] = 0 ;
}
}
@ -82,50 +85,8 @@ void Atreus::setup(void) {
TIMSK1 = _BV ( TOIE1 ) ;
TIMSK1 = _BV ( TOIE1 ) ;
}
}
void Atreus : : selectRow ( uint8_t row ) {
void Atreus : : toggleRow ( uint8_t row ) {
switch ( row ) {
PORTD ^ = _BV ( row_pins [ row ] ) ;
case 0 :
DDRD | = ( _BV ( 0 ) ) ;
PORTD & = ~ ( _BV ( 0 ) ) ;
break ;
case 1 :
DDRD | = ( _BV ( 1 ) ) ;
PORTD & = ~ ( _BV ( 1 ) ) ;
break ;
case 2 :
DDRD | = ( _BV ( 3 ) ) ;
PORTD & = ~ ( _BV ( 3 ) ) ;
break ;
case 3 :
DDRD | = ( _BV ( 2 ) ) ;
PORTD & = ~ ( _BV ( 2 ) ) ;
break ;
default :
break ;
}
}
void Atreus : : unselectRow ( uint8_t row ) {
switch ( row ) {
case 0 :
DDRD & = ~ ( _BV ( 0 ) ) ;
PORTD | = ( _BV ( 0 ) ) ;
break ;
case 1 :
DDRD & = ~ ( _BV ( 1 ) ) ;
PORTD | = ( _BV ( 1 ) ) ;
break ;
case 2 :
DDRD & = ~ ( _BV ( 3 ) ) ;
PORTD | = ( _BV ( 3 ) ) ;
break ;
case 3 :
DDRD & = ~ ( _BV ( 2 ) ) ;
PORTD | = ( _BV ( 2 ) ) ;
break ;
default :
break ;
}
}
}
uint16_t Atreus : : readCols ( ) {
uint16_t Atreus : : readCols ( ) {
@ -149,9 +110,9 @@ void Atreus::readMatrixRow(uint8_t current_row) {
mask = debounceMaskForRow ( current_row ) ;
mask = debounceMaskForRow ( current_row ) ;
select Row( current_row ) ;
toggle Row( current_row ) ;
cols = ( readCols ( ) & mask ) | ( keyState_ [ current_row ] & ~ mask ) ;
cols = ( readCols ( ) & mask ) | ( keyState_ [ current_row ] & ~ mask ) ;
unselect Row( current_row ) ;
toggle Row( current_row ) ;
debounceRow ( cols ^ keyState_ [ current_row ] , current_row ) ;
debounceRow ( cols ^ keyState_ [ current_row ] , current_row ) ;
keyState_ [ current_row ] = cols ;
keyState_ [ current_row ] = cols ;
}
}