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

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