|
|
@ -29,7 +29,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef DEBOUNCE
|
|
|
|
#ifndef DEBOUNCE
|
|
|
|
# define DEBOUNCE 5
|
|
|
|
# define DEBOUNCE 10
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
static uint8_t debouncing = DEBOUNCE;
|
|
|
|
static uint8_t debouncing = DEBOUNCE;
|
|
|
|
|
|
|
|
|
|
|
@ -135,77 +135,67 @@ uint8_t matrix_key_count(void)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Column pin configuration
|
|
|
|
/* Column pin configuration
|
|
|
|
* col: 0 1 2 3 4 5 6 7 8 9 10 11 12 13
|
|
|
|
* col: 0 1 2 3 4 5 6 7 8 9 10 11
|
|
|
|
* pin: F0 F1 E6 C7 C6 B6 D4 B1 B0 B5 B4 D7 D6 B3 (Rev.A)
|
|
|
|
* pin: F0 F1 F4 F5 F6 F7 B6 B5 B4 D7 D5 D4
|
|
|
|
* pin: B7 (Rev.B)
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
static void init_cols(void)
|
|
|
|
static void init_cols(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Input with pull-up(DDR:0, PORT:1)
|
|
|
|
DDRC &= ~(1<<6 | 1<<7);
|
|
|
|
DDRF &= ~(1<<0 | 1<<1);
|
|
|
|
PORTC |= (1<<6 | 1<<7);
|
|
|
|
PORTF |= (1<<0 | 1<<1);
|
|
|
|
DDRD &= ~(1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<5);
|
|
|
|
DDRE &= ~(1<<6);
|
|
|
|
PORTD |= (1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<5);
|
|
|
|
PORTE |= (1<<6);
|
|
|
|
DDRB &= ~(1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<7);
|
|
|
|
DDRD &= ~(1<<7 | 1<<6 | 1<<4);
|
|
|
|
PORTB |= (1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<7);
|
|
|
|
PORTD |= (1<<7 | 1<<6 | 1<<4);
|
|
|
|
|
|
|
|
DDRC &= ~(1<<7 | 1<<6);
|
|
|
|
|
|
|
|
PORTC |= (1<<7 | 1<<6);
|
|
|
|
|
|
|
|
DDRB &= ~(1<<7 | 1<<6 | 1<< 5 | 1<<4 | 1<<3 | 1<<1 | 1<<0);
|
|
|
|
|
|
|
|
PORTB |= (1<<7 | 1<<6 | 1<< 5 | 1<<4 | 1<<3 | 1<<1 | 1<<0);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static matrix_row_t read_cols(void)
|
|
|
|
static matrix_row_t read_cols(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return (PINF&(1<<0) ? 0 : (1<<0)) |
|
|
|
|
return (PIND&(1<<5) ? 0 : (1<< 0)) |
|
|
|
|
(PINF&(1<<1) ? 0 : (1<<1)) |
|
|
|
|
(PINC&(1<<7) ? 0 : (1<< 1)) |
|
|
|
|
(PINE&(1<<6) ? 0 : (1<<2)) |
|
|
|
|
(PINC&(1<<6) ? 0 : (1<< 2)) |
|
|
|
|
(PINC&(1<<7) ? 0 : (1<<3)) |
|
|
|
|
(PIND&(1<<3) ? 0 : (1<< 3)) |
|
|
|
|
(PINC&(1<<6) ? 0 : (1<<4)) |
|
|
|
|
(PIND&(1<<2) ? 0 : (1<< 4)) |
|
|
|
|
(PINB&(1<<6) ? 0 : (1<<5)) |
|
|
|
|
(PIND&(1<<1) ? 0 : (1<< 5)) |
|
|
|
|
(PIND&(1<<4) ? 0 : (1<<6)) |
|
|
|
|
(PIND&(1<<0) ? 0 : (1<< 6)) |
|
|
|
|
(PINB&(1<<1) ? 0 : (1<<7)) |
|
|
|
|
(PINB&(1<<7) ? 0 : (1<< 7)) |
|
|
|
|
((PINB&(1<<0) && PINB&(1<<7)) ? 0 : (1<<8)) | // Rev.A and B
|
|
|
|
(PINB&(1<<3) ? 0 : (1<< 8)) |
|
|
|
|
(PINB&(1<<5) ? 0 : (1<<9)) |
|
|
|
|
(PINB&(1<<2) ? 0 : (1<< 9)) |
|
|
|
|
(PINB&(1<<4) ? 0 : (1<<10)) |
|
|
|
|
(PINB&(1<<1) ? 0 : (1<<10)) |
|
|
|
|
(PIND&(1<<7) ? 0 : (1<<11)) |
|
|
|
|
(PINB&(1<<0) ? 0 : (1<<11));
|
|
|
|
(PIND&(1<<6) ? 0 : (1<<12)) |
|
|
|
|
|
|
|
|
(PINB&(1<<3) ? 0 : (1<<13));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Row pin configuration
|
|
|
|
/* Row pin configuration
|
|
|
|
* row: 0 1 2 3 4
|
|
|
|
* row: 0 1 2 3
|
|
|
|
* pin: D0 D1 D2 D3 D5
|
|
|
|
* pin: B0 B1 B2 B3
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static void unselect_rows(void)
|
|
|
|
static void unselect_rows(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Hi-Z(DDR:0, PORT:0) to unselect
|
|
|
|
// Hi-Z(DDR:0, PORT:0) to unselect
|
|
|
|
DDRD &= ~0b00101111;
|
|
|
|
DDRD &= ~(1<<4 | 1<<6 | 1<<7);
|
|
|
|
PORTD &= ~0b00101111;
|
|
|
|
PORTD |= (1<<4 | 1<<6 | 1<<7);
|
|
|
|
|
|
|
|
DDRB &= ~(1<<4);
|
|
|
|
|
|
|
|
PORTB |= (1<<4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void select_row(uint8_t row)
|
|
|
|
static void select_row(uint8_t row)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Output low(DDR:1, PORT:0) to select
|
|
|
|
|
|
|
|
switch (row) {
|
|
|
|
switch (row) {
|
|
|
|
case 0:
|
|
|
|
case 0:
|
|
|
|
DDRD |= (1<<0);
|
|
|
|
DDRD |= (1<<4);
|
|
|
|
PORTD &= ~(1<<0);
|
|
|
|
PORTD &= ~(1<<4);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 1:
|
|
|
|
DDRD |= (1<<1);
|
|
|
|
DDRD |= (1<<6);
|
|
|
|
PORTD &= ~(1<<1);
|
|
|
|
PORTD &= ~(1<<6);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 2:
|
|
|
|
DDRD |= (1<<2);
|
|
|
|
DDRD |= (1<<7);
|
|
|
|
PORTD &= ~(1<<2);
|
|
|
|
PORTD &= ~(1<<7);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 3:
|
|
|
|
DDRD |= (1<<3);
|
|
|
|
DDRB |= (1<<4);
|
|
|
|
PORTD &= ~(1<<3);
|
|
|
|
PORTB &= ~(1<<4);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
|
|
DDRD |= (1<<5);
|
|
|
|
|
|
|
|
PORTD &= ~(1<<5);
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|