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_ShiftRegsPISOSingleRow.h 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef ROWSCANNER_SHIFTREGSPISOSINGLEROW_H
  2. #define ROWSCANNER_SHIFTREGSPISOSINGLEROW_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_ShiftRegsPISOSingleRow 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. Row row_R0(scanner_R, 0, ptrsKeys_R0, sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0));
  15. Scanner_ShiftRegsPISOSingleRow scanner_R(HIGH, SS, 4);
  16. The Row "strobePin" parameter is ignored.
  17. In the above example, the "strobePin" argument is 0, but it doesn't matter what value is given.
  18. There are three Scanner_ShiftRegsPISOSingleRow parameters.
  19. "strobeOn" paramter is ignored, but should be active state HIGH or LOW required by ScannerInterface.
  20. "slaveSelect" paramter can be any controller pin connected to shift register's SHIFT-LOAD pin.
  21. slaveSelect pin SS (Arduino pin 10) has the fastest scan.
  22. "byte_count" is the number of bytes to read from shift registers (1 to 4).
  23. byte_count should cover all the row's keys:
  24. byte_count*8 >= row's keyCount
  25. Hardware setup:
  26. There is only one row, and it is permanently active.
  27. Switches are connected to shift-register parallel-input pins (diodes are not needed) and row.
  28. For active low:
  29. Shift-register parallel-input pins need 10k Ohm pull-up resistors powered.
  30. Switches connect powered row to parallel-input pins.
  31. Controller's MISO pin is connected to shift register's complementary serial output (/QH) pin
  32. For active high:
  33. Shift-register parallel-input pins need 10k pull-down resistors grounded.
  34. Switches connect grouned row to parallel-input pins.
  35. Controller's MISO pin is connected to shift register's serial output (QH) pin
  36. */
  37. class Scanner_ShiftRegsPISOSingleRow : public ScannerInterface
  38. {
  39. private:
  40. const uint8_t slaveSelect; //controller's pin number that is
  41. // connected to shift register's SHIFT-LOAD pin
  42. const uint8_t byte_count; //number of bytes to read from shift registers
  43. public:
  44. Scanner_ShiftRegsPISOSingleRow(const bool strobeOn,
  45. const uint8_t slaveSelect, const uint8_t byte_count);
  46. void init(const uint8_t strobePin);
  47. void begin();
  48. virtual read_pins_t scan(const uint8_t strobePin);
  49. };
  50. #endif