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.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 <ScannerInterface.h>
  8. #include <PortWriteInterface.h>
  9. #include <PortReadInterface.h>
  10. /* Scanner_ShiftRegs74HC165 reads shift registers.
  11. shift registers 74HC165 are Parallel-In-Serial-Out (PISO)
  12. Upto 4 shift registers can be in a daisy chained for a total of 32 read pins.
  13. For active low:
  14. Shift register parallel input pins have 10k pull-up resistors powered
  15. Orient diodes with cathode (banded end) towards the write pins (row)
  16. Controller's MISO pin is connected to shift register's complementary serial output (/QH) pin
  17. Use these two lines in the sketch:
  18. const bool Scanner_ShiftRegs74HC165::strobeOn = LOW;
  19. const bool Scanner_ShiftRegs74HC165::strobeOff = HIGH;
  20. For active high:
  21. Shift register parallel input pins have 10k pull-down resistors grounded
  22. Orient diodes with cathode (banded end) towards the read pins.
  23. Controller's MISO pin is connected to shift register's serial output (QH) pin
  24. Use these two lines in the sketch:
  25. const bool Scanner_ShiftRegs74HC165::strobeOn = HIGH;
  26. const bool Scanner_ShiftRegs74HC165::strobeOff = LOW;
  27. In addition, each row needs to be connected to a strobe pin from the controller.
  28. */
  29. class Scanner_ShiftRegs74HC165 : public ScannerInterface
  30. {
  31. private:
  32. const bool strobeOn; //logic level of strobe on, active state HIGH or LOW
  33. const bool strobeOff; //logic level of strobe off, complement of active state
  34. const uint8_t slaveSelect; //controller's pin number that is
  35. // connected to shift register's SHIFT-LOAD pin
  36. const uint8_t byte_count; //number of bytes to read from shift registers
  37. public:
  38. Scanner_ShiftRegs74HC165(const bool strobeOn, const uint8_t slaveSelect,
  39. const uint8_t readPinCount);
  40. void init(const uint8_t strobePin);
  41. void begin();
  42. virtual read_pins_t scan(const uint8_t strobePin);
  43. };
  44. #endif