keybrd library is an open source library for creating custom-keyboard firmware.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
此仓库已存档。您可以查看文件和克隆,但不能推送或创建工单/合并请求。

RowScanner_SPIShiftRegisters.h 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. const uint8_t STROBE_PIN; //Arduino pin number connected to this row
  29. const uint8_t SHIFT_LOAD; //controller's pin number that is connected to shift register's SHIFT_LOAD pin
  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, const uint8_t SHIFT_LOAD,
  34. uint8_t KEY_COUNT)
  35. : STROBE_PIN(STROBE_PIN), SHIFT_LOAD(SHIFT_LOAD),
  36. KEY_COUNT(KEY_COUNT), BYTE_COUNT(ceil (float(KEY_COUNT)/8)) {}
  37. virtual read_pins_t scan(read_pins_mask_t& rowEnd);
  38. void begin();
  39. };
  40. #endif