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.

Row_IOE.cpp 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "Row_IOE.h"
  2. void Row_IOE::process()
  3. {
  4. //these variables are all bitwise, one bit per key
  5. uint8_t rowState; //1 means pressed, 0 means released
  6. read_pins_mask_t rowEnd; //1 bit marks positioned after last key of row
  7. uint8_t debouncedChanged; //1 means debounced changed
  8. ColPort* ptrColPort; //new
  9. ptrColPort = scanner.scan(rowEnd);
  10. rowState = getRowState(ptrColPort, rowEnd); //new
  11. debouncedChanged = debouncer.debounce(rowState, debounced);
  12. pressRelease(rowEnd, debouncedChanged);
  13. }
  14. /*
  15. Copies column pins to rowState. Unused column pins are not copied.
  16. Sets rowEnd and returns rowState.
  17. rowEnd is a bitwise row mask, one col per bit, where active col bit is 1.
  18. At end of function, 1 bit marks place immediatly after last key of row.
  19. rowEnd is a larger type than portMask so that it can not overflow.
  20. */
  21. uint8_t Row_IOE::getRowState(ColPort* ptrColPort, read_pins_mask_t& rowEnd)
  22. {
  23. uint8_t rowState = 0; //bitwise, one key per bit, 1 means key is pressed
  24. uint8_t portMask; //bitwise, 1 bit is a colPortState position
  25. rowEnd = 1;
  26. //bitwise colPins, 1 means pin is connected to column
  27. uint8_t colPins = ptrColPort->getColPins();
  28. //bitwise colPortState, pin values where set in ColPort::read(), get them now
  29. uint8_t colPortState = ptrColPort->getPortState();
  30. /*if (activeHigh) //'activeHigh' was not declared in this scope
  31. {
  32. colPortState = ~colPortState; //todo configure IOE polarity to take care of this
  33. }*/
  34. for ( portMask = 1; portMask > 0; portMask <<= 1 ) //shift portMask until overflow
  35. { //for each pin of col port
  36. if (portMask & colPins) //if pin is connected to column
  37. {
  38. if (portMask & ~colPortState) //if pin detected a key press
  39. {
  40. rowState |= rowEnd; //set rowState bit for that key
  41. }
  42. rowEnd <<= 1; //shift rowEnd to next key
  43. }
  44. }
  45. return rowState;
  46. }