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.

Scanner_ShiftRegs74HC165.h 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef ROWSCANNER_SHIFTREGS74HC165_H
  2. #define ROWSCANNER_SHIFTREGS74HC165_H
  3. #include <Arduino.h>
  4. #include <inttypes.h>
  5. #include <config_keybrd.h>
  6. #include <SPI.h>
  7. #include <StrobePort.h>
  8. #include <ReadPort.h>
  9. /* Scanner_ShiftRegs74HC165 reads shift registers.
  10. shift registers 74HC165 is Parallel-In-Serial-Out (PISO)
  11. Upto 4 shift registers can be in a daisy chained.
  12. In sketch:
  13. const uint8_t Scanner_ShiftRegs74HC165::SHIFT_LOAD = 10;
  14. call begin() from setup()
  15. For active low:
  16. const bool Scanner_ShiftRegs74HC165::STROBE_ON = LOW;
  17. const bool Scanner_ShiftRegs74HC165::STROBE_OFF = HIGH;
  18. //shift register parallel input pins have 10k pull-down resistors powered
  19. //controller's MISO pin is connected to shift register's complementary serial output (/QH) pin
  20. For active high:
  21. const bool Scanner_ShiftRegs74HC165::STROBE_ON = HIGH;
  22. const bool Scanner_ShiftRegs74HC165::STROBE_OFF = LOW;
  23. //shift register parallel input pins have 10k pull-down resistors grounded
  24. //controller's MISO pin is connected to shift register's serial output (QH) pin
  25. In addition, each row needs to be connected to a strobe pin from controller.
  26. todo move this to tutorial
  27. The shift register needs 5 wires.
  28. The two parts of a split keyboard can be connected by one of:
  29. * eSATA cable (has 7 wires, good for 2 rows)
  30. * Ethernet cable (has 8 wires, good for 3 rows)
  31. */
  32. class Scanner_ShiftRegs74HC165
  33. {
  34. private:
  35. static const uint8_t SHIFT_LOAD; //controller's pin number that is connected to shift register's SHIFT_LOAD pin
  36. static const bool STROBE_ON; //logic level of strobe on, active state HIGH or LOW
  37. static const bool STROBE_OFF; //logic level of strobe off, complement of active state
  38. const uint8_t STROBE_PIN; //Arduino pin number connected to this row
  39. const uint8_t BYTE_COUNT; //number of bytes to read from shift registers
  40. uint8_t READ_PIN_COUNT;
  41. public:
  42. Scanner_ShiftRegs74HC165(const uint8_t STROBE_PIN, uint8_t READ_PIN_COUNT);
  43. virtual read_pins_t scan(uint8_t& READ_PIN_COUNT);
  44. void begin();
  45. };
  46. #endif