keybrd library is an open source library for creating custom-keyboard firmware.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
此仓库已存档。您可以查看文件和克隆,但不能推送或创建工单/合并请求。

tutorial_3cde_sublayer_keyboard.md 7.0KB

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