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.

Port_MCP23017.h 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef PORT_MCP23017_H
  2. #define PORT_MCP23017_H
  3. #include <Arduino.h>
  4. #include <inttypes.h>
  5. #include <Wire.h>
  6. #include "PortInterface.h"
  7. /* Port_MCP23017
  8. write pins are connected to matrix Row (strobe pin) or LED.
  9. readPins are connected to matrix column to read which keys are pressed.
  10. Instantiation
  11. ------------
  12. Example instantiation:
  13. const uint8_t IOE_ADDR = 0x20; //all three MCP23017 ADDR pins pins grounded
  14. Port_MCP23017 portB(IOE_ADDR, 1, 0); //all pins are set to output for strobes and LEDs
  15. Port_MCP23017 portA(IOE_ADDR, 0, 1<<0 | 1<<1 ); //pin 0 and pin 1 are set to input for reading,
  16. //remaining pins can be used for LEDs
  17. Diode orientation
  18. ----------------
  19. Diode orientation is explained in keybrd_library_user_guide.md > Diode orientation
  20. */
  21. class Port_MCP23017 : public PortInterface
  22. {
  23. private:
  24. const uint8_t deviceAddr;
  25. const uint8_t portNum; //port identification number, 0=A, 1=B
  26. uint8_t outputVal; //bit pattern for strobe and LEDs
  27. const uint8_t readPins; //bit pattern, IODIR 0=output, 1=input
  28. public:
  29. Port_MCP23017(const uint8_t deviceAddr, const uint8_t portNum, const uint8_t readPins)
  30. : deviceAddr(deviceAddr), portNum(portNum), outputVal(0), readPins(readPins) {}
  31. void beginProtocol();
  32. void begin(const uint8_t activeState);
  33. virtual void writeLow(const uint8_t pin);
  34. virtual void writeHigh(const uint8_t pin);
  35. virtual uint8_t read();
  36. };
  37. #endif