1
0

kimera: Fix bugs of keymap and mux driving

This commit is contained in:
Kai Ryu 2014-06-04 00:57:00 +09:00
parent 9365e69301
commit 2579b5bbf5
2 changed files with 11 additions and 8 deletions

View File

@ -136,10 +136,10 @@ void write_matrix_mapping(void)
void shift_out_word(uint16_t data) void shift_out_word(uint16_t data)
{ {
SPDR = (data & 0xFF);
while (!(SPSR & (1<<SPIF)));
SPDR = ((data>>8) & 0xFF); SPDR = ((data>>8) & 0xFF);
while (!(SPSR & (1<<SPIF))); while (!(SPSR & (1<<SPIF)));
SPDR = (data & 0xFF);
while (!(SPSR & (1<<SPIF)));
RCK_PORT &= ~(1<<RCK_BIT); RCK_PORT &= ~(1<<RCK_BIT);
RCK_PORT |= (1<<RCK_BIT); RCK_PORT |= (1<<RCK_BIT);
} }
@ -163,13 +163,14 @@ void init_cols(void)
matrix_row_t read_cols(void) matrix_row_t read_cols(void)
{ {
matrix_row_t cols = 0; matrix_row_t cols = 0;
for (uint8_t col = 0; col < MATRIX_COLS; col++) { for (uint8_t col = 0; col < col_max_count; col++) {
uint8_t px = col_mapping[col]; uint8_t px = col_mapping[col];
if (px != UNCONFIGURED) { if (px != UNCONFIGURED) {
shift_out_word(shift_out_cache | PX_TO_SHIFT_OUT(px)); uint8_t mux = PX_TO_MUX(px);
shift_out_word((shift_out_cache | PX_TO_SHIFT_OUT(px)) & ~(MUX_INH_TO_SHIFT_OUT(mux)));
_delay_us(10); _delay_us(10);
if (!(ZX_PIN & (1 << MUX_TO_ZX_BIT(PX_TO_MUX(px))))) { if (!(ZX_PIN & (1 << MUX_TO_ZX_BIT(mux)))) {
cols |= (1 << col); cols |= (1UL << col);
} }
} }
} }
@ -185,8 +186,9 @@ void select_row(uint8_t row)
{ {
uint8_t px = row_mapping[row]; uint8_t px = row_mapping[row];
if (px != UNCONFIGURED) { if (px != UNCONFIGURED) {
ZX_PORT &= ~(1 << MUX_TO_ZX_BIT(PX_TO_MUX(row))); uint8_t mux = PX_TO_MUX(px);
shift_out_cache = PX_TO_SHIFT_OUT(px) | MUX_INH_TO_SHIFT_OUT(PX_TO_MUX(px)); ZX_PORT &= ~(1 << MUX_TO_ZX_BIT(mux));
shift_out_cache = ((MUX_OFF_TO_SHIFT_OUT | PX_TO_SHIFT_OUT(px)) & ~(MUX_INH_TO_SHIFT_OUT(mux)));
shift_out_word(shift_out_cache); shift_out_word(shift_out_cache);
} }
} }

View File

@ -156,6 +156,7 @@ const uint16_t PROGMEM mux_inh_to_shift_out[] = {
#endif #endif
#define PX_TO_SHIFT_OUT(x) (pgm_read_word(px_to_shift_out + (x))) #define PX_TO_SHIFT_OUT(x) (pgm_read_word(px_to_shift_out + (x)))
#define MUX_INH_TO_SHIFT_OUT(x) (pgm_read_word(mux_inh_to_shift_out + (x))) #define MUX_INH_TO_SHIFT_OUT(x) (pgm_read_word(mux_inh_to_shift_out + (x)))
#define MUX_OFF_TO_SHIFT_OUT (1<<MUX1_INH | 1<<MUX2_INH | 1<<MUX3_INH | 1<<MUX4_INH)
/* Matrix Mapping in EEPROM */ /* Matrix Mapping in EEPROM */