Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

unimap.c 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "keyboard.h"
  2. #include "action.h"
  3. #include "unimap.h"
  4. #include "print.h"
  5. #if defined(__AVR__)
  6. # include <avr/pgmspace.h>
  7. #endif
  8. /* Keymapping with 16bit action codes */
  9. extern const action_t actionmaps[][UNIMAP_ROWS][UNIMAP_COLS];
  10. // table translates matrix to universal keymap
  11. extern const uint8_t unimap_trans[MATRIX_ROWS][MATRIX_COLS];
  12. // translates raw matrix to universal map
  13. keypos_t unimap_translate(keypos_t key)
  14. {
  15. uint8_t unimap_pos =
  16. #if defined(__AVR__)
  17. pgm_read_byte(&unimap_trans[key.row][key.col]);
  18. #else
  19. unimap_trans[key.row][key.col];
  20. #endif
  21. return (keypos_t) {
  22. .row = ((unimap_pos & 0x70) >> 4),
  23. .col = (unimap_pos & 0x0F)
  24. };
  25. }
  26. /* Converts key to action */
  27. __attribute__ ((weak))
  28. action_t action_for_key(uint8_t layer, keypos_t key)
  29. {
  30. keypos_t uni = unimap_translate(key);
  31. if ((uni.row << 4 | uni.col) == UNIMAP_NO) return (action_t)ACTION_NO;
  32. #if defined(__AVR__)
  33. return (action_t)pgm_read_word(&actionmaps[(layer)][(uni.row)][(uni.col)]);
  34. #else
  35. return actionmaps[(layer)][(uni.row)][(uni.col)];
  36. #endif
  37. }
  38. /* Macro */
  39. __attribute__ ((weak))
  40. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  41. {
  42. return MACRO_NONE;
  43. }
  44. /* Function */
  45. __attribute__ ((weak))
  46. void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
  47. {
  48. }