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.

RowPort_MCP23018.cpp 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "RowPort_MCP23018.h"
  2. /*
  3. configures column port's IODIR, GPIO.
  4. */
  5. RowPort_MCP23018::RowPort_MCP23018(IOExpanderPort& port)
  6. : port(port), IODIR(port.num), GPIO(port.num + 0x12)
  7. {}
  8. void RowPort_MCP23018::begin()
  9. {
  10. Wire.beginTransmission(port.ADDR);
  11. Wire.write(IODIR);
  12. Wire.write(0); //0=configure as output (for strobe pins and LED pins)
  13. Wire.endTransmission();
  14. }
  15. /*
  16. sets activePin pin output to low.
  17. activePin is port mask, where active-low pin is 1.
  18. */
  19. void RowPort_MCP23018::setActivePinLow(const uint8_t activePin)
  20. {
  21. Wire.beginTransmission(port.ADDR);
  22. Wire.write(GPIO);
  23. Wire.write(port.outputVal &= ~activePin);
  24. Wire.endTransmission();
  25. }
  26. /*
  27. sets activePin pin output to high, does not reset the other pins because they might be used by LEDs.
  28. activePin is port mask, where active-high pin is 1.
  29. */
  30. void RowPort_MCP23018::setActivePinHigh(const uint8_t activePin)
  31. {
  32. Wire.beginTransmission(port.ADDR);
  33. Wire.write(GPIO);
  34. Wire.write(port.outputVal |= activePin);
  35. Wire.endTransmission();
  36. }