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.

ColPort_PCA9655E.cpp 1.1KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "ColPort_PCA9655E.h"
  2. /*
  3. configures column port's configuration, input, and pins.
  4. */
  5. ColPort_PCA9655E::ColPort_PCA9655E
  6. (IOExpanderPort& port, const uint8_t colPins)
  7. : ColPort(colPins), port(port), configurationByteCommand(port.num + 6), inputByteCommand(port.num)
  8. {}
  9. void ColPort_PCA9655E::begin()
  10. {
  11. //Wire.begin() should only be called once https://www.arduino.cc/en/Reference/WireBegin
  12. #ifndef WIRE_BEGIN
  13. #define WIRE_BEGIN
  14. Wire.begin();
  15. #endif
  16. Wire.beginTransmission(port.ADDR);
  17. Wire.write(configurationByteCommand);
  18. Wire.write(colPins); //0=configure as output (for LED), 1=configure as input (for read)
  19. Wire.endTransmission();
  20. }
  21. /*
  22. Saves all port-pin values to portState.
  23. */
  24. void ColPort_PCA9655E::read()
  25. {
  26. Wire.beginTransmission(port.ADDR);
  27. Wire.write(inputByteCommand); //input immediately before requestFrom
  28. Wire.endTransmission(false); //PCA9655E needs false to send a restart
  29. Wire.requestFrom(port.ADDR, 1u); //request one byte from input port
  30. portState = Wire.read();
  31. }