1
0

Fix confusion of size and count

This commit is contained in:
Kai Ryu 2013-11-21 13:44:32 +09:00
parent d926950e17
commit 91f86df368
2 changed files with 12 additions and 11 deletions

View File

@ -30,7 +30,9 @@ void keymap_init(void) {
} }
bool check_keymap_in_eeprom(void) { bool check_keymap_in_eeprom(void) {
return false; uint16_t checksum_in_eeprom = eeprom_read_word(&((keymap_ex_t*)EECONFIG_KEYMAP_EX)->checksum);
uint16_t checksum = EECONFIG_MAGIC_NUMBER;
return (checksum_in_eeprom == checksum);
} }
void write_keymap_to_eeprom(void) { void write_keymap_to_eeprom(void) {
@ -39,10 +41,10 @@ void write_keymap_to_eeprom(void) {
const uint8_t *keymaps = keymaps_pointer(); const uint8_t *keymaps = keymaps_pointer();
// write fn_actions // write fn_actions
if (fn_actions != NULL) { if (fn_actions != NULL) {
uint16_t size_of_fn_actions = fn_actions_size(); uint16_t fn_actions_count_in_flash = fn_actions_count();
for (uint16_t i = 0; i < FN_ACTIONS_SIZE_EX; i++) { for (uint16_t i = 0; i < FN_ACTIONS_COUNT; i++) {
uint16_t fn_action = 0; uint16_t fn_action = 0;
if (i < size_of_fn_actions) { if (i < fn_actions_count_in_flash) {
fn_action = pgm_read_word(fn_actions + i); fn_action = pgm_read_word(fn_actions + i);
} }
eeconfig_write_keymap_fn_action(i, fn_action); eeconfig_write_keymap_fn_action(i, fn_action);
@ -51,10 +53,10 @@ void write_keymap_to_eeprom(void) {
} }
// write keymaps // write keymaps
if (keymaps != NULL) { if (keymaps != NULL) {
uint16_t size_of_keymaps = keymaps_size(); uint16_t keys_count_in_flash = keys_count();
for (uint16_t i = 0; i < KEYMAPS_SIZE_EX; i++) { for (uint16_t i = 0; i < KEYS_COUNT; i++) {
uint8_t keymap = 0; uint8_t keymap = 0;
if (i < size_of_keymaps) { if (i < keys_count_in_flash) {
keymap = pgm_read_byte(keymaps + i); keymap = pgm_read_byte(keymaps + i);
} }
eeconfig_write_keymap_key_by_index(i, keymap); eeconfig_write_keymap_key_by_index(i, keymap);

View File

@ -37,8 +37,7 @@ typedef struct {
#define EECONFIG_KEYMAP_FN_ACTIONS (EECONFIG_KEYMAP_EX + sizeof(uint16_t)) #define EECONFIG_KEYMAP_FN_ACTIONS (EECONFIG_KEYMAP_EX + sizeof(uint16_t))
#define EECONFIG_KEYMAP_KEYMAPS (EECONFIG_KEYMAP_FN_ACTIONS + sizeof(uint16_t) * FN_ACTIONS_COUNT) #define EECONFIG_KEYMAP_KEYMAPS (EECONFIG_KEYMAP_FN_ACTIONS + sizeof(uint16_t) * FN_ACTIONS_COUNT)
#define FN_ACTIONS_SIZE_EX (sizeof(uint16_t) * FN_ACTIONS_COUNT) #define KEYS_COUNT (KEYMAPS_COUNT * MATRIX_ROWS * MATRIX_COLS)
#define KEYMAPS_SIZE_EX (sizeof(uint8_t) * KEYMAPS_COUNT * MATRIX_ROWS * MATRIX_COLS)
#define FN_ACTION_OFFSET(index) (sizeof(uint16_t) * index) #define FN_ACTION_OFFSET(index) (sizeof(uint16_t) * index)
#define KEY_OFFSET(layer, row, col) (sizeof(uint8_t) * (layer * MATRIX_ROWS * MATRIX_COLS + row * MATRIX_COLS + col)) #define KEY_OFFSET(layer, row, col) (sizeof(uint8_t) * (layer * MATRIX_ROWS * MATRIX_COLS + row * MATRIX_COLS + col))
@ -54,8 +53,8 @@ void eeconfig_write_keymap_fn_action(uint8_t index, uint16_t fn_action);
const uint8_t* keymaps_pointer(void); const uint8_t* keymaps_pointer(void);
const uint16_t* fn_actions_pointer(void); const uint16_t* fn_actions_pointer(void);
uint16_t keymaps_size(void); uint16_t keys_count(void);
uint16_t fn_actions_size(void); uint16_t fn_actions_count(void);
#endif #endif