keybrd library is an open source library for creating custom-keyboard firmware.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
このリポジトリはアーカイブされています。 ファイルの閲覧とクローンは可能ですが、プッシュや、課題・プルリクエストのオープンはできません。

keybrd_4b_split_with_IOE.ino 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* keybrd_4_split_with_IOE_annotated.ino
  2. This sketch:
  3. is a simple 1-layer keyboard
  4. runs on two matrices of a breadboard keyboard
  5. is annotated with a walk-through narrative
  6. This layout table shows left and right matrices:
  7. | Left | **0** | **1** | | Right | **0** | **1** |
  8. |:-----:|-------|-------|-|:-----:|-------|-------|
  9. | **0** | a | b | | **0** | 1 | 2 |
  10. | **1** | shift | c | | **1** | 3 | shift |
  11. MARTIX NAMING CONVENTION
  12. Since this keyboard has two matrices, we need a naming convention to distinguish the matrices.
  13. Matrix IDs are the letters 'L' and 'R' (left and right).
  14. Port object names and Port pointer array names end with matrix ID:
  15. port1_R
  16. rowPortF_L rowPort1_R
  17. port0_R
  18. colPortB_L colPort0_R
  19. ptrsColPorts_L ptrsColPorts_R
  20. COL_PORT_L_COUNT COL_PORT_R_COUNT
  21. Key pointer array names and Row objects names end with matrix ID and row number:
  22. ptrsKeys_L0 ptrsKeys_R0
  23. row_L0 row_R0
  24. Matrix object names end with matrix ID:
  25. matrix_L matrix_R
  26. */
  27. // ################## GLOBAL ###################
  28. // ================= INCLUDES ==================
  29. //Ports
  30. #include <RowPort_AVR_Optic.h>
  31. #include <ColPort_AVR.h>
  32. #include <IOExpanderPort.h>
  33. #include <RowPort_PCA9655E.h>
  34. #include <ColPort_PCA9655E.h>
  35. //Codes
  36. #include <Code_Sc.h>
  37. //Matrix
  38. #include <Row.h>
  39. #include <Matrix.h>
  40. // ============ SPEED CONFIGURATIONS ============
  41. const unsigned int Row::DELAY_MICROSECONDS = 1000;
  42. // ================ LEFT PORTS =================
  43. /*
  44. The left matrix is scanned by a micro-controller.
  45. */
  46. RowPort_AVR_Optic rowPortF_L(DDRF, PORTF);
  47. ColPort_AVR colPortB_L(DDRB, PORTB, PINB, 1<<0 | 1<<1 );
  48. ColPort* const ptrsColPorts_L[] = { &colPortB_L };
  49. const uint8_t COL_PORT_L_COUNT = sizeof(ptrsColPorts_L)/sizeof(*ptrsColPorts_L);
  50. // =============== RIGHT PORTS =================
  51. /*
  52. The right matrix is scanned by an I/O expander.
  53. I/O expander I2C address is configured by hardware pins.
  54. ADDR is a static variable of class IOExpanderPort.
  55. */
  56. const uint8_t IOExpanderPort::ADDR = 0x18;
  57. /*
  58. The I/O expander has two ports. Each port has eight pins.
  59. One port is connected to the matrix's rows. The other port is connected to the matrix's columns.
  60. The IOExpanderPort constructor parameters specify the port number and initial output value.
  61. port1_R is port 1 and has an initial output value of 0.
  62. rowPort1_R uses port1_R.
  63. */
  64. IOExpanderPort port1_R(1, 0);
  65. RowPort_PCA9655E rowPort1_R(port1_R);
  66. /*
  67. port0_R is port 0 and has an initial output value of 0.
  68. colPort0_R uses port0_R to read pin 0 and pin 1.
  69. */
  70. IOExpanderPort port0_R(0, 0);
  71. ColPort_PCA9655E colPort0_R(port0_R, 1<<0 | 1<<1 );
  72. /*
  73. ColPort pointers are packed into an array.
  74. */
  75. ColPort* const ptrsColPorts_R[] = { &colPort0_R };
  76. const uint8_t COL_PORT_R_COUNT = sizeof(ptrsColPorts_R)/sizeof(*ptrsColPorts_R);
  77. // =================== CODES ===================
  78. /*
  79. Codes are not grouped into left and right because codes are independent of layout.
  80. - a keyboard can have differnt layouts
  81. - some codes may appear on both matrices
  82. */
  83. Code_Sc s_shiftL(MODIFIERKEY_LEFT_SHIFT);
  84. Code_Sc s_shiftR(MODIFIERKEY_RIGHT_SHIFT);
  85. Code_Sc s_a(KEY_A);
  86. Code_Sc s_b(KEY_B);
  87. Code_Sc s_c(KEY_C);
  88. Code_Sc s_1(KEY_1);
  89. Code_Sc s_2(KEY_2);
  90. Code_Sc s_3(KEY_3);
  91. // ================ LEFT MATRIX ================
  92. // ---------------- LEFT ROWS ------------------
  93. Key* const ptrsKeys_L0[] = { &s_a, &s_b };
  94. Row row_L0(rowPortF_L, 1<<0, ptrsColPorts_L, COL_PORT_L_COUNT, ptrsKeys_L0);
  95. Key* const ptrsKeys_L1[] = { &s_c, &s_shiftL };
  96. Row row_L1(rowPortF_L, 1<<1, ptrsColPorts_L, COL_PORT_L_COUNT, ptrsKeys_L1);
  97. // ---------------- LEFT MATRIX ----------------
  98. Row* const ptrsRows_L[] = { &row_L0, &row_L1 };
  99. const uint8_t ROW_L_COUNT = sizeof(ptrsRows_L)/sizeof(*ptrsRows_L);
  100. Matrix matrix_L(ptrsRows_L, ROW_L_COUNT, 1);
  101. // ================ RIGHT MATRIX ===============
  102. // ---------------- RIGHT ROWS -----------------
  103. Key* const ptrsKeys_R0[] = { &s_1, &s_2 };
  104. Row row_R0(rowPort1_R, 1<<0, ptrsColPorts_R, COL_PORT_R_COUNT, ptrsKeys_R0);
  105. Key* const ptrsKeys_R1[] = { &s_3, &s_shiftR };
  106. Row row_R1(rowPort1_R, 1<<1, ptrsColPorts_R, COL_PORT_R_COUNT, ptrsKeys_R1);
  107. // ---------------- RIGHT MATRIX ---------------
  108. Row* const ptrsRows_R[] = { &row_R0, &row_R1 };
  109. const uint8_t ROW_R_COUNT = sizeof(ptrsRows_R)/sizeof(*ptrsRows_R);
  110. Matrix matrix_R(ptrsRows_R, ROW_R_COUNT, 1);
  111. // ################### MAIN ####################
  112. void setup()
  113. {
  114. /*
  115. Call begin() for I/O expander's rowPort and colPort.
  116. */
  117. rowPort1_R.begin();
  118. colPort0_R.begin();
  119. Keyboard.begin();
  120. }
  121. /*
  122. loop() continually scans both Matrix objects.
  123. */
  124. void loop()
  125. {
  126. matrix_L.scan();
  127. matrix_R.scan();
  128. }