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_ShiftRegsReadStrobed.h 2.2KB

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