Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
Dieses Repo ist archiviert. Du kannst Dateien sehen und es klonen, kannst aber nicht pushen oder Issues/Pull-Requests öffnen.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. Copyright 2013 Kai Ryu <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <avr/pgmspace.h>
  15. #include <avr/eeprom.h>
  16. #include "eeconfig.h"
  17. #include "keymap_ex.h"
  18. #include "debug.h"
  19. #ifdef KEYMAP_EX_ENABLE
  20. void keymap_init(void) {
  21. if (!check_keymap_in_eeprom()) {
  22. write_keymap_to_eeprom();
  23. }
  24. }
  25. bool check_keymap_in_eeprom(void) {
  26. uint16_t checksum_in_eeprom = eeprom_read_word(&((keymap_ex_t*)EECONFIG_KEYMAP_EX)->checksum);
  27. uint16_t checksum = EECONFIG_MAGIC_NUMBER;
  28. for (uint16_t i = 0; i < KEYMAP_SIZE; i += 2) {
  29. checksum += eeprom_read_word((void*)(EECONFIG_KEYMAP_FN_ACTIONS + i));
  30. }
  31. #ifdef DEBUG
  32. eeprom_write_word((void*)(EECONFIG_KEYMAP_DEBUG), checksum);
  33. #endif
  34. return (checksum_in_eeprom == checksum);
  35. }
  36. void write_keymap_to_eeprom(void) {
  37. uint16_t checksum = EECONFIG_MAGIC_NUMBER;
  38. const uint16_t *fn_actions = fn_actions_pointer();
  39. const uint8_t *keymaps = keymaps_pointer();
  40. // write fn_actions
  41. if (fn_actions != NULL) {
  42. uint16_t fn_actions_count_in_flash = fn_actions_count();
  43. for (uint16_t i = 0; i < FN_ACTIONS_COUNT; i++) {
  44. uint16_t fn_action = 0;
  45. if (i < fn_actions_count_in_flash) {
  46. fn_action = pgm_read_word(fn_actions + i);
  47. }
  48. eeconfig_write_keymap_fn_action(i, fn_action);
  49. checksum += fn_action;
  50. }
  51. }
  52. // write keymaps
  53. if (keymaps != NULL) {
  54. uint16_t keys_count_in_flash = keys_count();
  55. for (uint16_t i = 0; i < KEYS_COUNT; i++) {
  56. uint8_t keymap = 0;
  57. if (i < keys_count_in_flash) {
  58. keymap = pgm_read_byte(keymaps + i);
  59. }
  60. eeconfig_write_keymap_key_by_index(i, keymap);
  61. uint16_t keymap_word = keymap;
  62. if (i & 1) {
  63. keymap_word = keymap << 8;
  64. }
  65. checksum += keymap_word;
  66. }
  67. }
  68. // write checksum
  69. eeprom_write_word(&((keymap_ex_t*)EECONFIG_KEYMAP_EX)->checksum, checksum);
  70. }
  71. uint8_t eeconfig_read_keymap_key(uint8_t layer, uint8_t row, uint8_t col) {
  72. //return eeprom_read_byte(&((keymap_ex_t*)(EECONFIG_KEYMAP_EX))->keymaps[layer][row][col]);
  73. return eeprom_read_byte((void*)(EECONFIG_KEYMAP_KEYMAPS + KEY_OFFSET(layer, row, col)));
  74. }
  75. void eeconfig_write_keymap_key(uint8_t layer, uint8_t row, uint8_t col, uint8_t key) {
  76. //return eeprom_write_byte(&((keymap_ex_t*)(EECONFIG_KEYMAP_EX))->keymaps[layer][row][col], key);
  77. return eeprom_write_byte((void*)(EECONFIG_KEYMAP_KEYMAPS + KEY_OFFSET(layer, row, col)), key);
  78. }
  79. uint8_t eeconfig_read_keymap_key_by_index(uint16_t index) {
  80. //return eeprom_read_byte(((keymap_ex_t*)(EECONFIG_KEYMAP_EX)) + index);
  81. return eeprom_read_byte((void*)(EECONFIG_KEYMAP_KEYMAPS + index));
  82. }
  83. void eeconfig_write_keymap_key_by_index(uint16_t index, uint8_t key) {
  84. //return eeprom_write_byte(((keymap_ex_t*)(EECONFIG_KEYMAP_EX)) + index, key);
  85. return eeprom_write_byte((void*)(EECONFIG_KEYMAP_KEYMAPS + index), key);
  86. }
  87. uint16_t eeconfig_read_keymap_fn_action(uint8_t index) {
  88. //return eeprom_read_word(&((keymap_ex_t*)(EECONFIG_KEYMAP_EX))->fn_actions[index]);
  89. return eeprom_read_word((void*)(EECONFIG_KEYMAP_FN_ACTIONS + FN_ACTION_OFFSET(index)));
  90. }
  91. void eeconfig_write_keymap_fn_action(uint8_t index, uint16_t fn_action) {
  92. //return eeprom_write_word(&((keymap_ex_t*)(EECONFIG_KEYMAP_EX))->fn_actions[index], fn_action);
  93. return eeprom_write_word((void*)(EECONFIG_KEYMAP_FN_ACTIONS + FN_ACTION_OFFSET(index)), fn_action);
  94. }
  95. #endif