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.

234 lines
8.2 KiB

[Keyboard] Update Symmetric70 keyboard prototype (#12707) * update handwired/symmetric70_proto/matrix.c * make keyboards/handwired/symmetric70_proto/promicro/ * add symmetric70_proto/debug_config.h, update symmetric70_proto/local_features.mk etc. set MATRIX_IO_DELAY macro make MTEST=mdelay0 symmetric70_proto/promicro:default:flash make MTEST=mdelay1 symmetric70_proto/promicro:default:flash make MTEST=mdelay10 symmetric70_proto/promicro:default:flash make MTEST=mdelay30 symmetric70_proto/promicro:default:flash set DEBUG_MATRIX_SCAN_RATE_ENABLE yes make MTEST=scan symmetric70_proto/promicro:default:flash set MATRIX_DEBUG_DELAY and MATRIX_IO_DELAY macro make MTEST=matrix_debug_delay,mdelay0 symmetric70_proto/promicro:default:flash set MATRIX_DEBUG_SCAN make MTEST=matrix_debug_scan symmetric70_proto/promicro:default:flash * add symmetric70_proto/matrix_debug/readme.md * update symmetric70_proto/matrix_debug/readme.md * update handwired/symmetric70_proto/readme.md * update handwired/symmetric70_proto/readme.md * update handwired/symmetric70_proto/*/readme.md * add handwired/symmetric70_proto/matrix_fast/ * update handwired/symmetric70_proto/matrix_fast/readme.md * fix typo in handwired/symmetric70_proto/matrix_fast/readme.md * update config.h under handwired/symmetric70_proto/promicro * add Proton C support to handwired/symmetric70_proto * add handwired/symmetric70_proto/proton_c/readme.md * add promicro/*/readme.md proton_c/*/readme.md * update handwired/symmetric70_proto/proton_c/proton_c.c support MATRIX_IO_DELAY_DEFAULT for testing. * Added another implementation of 'adaptive_delay'. * update symmetric70_proto/local_features.mk * update symmetric70_proto/matrix_fast/gpio_extr.h * add matrix_output_unselect_delay_ports() * add MTEST=adaptive_delay_fast option * update symmetric70_proto/matrix_debug/readme.md * update symmetric70_proto/matrix_fast/readme.md * update symmetric70_proto/matrix_debug/readme.md * Erase garbage * fix symmetric70_proto/proton_c/proton_c.c * improve adaptive_delay_fast in symmetric70_proto/matrix_debug/matrix.c * update symmetric70_proto/matrix_debug/readme.md * fix symmetric70_proto/matrix_debug/readme.md * Update keyboards/handwired/symmetric70_proto/proton_c/rules.mk Co-authored-by: Ryan <fauxpark@gmail.com> * Update keyboards/handwired/symmetric70_proto/proton_c/rules.mk Co-authored-by: Ryan <fauxpark@gmail.com> * Update keyboards/handwired/symmetric70_proto/local_features.mk Co-authored-by: Nick Brassel <nick@tzarc.org> * Update keyboards/handwired/symmetric70_proto/local_features.mk Co-authored-by: Nick Brassel <nick@tzarc.org> * Update keyboards/handwired/symmetric70_proto/matrix_debug/matrix.c Co-authored-by: Nick Brassel <nick@tzarc.org> * Update keyboards/handwired/symmetric70_proto/matrix_debug/matrix.c Co-authored-by: Nick Brassel <nick@tzarc.org> * Update keyboards/handwired/symmetric70_proto/local_features.mk Co-authored-by: Nick Brassel <nick@tzarc.org> * Update keyboards/handwired/symmetric70_proto/matrix_debug/matrix.c Co-authored-by: Nick Brassel <nick@tzarc.org> * Update keyboards/handwired/symmetric70_proto/matrix_debug/readme.md Co-authored-by: Nick Brassel <nick@tzarc.org> * Update keyboards/handwired/symmetric70_proto/matrix_debug/readme.md Co-authored-by: Nick Brassel <nick@tzarc.org> * Update keyboards/handwired/symmetric70_proto/matrix_debug/readme.md Co-authored-by: Nick Brassel <nick@tzarc.org> * Update keyboards/handwired/symmetric70_proto/matrix_fast/matrix_config_expand.c Co-authored-by: Nick Brassel <nick@tzarc.org> Co-authored-by: Ryan <fauxpark@gmail.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
2 years ago
  1. /*
  2. Copyright 2021 mtei
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. // clang-format off
  15. #include "matrix_extr.h"
  16. #ifdef DEBUG_MATRIX_CONFIG
  17. // config expand debug
  18. // avr-gcc -DDEBUG_MATRIX_CONFIG=\"test_config.h\" -E -C matrix_config_expand.c
  19. # include DEBUG_MATRIX_CONFIG
  20. #endif
  21. #undef NO_PIN /* cancel NO_PIN define in tmk_core/common/pin_defs.h */
  22. #define NO_PIN NO_PORT, 0
  23. #if MATRIX_TYPE == DIRECT_SWITCH
  24. # undef MATRIX_OUT_PORTS
  25. # define MATRIX_OUT_PINS (0, NO_PIN)
  26. #endif
  27. #include "cpp_map.h"
  28. #if defined(MATRIX_EXTENSION_74HC157) || defined(MATRIX_EXTENSION_74HC153)
  29. # define MATRIX_EXTENSION "matrix_extension_74hc15x.c"
  30. #endif
  31. #ifdef MATRIX_EXTENSION
  32. # include MATRIX_EXTENSION
  33. #endif
  34. #ifdef MATRIX_GPIO_NEED_SEPARATE_ATOMIC
  35. # ifndef setMatrixInputHigh
  36. # define setMatrixInputHigh(dev, port, bit) do { if ((dev) == MCU_GPIO) { setPortBitInputHigh_atomic(port, bit); }} while(0)
  37. # endif
  38. # ifndef setMatrixOutput_writeHighZ
  39. # define setMatrixOutput_writeHighZ(dev, port, bit) do { if ((dev) == MCU_GPIO) { setPortBitInputHigh_atomic(port, bit); }} while(0)
  40. # endif
  41. # ifndef setMatrixOutput_writeLow
  42. # define setMatrixOutput_writeLow(dev, port, bit) do { if ((dev) == MCU_GPIO) { setPortBitOutput_writeLow_atomic(port, bit); }} while(0)
  43. # endif
  44. #else
  45. # ifndef setMatrixInputHigh
  46. # define setMatrixInputHigh(dev, port, bit) do { if ((dev) == MCU_GPIO) { setPortBitInputHigh(port, bit); }} while(0)
  47. # endif
  48. # ifndef setMatrixOutput_writeHighZ
  49. # define setMatrixOutput_writeHighZ(dev, port, bit) do { if ((dev) == MCU_GPIO) { setPortBitInputHigh(port, bit); }} while(0)
  50. # endif
  51. # ifndef setMatrixOutput_writeLow
  52. # define setMatrixOutput_writeLow(dev, port, bit) do { if ((dev) == MCU_GPIO) { setPortBitOutput_writeLow(port, bit); }} while(0)
  53. # endif
  54. #endif
  55. #ifndef readMatrixPort
  56. # define readMatrixPort(dev, port) (((dev) == MCU_GPIO) ? readPort(port) : 0)
  57. #endif
  58. #ifndef getMatrixInputMaskBit
  59. # define getMatrixInputMaskBit(dev, bit) (((dev) != NO_DEVICE) ? _BV((bit)&0xF) : 0)
  60. #endif
  61. #ifndef init_extension
  62. # define init_extension()
  63. #endif
  64. enum DEVICE_NAME {
  65. MCU_GPIO,
  66. NO_DEVICE,
  67. #ifdef MATRIX_DEVICES
  68. MATRIX_DEVICES
  69. #endif
  70. };
  71. #define _INPUT_PORTS_ENUM_ELEMENT(name, dev, port) inport_index_##name,
  72. #define INPUT_PORTS_ENUM_ELEMENT(x) _INPUT_PORTS_ENUM_ELEMENT x
  73. enum INPUT_PORTS {
  74. INPUT_PORTS_ENUM_ELEMENT((NO_PORT, NO_DEVICE, 0))
  75. MAP(INPUT_PORTS_ENUM_ELEMENT, MATRIX_IN_PORTS)
  76. NUM_OF_INPUT_PORTS
  77. };
  78. #define _INPUT_PINS_ENUM_ELEMENT(index, port, bit) inpin_index_##index,
  79. #define INPUT_PINS_ENUM_ELEMENT(x) _INPUT_PINS_ENUM_ELEMENT x
  80. enum INPUT_PINS {
  81. MAP(INPUT_PINS_ENUM_ELEMENT, MATRIX_IN_PINS)
  82. END_inpin_index
  83. };
  84. #define _OUTPUT_PORTS_ENUM_ELEMENT(name, dev, port) outport_index_##name,
  85. #define OUTPUT_PORTS_ENUM_ELEMENT(x) _OUTPUT_PORTS_ENUM_ELEMENT x
  86. enum OUTPUT_PORTS {
  87. OUTPUT_PORTS_ENUM_ELEMENT((NO_PORT, NO_DEVICE, 0))
  88. #ifdef MATRIX_OUT_PORTS
  89. MAP(OUTPUT_PORTS_ENUM_ELEMENT, MATRIX_OUT_PORTS)
  90. #endif
  91. NUM_OF_OUTPUT_PORTS
  92. };
  93. #define _OUTPUT_PINS_ENUM_ELEMENT(index, port, bit) outpin_index_##index,
  94. #define OUTPUT_PINS_ENUM_ELEMENT(x) _OUTPUT_PINS_ENUM_ELEMENT x
  95. enum OUTPUT_PINS {
  96. MAP(OUTPUT_PINS_ENUM_ELEMENT, MATRIX_OUT_PINS)
  97. END_outpin_index
  98. };
  99. port_width_t iport_mask[NUM_OF_INPUT_PORTS];
  100. #define _INPUT_PORTS_LIST_ELEMENT(name, dev, port) \
  101. [inport_index_##name] = { dev, port },
  102. #define INPUT_PORTS_LIST_ELEMENT(x) _INPUT_PORTS_LIST_ELEMENT x
  103. LOCAL_DATA
  104. const port_descriptor inport_list[NUM_OF_INPUT_PORTS] = {
  105. INPUT_PORTS_LIST_ELEMENT((NO_PORT, NO_DEVICE, 0))
  106. MAP(INPUT_PORTS_LIST_ELEMENT, MATRIX_IN_PORTS)
  107. };
  108. #define _OUTPUT_PORTS_LIST_ELEMENT(name, dev, port) \
  109. [outport_index_##name] = { dev, port },
  110. #define OUTPUT_PORTS_LIST_ELEMENT(x) _OUTPUT_PORTS_LIST_ELEMENT x
  111. LOCAL_DATA
  112. const port_descriptor outport_list[NUM_OF_OUTPUT_PORTS] = {
  113. OUTPUT_PORTS_LIST_ELEMENT((NO_PORT, NO_DEVICE, 0))
  114. #ifdef MATRIX_OUT_PORTS
  115. MAP(OUTPUT_PORTS_LIST_ELEMENT, MATRIX_OUT_PORTS)
  116. #endif
  117. };
  118. #define _SELECT_OUTPUT_PIN(index, pname, bit) \
  119. case outpin_index_##index: \
  120. setMatrixOutput_writeLow(outport_list[outport_index_##pname].device, \
  121. outport_list[outport_index_##pname].port, bit); \
  122. break;
  123. #define SELECT_OUTPUT_PIN(x) _SELECT_OUTPUT_PIN x
  124. LOCAL_FUNC ALWAYS_INLINE void select_output(uint8_t out_index);
  125. LOCAL_FUNC
  126. void select_output(uint8_t out_index) {
  127. switch (out_index) {
  128. MAP(SELECT_OUTPUT_PIN, MATRIX_OUT_PINS)
  129. }
  130. }
  131. #define _UNSELECT_OUTPUT_PIN(index, pname, bit) \
  132. case outpin_index_##index: \
  133. setMatrixOutput_writeHighZ(outport_list[outport_index_##pname].device, \
  134. outport_list[outport_index_##pname].port, bit); \
  135. break;
  136. #define UNSELECT_OUTPUT_PIN(x) _UNSELECT_OUTPUT_PIN x
  137. LOCAL_FUNC ALWAYS_INLINE void unselect_output_inline(uint8_t out_index);
  138. LOCAL_FUNC
  139. void unselect_output_inline(uint8_t out_index) {
  140. switch (out_index) {
  141. MAP(UNSELECT_OUTPUT_PIN, MATRIX_OUT_PINS)
  142. }
  143. }
  144. #define _INIT_INPUT_PIN(index, pname, bit) \
  145. setMatrixInputHigh(inport_list[inport_index_##pname].device, \
  146. inport_list[inport_index_##pname].port, bit);
  147. #define INIT_INPUT_PIN(x) _INIT_INPUT_PIN x
  148. LOCAL_FUNC
  149. void init_input_ports(void) {
  150. MAP(INIT_INPUT_PIN, MATRIX_IN_PINS)
  151. }
  152. #define _INIT_INPORT_MASK(index, pname, bit) \
  153. iport_mask[inport_index_##pname] |= getMatrixInputMaskBit(inport_list[inport_index_##pname].device, bit);
  154. #define INIT_INPORT_MASK(x) _INIT_INPORT_MASK x
  155. LOCAL_FUNC
  156. void init_inport_mask(void) {
  157. for (int i = 0; i < NUM_OF_INPUT_PORTS; i++ ) {
  158. iport_mask[i] = 0;
  159. }
  160. MAP(INIT_INPORT_MASK, MATRIX_IN_PINS)
  161. }
  162. #define _READ_INPUT_PORT(name, dev, port) \
  163. buffer[inport_index_##name] = readMatrixPort(dev, port);
  164. #define READ_INPUT_PORT(x) _READ_INPUT_PORT x
  165. LOCAL_FUNC
  166. ALWAYS_INLINE void read_all_input_ports(port_width_t buffer[NUM_OF_INPUT_PORTS], bool wait_unselect);
  167. LOCAL_FUNC
  168. void read_all_input_ports(port_width_t buffer[NUM_OF_INPUT_PORTS], bool wait_unselect) {
  169. READ_INPUT_PORT((NO_PORT, NO_DEVICE, 0))
  170. MAP(READ_INPUT_PORT, MATRIX_IN_PORTS)
  171. }
  172. #define _MASK_INPUT(name, dev, port) \
  173. mask |= ((~buffer[inport_index_##name]) & iport_mask[inport_index_##name]);
  174. #define MASK_INPUT(x) _MASK_INPUT x
  175. LOCAL_FUNC ALWAYS_INLINE void wait_unselect_done(void);
  176. LOCAL_FUNC
  177. void wait_unselect_done(void) {
  178. port_width_t mask;
  179. port_width_t buffer[NUM_OF_INPUT_PORTS];
  180. do {
  181. read_all_input_ports(buffer, true);
  182. MATRIX_DEBUG_DELAY_END();
  183. mask = 0;
  184. MAP(MASK_INPUT, MATRIX_IN_PORTS);
  185. MATRIX_DEBUG_DELAY_START();
  186. } while (mask != 0);
  187. }
  188. #define _BUILD_INPUT_PORT(index, pname, bit) \
  189. result |= (buffer[inport_index_##pname] & _BV(bit)) ? 0 : _BV(inpin_index_##index);
  190. #define BUILD_INPUT_PORT(x) _BUILD_INPUT_PORT x
  191. LOCAL_FUNC ALWAYS_INLINE matrix_line_t build_matrix_line(port_width_t buffer[NUM_OF_INPUT_PORTS]);
  192. LOCAL_FUNC
  193. matrix_line_t build_matrix_line(port_width_t buffer[NUM_OF_INPUT_PORTS]) {
  194. matrix_line_t result = 0;
  195. MAP(BUILD_INPUT_PORT, MATRIX_IN_PINS);
  196. return result;
  197. }
  198. #define _BUILD_INPUT_PORT_DIRECT(index, pname, bit) \
  199. matrix[(inpin_index_##index)/MATRIX_COLS] \
  200. |= (buffer[inport_index_##pname] & _BV(bit)) ? 0 : _BV((inpin_index_##index)%MATRIX_COLS);
  201. #define BUILD_INPUT_PORT_DIRECT(x) _BUILD_INPUT_PORT_DIRECT x
  202. LOCAL_FUNC ALWAYS_INLINE void build_matrix_direct(port_width_t buffer[NUM_OF_INPUT_PORTS], matrix_line_t matrix[]);
  203. LOCAL_FUNC
  204. void build_matrix_direct(port_width_t buffer[NUM_OF_INPUT_PORTS], matrix_line_t matrix[]) {
  205. MAP(BUILD_INPUT_PORT_DIRECT, MATRIX_IN_PINS);
  206. }