keybrd library is an open source library for creating custom-keyboard firmware.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
Ce dépôt est archivé. Vous pouvez voir les fichiers et le cloner, mais vous ne pouvez pas pousser ni ouvrir de ticket/demande d'ajout.

keybrd_library_developer_guide.md 8.8KB

il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 7 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 7 ans
il y a 8 ans
il y a 8 ans
il y a 7 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 7 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 7 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 7 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. keybrd Library Developer's Guide
  2. ================================
  3. This guide if for maintaining and writing new classes for the keybrd library and its extension libraries.
  4. The most common reason for adding new classes are:
  5. * I/O expander classes
  6. * custom layer schemes for multi-layer keyboards
  7. * experimental features
  8. Who this guide is for
  9. ---------------------
  10. This guide is for the maintainers and developers of the keybrd library and it's extensions.
  11. It is assumed the reader is familiar with the C++ language including pointers, objects, classes, static class variables, composition, aggregation, inheritance, polymorphism, and enum.
  12. Row, Scanner, and Debouncer classes use bit manipulation.
  13. Class inheritance diagrams
  14. --------------------------
  15. Keybrd library class inheritance diagram
  16. ```
  17. Row
  18. ___ ScannerInterface ___
  19. / | \
  20. Scanner_uC Scanner_IOE Scanner_ShiftRegsPISO
  21. PortIOE
  22. PortInterface
  23. / \
  24. Port_PCA9655E Port_MCP23S17 (one Port class for each IOE type)
  25. LEDInterface
  26. / \
  27. LED_uC LED_IOE
  28. DebouncerInterface
  29. |
  30. Debouncer_Samples
  31. ScanDelay
  32. LayerStateInterface
  33. |
  34. LayerState
  35. Key
  36. |____
  37. | \
  38. | Key_LayeredKeysBase
  39. | \____________________
  40. | / \
  41. | Key_LayeredKeys Key_LayeredKeys1
  42. |
  43. |___________________________
  44. | \ \
  45. | Key_LayeredScScBase Key_LayeredCodeScBase
  46. | | |
  47. | Key_LayeredScSc Key_LayeredCodeSc
  48. |
  49. Code
  50. |_____________________
  51. | \ \
  52. | Code_LayerLock Code_LayerHold
  53. |
  54. \________________________________________________________
  55. \ \ \ \ \
  56. Code_Sc Code_Shift Code_AutoShift Code_LEDLock Code_Null
  57. / \
  58. Code_ScS Code_ScNS
  59. ```
  60. Dependency diagrams
  61. -------------------
  62. Dependency diagram of example single-layer keyboard with LEDs
  63. ```
  64. ____ Row ______
  65. / | \
  66. Scanner_uC Debouncer Key ___
  67. | | \
  68. readPins Code Code_LEDLock
  69. |
  70. LED_PinNumber
  71. ```
  72. Dependency diagram of example multi-layer keyboard with layer LEDs
  73. ```
  74. LayerStates
  75. ___________ Row ________________/__ | \
  76. / / \ / \ | \
  77. Scanner_uC Debouncer Key_LayeredKeys / Code_Layer LED_PinNumber
  78. | \ /
  79. readPins Code
  80. ```
  81. Dependency diagram of example shift registers Row
  82. ```
  83. _______ Row _______
  84. / | \
  85. RowScanner_ShiftRegsPISO Debouncer Key
  86. |
  87. Code
  88. ```
  89. Dependency diagram of example I/O expander matrix with LEDs
  90. ```
  91. _________ Row ________
  92. / \ \
  93. __ Scanner_IOE __ Debouncer Key
  94. / | \ / \
  95. strobePin PortWrite PortRead Code Code_LEDLock
  96. | \ / \ |
  97. | PortIOE readPins LED_IOE
  98. \___________________________/ \
  99. pin
  100. ```
  101. Class naming conventions
  102. ------------------------
  103. Class names start with upper case letter.
  104. Most derived-class names start with the base class name followed by "_" and a name e.g.
  105. ```
  106. Code
  107. |
  108. Code_LayerLock
  109. ```
  110. This convention leads to class names that convey information about the classes inheritance.
  111. Underscore delineates base class name and sub-class name. Capital letters delineate words.
  112. Interface class names end with "Interface".
  113. Except for Key, to reduce clutter because sketches define so many Key[] arrays.
  114. Layer-class naming conventions
  115. ------------------------------
  116. Layer classes are explained in [tutorial_3a_multi-layer_keyboard.md](../tutorials/tutorial_3a_multi-layer_keyboard.md).
  117. *Code_Layer* class names are concatenations of "Code_", "Layer" or layer name, and persistence.
  118. Example persistences are:
  119. * "Lock" - layer remains active after the layer key is released
  120. * "Hold" - layer is active for as long as layer key is held down
  121. Example Code_Layer class names:
  122. * Code_LayerHold
  123. * Code_LayerLock
  124. *LayerState* class names start with "LayerState" and end with a descriptive name.
  125. Example LayerState class names:
  126. * LayerState - basic LayerState class in keybrd library
  127. * LayerState_DH - main LayerState for the keybrd_DH library
  128. * LayerState_MF - LayerState for Mouse Function sub-layers in the keybrd_DH library
  129. *Key_Layered* class names start with "Key_Layered" and end with a descriptive name.
  130. Example Key_Layered class names:
  131. * Key_LayeredScSc
  132. * Key_LayeredKeys
  133. Style guide
  134. -----------
  135. Following the style guide makes it easier for the next programmer to understand your code.
  136. * For class names, see above section "Class naming conventions".
  137. * Member names use camelCase starting with lowercase letter.
  138. * Use constants rather than macros, except for header guards.
  139. * Global const names and static const names use ALL_CAPS_WITH_UNDERSCORE.
  140. * Macros use ALL_CAPS_WITH_UNDERSCORE and have _MACRO suffix e.g. SAMPLE_COUNT_MACRO
  141. * Header guards have _H suffix e.g. #ifndef FILE_NAME_H
  142. * Pointer names are prefixed with "ptr" e.g. ptrRow = &row;
  143. * Arrays names use the plural of the element name e.g. Row* const = ptrsRows { &row0, &row1 };
  144. * Pass arrays using array notation rather than pointer notation:
  145. ```
  146. void printArray(char[] array);
  147. not
  148. void printArray( char* array);
  149. ```
  150. * In constructor's initialization list, use same names for fields and constructor parameters.
  151. * Do not use new or malloc (make memory leaks impossible).
  152. * Document class interface in .h file, above the class declaration.
  153. * Code should be self-documenting. A simple function with a good name needs no comment.
  154. * Code is automatically formatted before being pushed to the keybrd repository.
  155. The [astyle_cpp](astyle_cpp) file specifies the format:
  156. * Allman style indentation
  157. * indent 4 spaces
  158. * replace tabs with spaces
  159. * maximum code width of 100 columns
  160. <!-- http://stackoverflow.com/questions/2198241/best-practice-for-c-function-commenting -->
  161. Trace of keybrd scan
  162. --------------------
  163. Arduino does not have a debugger.
  164. So here is a list of functions in the order that they are called.
  165. The trace is of a one-row single-layer keybrd scan.
  166. ```
  167. loop() for each row
  168. Row::process()
  169. Scanner_uC::scan() strobe row on
  170. for each readPin
  171. set readState bit
  172. strobe row off
  173. Debouncer_Samples::debounce() debounce
  174. Row::send() for each key in row
  175. if falling edge
  176. Key_*::release() scanCode->release()
  177. Code_*::release() Keyboard.release(scancode)
  178. if rising edge
  179. Key_*::press() scanCode->press()
  180. Code_*::press() Keyboard.press(scancode)
  181. scanDelay.delay();
  182. ```
  183. The Arduino libraries
  184. ---------------------
  185. The keybrd libraries compile on the Arduino IDE and make extensive use of the following [Arduino libraries](https://www.arduino.cc/en/Reference/Libraries):
  186. #include <Arduino.h>
  187. #include <Wire.h>
  188. #include <Keyboard.h>
  189. #include <Mouse.h>
  190. <a rel="license" href="https://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://licensebuttons.net/l/by/4.0/88x31.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">keybrd guide</span> by <a xmlns:cc="https://creativecommons.org/ns" href="https://github.com/wolfv6/keybrd" property="cc:attributionName" rel="cc:attributionURL">Wolfram Volpi</a> is licensed under a <a rel="license" href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.<br />Permissions beyond the scope of this license may be available at <a xmlns:cc="https://creativecommons.org/ns" href="https://github.com/wolfv6/keybrd/issues/new" rel="cc:morePermissions">https://github.com/wolfv6/keybrd/issues/new</a>.