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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef ROWSCANNER_SHIFTREGSREAD_H
  2. #define ROWSCANNER_SHIFTREGSREAD_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. Upto 4 shift registers can be in a daisy chained for a total of 32 read pins.
  10. This was tested on 74HC165 shift registers, which are Parallel-In-Serial-Out (PISO).
  11. The row is always powered (there is no strobe that turns off).
  12. Example instantiation:
  13. Row row_R0(scanner_R, 0, ptrsKeys_R0, sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0));
  14. Scanner_ShiftRegsRead scanner_R(HIGH, 6, 4);
  15. In the above Row instantiation, argument 0 for "strobePin" is ignored because there is no strobe.
  16. There are three Scanner_ShiftRegsRead parameters.
  17. 1. "activeState" paramter is ignored, but should be active state HIGH or LOW for ScannerInterface.
  18. 2. "slaveSelect" paramter can be any controller pin connected to shift register's SHIFT-LOAD pin.
  19. 3. "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: byte_count*8 >= row's keyCount
  21. Hardware setup:
  22. The row of keys is connected to a controller by 5 wires:
  23. * GND
  24. * power
  25. * CLK
  26. * Slave Select
  27. * MISO
  28. Switches are connected to shift-register parallel-input pins and row.
  29. Diodes are not needed if there is only one row.
  30. For active low:
  31. Shift-register parallel-input pins need 10k Ohm pull-up resistors powered.
  32. Switches connect powered row to parallel-input pins.
  33. Controller's MISO pin is connected to shift register's complementary serial output (/QH) pin
  34. For active high:
  35. Shift-register parallel-input pins need 10k pull-down resistors grounded.
  36. Switches connect grouned row to parallel-input pins.
  37. Controller's MISO pin is connected to shift register's serial output (QH) pin
  38. If multiple rows (or any SPI divice) share a MISO line, the shift registers need to be isolated by a tri-state buffer chip.
  39. */
  40. class Scanner_ShiftRegsRead : public ScannerInterface
  41. {
  42. private:
  43. const uint8_t slaveSelect;//controller pin number connected to shift register SHIFT-LOAD pin
  44. const uint8_t byte_count; //number of bytes to read from shift registers
  45. public:
  46. Scanner_ShiftRegsRead(const bool activeState,
  47. const uint8_t slaveSelect, const uint8_t byte_count);
  48. void init(const uint8_t strobePin);
  49. void begin();
  50. virtual read_pins_t scan(const uint8_t strobePin);
  51. };
  52. #endif