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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef PORTWRITE_MCP23S17_H
  2. #define PORTWRITE_MCP23S17_H
  3. #include <Arduino.h>
  4. #include <inttypes.h>
  5. #include <SPI.h>
  6. #include <PortWriteInterface.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. WARNING: This class hardcodes Slave Select to Arduino Pin 10 to avoid the speed penalty of digitalWrite
  29. */
  30. class PortWrite_MCP23S17 : public PortWriteInterface
  31. {
  32. private:
  33. PortIOE& port;
  34. void writePort(const uint8_t registerAddr, const uint8_t data);
  35. public:
  36. PortWrite_MCP23S17(PortIOE& port) : port(port) {}
  37. void begin();
  38. virtual void write(const uint8_t pin, const bool pinLogicLevel);
  39. };
  40. #endif