logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

readme.md (6165B)


  1. # Fast and extensible matrix.c
  2. This matrix.c is faster and more extensible than the standard quantum/matrix.c.
  3. * The execution speed of the `matrix_scan()` function is several times faster than quantum/matrix.c.
  4. * In addition to handling MCU GPIOs, it can be extended to handle I/O extenders.
  5. ## ToDo list
  6. - [x] support Pro Micro
  7. - [x] support Proton-C
  8. - [x] support DIRECT_PINS
  9. - [x] support DIODE_DIRECTION == ROW2COL
  10. - [x] support 74HC157: quadruple 2-line to 1-line data selectors / multiplexers
  11. - [x] support 74HC153: dual 4-line to 1-line data selectors / multiplexers
  12. - [ ] support I/O expander (MCP23018)
  13. - [ ] support MCU & I/O expander (MCP23018) mixture like ErgoDox
  14. ## Current performance
  15. | MCU | delay type | execution time <br> of <br> `matrix_scan()` | matrix scan rate |
  16. |-------------------|---------------|------------|-----------------|
  17. | Pro Micro (16MHz) | fast adaptive | 75.6us | 8090 scans/sec |
  18. | Proton C (72MHz) | fast adaptive | 49.8us | 15100 scans/sec |
  19. ## Configuration
  20. This matrix.c requires a different configuration than quantum/matrix.c.
  21. ### Output pins configuration
  22. The output pins is the Row pins if `DIODE_DIRECTION == COL2ROW`, and the Col pins if `DIODE_DIRECTION == ROW2COL`. When DIRECT_PINS is defined, the output pins do not need to be set.
  23. Example:
  24. ```c
  25. // list of OUTPUT(row) ports
  26. #define MATRIX_OUT_PORTS \
  27. (Port_D, MCU_GPIO, D0), \
  28. (Port_C, MCU_GPIO, C0), \
  29. (Port_E, MCU_GPIO, E0), \
  30. (Port_B, MCU_GPIO, B0)
  31. // list of OUTPUT pins
  32. #define MATRIX_OUT_PINS \
  33. (0, Port_D, 4), \
  34. (1, Port_C, 6), \
  35. (2, Port_D, 7), \
  36. (3, Port_E, 6), \
  37. (4, Port_B, 4), \
  38. (5, Port_B, 5)
  39. ```
  40. ### Input pins configuration
  41. The input pins is the Col pins if `DIODE_DIRECTION == COL2ROW`, and the Row pins if `DIODE_DIRECTION == ROW2COL`. When DIRECT_PINS is defined, the input pin settings will enumerate the connection pins of all switches.
  42. Example:
  43. ```c
  44. // list of INPUT ports
  45. #define MATRIX_IN_PORTS (Port_F, MCU_GPIO, F0), (Port_B, MCU_GPIO, B0)
  46. // list of INPUT pins
  47. #define MATRIX_IN_PINS \
  48. (0, Port_F, 4), \
  49. (1, Port_F, 5), \
  50. (2, Port_F, 6), \
  51. (3, Port_F, 7), \
  52. (4, Port_B, 1), \
  53. (5, Port_B, 3)
  54. ```
  55. ### Multiplexer Extension
  56. By defining the `MATRIX_EXTENSION_74HC157` macro or `MATRIX_EXTENSION_74HC153` macro, you can connect a multiplexer to the GPIO to extend the input pins.
  57. Example:
  58. ```c
  59. #define MATRIX_EXTENSION_74HC157 B2 /* or #define MATRIX_EXTENSION_74HC153 B2, B6 */
  60. // list of OUTPUT ports
  61. #define MATRIX_OUT_PORTS (Port_D, MCU_GPIO, D0), (Port_C, MCU_GPIO, C0), (Port_E, MCU_GPIO, E0), (Port_B, MCU_GPIO, B0)
  62. // list of OUTPUT pins
  63. #define MATRIX_OUT_PINS (0, Port_D, 4), (1, Port_C, 6), (2, Port_D, 7), (3, Port_E, 6), (4, Port_B, 4), (5, Port_B, 5)
  64. // list of INPUT ports
  65. #define MATRIX_IN_PORTS \
  66. (Port_Fa, MCU_GPIOa, F0), \
  67. (Port_Ba, MCU_GPIOa, B0), \
  68. (Port_Fb, MCU_GPIOb, F0), \
  69. (Port_Bb, MCU_GPIOb, B0)
  70. // list of INPUT pins
  71. #define MATRIX_IN_PINS \
  72. (0, Port_Fa, 4), \
  73. (1, Port_Fb, 5), \
  74. (2, Port_Fb, 6), \
  75. (3, Port_Fa, 7), \
  76. (4, Port_Ba, 1), \
  77. (5, Port_Bb, 3)
  78. ```
  79. ### I/O expander Extension
  80. I plan to provide extensions to support I/O expanders such as MCP23018 and PCA9555.
  81. ## Compile
  82. * Measure the execution time of matrix_scan()
  83. * `make MTEST=matrix_debug_scan[,<other options>..] handwired/symmetric70_proto/promicro/fast:default:flash`
  84. * Measure delay time.
  85. * `make MTEST=matrix_debug_delay[,<other options>..] handwired/symmetric70_proto/promicro/fast:default:flash`
  86. ## Measurement result
  87. ### Pro Micro (ATmega32u4 16Mhz)
  88. #### Default setting (show `matrix_scan()` time)
  89. - `make MTEST=matrix_debug_scan handwired/symmetric70_proto/promicro/fast:default:flash`
  90. - CH1: Row 0
  91. - CH2: Row 1
  92. - CH3: Row 4
  93. - CH4: matrix_scan()
  94. - Execution time of matrix_scan() 75.6us
  95. - Frequency of matrix scan 8.09kHz (123.6us)
  96. ![DS1Z_QuickPrint7](https://user-images.githubusercontent.com/2170248/116003927-538d9100-a63b-11eb-9b36-7db47d9b1541.png)
  97. #### Default setting (show delay time)
  98. - `make MTEST=matrix_debug_delay handwired/symmetric70_proto/promicro/fast:default:flash`
  99. ##### Press R0C0 key
  100. - CH1: Row 0
  101. - CH2: Row 1
  102. - CH3: Row 4
  103. - CH4: delay time
  104. - Frequency of matrix scan 7.84kHz (127.6us)
  105. ![DS1Z_QuickPrint9](https://user-images.githubusercontent.com/2170248/116003974-99e2f000-a63b-11eb-9c9e-3b3b1025db66.png)
  106. ![DS1Z_QuickPrint10](https://user-images.githubusercontent.com/2170248/116003978-a1a29480-a63b-11eb-97d8-5a6e11c0db2f.png)
  107. ### Proton C
  108. #### Default setting (show `matrix_scan()` time)
  109. - `make MTEST=matrix_debug_scan handwired/symmetric70_proto/proton_c/fast:default:flash`
  110. - CH1: Row 0
  111. - CH2: Row 1
  112. - CH3: Row 4
  113. - CH4: matrix_scan()
  114. - Execution time of matrix_scan() 49.8us
  115. - Frequency of matrix scan 15.1kHz (66.2.6us)
  116. ![DS1Z_QuickPrint11](https://user-images.githubusercontent.com/2170248/116088141-8cca0d80-a6dc-11eb-8782-1d29c57690b8.png)
  117. #### Default setting (show delay time)
  118. - `make MTEST=matrix_debug_delay handwired/symmetric70_proto/proton_c/fast:default:flash`
  119. ##### Press R0C0 key
  120. - CH1: Row 0
  121. - CH2: Row 1
  122. - CH3: Row 4
  123. - CH4: delay time
  124. - Frequency of matrix scan 13.9kHz (71.8us)
  125. ![DS1Z_QuickPrint12](https://user-images.githubusercontent.com/2170248/116088247-a8cdaf00-a6dc-11eb-8a47-104694a40117.png)
  126. ![DS1Z_QuickPrint13](https://user-images.githubusercontent.com/2170248/116088262-ac613600-a6dc-11eb-804c-7dcbd71c83d5.png)
  127. ##### Connect a 500pF capacitor between C0 line and GND, Press R0C0, R1C0, R2C0, R3C0, R4C0 keys
  128. - CH1: Row 0
  129. - CH2: Row 1
  130. - CH3: Col 0
  131. - CH4: delay time
  132. - Delay time 11.6us
  133. - Threshold Voltage 1.9V
  134. ![DS1Z_QuickPrint14](https://user-images.githubusercontent.com/2170248/116089205-90aa5f80-a6dd-11eb-89c4-72315c80ba0e.png)
  135. ##### Connect a 1000pF capacitor between C0 line and GND, Press R0C0, R1C0, R2C0, R3C0, R4C0 keys
  136. - CH1: Row 0
  137. - CH2: Row 1
  138. - CH3: Col 0
  139. - CH4: delay time
  140. - Delay time 18.6us
  141. - Threshold Voltage 1.9V
  142. ![DS1Z_QuickPrint15](https://user-images.githubusercontent.com/2170248/116089229-96a04080-a6dd-11eb-8b63-f91b03a9db0c.png)