csc027.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "csc027.h"
  2. // Declare the strings in PROGMEM using the convenience macro
  3. CUSTOM_MACROS(CUSTOM_DEF, CUSTOM_MACRO_STRING, SEMI_DELIM);
  4. static const char* const custom_macros[] PROGMEM = {
  5. // Declare the pointer to the strings in PROGMEM
  6. CUSTOM_MACROS(CUSTOM_VAR, DROP, COMMA_DELIM)
  7. };
  8. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  9. switch(keycode) {
  10. case LOWER:
  11. if(record->event.pressed) {
  12. layer_on(_LW);
  13. } else {
  14. layer_off(_LW);
  15. }
  16. update_tri_layer(_LW, _RS, _MS);
  17. return false;
  18. case RAISE:
  19. if(record->event.pressed) {
  20. layer_on(_RS);
  21. } else {
  22. layer_off(_RS);
  23. }
  24. update_tri_layer(_LW, _RS, _MS);
  25. return false;
  26. case (MC_first + 1)...(MC_last - 1):
  27. if(record->event.pressed) {
  28. send_string_P(
  29. #if defined(__AVR__)
  30. // The accessor here first reads from the pointer array that is located
  31. // in PROGMEM. The pointer is taken and passed to the send_string_P
  32. // function, which is aware of the difference between RAM and PROGMEM
  33. // pointers.
  34. (char*)pgm_read_word(&custom_macros[keycode - MC_first - 1])
  35. #else
  36. // For non-AVR MCUs, the PROGMEM macro is defined as nothing. So, the strings are
  37. // declared in RAM instead of flash. The send_string_P function, when compiled for
  38. // non-AVR targets, uses a different definition of pgm_read_byte internally. This
  39. // definition uses RAM pointers instead. This is why the raw pointer is passed for
  40. // non-AVR MCUs.
  41. custom_macros[keycode - MC_first - 1]
  42. #endif
  43. );
  44. return true;
  45. }
  46. return false;
  47. default:
  48. return true;
  49. }
  50. }