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.

IOExpanderPort.h 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef IOEXPANDERPORT_H
  2. #define IOEXPANDERPORT_H
  3. #include <inttypes.h>
  4. /* The pins of an IC's port can be split between RowPort, ColPort, and LED.
  5. IOExpanderPort contains outputVal, the value of a port's output register.
  6. outputVal is used for port manipulation by classes RowPort and LED.
  7. One port's outputVal can be shared by one RowPort object and multiple LED objects.
  8. IOExpanderPort is only used by I/O expander port classes.
  9. AVR port classes do not need a similar class because PORTx is global in the Arduino library.
  10. Instantiation
  11. ------------
  12. Example IOExpanderPort::ADDR initilization:
  13. const uint8_t IOExpanderPort::ADDR = 0x18;
  14. Be careful with the ADDR.
  15. Table 6 in PCA9655E datasheet lists 8-bit versions of I2C addresses.
  16. The Arduino Wire library uses 7-bit addresses throughout, so drop the low bit.
  17. For example, I2C address with AD2=GND AD1=SCL AD0=SCL,
  18. Table 6 lists 8-bit ADDR = 0x30 (b 00110000)
  19. while Arduino uses 7-bit ADDR = 0x18 (b 00011000)
  20. http://playground.arduino.cc/Main/WireLibraryDetailedReference
  21. The PCA9655E data sheet is on http://www.onsemi.com/pub_link/Collateral/PCA9655E-D.PDF
  22. portNumber: If the I/O expander uses port letters, use 0 instead of A, use 1 instead of B.
  23. outputVal: For pins that are connected to active low rows, set outputVal bit to 1.
  24. Set all other outputVal bits to 0.
  25. Example instantiation for port0 with active low rows on all pins:
  26. IOExpanderPort port0(0, ~0);
  27. Example instantiation for portA with active low rows on pins 0,1,2:
  28. IOExpanderPort portA(0, 1<<0 | 1<<1 | 1<<2 );
  29. Example instantiation for portB with active high rows on pins 0,1,2:
  30. IOExpanderPort portB(1, 0);
  31. */
  32. struct IOExpanderPort
  33. {
  34. static const uint8_t ADDR; //I2C address
  35. const uint8_t num; //port number
  36. uint8_t outputVal; //bitwise value of output register
  37. IOExpanderPort(const uint8_t portNumber, uint8_t outputVal)
  38. : num(portNumber), outputVal(outputVal) {}
  39. };
  40. #endif