瀏覽代碼

kimera: Fix a bug of program memory const

kimera
Kai Ryu 10 年之前
父節點
當前提交
9365e69301
共有 2 個檔案被更改,包括 40 行新增34 行删除
  1. 37
    34
      keyboard/kimera/kimera.c
  2. 3
    0
      keyboard/kimera/kimera.h

+ 37
- 34
keyboard/kimera/kimera.c 查看文件



#include <stdbool.h> #include <stdbool.h>
#include <avr/eeprom.h> #include <avr/eeprom.h>
#include <util/delay.h>
#include "kimera.h" #include "kimera.h"
#include "debug.h" #include "debug.h"


void kimera_init(void) void kimera_init(void)
{ {
// read config // read config
write_matrix_mapping();
if (read_matrix_mapping()) { if (read_matrix_mapping()) {
write_matrix_mapping(); write_matrix_mapping();
} }
return error; return error;
} }


for (uint8_t i = 0; i < MUX_COUNT; i++) {
mux_mapping[i] = mux_config & (1<<i);
if (mux_mapping[i] == MUX_FOR_COL) {
for (uint8_t mux = 0; mux < MUX_COUNT; mux++) {
mux_mapping[mux] = mux_config & (1 << mux);
if (mux_mapping[mux] == MUX_FOR_COL) {
col_max_count += MUX_PORTS; col_max_count += MUX_PORTS;
} }
else { else {
} }


uint8_t *mapping = EECONFIG_ROW_COL_MAPPING; uint8_t *mapping = EECONFIG_ROW_COL_MAPPING;
for (uint8_t i = 0; i < row_max_count; i++) {
row_mapping[i] = eeprom_read_byte(mapping++);
if (row_mapping[i] != UNCONFIGURED) {
if (mux_mapping[PX_TO_MUX(row_mapping[i])] != MUX_FOR_ROW) {
row_mapping[i] = UNCONFIGURED;
for (uint8_t row = 0; row < row_max_count; row++) {
row_mapping[row] = eeprom_read_byte(mapping++);
if (row_mapping[row] != UNCONFIGURED) {
if (mux_mapping[PX_TO_MUX(row_mapping[row])] != MUX_FOR_ROW) {
row_mapping[row] = UNCONFIGURED;
error++; error++;
} }
} }
} }
for (uint8_t i = 0; i < col_max_count; i++) {
col_mapping[i] = eeprom_read_byte(mapping++);
if (col_mapping[i] != UNCONFIGURED) {
if (mux_mapping[PX_TO_MUX(col_mapping[i])] != MUX_FOR_COL) {
col_mapping[i] = UNCONFIGURED;
for (uint8_t col = 0; col < col_max_count; col++) {
col_mapping[col] = eeprom_read_byte(mapping++);
if (col_mapping[col] != UNCONFIGURED) {
if (mux_mapping[PX_TO_MUX(col_mapping[col])] != MUX_FOR_COL) {
col_mapping[col] = UNCONFIGURED;
error++; error++;
} }
} }
row_max_count = 0; row_max_count = 0;
col_max_count = 0; col_max_count = 0;


for (uint8_t i = 0; i < MUX_COUNT; i++) {
mux_config |= (mux_mapping[i] << i);
if (mux_mapping[i] == MUX_FOR_COL) {
for (uint8_t mux = 0; mux < MUX_COUNT; mux++) {
mux_config |= (mux_mapping[mux] << mux);
if (mux_mapping[mux] == MUX_FOR_COL) {
col_max_count += MUX_PORTS; col_max_count += MUX_PORTS;
} }
else { else {
eeprom_write_byte(EECONFIG_MUX_MAPPING, mux_config); eeprom_write_byte(EECONFIG_MUX_MAPPING, mux_config);


uint8_t *mapping = EECONFIG_ROW_COL_MAPPING; uint8_t *mapping = EECONFIG_ROW_COL_MAPPING;
for (uint8_t i = 0; i < row_max_count; i++) {
eeprom_write_byte(mapping++, row_mapping[i]);
for (uint8_t row = 0; row < row_max_count; row++) {
eeprom_write_byte(mapping++, row_mapping[row]);
} }
for (uint8_t i = 0; i < col_max_count; i++) {
eeprom_write_byte(mapping++, col_mapping[i]);
for (uint8_t col = 0; col < col_max_count; col++) {
eeprom_write_byte(mapping++, col_mapping[col]);
} }
} }


void init_cols(void) void init_cols(void)
{ {
// init mux io pins // init mux io pins
for (uint8_t i = 0; i < MUX_COUNT; i++) {
if (mux_mapping[i] == MUX_FOR_COL) {
ZX_DDR &= ~(1 << zx_bit[i]);
ZX_PORT |= (1 << zx_bit[i]);
for (uint8_t mux = 0; mux < MUX_COUNT; mux++) {
uint8_t bit = MUX_TO_ZX_BIT(mux);
if (mux_mapping[mux] == MUX_FOR_COL) {
ZX_DDR &= ~(1 << bit);
ZX_PORT |= (1 << bit);
} }
else { else {
ZX_DDR |= (1 << zx_bit[i]);
ZX_PORT |= (1 << zx_bit[i]);
ZX_DDR |= (1 << bit);
ZX_PORT |= (1 << bit);
} }
} }
} }
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 i = 0; i < MATRIX_COLS; i++) {
uint8_t px = col_mapping[i];
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
uint8_t px = col_mapping[col];
if (px != UNCONFIGURED) { if (px != UNCONFIGURED) {
shift_out_word(shift_out_cache | px_to_shift_out[px]);
// TODO: delay
if (!(ZX_PIN & (1 << zx_bit[PX_TO_MUX(px)]))) {
cols |= (1 << i);
shift_out_word(shift_out_cache | PX_TO_SHIFT_OUT(px));
_delay_us(10);
if (!(ZX_PIN & (1 << MUX_TO_ZX_BIT(PX_TO_MUX(px))))) {
cols |= (1 << col);
} }
} }
} }
{ {
uint8_t px = row_mapping[row]; uint8_t px = row_mapping[row];
if (px != UNCONFIGURED) { if (px != UNCONFIGURED) {
ZX_PORT &= ~(1 << zx_bit[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(PX_TO_MUX(row)));
shift_out_cache = PX_TO_SHIFT_OUT(px) | MUX_INH_TO_SHIFT_OUT(PX_TO_MUX(px));
shift_out_word(shift_out_cache); shift_out_word(shift_out_cache);
} }
} }

+ 3
- 0
keyboard/kimera/kimera.h 查看文件

PF5, PF6, PF7, PF4 PF5, PF6, PF7, PF4
}; };
#endif #endif
#define MUX_TO_ZX_BIT(x) (pgm_read_byte(zx_bit + (x)))


/* /*
Shift Register Multiplexer Shift Register Multiplexer
1<<MUX1_INH, 1<<MUX2_INH, 1<<MUX3_INH, 1<<MUX4_INH 1<<MUX1_INH, 1<<MUX2_INH, 1<<MUX3_INH, 1<<MUX4_INH
}; };
#endif #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)))


/* Matrix Mapping in EEPROM */ /* Matrix Mapping in EEPROM */