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 1.2KB

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