keybrd library is an open source library for creating custom-keyboard firmware.
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

keybrd_7b_mapping_multi-layer.ino 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* keybrd_7b_mapping_multi-layer.ino
  2. This sketch:
  3. is modified from keybrd_3a_multi-layerHold.ino by swaping readPins numbers with Row-pin numbers
  4. runs on basic breadboard keyboard modified by flipping diodes, anodes towards rows (blue bus)
  5. demonstrates mapping from LAYOUT to MATRIX on a multi-layer keyboard
  6. assumes you undstand keybrd Tutorial 2 - keybrd multi-layer
  7. | Layout | **0** | **1** |
  8. |:------:|-------|-------|
  9. | **0** | a - | b = |
  10. | **1** | fn | shift |
  11. */
  12. // ################## GLOBAL ###################
  13. // ================= INCLUDES ==================
  14. //Keys
  15. #include <Code_Sc.h>
  16. #include <LayerState.h>
  17. #include <Code_LayerHold.h>
  18. #include <Key_LayeredKeys.h>
  19. //Matrix
  20. #include <Row.h>
  21. #include <Scanner_uC.h>
  22. #include <ScanDelay.h>
  23. // ============ SPEED CONFIGURATION ============
  24. ScanDelay scanDelay(9000);
  25. // ================== SCANNER ==================
  26. uint8_t readPins[] = {0, 1};
  27. uint8_t readPinCount = sizeof(readPins)/sizeof(*readPins);
  28. Scanner_uC scanner(LOW, readPins, readPinCount);
  29. // =================== CODES ===================
  30. // ---------------- LAYER CODE -----------------
  31. enum layerIds { NORMAL, FN };
  32. LayerState layerState;
  33. Code_LayerHold l_fn(FN, layerState);
  34. // ----------------- SCANCODES -----------------
  35. Code_Sc s_a(KEY_A);
  36. Code_Sc s_b(KEY_B);
  37. Code_Sc s_minus(KEY_MINUS);
  38. Code_Sc s_equal(KEY_EQUAL);
  39. Code_Sc s_shift(MODIFIERKEY_LEFT_SHIFT);
  40. /* ================== LAYOUT ===================
  41. Keyboard layout is the placement of keys.
  42. nullptrs are place holders that are not mapped to the matrix.
  43. By convention, single-layer keys are placed on layer0, and nulls are placed in the remaining layers.
  44. If you replace a null with a code, make sure its coordinate is in the KEYS MAPPING section.
  45. Each non-nullptr array element consums 4 bytes of SRAM (on Teensy LC 32 bit controller).
  46. */
  47. Key* const ptrsLayout[2][2][2] = { //[layer][row][col]
  48. //layer0
  49. {//col0 col1
  50. { &s_a, &s_b }, //row0
  51. { &l_fn, &s_shift } //row1
  52. },
  53. //layer1
  54. {//col0 col1
  55. { &s_minus, &s_equal }, //row0
  56. { nullptr, nullptr } //row1
  57. }
  58. };
  59. /* ================== MATRIX ===================
  60. ptrsLayout[layer][row][col] coordinates correspond to the elements in the layout.
  61. // --------------- CODE MAPPINGS ---------------
  62. Each ptrsLayout in this section maps a Code to one layer in a Key.
  63. Only Key_LayeredKeys are instantiated in this section.
  64. */
  65. Key* const ptrsKeys_00[] = { ptrsLayout[0][0][0], ptrsLayout[1][0][0] }; // { &s_a, &s_minus };
  66. Key_LayeredKeys k_00(ptrsKeys_00);
  67. Key* const ptrsKeys_01[] = { ptrsLayout[0][0][1], ptrsLayout[1][0][1] }; // { &s_b, &s_equal };
  68. Key_LayeredKeys k_01(ptrsKeys_01);
  69. LayerStateInterface& Key_LayeredKeys::refLayerState = layerState;
  70. /* --------------- KEY MAPPINGS ----------------
  71. The Keys are transposed (layout rows are placed in matrix columns).
  72. ptrsLayout elements are from the LAYOUT section.
  73. Key_LayeredKeys are from the CODE MAPPINGS section.
  74. */
  75. Key* const ptrsKeys_0[] = { &k_00, ptrsLayout[0][1][0] }; // { { &s_a, &s_minus }, &l_fn };
  76. uint8_t keyCount_0 = sizeof(ptrsKeys_0)/sizeof(*ptrsKeys_0);
  77. Row row_0(scanner, 14, ptrsKeys_0, keyCount_0);
  78. Key* const ptrsKeys_1[] = { &k_01, ptrsLayout[0][1][1] }; // { { &s_b, &s_equal }, &s_shift };
  79. uint8_t keyCount_1 = sizeof(ptrsKeys_1)/sizeof(*ptrsKeys_1);
  80. Row row_1(scanner, 15, ptrsKeys_1, keyCount_1);
  81. // ################### MAIN ####################
  82. void setup()
  83. {
  84. }
  85. void loop()
  86. {
  87. row_0.process();
  88. row_1.process();
  89. scanDelay.delay();
  90. }