kimera: Make two-handed kimera can work with keymap-in-eeprom
This commit is contained in:
parent
abf70607d1
commit
7a1eeebaa7
@ -35,7 +35,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#define MATRIX_SIZE 16 * 16
|
||||
#define FN_ACTIONS_COUNT 32
|
||||
#define KEYMAPS_COUNT 3
|
||||
#ifndef TWO_HEADED_KIMERA
|
||||
#define EECONFIG_KEYMAP_IN_EEPROM 45
|
||||
#else
|
||||
#define EECONFIG_KEYMAP_IN_EEPROM 77
|
||||
#endif
|
||||
|
||||
/* define if matrix has ghost */
|
||||
//#define MATRIX_HAS_GHOST
|
||||
|
@ -8,7 +8,7 @@ const uint8_t keymaps[][MATRIX_SIZE] PROGMEM = {
|
||||
#endif
|
||||
/* 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|
|
||||
* |---------------||-------------------------. `-----------------------------------||-----------|
|
||||
@ -18,7 +18,7 @@ const uint8_t keymaps[][MATRIX_SIZE] PROGMEM = {
|
||||
* |---------------||----------------------------. `-------------------------------|| ,---. |
|
||||
* | 1| 2| 3| ||Shift | Z| X| C| V| B| | N| M| ,| .| /|Shift || |Up | |
|
||||
* |-----------|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(
|
||||
@ -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, \
|
||||
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, \
|
||||
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 ),
|
||||
};
|
||||
|
@ -32,7 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#define SCL_DURATION (1000000L/SCL_CLOCK)/2
|
||||
extern uint8_t i2c_force_stop;
|
||||
|
||||
uint8_t row_mapping[PX_COUNT] = {
|
||||
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,
|
||||
@ -45,7 +45,7 @@ uint8_t row_mapping[PX_COUNT] = {
|
||||
UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED
|
||||
#endif
|
||||
};
|
||||
uint8_t col_mapping[PX_COUNT] = {
|
||||
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,
|
||||
@ -59,14 +59,17 @@ uint8_t col_mapping[PX_COUNT] = {
|
||||
#endif
|
||||
};
|
||||
#ifndef TWO_HEADED_KIMERA
|
||||
uint8_t row_count = 8;
|
||||
uint8_t col_count = 24;
|
||||
static uint8_t row_count = 8;
|
||||
static uint8_t col_count = 24;
|
||||
#else
|
||||
uint8_t row_count = 16;
|
||||
uint8_t col_count = 32;
|
||||
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
|
||||
uint8_t data[EXP_COUNT][EXP_PORT_COUNT];
|
||||
uint8_t exp_status = 0;
|
||||
static uint8_t data[EXP_COUNT][EXP_PORT_COUNT];
|
||||
static uint8_t exp_status = 0;
|
||||
|
||||
void kimera_init(void)
|
||||
{
|
||||
@ -109,6 +112,11 @@ uint8_t read_matrix_mapping(void)
|
||||
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 << row_left_count) - 1;
|
||||
#endif
|
||||
|
||||
/* read row 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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
void unselect_rows(void)
|
||||
void kimera_unselect_rows(void)
|
||||
{
|
||||
/* set all output registers to 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 */
|
||||
init_data(0xFF);
|
||||
|
@ -128,9 +128,11 @@ void wdt_init(void);
|
||||
uint8_t read_matrix_mapping(void);
|
||||
void write_matrix_mapping(void);
|
||||
void kimera_scan(void);
|
||||
matrix_row_t read_cols(void);
|
||||
void unselect_rows(void);
|
||||
void select_row(uint8_t row);
|
||||
uint8_t kimera_matrix_rows(void);
|
||||
uint8_t kimera_matrix_cols(void);
|
||||
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);
|
||||
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);
|
||||
|
@ -39,24 +39,16 @@ static uint8_t debouncing = DEBOUNCE;
|
||||
static matrix_row_t matrix[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
|
||||
uint8_t matrix_rows(void)
|
||||
{
|
||||
return row_count;
|
||||
return kimera_matrix_rows();
|
||||
}
|
||||
|
||||
inline
|
||||
uint8_t matrix_cols(void)
|
||||
{
|
||||
#ifndef TWO_HEADED_KIMERA
|
||||
return col_count;
|
||||
#else
|
||||
return col_count / 2;
|
||||
#endif
|
||||
return kimera_matrix_cols();
|
||||
}
|
||||
|
||||
void matrix_init(void)
|
||||
@ -68,7 +60,7 @@ void matrix_init(void)
|
||||
kimera_init();
|
||||
|
||||
// initialize row and col
|
||||
unselect_rows();
|
||||
kimera_unselect_rows();
|
||||
|
||||
// initialize matrix state: all keys off
|
||||
for (uint8_t i=0; i < matrix_rows(); i++) {
|
||||
@ -85,19 +77,9 @@ uint8_t matrix_scan(void)
|
||||
kimera_scan();
|
||||
|
||||
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.
|
||||
#ifndef TWO_HEADED_KIMERA
|
||||
matrix_row_t cols = read_cols();
|
||||
#else
|
||||
matrix_row_t cols = read_cols();
|
||||
if (i < 8) {
|
||||
cols &= 0xFFFFUL;
|
||||
}
|
||||
else {
|
||||
cols >>= 16;
|
||||
}
|
||||
#endif
|
||||
matrix_row_t cols = kimera_read_cols(i);
|
||||
if (matrix_debouncing[i] != cols) {
|
||||
matrix_debouncing[i] = cols;
|
||||
if (debouncing) {
|
||||
@ -105,7 +87,7 @@ uint8_t matrix_scan(void)
|
||||
}
|
||||
debouncing = DEBOUNCE;
|
||||
}
|
||||
unselect_rows();
|
||||
kimera_unselect_rows();
|
||||
}
|
||||
|
||||
if (debouncing) {
|
||||
|
Reference in New Issue
Block a user