keybrd library is an open source library for creating custom-keyboard firmware.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
Dieses Repo ist archiviert. Du kannst Dateien sehen und es klonen, kannst aber nicht pushen oder Issues/Pull-Requests öffnen.

ColPort_MCP23018.cpp 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "ColPort_MCP23018.h"
  2. /*
  3. configures column port's IODIR, GPIO, and GPPU.
  4. */
  5. ColPort_MCP23018::ColPort_MCP23018(IOExpanderPort& port, const uint8_t colPins)
  6. : ColPort(colPins), port(port), IODIR(port.num), GPIO(port.num + 0x12), GPPU(port.num + 0x0C)
  7. {}
  8. void ColPort_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(colPins); //0=configure as output (for LED), 1=configure as input (for read)
  18. Wire.endTransmission();
  19. Wire.beginTransmission(port.ADDR);
  20. Wire.write(GPPU);
  21. Wire.write(colPins); //0=pull-up disabled (for LED), 1=pull-up enabled (for read)
  22. Wire.endTransmission();
  23. }
  24. /*
  25. Saves all port-pin values to portState.
  26. */
  27. void ColPort_MCP23018::read()
  28. {
  29. Wire.beginTransmission(port.ADDR);
  30. Wire.write(GPIO); //GPIO immediately before requestFrom
  31. Wire.endTransmission();
  32. Wire.requestFrom(port.ADDR, 1u); //request one byte from input port
  33. portState = Wire.read();
  34. }