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.

tutorial_3cde_sublayer_keyboard.md 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. Tutorial 3cde - sublayer keyboard
  2. =================================
  3. This tutorial assumes you have read tutorial_3ab_multi-layer_keyboard.
  4. When you finish this tutorial you will be able to be able to modify a multi-layer keybrd sketch.
  5. Sublayer nomenclature
  6. ---------------------
  7. These definitions are specific to the keybrd library.
  8. **layer group** - is a group of layers that occupy a group of keys.
  9. **layer subgroup** - is a layer group nested in a layer of another layer group.
  10. Layout with a sublayer
  11. ----------------------
  12. The next three example sketches all use this layout:
  13. | Layout | **0** | **1** | **2** |
  14. |:------:|:-----:|:-----:|:-----:|
  15. | **0** | a - 1 | b = | c Num |
  16. | **1** | Alpha | Sym | Enter |
  17. Each cell in the table's body represents a key.
  18. Each element in a cell represents a scancode or layer code.
  19. Pressing the Alpha-layer key locks the Alpha layer.
  20. Letters 'a' 'b' 'c' are on the Alpha layer.
  21. Pressing the Sym-layer key locks the Sym layer.
  22. Symbols '-' '=' and "Num" layer key are on the Sym layer.
  23. If the keyboard is locked on the Sym layer, holding Num down makes it the active layer.
  24. Number '1' is on the Num sublayer.
  25. Releasing the Num key makes the locked layer active.
  26. Example sketches 3c, 3d, and 3e implement the above layout.
  27. Each sketch uses a different layer scheme.
  28. The sketches will run on the basic breadboard keyboard described in [tutorial_1_breadboard_keyboard.md](tutorial_1_breadboard_keyboard.md) with a 3rd column added to pin 16:
  29. ![3-column breadboard keyboard](keybrd_3c_sublayerNull/front.JPG "3-column breadboard keyboard")
  30. Sketch 3c - two layer groups
  31. ----------------------------
  32. This layer scheme has two layer groups:
  33. | group_1 | **0** | **1** | **2** |
  34. |:-------:|:-----:|:-----:|:----------:|
  35. | **0** | a - 1 | b = = | c Num null | layer group with three layers: Alpha Sym Num
  36. | **1** | | | |
  37. | group_0 | **0** | **1** | **2** |
  38. |:-------:|:-----:|:-----:|:-----:|
  39. | **0** | | | |
  40. | **1** | Alpha | Sym | Enter | layer group with a one layer
  41. group_1 covers the entire top row, therefore Num layer covers the entire top row.
  42. Meanwhile, the layout's Num layer only covers the first key.
  43. The unused num-layer space is filled with duplicate and null codes.
  44. A little filler is the simplest way in some situations.
  45. The layer scheme is implemented in keybrd_3c_sublayerNull.ino
  46. The null is not really needed because null is on the same key as Num layer code.
  47. And Num is the only layer code that can activate the Num layer.
  48. The null key would be needed if another Num key where added to the layout.
  49. The next example sketch has three layer groups that fit the layout perfectly.
  50. Sketch 3d - three layer groups
  51. ------------------------------
  52. This layer scheme has three layer groups:
  53. | group_2 | **0** | **1** | **2** |
  54. |:-------:|:-----:|:-----:|:-----:|
  55. | **0** | - 1 | | | layer subgroup with two layers: Sym Num
  56. | **1** | | | |
  57. | group_1 | **0** | **1** | **2** |
  58. |:-------:|:---------:|:-----:|:-----:|
  59. | **0** | a group_2 | b = | c Num | layer group with two layers: Alpha Sym
  60. | **1** | | | |
  61. | group_0 | **0** | **1** | **2** |
  62. |:-------:|:-----:|:-----:|:-----:|
  63. | **0** | | | |
  64. | **1** | Alpha | Sym | Enter | layer group with a one layer
  65. The three layer groups model the logic of the layout accurately, without resorting to fillers.
  66. The layer scheme is implemented in keybrd_3d_sublayerNestedKeys.ino.
  67. Sketch 3e - specialized layered keys
  68. ------------------------------------
  69. Key_LayeredKeys constructor takes any number of code or key arguments.
  70. Key_LayeredScSc is more specialized. It's constructor takes exactly two scancode arguments.
  71. Key_LayeredScSc has advantages when a large layer group has two layers:
  72. * no array is created for the two scancodes, which means less clutter in the sketch
  73. * uses less SRAM
  74. The layer scheme is implemented in keybrd_3e_sublayerNestedScSc.ino.
  75. It is similar to the previous sketch, but Key_LayeredKeysArray1 is replaced with Key_LayeredScSc.
  76. Key_Layered classes include:
  77. * Key_LayeredKeys (any number of codes or keys)
  78. * Key_LayeredScSc (specialized for two scancodes)
  79. * Key_LayeredCodeSc (specialized for one code and one scancode)
  80. Subgroup layer-key placement
  81. ----------------------------
  82. A subgroup's layer key(s) can be placed in one of two ways.
  83. 1) A subgroup and it's layer key(s) on the same layer.
  84. This layout has a '1' in the Num layer and the Num layer key on the Sym layer:
  85. | Layout | **0** | **1** | **2** |
  86. |:------:|:-----:|:-----:|:-----:|
  87. | **0** | a - 1 | b = | c Num |
  88. | **1** | Alpha | Sym | Enter |
  89. This arrangement presents the Num layer as a "sublayer".
  90. 2) A subgroup with it's layer key(s) on single-layer key(s).
  91. This layout has a '1' in the Num layer and the Num layer key on the bottom row:
  92. | Layout | **0** | **1** | **2** |
  93. |:------:|:-----:|:-----:|:-----:|
  94. | **0** | a - 1 | b = | c Ent |
  95. | **1** | Alpha | Sym | Num |
  96. This arrangement presents the Num layer as just another layer that happens to cover fewer keys than Alpha and Sym layers.
  97. The top row is easily implemented in one layer group with duplicate keys filling the Num layer:
  98. | group_1 | **0** | **1** | **2** |
  99. |:-------:|:-----:|:------:|:---------:|
  100. | **0** | a - 1 | b = = | c Ent Ent | layer group with three layers: Alpha Sym Num
  101. | **1** | | | |
  102. Complex layerschemes
  103. --------------------
  104. The basic LayerState class used in the tutorials is sufficient for implementing many layer schemes.
  105. More complicated layer schemes would need custom LayerState classes, and possibly custom Code_Layer and Key_Layered classes as well.
  106. Any layer scheme can be implemented with the right custom layer classes.
  107. [keybrd_DH](https://github.com/wolfv6/keybrd_DH) is an example of a complex layer scheme.
  108. It emulates the DataHand keyboard, which has the most complex layout I know of.
  109. Most layer schemes are much simpler.
  110. Layer-scheme classes used by keybrd_DH are listed below.
  111. Most of the layer-scheme classes are custom classes which reside in the keybrd_DH library.
  112. DH Code_Layer classes include:
  113. * Code_LayerLock
  114. * Code_LayerLockMF_Protector
  115. * Code_LayerState_Toggle
  116. DH LayerState classes include:
  117. * LayerState
  118. * LayerState_DH
  119. * LayerState_NAS
  120. DH Key_Layered classes include:
  121. * Key_LayeredKeys
  122. * Key_LayeredScSc
  123. * Key_LayeredNav
  124. * Key_LayeredDoublePressToggle
  125. * Key_LayeredCodeSc_MF
  126. * Key_LayeredOperator
  127. * Key_LayeredNumber
  128. * Key_LayeredNumber_00
  129. Exercises
  130. ---------
  131. 1) Modify keybrd_3e_sublayerNestedScSc.ino to match the following layout
  132. (add the number '2' to the Num layer):
  133. | Layout | **0** | **1** | **2** |
  134. |:------:|:-----:|:-----:|:-----:|
  135. | **0** | a - 1 | b = 2 | c Num |
  136. | **1** | Alpha | Sym | Enter |
  137. 2) Modify keybrd_3c_sublayerNull.ino to match the following layout
  138. (this was described above in "Subgroup layer-key placement"):
  139. | Layout | **0** | **1** | **2** |
  140. |:------:|:-----:|:-----:|:-----:|
  141. | **0** | a - 1 | b = | c Ent |
  142. | **1** | Alpha | Sym | Num |