1
0

kimera: Make two-handed kimera can work with keymap-in-eeprom

This commit is contained in:
Kai Ryu 2014-11-13 19:28:03 +09:00
parent abf70607d1
commit 7a1eeebaa7
5 changed files with 63 additions and 41 deletions

View File

@ -35,7 +35,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define MATRIX_SIZE 16 * 16 #define MATRIX_SIZE 16 * 16
#define FN_ACTIONS_COUNT 32 #define FN_ACTIONS_COUNT 32
#define KEYMAPS_COUNT 3 #define KEYMAPS_COUNT 3
#ifndef TWO_HEADED_KIMERA
#define EECONFIG_KEYMAP_IN_EEPROM 45 #define EECONFIG_KEYMAP_IN_EEPROM 45
#else
#define EECONFIG_KEYMAP_IN_EEPROM 77
#endif
/* define if matrix has ghost */ /* define if matrix has ghost */
//#define MATRIX_HAS_GHOST //#define MATRIX_HAS_GHOST

View File

@ -8,7 +8,7 @@ const uint8_t keymaps[][MATRIX_SIZE] PROGMEM = {
#endif #endif
/* Keymap 0: Default Layer /* Keymap 0: Default Layer
* ,----------------------------------------. ,------------------------------------------------. * ,----------------------------------------. ,------------------------------------------------.
* | ||Esc| | F1| F2| F3| F4| | | F5| F6| F7| F8| | F9|F10|F11|F12||Psc|Slk|Pus| * | | | | ||Esc| | F1| F2| F3| F4| | | F5| F6| F7| F8| | F9|F10|F11|F12||Psc|Slk|Pus|
* |---------------||-----------------------| |-----------------------------------||-----------| * |---------------||-----------------------| |-----------------------------------||-----------|
* |Num| /| *| -|| `| 1| 2| 3| 4| 5| | 6| 7| 8| 9| 0| -| =|Backsp ||Ins|Hom|PgU| * |Num| /| *| -|| `| 1| 2| 3| 4| 5| | 6| 7| 8| 9| 0| -| =|Backsp ||Ins|Hom|PgU|
* |---------------||-------------------------. `-----------------------------------||-----------| * |---------------||-------------------------. `-----------------------------------||-----------|
@ -18,7 +18,7 @@ const uint8_t keymaps[][MATRIX_SIZE] PROGMEM = {
* |---------------||----------------------------. `-------------------------------|| ,---. | * |---------------||----------------------------. `-------------------------------|| ,---. |
* | 1| 2| 3| ||Shift | Z| X| C| V| B| | N| M| ,| .| /|Shift || |Up | | * | 1| 2| 3| ||Shift | Z| X| C| V| B| | N| M| ,| .| /|Shift || |Up | |
* |-----------|Ent||----------------------------| |------------------------------||-----------| * |-----------|Ent||----------------------------| |------------------------------||-----------|
* | 0| .| ||Ctrl|Gui |Alt | Space | | Space |Alt |Gui |Fn0 |Ctrl||Lef|Dow|Rig| * | 0| .| ||Ctrl|Gui |Alt | Space | | Space |Alt |Gui |App |Ctrl||Lef|Dow|Rig|
* `---------------------------------------------' `-------------------------------------------' * `---------------------------------------------' `-------------------------------------------'
*/ */
KEYMAP_16x16( KEYMAP_16x16(
@ -36,7 +36,7 @@ const uint8_t keymaps[][MATRIX_SIZE] PROGMEM = {
Y, U, I, O, P, LBRC,RBRC,BSLS,DEL, END, PGDN,NO, NO, NO, NO, NO, \ Y, U, I, O, P, LBRC,RBRC,BSLS,DEL, END, PGDN,NO, NO, NO, NO, NO, \
H, J, K, L, SCLN,QUOT,NO, ENT, NO, NO, NO, NO, NO, NO, NO, NO, \ H, J, K, L, SCLN,QUOT,NO, ENT, NO, NO, NO, NO, NO, NO, NO, NO, \
N, M, COMM,DOT, SLSH,NO, NO, RSFT,NO, UP, NO, NO, NO, NO, NO, NO, \ N, M, COMM,DOT, SLSH,NO, NO, RSFT,NO, UP, NO, NO, NO, NO, NO, NO, \
NO, SPC, NO, RALT,RGUI,FN0, RCTL,NO, LEFT,DOWN,RGHT,NO, NO, NO, NO, NO, \ NO, SPC, NO, RALT,RGUI,APP, RCTL,NO, LEFT,DOWN,RGHT,NO, NO, NO, NO, NO, \
NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \
NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO ), NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO ),
}; };

View File

@ -32,7 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define SCL_DURATION (1000000L/SCL_CLOCK)/2 #define SCL_DURATION (1000000L/SCL_CLOCK)/2
extern uint8_t i2c_force_stop; extern uint8_t i2c_force_stop;
uint8_t row_mapping[PX_COUNT] = { static uint8_t row_mapping[PX_COUNT] = {
#ifndef TWO_HEADED_KIMERA #ifndef TWO_HEADED_KIMERA
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7,
UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED,
@ -45,7 +45,7 @@ uint8_t row_mapping[PX_COUNT] = {
UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED
#endif #endif
}; };
uint8_t col_mapping[PX_COUNT] = { static uint8_t col_mapping[PX_COUNT] = {
#ifndef TWO_HEADED_KIMERA #ifndef TWO_HEADED_KIMERA
8, 9, 10, 11, 12, 13, 14, 15, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 16, 17, 18, 19, 20, 21, 22, 23,
@ -59,14 +59,17 @@ uint8_t col_mapping[PX_COUNT] = {
#endif #endif
}; };
#ifndef TWO_HEADED_KIMERA #ifndef TWO_HEADED_KIMERA
uint8_t row_count = 8; static uint8_t row_count = 8;
uint8_t col_count = 24; static uint8_t col_count = 24;
#else #else
uint8_t row_count = 16; static uint8_t row_count = 16;
uint8_t col_count = 32; 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 #endif
uint8_t data[EXP_COUNT][EXP_PORT_COUNT]; static uint8_t data[EXP_COUNT][EXP_PORT_COUNT];
uint8_t exp_status = 0; static uint8_t exp_status = 0;
void kimera_init(void) void kimera_init(void)
{ {
@ -109,6 +112,11 @@ uint8_t read_matrix_mapping(void)
if (error) return error; if (error) return error;
row_count = rows; row_count = rows;
col_count = cols; col_count = cols;
#ifdef TWO_HEADED_KIMERA
row_left_count = (rows + 1) / 2;
col_left_count = (cols + 1) / 2;
col_left_mask = (1 << row_left_count) - 1;
#endif
/* read row mapping */ /* read row mapping */
uint8_t *mapping = EECONFIG_ROW_COL_MAPPING; uint8_t *mapping = EECONFIG_ROW_COL_MAPPING;
@ -177,7 +185,23 @@ void kimera_scan(void)
} }
} }
matrix_row_t read_cols(void) inline
uint8_t kimera_matrix_rows(void)
{
return row_count;
}
inline
uint8_t kimera_matrix_cols(void)
{
#ifndef TWO_HEADED_KIMERA
return col_count;
#else
return col_left_count;
#endif
}
matrix_row_t kimera_read_cols(uint8_t row)
{ {
init_data(0xFF); init_data(0xFF);
@ -196,10 +220,20 @@ matrix_row_t read_cols(void)
} }
} }
} }
#ifdef TWO_HEADED_KIMERA
if (row < row_left_count) {
cols &= col_left_mask;
}
else {
cols >>= col_left_count;
}
#endif
return cols; return cols;
} }
void unselect_rows(void) void kimera_unselect_rows(void)
{ {
/* set all output registers to 0xFF */ /* set all output registers to 0xFF */
init_data(0xFF); init_data(0xFF);
@ -208,7 +242,7 @@ void unselect_rows(void)
} }
} }
void select_row(uint8_t row) void kimera_select_row(uint8_t row)
{ {
/* set selected row to low */ /* set selected row to low */
init_data(0xFF); init_data(0xFF);

View File

@ -128,9 +128,11 @@ void wdt_init(void);
uint8_t read_matrix_mapping(void); uint8_t read_matrix_mapping(void);
void write_matrix_mapping(void); void write_matrix_mapping(void);
void kimera_scan(void); void kimera_scan(void);
matrix_row_t read_cols(void); uint8_t kimera_matrix_rows(void);
void unselect_rows(void); uint8_t kimera_matrix_cols(void);
void select_row(uint8_t row); matrix_row_t kimera_read_cols(uint8_t row);
void kimera_unselect_rows(void);
void kimera_select_row(uint8_t row);
void expander_init(uint8_t exp); void expander_init(uint8_t exp);
uint8_t expander_write(uint8_t exp, uint8_t command, uint8_t *data); uint8_t expander_write(uint8_t exp, uint8_t command, uint8_t *data);
uint8_t expander_read(uint8_t exp, uint8_t command, uint8_t *data); uint8_t expander_read(uint8_t exp, uint8_t command, uint8_t *data);

View File

@ -39,24 +39,16 @@ static uint8_t debouncing = DEBOUNCE;
static matrix_row_t matrix[MATRIX_ROWS]; static matrix_row_t matrix[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS]; static matrix_row_t matrix_debouncing[MATRIX_ROWS];
extern uint8_t row_count;
extern uint8_t col_count;
extern uint8_t data[EXP_COUNT][EXP_PORT_COUNT];
inline inline
uint8_t matrix_rows(void) uint8_t matrix_rows(void)
{ {
return row_count; return kimera_matrix_rows();
} }
inline inline
uint8_t matrix_cols(void) uint8_t matrix_cols(void)
{ {
#ifndef TWO_HEADED_KIMERA return kimera_matrix_cols();
return col_count;
#else
return col_count / 2;
#endif
} }
void matrix_init(void) void matrix_init(void)
@ -68,7 +60,7 @@ void matrix_init(void)
kimera_init(); kimera_init();
// initialize row and col // initialize row and col
unselect_rows(); kimera_unselect_rows();
// initialize matrix state: all keys off // initialize matrix state: all keys off
for (uint8_t i=0; i < matrix_rows(); i++) { for (uint8_t i=0; i < matrix_rows(); i++) {
@ -85,19 +77,9 @@ uint8_t matrix_scan(void)
kimera_scan(); kimera_scan();
for (uint8_t i = 0; i < matrix_rows(); i++) { for (uint8_t i = 0; i < matrix_rows(); i++) {
select_row(i); kimera_select_row(i);
_delay_us(30); // without this wait read unstable value. _delay_us(30); // without this wait read unstable value.
#ifndef TWO_HEADED_KIMERA matrix_row_t cols = kimera_read_cols(i);
matrix_row_t cols = read_cols();
#else
matrix_row_t cols = read_cols();
if (i < 8) {
cols &= 0xFFFFUL;
}
else {
cols >>= 16;
}
#endif
if (matrix_debouncing[i] != cols) { if (matrix_debouncing[i] != cols) {
matrix_debouncing[i] = cols; matrix_debouncing[i] = cols;
if (debouncing) { if (debouncing) {
@ -105,7 +87,7 @@ uint8_t matrix_scan(void)
} }
debouncing = DEBOUNCE; debouncing = DEBOUNCE;
} }
unselect_rows(); kimera_unselect_rows();
} }
if (debouncing) { if (debouncing) {