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_ShiftRegsPISOMultiRow.h 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef ROWSCANNER_SHIFTREGSPISOMULTIROW_H
  2. #define ROWSCANNER_SHIFTREGSPISOMULTIROW_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_ShiftRegsPISOMultiRow reads shift registers.
  11. This was tested on 74HC165 shift registers, which 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. Example instantiation:
  14. Scanner_ShiftRegsPISOMultiRow scanner_R(HIGH, SS, 4);
  15. There are three Scanner_ShiftRegsPISOMultiRow parameters.
  16. "strobeOn" paramter is active state HIGH or LOW.
  17. "slaveSelect" paramter can be any controller pin connected to shift register's SHIFT-LOAD pin.
  18. slaveSelect pin SS (Arduino pin 10) has the fastest scan.
  19. "byte_count" is the number of bytes to read from shift registers (1 to 4).
  20. byte_count should cover all the row's keys:
  21. byte_count*8 >= row's keyCount
  22. Hardware setup:
  23. Each row needs to be connected to a strobe pin from the controller.
  24. Switche and diode in series are connected to shift-register parallel-input pins and strobed row.
  25. For active low:
  26. Shift-register parallel-input pins need 10k Ohm pull-up resistors powered.
  27. Orient diodes with cathode (banded end) towards the write pins (row)
  28. Controller's MISO pin is connected to shift register's complementary serial output (/QH) pin
  29. For active high:
  30. Shift-register parallel-input pins need 10k pull-down resistors grounded.
  31. Orient diodes with cathode (banded end) towards the read pins.
  32. Controller's MISO pin is connected to shift register's serial output (QH) pin
  33. */
  34. class Scanner_ShiftRegsPISOMultiRow : public ScannerInterface
  35. {
  36. private:
  37. const bool strobeOn; //logic level of strobe on, active state HIGH or LOW
  38. const bool strobeOff; //logic level of strobe off, complement of strobeOn
  39. const uint8_t slaveSelect; //controller's pin number that is
  40. // connected to shift register's SHIFT-LOAD pin
  41. const uint8_t byte_count; //number of bytes to read from shift registers
  42. public:
  43. Scanner_ShiftRegsPISOMultiRow(const bool strobeOn,
  44. const uint8_t slaveSelect, const uint8_t byte_count);
  45. virtual void init(const uint8_t strobePin);
  46. virtual void begin();
  47. virtual read_pins_t scan(const uint8_t strobePin);
  48. };
  49. #endif