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