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_ShiftRegsRead.h 2.3KB

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