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_IOE.cpp 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "Scanner_IOE.h"
  2. /* init() is called once for each row from Row constructor.
  3. */
  4. void Scanner_IOE::init(const uint8_t strobePin)
  5. {
  6. //empty
  7. }
  8. /* begin() should be called once from sketch setup().
  9. */
  10. void Scanner_IOE::begin()
  11. {
  12. refPortWrite.begin(); //configure SPI bus
  13. refPortRead.begin(strobeOn);
  14. }
  15. /* scan() is called on every iteration of sketch loop().
  16. scan() strobes the row's strobePin and retuns state of port's input pins.
  17. Bitwise variables are 1 bit per key.
  18. */
  19. read_pins_t Scanner_IOE::scan(const uint8_t strobePin)
  20. {
  21. uint8_t readState; //bitwise, 1 means key is pressed, 0 means released
  22. //strobe on
  23. refPortWrite.write(strobePin, strobeOn);
  24. delayMicroseconds(3); //time to stabilize voltage
  25. //read the port pins
  26. readState = refPortRead.read();
  27. //strobe off
  28. refPortWrite.write(strobePin, strobeOff);
  29. if (strobeOn == LOW) //if active low
  30. {
  31. readState = ~readState;
  32. }
  33. return readState;
  34. }