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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 & 0xf0) >> 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) {
  32. return (action_t)ACTION_NO;
  33. }
  34. #if defined(__AVR__)
  35. return (action_t)pgm_read_word(&actionmaps[(layer)][(uni.row & 0x7)][(uni.col)]);
  36. #else
  37. return actionmaps[(layer)][(uni.row & 0x7)][(uni.col)];
  38. #endif
  39. }
  40. /* Macro */
  41. __attribute__ ((weak))
  42. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  43. {
  44. return MACRO_NONE;
  45. }
  46. /* Function */
  47. __attribute__ ((weak))
  48. void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
  49. {
  50. }