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_MCP23018.h 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef COLPORT_MCP23018_H
  2. #define COLPORT_MCP23018_H
  3. #include <Arduino.h>
  4. #include <inttypes.h>
  5. #include <Wire.h>
  6. #include <ColPort.h>
  7. #include "IOExpanderPort.h"
  8. /* One MCP23018 I/O expander port connected to matrix columns.
  9. Instantiation
  10. ------------
  11. colPins parameter is port's bitwise pin configuration
  12. 1=configure as input (for read)
  13. 0=configure as output (for LED or not connected to a column)
  14. example instantiation for column port A, with pins 2 and 3 connected to columnss:
  15. IOExpanderPort portA(0, ~0);
  16. ColPort_MCP23018 colPortA(portA, 1<<2 | 1<<3 );
  17. example instantiation for column port B, with pins 2 and 3 connected to columns:
  18. IOExpanderPort portB(1, ~0);
  19. ColPort_MCP23018 colPortB(portB, 1<<2 | 1<<3 );
  20. colPins are read from pin 0 on up.
  21. Diode orientation
  22. ----------------
  23. Rows, columns, and diode orientation are explained in Matrix.h
  24. */
  25. class ColPort_MCP23018 : public ColPort
  26. {
  27. private:
  28. IOExpanderPort& port;
  29. const uint8_t IODIR; //Input/Ouput Direction register
  30. const uint8_t GPIO; //General Purpose Input/Ouput register
  31. const uint8_t GPPU; //General Purpose Pullup register
  32. public:
  33. //The constructor initialization list is in .cpp
  34. ColPort_MCP23018(IOExpanderPort& port, const uint8_t colPins);
  35. void begin();
  36. //read port and store result in portState
  37. virtual void read();
  38. };
  39. #endif