csc027.c 2.6 KB

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