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