Browse Source

kimera: Fix bugs of keymap and mux driving

kimera
Kai Ryu 10 years ago
parent
commit
2579b5bbf5
2 changed files with 11 additions and 8 deletions
  1. 10
    8
      keyboard/kimera/kimera.c
  2. 1
    0
      keyboard/kimera/kimera.h

+ 10
- 8
keyboard/kimera/kimera.c View File

@@ -136,10 +136,10 @@ void write_matrix_mapping(void)

void shift_out_word(uint16_t data)
{
SPDR = (data & 0xFF);
while (!(SPSR & (1<<SPIF)));
SPDR = ((data>>8) & 0xFF);
while (!(SPSR & (1<<SPIF)));
SPDR = (data & 0xFF);
while (!(SPSR & (1<<SPIF)));
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 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];
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);
if (!(ZX_PIN & (1 << MUX_TO_ZX_BIT(PX_TO_MUX(px))))) {
cols |= (1 << col);
if (!(ZX_PIN & (1 << MUX_TO_ZX_BIT(mux)))) {
cols |= (1UL << col);
}
}
}
@@ -185,8 +186,9 @@ void select_row(uint8_t row)
{
uint8_t px = row_mapping[row];
if (px != UNCONFIGURED) {
ZX_PORT &= ~(1 << MUX_TO_ZX_BIT(PX_TO_MUX(row)));
shift_out_cache = PX_TO_SHIFT_OUT(px) | MUX_INH_TO_SHIFT_OUT(PX_TO_MUX(px));
uint8_t mux = 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);
}
}

+ 1
- 0
keyboard/kimera/kimera.h View File

@@ -156,6 +156,7 @@ const uint16_t PROGMEM mux_inh_to_shift_out[] = {
#endif
#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_OFF_TO_SHIFT_OUT (1<<MUX1_INH | 1<<MUX2_INH | 1<<MUX3_INH | 1<<MUX4_INH)

/* Matrix Mapping in EEPROM */