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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef ROWSCANNER_SHIFTREGSREADSTROBED_H
  2. #define ROWSCANNER_SHIFTREGSREADSTROBED_H
  3. #include <Arduino.h>
  4. #include <inttypes.h>
  5. #include <SPI.h>
  6. #include "config_keybrd.h"
  7. #include "ScannerInterface.h"
  8. /* Scanner_ShiftRegsReadStrobed reads shift registers.
  9. Shift registers can be 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 class works with machanical switches or photointerrupter switches.
  12. A "strobe" powers the IR LEDs for a short time while the shift registers read the photo transistors.
  13. The IR LEDs are off most of the time to preserve IR LED life.
  14. Example instantiation:
  15. Scanner_ShiftRegsReadStrobed scanner_R(HIGH, 6, 4);
  16. There are three Scanner_ShiftRegsReadStrobed parameters.
  17. 1. "activeState" paramter is active state HIGH or LOW.
  18. 2. "slaveSelect" paramter is 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. Each row of keys is connected to a controller by 6 wires:
  23. * GND
  24. * power
  25. * CLK
  26. * Slave Select
  27. * MISO
  28. * strobe
  29. For active low:
  30. Shift-register parallel-input pins need 10k Ohm pull-up resistors powered.
  31. Orient diodes with cathode (banded end) towards the write pins (row)
  32. Controller's MISO pin is connected to shift register's complementary serial output (/QH) pin
  33. For active high:
  34. Shift-register parallel-input pins need 10k pull-down resistors grounded.
  35. Orient diodes with cathode (banded end) towards the read pins.
  36. Controller's MISO pin is connected to shift register's serial output (QH) pin
  37. If multiple rows (or any SPI divice) share a MISO line, the shift registers need to be isolated by a tri-state buffer chip.
  38. */
  39. class Scanner_ShiftRegsReadStrobed : public ScannerInterface
  40. {
  41. private:
  42. const bool activeState; //logic level of strobe on, active state HIGH or LOW
  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_ShiftRegsReadStrobed(const bool activeState,
  47. const uint8_t slaveSelect, const uint8_t byte_count);
  48. virtual void init(const uint8_t strobePin);
  49. virtual read_pins_t scan(const uint8_t strobePin);
  50. };
  51. #endif