From 45e42106731ffd72ad7fa09096bd00dfa56f081e Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Wed, 27 Apr 2016 10:15:28 +0900 Subject: [PATCH] kimera: Improve flexibility of combining of keymap - Assign combining in row/col mapping - Remove macro TWO_HEADED_KIMERA - Now Kimera and Two Headed Kimera can use a common firmware --- keyboard/kimera/config.h | 4 -- keyboard/kimera/kimera.c | 142 ++++++++++++++------------------------- keyboard/kimera/kimera.h | 11 +-- 3 files changed, 56 insertions(+), 101 deletions(-) diff --git a/keyboard/kimera/config.h b/keyboard/kimera/config.h index 8fef70fb..c08c676d 100644 --- a/keyboard/kimera/config.h +++ b/keyboard/kimera/config.h @@ -35,11 +35,7 @@ along with this program. If not, see . #define MATRIX_SIZE 16 * 16 #define FN_ACTIONS_COUNT 32 #define KEYMAPS_COUNT 3 -#ifndef TWO_HEADED_KIMERA -#define EECONFIG_KEYMAP_IN_EEPROM 50 -#else #define EECONFIG_KEYMAP_IN_EEPROM 82 -#endif /* define if matrix has ghost */ //#define MATRIX_HAS_GHOST diff --git a/keyboard/kimera/kimera.c b/keyboard/kimera/kimera.c index af85685c..500437a8 100644 --- a/keyboard/kimera/kimera.c +++ b/keyboard/kimera/kimera.c @@ -25,41 +25,23 @@ along with this program. If not, see . #include "debug.h" static uint8_t row_mapping[PX_COUNT] = { -#ifndef TWO_HEADED_KIMERA - 0, 1, 2, 3, 4, 5, 6, 7, - UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, - UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, - UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED -#else 0, 1, 2, 3, 4, 5, 6, 7, 32, 33, 34, 35, 36, 37, 38, 39, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED -#endif }; static uint8_t col_mapping[PX_COUNT] = { -#ifndef TWO_HEADED_KIMERA - 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31, - UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED -#else 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55 -#endif }; -#ifndef TWO_HEADED_KIMERA -static uint8_t row_count = 8; -static uint8_t col_count = 24; -#else static uint8_t row_count = 16; static uint8_t col_count = 32; static uint8_t row_left_count = 8; static uint8_t col_left_count = 16; static matrix_row_t col_left_mask; -#endif +static uint8_t combining = COMBINING_NONE; static uint8_t data[EXP_COUNT][EXP_PORT_COUNT]; static uint8_t exp_in_use = 0; static uint8_t exp_online = 0; @@ -95,18 +77,28 @@ uint8_t read_matrix_mapping(void) uint8_t rows = eeprom_read_byte(EECONFIG_ROW_COUNT); uint8_t cols = eeprom_read_byte(EECONFIG_COL_COUNT); if (rows == 0) error++; - if (rows == UNCONFIGURED) error++; + else if (rows == UNCONFIGURED) error++; + else if (rows & COMBINING_BIT) { + if (combining != COMBINING_NONE) error++; + combining = COMBINING_ROW; + rows -= COMBINING_BIT; + } if (cols == 0) error++; - if (cols == UNCONFIGURED) error++; + else if (cols == UNCONFIGURED) error++; + else if (cols & COMBINING_BIT) { + if (combining != COMBINING_NONE) error++; + combining = COMBINING_COL; + cols -= COMBINING_BIT; + } if (rows + cols > PX_COUNT) error++; if (error) return error; row_count = rows; col_count = cols; -#ifdef TWO_HEADED_KIMERA - row_left_count = (rows + 1) / 2; - col_left_count = (cols + 1) / 2; - col_left_mask = (1 << col_left_count) - 1; -#endif + if (combining != COMBINING_NONE) { + row_left_count = (rows + 1) / 2; + col_left_count = (cols + 1) / 2; + col_left_mask = (1 << col_left_count) - 1; + } /* read row mapping */ uint8_t *mapping = EECONFIG_ROW_COL_MAPPING; @@ -166,8 +158,8 @@ void write_matrix_mapping(void) void kimera_scan(void) { uint8_t ret; - xprintf("exp in use: %d\n", exp_in_use); - xprintf("exp online: %d\n", exp_online); + dprintf("exp in use: %d\n", exp_in_use); + dprintf("exp online: %d\n", exp_online); for (uint8_t exp = 0; exp < EXP_COUNT; exp++) { if (exp_in_use & (1<= row_left_count) { - col += col_left_count; + if (combining == COMBINING_ROW) { + if (row >= row_left_count) { + col += col_left_count; + } } -#endif -#endif uint8_t px = col_mapping[col]; if (px != UNCONFIGURED) { @@ -286,17 +246,14 @@ matrix_row_t kimera_read_row(uint8_t row) } } -#if CHANGE_COMBINING -#else -#ifdef TWO_HEADED_KIMERA - if (row < row_left_count) { - cols &= col_left_mask; + if (combining == COMBINING_COL) { + if (row < row_left_count) { + cols &= col_left_mask; + } + else { + cols >>= col_left_count; + } } - else { - cols >>= col_left_count; - } -#endif -#endif return cols; } @@ -320,13 +277,12 @@ void kimera_select_row(uint8_t row) data[exp][PX_TO_PORT(px)] &= ~(1 << PX_TO_PIN(px)); expander_write_config(exp, data[exp]); } -#if CHANGE_COMBINING -#ifdef TWO_HEADED_KIMERA - if (row < row_left_count) { - kimera_select_row(row + row_left_count); + + if (combining == COMBINING_ROW) { + if (row < row_left_count) { + kimera_select_row(row + row_left_count); + } } -#endif -#endif } void expander_init(uint8_t exp) @@ -387,7 +343,7 @@ uint8_t expander_read(uint8_t exp, uint8_t command, uint8_t *data) if (ret) goto stop; ret = i2c_write(command); if (ret) goto stop; - ret = i2c_start(addr | I2C_READ); + ret = i2c_rep_start(addr | I2C_READ); if (ret) goto stop; *data++ = i2c_readAck(); *data = i2c_readNak(); diff --git a/keyboard/kimera/kimera.h b/keyboard/kimera/kimera.h index 7769efe3..74c1127c 100644 --- a/keyboard/kimera/kimera.h +++ b/keyboard/kimera/kimera.h @@ -111,11 +111,7 @@ along with this program. If not, see . `----------' `----------' */ -#ifndef TWO_HEADED_KIMERA -#define EXP_COUNT 2 -#else #define EXP_COUNT 4 -#endif #define EXP_ADDR(n) ((0x20+(n))<<1) #define EXP_OUTPUT 0 #define EXP_INPUT 1 @@ -153,6 +149,13 @@ const uint16_t PROGMEM dummy[] = { #define EECONFIG_ROW_COL_MAPPING (uint8_t *)18 #define UNCONFIGURED 0xFF +enum { + COMBINING_NONE = 0, + COMBINING_COL, + COMBINING_ROW +}; +#define COMBINING_BIT (0x80) + /* Functions */ void kimera_init(void);