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.cpp 1018B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "RowScanner_SPIShiftRegisters.h"
  2. void RowScanner_SPIShiftRegisters::begin()
  3. {
  4. //configure row
  5. pinMode(STROBE_PIN, OUTPUT);
  6. //initialize shift register's shift/load pin
  7. pinMode(SHIFT_LOAD, OUTPUT);
  8. digitalWrite(SHIFT_LOAD, HIGH);
  9. }
  10. /*
  11. Sets rowEnd and returns rowState.
  12. */
  13. read_pins_t RowScanner_SPIShiftRegisters::scan(read_pins_mask_t& rowEnd)
  14. {
  15. read_pins_t rowState = 0;
  16. //strobe row on
  17. digitalWrite(STROBE_PIN, HIGH);
  18. delayMicroseconds(3); //time to stablize voltage
  19. //read all the column pins
  20. digitalWrite(SHIFT_LOAD, LOW); //load parallel inputs to the register
  21. digitalWrite(SHIFT_LOAD, HIGH); //shift the data toward a serial output
  22. SPI.transfer(&rowState, BYTE_COUNT);
  23. //strobe row off
  24. digitalWrite(STROBE_PIN, LOW);
  25. rowEnd = 1 << KEY_COUNT;
  26. //clear unpowered pins (for testing bb) todo
  27. rowState &= 0b01010001000100010001000100010001; //also 31st key
  28. return rowState;
  29. }