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_5b_LED_on_IOE.ino 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* keybrd_5b_LED_on_IOE.ino
  2. This sketch:
  3. is a simple 1-layer keyboard with CapsLck indicator LED on I/O expander
  4. runs on two matrices of a breadboard keyboard
  5. modified keybrd_4c_split_keyboard_with_IOE.ino by adding LED_CapsLck
  6. This layout table shows left and right matrices:
  7. | Left | **0** | **1** | | Right | **0** | **1** |
  8. |:-----:|-------|-------|-|:-----:|-------|-------|
  9. | **1** |CapsLck| a 1 | | **1** | b 2 | c 3 |
  10. | **0** | fn | x = | | **0** | y - | z / |
  11. */
  12. // ################## GLOBAL ###################
  13. // ================= INCLUDES ==================
  14. #include <ScanDelay.h>
  15. #include <LayerState_LED.h>
  16. #include <Code_LayerHold.h>
  17. #include <Code_LEDLock.h>
  18. #include <Key_LayeredKeys.h>
  19. #include <Code_Sc.h>
  20. #include <Row.h>
  21. //left matrix
  22. #include <Scanner_uC.h>
  23. #include <LED_uC.h>
  24. //right matrix
  25. #include <PortMCP23S17.h>
  26. #include <Scanner_IOE.h>
  27. #include <LED_IOE.h>
  28. // ============ SPEED CONFIGURATION ============
  29. ScanDelay scanDelay(9000);
  30. // ================= LEFT PINS =================
  31. // ---------------- LEFT SCANNER ---------------
  32. uint8_t readPins[] = {14, 15};
  33. const uint8_t readPinCount = sizeof(readPins)/sizeof(*readPins);
  34. Scanner_uC scanner_L(LOW, readPins, readPinCount);
  35. // ----------------- LEFT LEDs -----------------
  36. LED_uC LED_CapsLck(21);
  37. // ================ RIGHT PINS =================
  38. // --------------- RIGHT SCANNER ---------------
  39. const uint8_t IOE_ADDR = 0x20; //MCP23S17 address, all 3 ADDR pins are grounded
  40. PortMCP23S17 portA(IOE_ADDR, 0, 1<<0 | 1<<1 ); //for read and LED
  41. PortMCP23S17 portB(IOE_ADDR, 1, 0); //for strobe and LED
  42. Scanner_IOE scanner_R(LOW, portB, portA);
  43. // ---------------- RIGHT LEDs -----------------
  44. LED_IOE LED_normal(portA, 1<<5);
  45. LED_IOE LED_fn(portB, 1<<4);
  46. // =================== CODES ===================
  47. // ---------------- LAYER CODE -----------------
  48. enum layers { NORMAL, FN };
  49. LED* prtsLayerLEDs[] = { &LED_normal, &LED_fn }; //array index matches enum layerIds
  50. LayerState_LED layerState(prtsLayerLEDs);
  51. Code_LayerHold l_fn(FN, layerState);
  52. // ---------------- SCAN CODES -----------------
  53. Code_Sc s_a(KEY_A);
  54. Code_Sc s_b(KEY_B);
  55. Code_Sc s_c(KEY_C);
  56. Code_Sc s_x(KEY_X);
  57. Code_Sc s_y(KEY_Y);
  58. Code_Sc s_z(KEY_Z);
  59. Code_Sc s_1(KEY_1);
  60. Code_Sc s_2(KEY_2);
  61. Code_Sc s_3(KEY_3);
  62. Code_Sc s_minus(KEY_MINUS);
  63. Code_Sc s_equal(KEY_EQUAL);
  64. Code_Sc s_slash(KEY_SLASH);
  65. Code_LEDLock o_capsLock(KEY_CAPS_LOCK, LED_CapsLck);
  66. // =================== KEYS ====================
  67. //row0
  68. Key* const ptrsKeys_01[] = { &s_a, &s_1 };
  69. Key_LayeredKeys k_01(ptrsKeys_01);
  70. Key* const ptrsKeys_02[] = { &s_b, &s_2 };
  71. Key_LayeredKeys k_02(ptrsKeys_02);
  72. Key* const ptrsKeys_03[] = { &s_c, &s_3 };
  73. Key_LayeredKeys k_03(ptrsKeys_03);
  74. //row1
  75. Key* const ptrsKeys_11[] = { &s_x, &s_equal };
  76. Key_LayeredKeys k_11(ptrsKeys_11);
  77. Key* const ptrsKeys_12[] = { &s_y, &s_minus };
  78. Key_LayeredKeys k_12(ptrsKeys_12);
  79. Key* const ptrsKeys_13[] = { &s_z, &s_slash };
  80. Key_LayeredKeys k_13(ptrsKeys_13);
  81. LayerStateInterface& Key_LayeredKeys::refLayerState = layerState;
  82. // =================== ROWS ====================
  83. // ---------------- LEFT ROWS ------------------
  84. Key* ptrsKeys_L0[] = { &o_capsLock, &k_01 };
  85. const uint8_t KEY_COUNT_L0 = sizeof(ptrsKeys_L0)/sizeof(*ptrsKeys_L0);
  86. Row row_L0(scanner_L, 0, ptrsKeys_L0, KEY_COUNT_L0);
  87. Key* ptrsKeys_L1[] = { &l_fn, &k_11 };
  88. const uint8_t KEY_COUNT_L1 = sizeof(ptrsKeys_L1)/sizeof(*ptrsKeys_L1);
  89. Row row_L1(scanner_L, 1, ptrsKeys_L1, KEY_COUNT_L1);
  90. // ---------------- RIGHT ROWS -----------------
  91. Key* ptrsKeys_R0[] = { &k_02, &k_03};
  92. const uint8_t KEY_COUNT_R0 = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
  93. Row row_R0(scanner_R, 1<<0, ptrsKeys_R0, KEY_COUNT_R0);
  94. Key* ptrsKeys_R1[] = { &k_12, &k_13 };
  95. const uint8_t KEY_COUNT_R1 = sizeof(ptrsKeys_R1)/sizeof(*ptrsKeys_R1);
  96. Row row_R1(scanner_R, 1<<1, ptrsKeys_R1, KEY_COUNT_R1);
  97. // ################### MAIN ####################
  98. void setup()
  99. {
  100. Keyboard.begin();
  101. scanner_R.begin();
  102. layerState.begin();//must be after scanner begin for IOE ?? todo
  103. }
  104. void loop()
  105. {
  106. //left matrix
  107. row_L0.process();
  108. row_L1.process();
  109. //right matrix
  110. row_R0.process();
  111. row_R1.process();
  112. scanDelay.delay();
  113. //debug.print_scans_per_second();
  114. //debug.print_microseconds_per_scan();
  115. }