keybrd library is an open source library for creating custom-keyboard firmware.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
此仓库已存档。您可以查看文件和克隆,但不能推送或创建工单/合并请求。

Row_IOE.cpp 2.2KB

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