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.

RowBase.cpp 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "RowBase.h"
  2. /*
  3. pressRelease() calls key's press() or release() function if it was pressed or released.
  4. Both parameters are bitwise.
  5. rowEnd bit marks positioned immediatly after last key of row.
  6. */
  7. void RowBase::pressRelease(const uint8_t KEY_COUNT, const read_pins_t debouncedChanged)
  8. {
  9. read_pins_t isFallingEdge; //bitwise, 1 means falling edge
  10. read_pins_t isRisingEdge; //bitwise, 1 means rising edge
  11. read_pins_mask_t rowMask; //bitwise, active col bit is 1
  12. uint8_t col; //index for ptrsKeys[col] array
  13. //bit=1 if last debounced changed from 1 to 0, else bit=0
  14. isFallingEdge = debouncedChanged & ~debounced;
  15. //bit=1 if last debounced changed from 0 to 1, else bit=0
  16. isRisingEdge = debouncedChanged & debounced;
  17. for (rowMask=1, col=0; col < KEY_COUNT; rowMask<<=1, col++) //for each key in row
  18. {
  19. //release before press avoids impossible key sequence
  20. if (rowMask & isFallingEdge) //if key was released
  21. {
  22. ptrsKeys[col]->release();
  23. }
  24. if (rowMask & isRisingEdge) //if key was pressed
  25. {
  26. ptrsKeys[col]->press();
  27. keyWasPressed();
  28. }
  29. }
  30. }
  31. void RowBase::keyWasPressed()
  32. {
  33. //empty in RowBase class. To unstick sticky keys, override keyWasPressed() in derived class.
  34. }