Implement matrix and keymap
This commit is contained in:
parent
2546eacdd5
commit
932cdb7de5
@ -56,7 +56,7 @@ SRC = keymap_common.c \
|
||||
ifdef KEYMAP
|
||||
SRC := keymap_$(KEYMAP).c $(SRC)
|
||||
else
|
||||
SRC := keymap_poker.c $(SRC)
|
||||
SRC := keymap_default.c $(SRC)
|
||||
endif
|
||||
|
||||
|
||||
|
@ -28,8 +28,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#define DESCRIPTION t.m.k. keyboard firmware for LR96
|
||||
|
||||
/* key matrix size */
|
||||
#define MATRIX_ROWS 7
|
||||
#define MATRIX_COLS 16
|
||||
#define MATRIX_ROWS 16
|
||||
#define MATRIX_COLS 7
|
||||
|
||||
/* keymap in eeprom */
|
||||
#define FN_ACTIONS_COUNT 32
|
||||
|
@ -43,50 +43,49 @@ extern const uint16_t fn_actions[];
|
||||
|
||||
|
||||
/* LR96 keymap definition macro
|
||||
* K2C, K31 and K3C are extra keys for ISO
|
||||
* K1J, K3M and K2B are extra keys for ISO
|
||||
*/
|
||||
#define KEYMAP( \
|
||||
K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, \
|
||||
K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \
|
||||
K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D, \
|
||||
K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, \
|
||||
K40, K41, K42, K45, K49, K4A, K4B, K4C, K4D \
|
||||
K6A, K6B, K6C, K6D, K6E, K6F, K6G, K6H, K6I, K6J, K6K, K6L, K6M, K6N, K6P, K6Q, K0J, K5P, \
|
||||
K5A, K5B, K5C, K5D, K5E, K5F, K5G, K5H, K5I, K5J, K5K, K5L, K5M, K5N, K1J, K5Q, K0K, K4P, \
|
||||
K4A, K4B, K4C, K4D, K4E, K4F, K4G, K4H, K4I, K4J, K4K, K4L, K4M, K4N, K4Q, K0L, K3P, \
|
||||
K3A, K3B, K3C, K3D, K3E, K3F, K3G, K3H, K3I, K3J, K3K, K3L, K3M, K3N, K3Q, K0M, K2P, \
|
||||
K2A, K2B, K2C, K2D, K2E, K2F, K2G, K2H, K2I, K2J, K2K, K2L, K2N, K2M, K2Q, K0N, K1P, \
|
||||
K1A, K1B, K1C, K1F, K1K, K1L, K1M, K1N, K1Q, K0P, K0Q \
|
||||
) { \
|
||||
{ KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07, KC_##K08, KC_##K09, KC_##K0A, KC_##K0B, KC_##K0C, KC_##K0D }, \
|
||||
{ KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17, KC_##K18, KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D }, \
|
||||
{ KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27, KC_##K28, KC_##K29, KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D }, \
|
||||
{ KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37, KC_##K38, KC_##K39, KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D }, \
|
||||
{ KC_##K40, KC_##K41, KC_##K42, KC_NO, KC_NO, KC_##K45, KC_NO, KC_NO, KC_NO, KC_##K49, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D } \
|
||||
{ KC_NO, KC_##K1A, KC_##K2A, KC_##K3A, KC_##K4A, KC_##K5A, KC_##K6A }, \
|
||||
{ KC_NO, KC_##K1B, KC_##K2B, KC_##K3B, KC_##K4B, KC_##K5B, KC_##K6B }, \
|
||||
{ KC_NO, KC_##K1C, KC_##K2C, KC_##K3C, KC_##K4C, KC_##K5C, KC_##K6C }, \
|
||||
{ KC_NO, KC_NO, KC_##K2D, KC_##K3D, KC_##K4D, KC_##K5D, KC_##K6D }, \
|
||||
{ KC_NO, KC_NO, KC_##K2E, KC_##K3E, KC_##K4E, KC_##K5E, KC_##K6E }, \
|
||||
{ KC_NO, KC_##K1F, KC_##K2F, KC_##K3F, KC_##K4F, KC_##K5F, KC_##K6F }, \
|
||||
{ KC_NO, KC_NO, KC_##K2G, KC_##K3G, KC_##K4G, KC_##K5G, KC_##K6G }, \
|
||||
{ KC_NO, KC_NO, KC_##K2H, KC_##K3H, KC_##K4H, KC_##K5H, KC_##K6H }, \
|
||||
{ KC_NO, KC_NO, KC_##K2I, KC_##K3I, KC_##K4I, KC_##K5I, KC_##K6I }, \
|
||||
{ KC_##K0J, KC_##K1J, KC_##K2J, KC_##K3J, KC_##K4J, KC_##K5J, KC_##K6J }, \
|
||||
{ KC_##K0K, KC_##K1K, KC_##K2K, KC_##K3K, KC_##K4K, KC_##K5K, KC_##K6K }, \
|
||||
{ KC_##K0L, KC_##K1L, KC_##K2L, KC_##K3L, KC_##K4L, KC_##K5L, KC_##K6L }, \
|
||||
{ KC_##K0M, KC_##K1M, KC_##K2M, KC_##K3M, KC_##K4M, KC_##K5M, KC_##K6M }, \
|
||||
{ KC_##K0N, KC_##K1N, KC_##K2N, KC_##K3N, KC_##K4N, KC_##K5N, KC_##K6N }, \
|
||||
{ KC_##K0P, KC_##K1P, KC_##K2P, KC_##K3P, KC_##K4P, KC_##K5P, KC_##K6P }, \
|
||||
{ KC_##K0Q, KC_##K1Q, KC_##K2Q, KC_##K3Q, KC_##K4Q, KC_##K5Q, KC_##K6Q } \
|
||||
}
|
||||
|
||||
/* ANSI valiant. No extra keys for ISO */
|
||||
#define KEYMAP_ANSI( \
|
||||
K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, \
|
||||
K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \
|
||||
K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2D, \
|
||||
K30, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3D, \
|
||||
K40, K41, K42, K45, K4A, K4B, K4C, K4D \
|
||||
K6A, K6C, K6D, K6E, K6F, K6G, K6H, K6I, K6J, K6K, K6L, K6M, K6N, K6P, K6Q, K0J, K5P, \
|
||||
K5A, K5B, K5C, K5D, K5E, K5F, K5G, K5H, K5I, K5J, K5K, K5L, K5M, K5N, K5Q, K0K, K4P, \
|
||||
K4A, K4B, K4C, K4D, K4E, K4F, K4G, K4H, K4I, K4J, K4K, K4L, K4M, K4N, K4Q, K0L, K3P, \
|
||||
K3A, K3B, K3C, K3D, K3E, K3F, K3G, K3H, K3I, K3J, K3K, K3L, K3N, \
|
||||
K2A, K2C, K2D, K2E, K2F, K2G, K2H, K2I, K2J, K2K, K2L, K2N, K0N, \
|
||||
K1A, K1B, K1C, K1F, K1K, K1L, K1M, K1N, K1Q, K0P, K0Q \
|
||||
) KEYMAP( \
|
||||
K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, \
|
||||
K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \
|
||||
K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, NO, K2D, \
|
||||
K30, NO, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, NO, K3D, \
|
||||
K40, K41, K42, K45, NO, K4A, K4B, K4C, K4D \
|
||||
)
|
||||
|
||||
|
||||
#define KEYMAP_HHKB( \
|
||||
K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K49,\
|
||||
K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \
|
||||
K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2D, \
|
||||
K30, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3D, K3C, \
|
||||
K40, K41, K42, K45, K4A, K4B, K4C, K4D \
|
||||
) KEYMAP( \
|
||||
K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, \
|
||||
K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \
|
||||
K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, NO, K2D, \
|
||||
K30, NO, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, \
|
||||
K40, K41, K42, K45, K49, K4A, K4B, K4C, K4D \
|
||||
K6A, NO, K6C, K6D, K6E, K6F, K6G, K6H, K6I, K6J, K6K, K6L, K6M, K6N, K6P, K6Q, K0J, K5P, \
|
||||
K5A, K5B, K5C, K5D, K5E, K5F, K5G, K5H, K5I, K5J, K5K, K5L, K5M, K5N, NO, K5Q, K0K, K4P, \
|
||||
K4A, K4B, K4C, K4D, K4E, K4F, K4G, K4H, K4I, K4J, K4K, K4L, K4M, K4N, K4Q, K0L, K3P, \
|
||||
K3A, K3B, K3C, K3D, K3E, K3F, K3G, K3H, K3I, K3J, K3K, K3L, NO, K3N, NO, NO, NO, \
|
||||
K2A, NO, K2C, K2D, K2E, K2F, K2G, K2H, K2I, K2J, K2K, K2L, NO, K2N, NO, K0N, NO, \
|
||||
K1A, K1B, K1C, K1F, K1K, K1L, K1M, K1N, K1Q, K0P, K0Q \
|
||||
)
|
||||
|
||||
#endif
|
||||
|
@ -32,17 +32,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# define DEBOUNCE 5
|
||||
#endif
|
||||
static uint8_t debouncing = DEBOUNCE;
|
||||
typedef uint8_t matrix_col_t;
|
||||
|
||||
/* matrix state(1:on, 0:off) */
|
||||
static matrix_col_t matrix[MATRIX_COLS];
|
||||
static matrix_col_t matrix_debouncing[MATRIX_COLS];
|
||||
|
||||
static matrix_col_t read_rows(void);
|
||||
static void init_rows(void);
|
||||
static void unselect_cols(void);
|
||||
static void select_col(uint8_t col);
|
||||
static matrix_row_t matrix[MATRIX_ROWS];
|
||||
static matrix_row_t matrix_debouncing[MATRIX_ROWS];
|
||||
|
||||
static matrix_row_t read_cols(void);
|
||||
static void init_cols(void);
|
||||
static void unselect_rows(void);
|
||||
static void select_row(uint8_t row);
|
||||
|
||||
inline
|
||||
uint8_t matrix_rows(void)
|
||||
@ -59,8 +57,8 @@ uint8_t matrix_cols(void)
|
||||
void matrix_init(void)
|
||||
{
|
||||
// initialize row and col
|
||||
unselect_cols();
|
||||
init_rows();
|
||||
unselect_rows();
|
||||
init_cols();
|
||||
|
||||
// initialize matrix state: all keys off
|
||||
for (uint8_t i=0; i < MATRIX_ROWS; i++) {
|
||||
@ -71,25 +69,25 @@ void matrix_init(void)
|
||||
|
||||
uint8_t matrix_scan(void)
|
||||
{
|
||||
for (uint8_t i = 0; i < MATRIX_COLS; i++) {
|
||||
select_col(i);
|
||||
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
|
||||
select_row(i);
|
||||
_delay_us(30); // without this wait read unstable value.
|
||||
matrix_col_t rows = read_rows();
|
||||
if (matrix_debouncing[i] != rows) {
|
||||
matrix_debouncing[i] = rows;
|
||||
matrix_row_t cols = read_cols();
|
||||
if (matrix_debouncing[i] != cols) {
|
||||
matrix_debouncing[i] = cols;
|
||||
if (debouncing) {
|
||||
debug("bounce!: "); debug_hex(debouncing); debug("\n");
|
||||
}
|
||||
debouncing = DEBOUNCE;
|
||||
}
|
||||
unselect_cols();
|
||||
unselect_rows();
|
||||
}
|
||||
|
||||
if (debouncing) {
|
||||
if (--debouncing) {
|
||||
_delay_ms(1);
|
||||
} else {
|
||||
for (uint8_t i = 0; i < MATRIX_COLS; i++) {
|
||||
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
|
||||
matrix[i] = matrix_debouncing[i];
|
||||
}
|
||||
}
|
||||
@ -107,21 +105,21 @@ bool matrix_is_modified(void)
|
||||
inline
|
||||
bool matrix_is_on(uint8_t row, uint8_t col)
|
||||
{
|
||||
return (matrix[col] & ((matrix_col_t)1<<row));
|
||||
return (matrix[row] & ((matrix_row_t)1<<col));
|
||||
}
|
||||
|
||||
inline
|
||||
matrix_col_t matrix_get_col(uint8_t col)
|
||||
matrix_row_t matrix_get_row(uint8_t row)
|
||||
{
|
||||
return matrix[col];
|
||||
return matrix[row];
|
||||
}
|
||||
|
||||
void matrix_print(void)
|
||||
{
|
||||
print("\nc/r 0123456789ABCDEF\n");
|
||||
for (uint8_t col = 0; row < MATRIX_COLS; col++) {
|
||||
phex(col); print(": ");
|
||||
pbin_reverse16(matrix_get_col(col));
|
||||
print("\nr/c 0123456789ABCDEF\n");
|
||||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
|
||||
phex(row); print(": ");
|
||||
pbin_reverse16(matrix_get_row(row));
|
||||
print("\n");
|
||||
}
|
||||
}
|
||||
@ -129,82 +127,85 @@ void matrix_print(void)
|
||||
uint8_t matrix_key_count(void)
|
||||
{
|
||||
uint8_t count = 0;
|
||||
for (uint8_t i = 0; i < MATRIX_COLS; i++) {
|
||||
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
|
||||
count += bitpop16(matrix[i]);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/* Row pin configuration
|
||||
/* Column pin configuration
|
||||
* pin: D0 D1 D2 D3 D4 D5 D6
|
||||
*/
|
||||
static void init_rows(void)
|
||||
static void init_cols(void)
|
||||
{
|
||||
// Input with pull-up(DDR:0, PORT:1)
|
||||
DDRD &= ~(1<<PD6 | 1<<PD5 | 1<<PD4 | 1<<PD3 | 1<<PD2 | 1<<PD1 | 1<<PD0);
|
||||
PORTD |= (1<<PD6 | 1<<PD5 | 1<<PD4 | 1<<PD3 | 1<<PD2 | 1<<PD1 | 1<<PD0);
|
||||
}
|
||||
|
||||
/* Row pin configuration
|
||||
/* Column pin configuration
|
||||
* col: 0 1 2 3 4 5 6
|
||||
* pin: D0 D1 D2 D3 D4 D5 D6
|
||||
*/
|
||||
static matrix_col_t read_rows(void)
|
||||
static matrix_row_t read_cols(void)
|
||||
{
|
||||
return PINF & ~(1<<PF7);
|
||||
return PIND & ~(1<<PD7);
|
||||
}
|
||||
|
||||
/* Column pin configuration
|
||||
* pin: F0 B4 E6 F1
|
||||
* col: 0 0 0 0 0
|
||||
* 1 0 0 0 1
|
||||
* 2 0 0 1 0
|
||||
* 3 0 0 1 1
|
||||
* 4 0 1 0 0
|
||||
* 5 0 1 0 1
|
||||
* 6 0 1 1 0
|
||||
* 7 0 1 1 1
|
||||
* 8 1 0 0 0
|
||||
* 9 1 0 0 1
|
||||
* 10 1 0 1 0
|
||||
* 11 1 0 1 1
|
||||
* 12 1 1 0 0
|
||||
* 13 1 1 0 1
|
||||
* 14 1 1 1 0
|
||||
* 15 1 1 1 1
|
||||
/* Row pin configuration
|
||||
* pin: B0 F0 B4 E6 F1
|
||||
* row: off 0 x x x x
|
||||
* 0 1 0 0 0 0
|
||||
* 1 1 0 0 0 1
|
||||
* 2 1 0 0 1 0
|
||||
* 3 1 0 0 1 1
|
||||
* 4 1 0 1 0 0
|
||||
* 5 1 0 1 0 1
|
||||
* 6 1 0 1 1 0
|
||||
* 7 1 0 1 1 1
|
||||
* 8 1 1 0 0 0
|
||||
* 9 1 1 0 0 1
|
||||
* 10 1 1 0 1 0
|
||||
* 11 1 1 0 1 1
|
||||
* 12 1 1 1 0 0
|
||||
* 13 1 1 1 0 1
|
||||
* 14 1 1 1 1 0
|
||||
* 15 1 1 1 1 1
|
||||
*/
|
||||
static void unselect_cols(void)
|
||||
static void unselect_rows(void)
|
||||
{
|
||||
// Output low(DDR:1, PORT:0) to unselect
|
||||
DDRB |= (1<<PB4);
|
||||
PORTB &= ~(1<<PB4);
|
||||
DDRE |= (1<<PE6);
|
||||
PORTE &= ~(1<<PE6);
|
||||
DDRF |= (1<<PF1 | 1<<PF0);
|
||||
PORTF &= ~(1<<PF1 | 1<<PF0);
|
||||
DDRB |= (1<<PB0);
|
||||
PORTB |= (1<<PB0);
|
||||
}
|
||||
|
||||
static void select_cols(uint8_t col)
|
||||
static void select_row(uint8_t row)
|
||||
{
|
||||
if (col & (1<<0)) {
|
||||
DDRB |= (1<<PB4 | 1<<PB0);
|
||||
DDRE |= (1<<PE6);
|
||||
DDRF |= (1<<PF1 | 1<<PF0);
|
||||
|
||||
PORTB &= ~(1<<PB0);
|
||||
|
||||
if (row & (1<<0)) {
|
||||
PORTF |= (1<<PF1);
|
||||
}
|
||||
else {
|
||||
PORTF &= ~(1<<PF1);
|
||||
}
|
||||
if (col & (1<<1)) {
|
||||
if (row & (1<<1)) {
|
||||
PORTE |= (1<<PE6);
|
||||
}
|
||||
else {
|
||||
PORTE &= ~(1<<PE6);
|
||||
}
|
||||
if (col & (1<<2)) {
|
||||
if (row & (1<<2)) {
|
||||
PORTB |= (1<<PB4);
|
||||
}
|
||||
else {
|
||||
PORTB &= ~(1<<PB4);
|
||||
}
|
||||
if (col & (1<<3)) {
|
||||
if (row & (1<<3)) {
|
||||
PORTF |= (1<<PF0);
|
||||
}
|
||||
else {
|
||||
|
Reference in New Issue
Block a user