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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef ROWSCANNER_SHIFTREGSREAD_H
  2. #define ROWSCANNER_SHIFTREGSREAD_H
  3. #include <Arduino.h>
  4. #include <inttypes.h>
  5. #include <SPI.h>
  6. #include "config_keybrd.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-constructor parameters.
  17. 1. "activeState" paramter is ignored, but should be HIGH or LOW for documention.
  18. activeState is required by ScannerInterface.
  19. Actual activeState is determined by external pull-up or pull-down resistors described below.
  20. 2. "slaveSelect" paramter can be any controller pin connected to shift register's SHIFT-LOAD pin.
  21. 3. "byte_count" is the number of bytes to read from shift registers (1, 2, 3, or 4).
  22. byte_count should cover all the row's keys: byte_count*8 >= row's keyCount
  23. Hardware setup:
  24. The row of keys is connected to a controller by 5 wires:
  25. * GND
  26. * power
  27. * CLK
  28. * Slave Select
  29. * MISO
  30. Switches are connected to shift-register parallel-input pins and row.
  31. Diodes are not needed if there is only one row.
  32. For active low:
  33. Shift-register parallel-input pins need 10k Ohm pull-up resistors powered.
  34. Switches connect powered row to parallel-input pins.
  35. Controller's MISO pin is connected to shift register's complementary serial output (/QH) pin
  36. For active high:
  37. Shift-register parallel-input pins need 10k pull-down resistors grounded.
  38. Switches connect grouned row to parallel-input pins.
  39. Controller's MISO pin is connected to shift register's serial output (QH) pin
  40. If multiple rows (or any SPI divice) share a MISO line, the shift registers need to be isolated by a tri-state buffer chip.
  41. */
  42. class Scanner_ShiftRegsRead : public ScannerInterface
  43. {
  44. private:
  45. const uint8_t slaveSelect;//controller pin number connected to shift register SHIFT-LOAD pin
  46. const uint8_t byte_count; //number of bytes to read from shift registers
  47. public:
  48. Scanner_ShiftRegsRead(const bool activeState,
  49. const uint8_t slaveSelect, const uint8_t byte_count);
  50. void init(const uint8_t strobePin);
  51. void begin();
  52. virtual read_pins_t scan(const uint8_t strobePin);
  53. };
  54. #endif