|
|
|
@ -271,6 +271,14 @@ uint8_t matrix_key_count(void)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define PIN(p) (*((volatile uint8_t*)(p >> 4) + 0))
|
|
|
|
|
#define DDR(p) (*((volatile uint8_t*)(p >> 4) + 1))
|
|
|
|
|
#define PORT(p) (*((volatile uint8_t*)(p >> 4) + 2))
|
|
|
|
|
|
|
|
|
|
_Static_assert(1==2, "wat");
|
|
|
|
|
_Static_assert(PIN(F0)==PINC, "Pin does not match");
|
|
|
|
|
_Static_assert(PIN(D0)==PIND, "Pin does not match");
|
|
|
|
|
_Static_assert(PIN(E0)==PINE, "Pin does not match");
|
|
|
|
|
|
|
|
|
|
#if (DIODE_DIRECTION == COL2ROW)
|
|
|
|
|
|
|
|
|
@ -278,8 +286,8 @@ static void init_cols(void)
|
|
|
|
|
{
|
|
|
|
|
for(uint8_t x = 0; x < MATRIX_COLS; x++) {
|
|
|
|
|
uint8_t pin = col_pins[x];
|
|
|
|
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
|
|
|
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
|
|
|
|
DDR(pin) &= ~_BV(pin & 0xF); // IN
|
|
|
|
|
PORT(pin) |= _BV(pin & 0xF); // HI
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -300,7 +308,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
|
|
|
|
|
|
|
|
|
|
// Select the col pin to read (active low)
|
|
|
|
|
uint8_t pin = col_pins[col_index];
|
|
|
|
|
uint8_t pin_state = (_SFR_IO8(pin >> 4) & _BV(pin & 0xF));
|
|
|
|
|
uint8_t pin_state = (PIN(pin) & _BV(pin & 0xF));
|
|
|
|
|
|
|
|
|
|
// Populate the matrix row with the state of the col pin
|
|
|
|
|
current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index);
|
|
|
|
@ -315,23 +323,23 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
|
|
|
|
|
static void select_row(uint8_t row)
|
|
|
|
|
{
|
|
|
|
|
uint8_t pin = row_pins[row];
|
|
|
|
|
_SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT
|
|
|
|
|
_SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW
|
|
|
|
|
DDR(pin) |= _BV(pin & 0xF); // OUT
|
|
|
|
|
PORT(pin) &= ~_BV(pin & 0xF); // LOW
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void unselect_row(uint8_t row)
|
|
|
|
|
{
|
|
|
|
|
uint8_t pin = row_pins[row];
|
|
|
|
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
|
|
|
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
|
|
|
|
DDR(pin) &= ~_BV(pin & 0xF); // IN
|
|
|
|
|
PORT(pin) |= _BV(pin & 0xF); // HI
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void unselect_rows(void)
|
|
|
|
|
{
|
|
|
|
|
for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
|
|
|
|
|
uint8_t pin = row_pins[x];
|
|
|
|
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
|
|
|
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
|
|
|
|
DDR(pin) &= ~_BV(pin & 0xF); // IN
|
|
|
|
|
PORT(pin) |= _BV(pin & 0xF); // HI
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -341,8 +349,8 @@ static void init_rows(void)
|
|
|
|
|
{
|
|
|
|
|
for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
|
|
|
|
|
uint8_t pin = row_pins[x];
|
|
|
|
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
|
|
|
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
|
|
|
|
DDR(pin) &= ~_BV(pin & 0xF); // IN
|
|
|
|
|
PORT(pin) |= _BV(pin & 0xF); // HI
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -362,7 +370,7 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
|
|
|
|
|
matrix_row_t last_row_value = current_matrix[row_index];
|
|
|
|
|
|
|
|
|
|
// Check row pin state
|
|
|
|
|
if ((_SFR_IO8(row_pins[row_index] >> 4) & _BV(row_pins[row_index] & 0xF)) == 0)
|
|
|
|
|
if ((PIN(row_pins[row_index]) & _BV(row_pins[row_index] & 0xF)) == 0)
|
|
|
|
|
{
|
|
|
|
|
// Pin LO, set col bit
|
|
|
|
|
current_matrix[row_index] |= (ROW_SHIFTER << current_col);
|
|
|
|
@ -389,23 +397,23 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
|
|
|
|
|
static void select_col(uint8_t col)
|
|
|
|
|
{
|
|
|
|
|
uint8_t pin = col_pins[col];
|
|
|
|
|
_SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT
|
|
|
|
|
_SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW
|
|
|
|
|
DDR(pin) |= _BV(pin & 0xF); // OUT
|
|
|
|
|
PORT(pin) &= ~_BV(pin & 0xF); // LOW
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void unselect_col(uint8_t col)
|
|
|
|
|
{
|
|
|
|
|
uint8_t pin = col_pins[col];
|
|
|
|
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
|
|
|
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
|
|
|
|
DDR(pin) &= ~_BV(pin & 0xF); // IN
|
|
|
|
|
PORT(pin) |= _BV(pin & 0xF); // HI
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void unselect_cols(void)
|
|
|
|
|
{
|
|
|
|
|
for(uint8_t x = 0; x < MATRIX_COLS; x++) {
|
|
|
|
|
uint8_t pin = col_pins[x];
|
|
|
|
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
|
|
|
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
|
|
|
|
DDR(pin) &= ~_BV(pin & 0xF); // IN
|
|
|
|
|
PORT(pin) |= _BV(pin & 0xF); // HI
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|