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_ShiftRegsPISOSingleRow.cpp 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "Scanner_ShiftRegsPISOSingleRow.h"
  2. /* constructor
  3. */
  4. Scanner_ShiftRegsPISOSingleRow::Scanner_ShiftRegsPISOSingleRow(const bool strobeOn,
  5. const uint8_t slaveSelect, const uint8_t byte_count)
  6. : slaveSelect(slaveSelect), byte_count(byte_count)
  7. {
  8. pinMode(slaveSelect, OUTPUT);
  9. }
  10. /* init() is called once for each row from Row constructor.
  11. */
  12. void Scanner_ShiftRegsPISOSingleRow::init(const uint8_t strobePin)
  13. {
  14. //empty function
  15. }
  16. /* begin() should be called once from sketch setup().
  17. Initializes shift register's shift/load pin.
  18. */
  19. void Scanner_ShiftRegsPISOSingleRow::begin()
  20. {
  21. SPI.begin();
  22. digitalWrite(slaveSelect, HIGH);
  23. }
  24. /* scan() returns state of the shift register's input pins.
  25. No strobe pin is needed, the shift register is wired so the strobe is effectivley always "on".
  26. Bit patterns are 1 bit per key.
  27. */
  28. read_pins_t Scanner_ShiftRegsPISOSingleRow::scan(const uint8_t strobePin)
  29. {
  30. read_pins_t readState = 0; //bits, 1 means key is pressed, 0 means released
  31. //read all the column pins
  32. digitalWrite(slaveSelect, LOW); //load parallel inputs to the register
  33. digitalWrite(slaveSelect, HIGH); //shift the data toward a serial output
  34. SPI.transfer(&readState, byte_count);
  35. return readState;
  36. }