add port shortcuts
This commit is contained in:
parent
ba132db308
commit
8f9ba77f72
@ -1 +1 @@
|
|||||||
Subproject commit d34e8eb83101a95f98892bf68605fe545821f320
|
Subproject commit 8fce03b3a75c743e5d5c40b9d59c1637c59d22a7
|
@ -17,14 +17,28 @@
|
|||||||
#ifndef CONFIG_DEFINITIONS_H
|
#ifndef CONFIG_DEFINITIONS_H
|
||||||
#define CONFIG_DEFINITIONS_H
|
#define CONFIG_DEFINITIONS_H
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
/* diode directions */
|
/* diode directions */
|
||||||
#define COL2ROW 0
|
#define COL2ROW 0
|
||||||
#define ROW2COL 1
|
#define ROW2COL 1
|
||||||
#define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */
|
#define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */
|
||||||
|
|
||||||
/* I/O pins */
|
/* I/O pins */
|
||||||
#ifndef F0
|
|
||||||
#define PINDEF(port, pin) (uint8_t)((((uint16_t)&PORT##port) << 4) + PIN##port##pin)
|
#define PINDEF(port, pin) (uint8_t)((((uint16_t)&PORT##port) << 4) + PIN##port##pin)
|
||||||
|
|
||||||
|
#define PIN(p) (*((volatile uint8_t*)(p >> 4) + 0))
|
||||||
|
#define PIN_VALUE(p) (PIN(p) & _BV(p & 0xF))
|
||||||
|
|
||||||
|
#define DDR(p) (*((volatile uint8_t*)(p >> 4) + 1))
|
||||||
|
#define DDR_OUTPUT(p) (DDR(p) |= _BV(p & 0xF))
|
||||||
|
#define DDR_INPUT(p) (DDR(p) &= ~_BV(p & 0xF))
|
||||||
|
|
||||||
|
#define PORT(p) (*((volatile uint8_t*)(p >> 4) + 2))
|
||||||
|
#define PORT_HIGH(p) (PORT(p) |= _BV(p & 0xF))
|
||||||
|
#define PORT_LOW(p) (PORT(p) &= ~_BV(p & 0xF))
|
||||||
|
|
||||||
|
#ifdef PORTA
|
||||||
#define A0 PINDEF(A, 0)
|
#define A0 PINDEF(A, 0)
|
||||||
#define A1 PINDEF(A, 1)
|
#define A1 PINDEF(A, 1)
|
||||||
#define A2 PINDEF(A, 1)
|
#define A2 PINDEF(A, 1)
|
||||||
@ -33,6 +47,8 @@
|
|||||||
#define A5 PINDEF(A, 5)
|
#define A5 PINDEF(A, 5)
|
||||||
#define A6 PINDEF(A, 6)
|
#define A6 PINDEF(A, 6)
|
||||||
#define A7 PINDEF(A, 7)
|
#define A7 PINDEF(A, 7)
|
||||||
|
#endif
|
||||||
|
#ifdef PORTB
|
||||||
#define B0 PINDEF(B, 0)
|
#define B0 PINDEF(B, 0)
|
||||||
#define B1 PINDEF(B, 1)
|
#define B1 PINDEF(B, 1)
|
||||||
#define B2 PINDEF(B, 2)
|
#define B2 PINDEF(B, 2)
|
||||||
@ -41,6 +57,8 @@
|
|||||||
#define B5 PINDEF(B, 5)
|
#define B5 PINDEF(B, 5)
|
||||||
#define B6 PINDEF(B, 6)
|
#define B6 PINDEF(B, 6)
|
||||||
#define B7 PINDEF(B, 7)
|
#define B7 PINDEF(B, 7)
|
||||||
|
#endif
|
||||||
|
#ifdef PORTC
|
||||||
#define C0 PINDEF(C, 0)
|
#define C0 PINDEF(C, 0)
|
||||||
#define C1 PINDEF(C, 1)
|
#define C1 PINDEF(C, 1)
|
||||||
#define C2 PINDEF(C, 2)
|
#define C2 PINDEF(C, 2)
|
||||||
@ -49,6 +67,8 @@
|
|||||||
#define C5 PINDEF(C, 5)
|
#define C5 PINDEF(C, 5)
|
||||||
#define C6 PINDEF(C, 6)
|
#define C6 PINDEF(C, 6)
|
||||||
#define C7 PINDEF(C, 7)
|
#define C7 PINDEF(C, 7)
|
||||||
|
#endif
|
||||||
|
#ifdef PORTD
|
||||||
#define D0 PINDEF(D, 0)
|
#define D0 PINDEF(D, 0)
|
||||||
#define D1 PINDEF(D, 1)
|
#define D1 PINDEF(D, 1)
|
||||||
#define D2 PINDEF(D, 2)
|
#define D2 PINDEF(D, 2)
|
||||||
@ -57,6 +77,8 @@
|
|||||||
#define D5 PINDEF(D, 5)
|
#define D5 PINDEF(D, 5)
|
||||||
#define D6 PINDEF(D, 6)
|
#define D6 PINDEF(D, 6)
|
||||||
#define D7 PINDEF(D, 7)
|
#define D7 PINDEF(D, 7)
|
||||||
|
#endif
|
||||||
|
#ifdef PORTE
|
||||||
#define E0 PINDEF(E, 0)
|
#define E0 PINDEF(E, 0)
|
||||||
#define E1 PINDEF(E, 1)
|
#define E1 PINDEF(E, 1)
|
||||||
#define E2 PINDEF(E, 2)
|
#define E2 PINDEF(E, 2)
|
||||||
@ -65,6 +87,8 @@
|
|||||||
#define E5 PINDEF(E, 5)
|
#define E5 PINDEF(E, 5)
|
||||||
#define E6 PINDEF(E, 6)
|
#define E6 PINDEF(E, 6)
|
||||||
#define E7 PINDEF(E, 7)
|
#define E7 PINDEF(E, 7)
|
||||||
|
#endif
|
||||||
|
#ifdef PORTF
|
||||||
#define F0 PINDEF(F, 0)
|
#define F0 PINDEF(F, 0)
|
||||||
#define F1 PINDEF(F, 1)
|
#define F1 PINDEF(F, 1)
|
||||||
#define F2 PINDEF(F, 2)
|
#define F2 PINDEF(F, 2)
|
||||||
@ -75,6 +99,7 @@
|
|||||||
#define F7 PINDEF(F, 7)
|
#define F7 PINDEF(F, 7)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* USART configuration */
|
/* USART configuration */
|
||||||
#ifdef BLUETOOTH_ENABLE
|
#ifdef BLUETOOTH_ENABLE
|
||||||
# ifdef __AVR_ATmega32U4__
|
# ifdef __AVR_ATmega32U4__
|
||||||
|
@ -271,23 +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)
|
#if (DIODE_DIRECTION == COL2ROW)
|
||||||
|
|
||||||
static void init_cols(void)
|
static void init_cols(void)
|
||||||
{
|
{
|
||||||
for(uint8_t x = 0; x < MATRIX_COLS; x++) {
|
for(uint8_t x = 0; x < MATRIX_COLS; x++) {
|
||||||
uint8_t pin = col_pins[x];
|
uint8_t pin = col_pins[x];
|
||||||
DDR(pin) &= ~_BV(pin & 0xF); // IN
|
DDR_INPUT(pin); // IN
|
||||||
PORT(pin) |= _BV(pin & 0xF); // HI
|
PORT_HIGH(pin); // HI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,7 +299,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
|
|||||||
|
|
||||||
// Select the col pin to read (active low)
|
// Select the col pin to read (active low)
|
||||||
uint8_t pin = col_pins[col_index];
|
uint8_t pin = col_pins[col_index];
|
||||||
uint8_t pin_state = (PIN(pin) & _BV(pin & 0xF));
|
uint8_t pin_state = PIN_VALUE(pin);
|
||||||
|
|
||||||
// Populate the matrix row with the state of the col pin
|
// Populate the matrix row with the state of the col pin
|
||||||
current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index);
|
current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index);
|
||||||
@ -323,23 +314,23 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
|
|||||||
static void select_row(uint8_t row)
|
static void select_row(uint8_t row)
|
||||||
{
|
{
|
||||||
uint8_t pin = row_pins[row];
|
uint8_t pin = row_pins[row];
|
||||||
DDR(pin) |= _BV(pin & 0xF); // OUT
|
DDR_OUTPUT(pin); // OUT
|
||||||
PORT(pin) &= ~_BV(pin & 0xF); // LOW
|
PORT_LOW(pin); // LOW
|
||||||
}
|
}
|
||||||
|
|
||||||
static void unselect_row(uint8_t row)
|
static void unselect_row(uint8_t row)
|
||||||
{
|
{
|
||||||
uint8_t pin = row_pins[row];
|
uint8_t pin = row_pins[row];
|
||||||
DDR(pin) &= ~_BV(pin & 0xF); // IN
|
DDR_INPUT(pin); // IN
|
||||||
PORT(pin) |= _BV(pin & 0xF); // HI
|
PORT_HIGH(pin); // HI
|
||||||
}
|
}
|
||||||
|
|
||||||
static void unselect_rows(void)
|
static void unselect_rows(void)
|
||||||
{
|
{
|
||||||
for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
|
for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
|
||||||
uint8_t pin = row_pins[x];
|
uint8_t pin = row_pins[x];
|
||||||
DDR(pin) &= ~_BV(pin & 0xF); // IN
|
DDR_INPUT(pin); // IN
|
||||||
PORT(pin) |= _BV(pin & 0xF); // HI
|
PORT_HIGH(pin); // HI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,8 +340,8 @@ static void init_rows(void)
|
|||||||
{
|
{
|
||||||
for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
|
for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
|
||||||
uint8_t pin = row_pins[x];
|
uint8_t pin = row_pins[x];
|
||||||
DDR(pin) &= ~_BV(pin & 0xF); // IN
|
DDR_INPUT(pin); // IN
|
||||||
PORT(pin) |= _BV(pin & 0xF); // HI
|
PORT_HIGH(pin); // HI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,7 +361,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];
|
matrix_row_t last_row_value = current_matrix[row_index];
|
||||||
|
|
||||||
// Check row pin state
|
// Check row pin state
|
||||||
if ((PIN(row_pins[row_index]) & _BV(row_pins[row_index] & 0xF)) == 0)
|
if (PIN_VALUE(row_pins[row_index]) == 0)
|
||||||
{
|
{
|
||||||
// Pin LO, set col bit
|
// Pin LO, set col bit
|
||||||
current_matrix[row_index] |= (ROW_SHIFTER << current_col);
|
current_matrix[row_index] |= (ROW_SHIFTER << current_col);
|
||||||
@ -397,23 +388,23 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
|
|||||||
static void select_col(uint8_t col)
|
static void select_col(uint8_t col)
|
||||||
{
|
{
|
||||||
uint8_t pin = col_pins[col];
|
uint8_t pin = col_pins[col];
|
||||||
DDR(pin) |= _BV(pin & 0xF); // OUT
|
DDR_OUTPUT(pin); // OUT
|
||||||
PORT(pin) &= ~_BV(pin & 0xF); // LOW
|
PORT_LOW(pin); // LOW
|
||||||
}
|
}
|
||||||
|
|
||||||
static void unselect_col(uint8_t col)
|
static void unselect_col(uint8_t col)
|
||||||
{
|
{
|
||||||
uint8_t pin = col_pins[col];
|
uint8_t pin = col_pins[col];
|
||||||
DDR(pin) &= ~_BV(pin & 0xF); // IN
|
DDR_INPUT(pin); // IN
|
||||||
PORT(pin) |= _BV(pin & 0xF); // HI
|
PORT_HIGH(pin); // HI
|
||||||
}
|
}
|
||||||
|
|
||||||
static void unselect_cols(void)
|
static void unselect_cols(void)
|
||||||
{
|
{
|
||||||
for(uint8_t x = 0; x < MATRIX_COLS; x++) {
|
for(uint8_t x = 0; x < MATRIX_COLS; x++) {
|
||||||
uint8_t pin = col_pins[x];
|
uint8_t pin = col_pins[x];
|
||||||
DDR(pin) &= ~_BV(pin & 0xF); // IN
|
DDR_INPUT(pin); // IN
|
||||||
PORT(pin) |= _BV(pin & 0xF); // HI
|
PORT_HIGH(pin); // HI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user