keybrd library is an open source library for creating custom-keyboard firmware.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
Dieses Repo ist archiviert. Du kannst Dateien sehen und es klonen, kannst aber nicht pushen oder Issues/Pull-Requests öffnen.

RowScanner_SPIShiftRegisters.h 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 uint8_t KEY_COUNT; //number of keys in 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. : STROBE_PIN(STROBE_PIN), KEY_COUNT(KEY_COUNT), BYTE_COUNT(ceil (float(KEY_COUNT)/8)) {}
  35. virtual read_pins_t scan(read_pins_mask_t& rowEnd);
  36. void begin();
  37. };
  38. #endif