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.

RowScanner_SPIShiftRegisters.h 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef ROWSCANNER_SPI_SHIFTREGISTERS_H
  2. #define ROWSCANNER_SPI_SHIFTREGISTERS_H
  3. #include <Arduino.h>
  4. #include <inttypes.h>
  5. #include <SPI.h>
  6. #include <RowScannerInterface.h>
  7. #include <RowPort.h>
  8. #include <ColPort.h>
  9. /* RowScanner_SPIShiftRegisters reads shift registers.
  10. shift registers 74HC165 Parallel-In-Serial-Out (PISO)
  11. in sketch:
  12. const uint8_t RowScanner_SPIShiftRegisters::SHIFT_LOAD = 10;
  13. call begin() from setup()
  14. Upto 4 shift registers can be in a daisy chained.
  15. The maximum keys per row is 31, because Arduino's largest type is 32 bits and rowEnd consumes the last bit.
  16. The shift registers are active high:
  17. 10k pull-down resistors are grounded
  18. connect controller's MISO pin to shift register's QH pin
  19. The shift register needs 5 wires.
  20. In addition, each row needs to be connected to a strobe pin from controller.
  21. The two parts of a split keyboard can be connected by one of:
  22. * eSATA cable (has 7 wires, good for 2 rows)
  23. * Ethernet cable (has 8 wires, good for 3 rows)
  24. */
  25. class RowScanner_SPIShiftRegisters : public RowScannerInterface
  26. {
  27. private:
  28. static const uint8_t SHIFT_LOAD; //controller's pin number that is connected to shift register's SHIFT_LOAD pin
  29. const uint8_t STROBE_PIN; //Arduino pin number connected to this row
  30. const read_pins_mask_t ROW_END; //bitwise, 1 bit marks positioned after last key of row
  31. const uint8_t BYTE_COUNT; //number of bytes to read from shift registers
  32. public:
  33. RowScanner_SPIShiftRegisters(const uint8_t STROBE_PIN, uint8_t KEY_COUNT);
  34. virtual read_pins_t scan(read_pins_mask_t& rowEnd);
  35. void begin();
  36. };
  37. #endif