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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. Initiates communication protocal and configs ports.
  10. */
  11. void Scanner_IOE::begin()
  12. {
  13. refPortWrite.beginProtocol();
  14. refPortWrite.begin(activeState);
  15. refPortRead.begin(activeState);
  16. }
  17. /* scan() is called on every iteration of sketch loop().
  18. strobePin is a bit pattern, 1 means that row pin is active.
  19. scan() strobes the row's strobePin and retuns state of port's input pins.
  20. */
  21. read_pins_t Scanner_IOE::scan(const uint8_t strobePin)
  22. {
  23. uint8_t readState; //bits, 1 means key is pressed, 0 means released
  24. //strobe on
  25. if (activeState == LOW) //if active low
  26. {
  27. refPortWrite.writeLow(strobePin);
  28. }
  29. else //if active high
  30. {
  31. refPortWrite.writeHigh(strobePin);
  32. }
  33. delayMicroseconds(3); //time to stabilize voltage
  34. //read the port pins
  35. readState = refPortRead.read();
  36. //strobe off
  37. if (activeState == LOW) //if active low
  38. {
  39. refPortWrite.writeHigh(strobePin);
  40. readState = ~readState;
  41. }
  42. else //if active high
  43. {
  44. refPortWrite.writeLow(strobePin);
  45. }
  46. return readState;
  47. }