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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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.begin() should only be called once https://www.arduino.cc/en/Reference/WireBegin
  11. #ifndef WIRE_BEGIN
  12. #define WIRE_BEGIN
  13. Wire.begin();
  14. #endif
  15. Wire.beginTransmission(port.ADDR);
  16. Wire.write(IODIR);
  17. Wire.write(0); //0=configure as output (for strobe pins and LED pins)
  18. Wire.endTransmission();
  19. }
  20. /*
  21. sets activePin pin output to low.
  22. activePin is port mask, where active-low pin is 1.
  23. */
  24. void RowPort_MCP23018::setActivePinLow(const uint8_t activePin)
  25. {
  26. Wire.beginTransmission(port.ADDR);
  27. Wire.write(GPIO);
  28. Wire.write(port.outputVal &= ~activePin);
  29. Wire.endTransmission();
  30. }
  31. /*
  32. sets activePin pin output to high, does not reset the other pins because they might be used by LEDs.
  33. activePin is port mask, where active-high pin is 1.
  34. */
  35. void RowPort_MCP23018::setActivePinHigh(const uint8_t activePin)
  36. {
  37. Wire.beginTransmission(port.ADDR);
  38. Wire.write(GPIO);
  39. Wire.write(port.outputVal |= activePin);
  40. Wire.endTransmission();
  41. }