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

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 all shift registers in a daisy chain.
  10. The maximum keys per row is 31, because Arduino's largest type is 32 bits and rowEnd consumes the last bit.
  11. //todo delete: Assumes only one row of shift registers is connected (no Slave Select).
  12. For active low:
  13. 10k pull-up resistor are connected to power
  14. connect controller's MISO pin to shift register's /QH pin
  15. in sketch, const bool RowScanner_PinsArray::ACTIVE_HIGH = 0;
  16. For active high:
  17. 10k pull-down resistors are grounded
  18. connect controller's MISO pin to shift register's QH pin
  19. in sketch, const bool RowScanner_PinsArray::ACTIVE_HIGH = 1;
  20. shift registers 74HC165 Parallel-In-Serial-Out (PISO) are Daisy chained
  21. The maximum keys per row is 31, because Arduino's largest type is 32 bits and rowEnd consumes the last bit.
  22. call begin() from setup()
  23. */
  24. class RowScanner_SPIShiftRegisters : public RowScannerInterface
  25. {
  26. private:
  27. //todo static const bool ACTIVE_HIGH; //logic level of strobe pin: 0=activeLow, 1=activeHigh
  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; //number of keys in row + 1
  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