keybrd library is an open source library for creating custom-keyboard firmware.
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

keybrd_PCA9655E.ino 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* keybrd_PCA9655E.ino
  2. Teensy 2.0 controller PCA9655E I/O expander
  3. | Left | **0** | **1** | | Right | **0** | **1** |
  4. |:-----:|-------|-------| |:-----:|-------|-------|
  5. | **1** | 1 | 2 | | **1** | 3 | 4 |
  6. | **0** | a | b | | **0** | c | d |
  7. */
  8. // ################## GLOBAL ###################
  9. // ================= INCLUDES ==================
  10. #include <ScanDelay.h>
  11. #include <Code_Sc.h>
  12. //left matrix
  13. #include <Row_uC.h>
  14. //right matrix
  15. #include <Row_IOE.h>
  16. #include <PortIOE.h>
  17. #include <PortWrite_PCA9655E.h>
  18. #include <PortRead_PCA9655E.h>
  19. // ============ SPEED CONFIGURATION ============
  20. ScanDelay scanDelay(9000);
  21. // =============== LEFT uC MATRIX ==============
  22. const bool Scanner_uC::STROBE_ON = HIGH; //active high
  23. const bool Scanner_uC::STROBE_OFF = LOW;
  24. uint8_t readPins_L[] = {0, 1};
  25. // ============== RIGHT IOE MATRIX =============
  26. const bool Scanner_Port::STROBE_ON = HIGH; //active high
  27. const bool Scanner_Port::STROBE_OFF = LOW;
  28. const uint8_t PortIOE::DEVICE_ADDR = 0x18;
  29. // ------------------ PORT 1 -------------------
  30. PortIOE port1_R(1, 0);
  31. PortWrite_PCA9655E portWrite1_R(port1_R);
  32. // ------------------ PORT 0 -------------------
  33. PortIOE port0_R(0, 0);
  34. PortWrite_PCA9655E portWrite0_R(port0_R);
  35. PortRead_PCA9655E portRead0_R(port0_R, 1<<0 | 1<<1 );
  36. // =================== CODES ===================
  37. Code_Sc s_a(KEY_A);
  38. Code_Sc s_b(KEY_B);
  39. Code_Sc s_c(KEY_C);
  40. Code_Sc s_d(KEY_D);
  41. Code_Sc s_1(KEY_1);
  42. Code_Sc s_2(KEY_2);
  43. Code_Sc s_3(KEY_3);
  44. Code_Sc s_4(KEY_4);
  45. // =================== ROWS ====================
  46. // ---------------- LEFT ROWS ------------------
  47. Key* ptrsKeys_L0[] = { &s_1, &s_2 };
  48. uint8_t KEY_COUNT_L0 = sizeof(ptrsKeys_L0)/sizeof(*ptrsKeys_L0);
  49. Row_uC row_L0(21, readPins_L, KEY_COUNT_L0, ptrsKeys_L0);
  50. Key* ptrsKeys_L1[] = { &s_a, &s_b };
  51. uint8_t KEY_COUNT_L1 = sizeof(ptrsKeys_L1)/sizeof(*ptrsKeys_L1);
  52. Row_uC row_L1(20, readPins_L, KEY_COUNT_L1, ptrsKeys_L1);
  53. // ---------------- RIGHT ROWS -----------------
  54. Key* ptrsKeys_R0[] = { &s_3, &s_4 };
  55. uint8_t KEY_COUNT_R0 = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
  56. Row_IOE row_R0(portWrite1_R, 1<<0, portRead0_R, KEY_COUNT_R0, ptrsKeys_R0);
  57. Key* ptrsKeys_R1[] = { &s_c, &s_d };
  58. uint8_t KEY_COUNT_R1 = sizeof(ptrsKeys_R1)/sizeof(*ptrsKeys_R1);
  59. Row_IOE row_R1(portWrite1_R, 1<<1, portRead0_R, KEY_COUNT_R1, ptrsKeys_R1);
  60. // ################### MAIN ####################
  61. void setup()
  62. {
  63. Keyboard.begin();
  64. Wire.begin(); //Wire.begin() must be called before port begin()
  65. portWrite1_R.begin();
  66. portRead0_R.begin();
  67. }
  68. void loop()
  69. {
  70. //left matrix
  71. row_L0.process();
  72. row_L1.process();
  73. //right matrix
  74. row_R0.process();
  75. row_R1.process();
  76. scanDelay.delay();
  77. //debug.print_scans_per_second();
  78. //debug.print_microseconds_per_scan();
  79. }