keycode_cache_mock.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Copyright 2025 Garretonzo
  2. *
  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. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "keycode_cache_mock.h"
  17. #include "quantum/action.h"
  18. #include "quantum/quantum_keycodes.h"
  19. // Mock keymap storage
  20. static uint16_t mock_keymap[4][4] = {{KC_NO}};
  21. // Mock functions needed for testing
  22. uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) {
  23. if (layer < 4 && key.row < 4 && key.col < 4) {
  24. return mock_keymap[key.row][key.col];
  25. }
  26. return KC_NO;
  27. }
  28. void dynamic_keymap_set_keycode(uint8_t layer, uint8_t row, uint8_t column, uint16_t keycode) {
  29. if (layer < 4 && row < 4 && column < 4) {
  30. mock_keymap[row][column] = keycode;
  31. }
  32. }
  33. uint16_t dynamic_keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t column) {
  34. if (layer < 4 && row < 4 && column < 4) {
  35. return mock_keymap[row][column];
  36. }
  37. return KC_NO;
  38. }
  39. action_t action_for_keycode(uint16_t keycode) {
  40. action_t action;
  41. action.code = keycode;
  42. return action;
  43. }
  44. action_t action_for_key(uint8_t layer, keypos_t key) {
  45. uint16_t keycode = keymap_key_to_keycode(layer, key);
  46. return action_for_keycode(keycode);
  47. }
  48. // Utilities for debug
  49. uint8_t biton(uint8_t bits) {
  50. for (uint8_t i = 0; i < 8; i++) {
  51. if (bits & (1 << i)) return i;
  52. }
  53. return 0;
  54. }
  55. uint8_t biton16(uint16_t bits) {
  56. for (uint8_t i = 0; i < 16; i++) {
  57. if (bits & (1 << i)) return i;
  58. }
  59. return 0;
  60. }
  61. uint8_t biton32(uint32_t bits) {
  62. for (uint8_t i = 0; i < 32; i++) {
  63. if (bits & (1UL << i)) return i;
  64. }
  65. return 0;
  66. }
  67. // Keyboard functions
  68. void clear_keyboard_but_mods(void) {
  69. // No-op for tests
  70. }
  71. void clear_keyboard_but_mods_and_keys(void) {
  72. // No-op for tests
  73. }