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_MCP23S17.h 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef PORTWRITE_MCP23S17_H
  2. #define PORTWRITE_MCP23S17_H
  3. #include <Arduino.h>
  4. #include <inttypes.h>
  5. #include <SPI.h>
  6. #include <PortWrite.h>
  7. #include "PortIOE.h"
  8. /* One MCP23S17 I/O expander port connected to matrix rows.
  9. MCP23S17 does not have internal pull-up resistors (PCA9535E does).
  10. begin() configures column port's configuration and output.
  11. This should normally be called once in sketch's setup().
  12. If PortRead_MCP23S17 is instantiated on the same port, do NOT use PortWrite_MCP23S17::begin().
  13. Otherwise readPins could be overwritten.
  14. Instantiation
  15. ------------
  16. Example instantiation for row port 0:
  17. PortIOE port0(0, 0);
  18. PortWrite_MCP23S17 rowPort0(port0);
  19. Example instantiation for row port 1:
  20. PortIOE port1(1, 0);
  21. PortWrite_MCP23S17 rowPort1(port1);
  22. Diode orientation
  23. ----------------
  24. Diode orientation is explained in keybrd_library_user_guide.md > Diode orientation
  25. MCP23S17 data sheet
  26. ----------------
  27. http://www.onsemi.com/pub_link/Collateral/MCP23S17-D.PDF
  28. */
  29. class PortWrite_MCP23S17 : public PortWrite
  30. {
  31. private:
  32. PortIOE& port;
  33. void writePort(const uint8_t registerAddr, const uint8_t data);
  34. public:
  35. PortWrite_MCP23S17(PortIOE& port) : port(port) {}
  36. void begin();
  37. virtual void write(const uint8_t pin, const bool level);
  38. };
  39. #endif