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.

PortWrite_PCA9655E.cpp 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "PortWrite_PCA9655E.h"
  2. /*
  3. configures column port's configuration and output.
  4. */
  5. PortWrite_PCA9655E::PortWrite_PCA9655E(PortIOE& port)
  6. : port(port), configurationByteCommand(port.num + 6), outputByteCommand(port.num + 2) {}
  7. /*
  8. If PortRead_PCA9655E is instantiated on the same port, do NOT use PortWrite_PCA9655E::begin().
  9. Otherwise readPins could be overwritten.
  10. */
  11. void PortWrite_PCA9655E::begin()
  12. {
  13. Wire.beginTransmission(port.DEVICE_ADDR);
  14. Wire.write(configurationByteCommand);
  15. Wire.write(0); //0=configure as output (for strobe pins and LED)
  16. Wire.endTransmission();
  17. }
  18. /*
  19. pin is bitwise, where pin being strobed is 1.
  20. value is HIGH or LOW.
  21. Does not reset the other pins because LEDs could be using some of the pins.
  22. Syntax is similar to Arduino DigitalWrite().
  23. */
  24. void PortWrite_PCA9655E::write(const uint8_t pin, const bool value)
  25. {
  26. if (value == LOW) //if active low
  27. {
  28. port.outputVal &= ~pin; //set pin output to low
  29. }
  30. else //if active high
  31. {
  32. port.outputVal |= pin; //set pin output to high
  33. }
  34. Wire.beginTransmission(port.DEVICE_ADDR);
  35. Wire.write(outputByteCommand);
  36. Wire.write(port.outputVal);
  37. Wire.endTransmission();
  38. }