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.

PortRead_MCP23S17.h 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef PORTREAD_MCP23S17_H
  2. #define PORTREAD_MCP23S17_H
  3. #include <Arduino.h>
  4. #include <inttypes.h>
  5. #include <SPI.h>
  6. #include <PortReadInterface.h>
  7. #include "PortMCP23S17.h"
  8. #include "PortIOE.h"
  9. #include "Scanner_IOE.h"
  10. /* One MCP23S17 I/O expander port connected to matrix columns.
  11. This class has Slave Select hardcoded to Arduino Pin 10.
  12. Arduino Pin 10 avoids the speed penalty of digitalWrite.
  13. Instantiation
  14. ------------
  15. readPins parameter is port's bit pattern pin configuration
  16. 1=configure as input (for read pins connected to column)
  17. 0=configure as output (for LED or not connected to a column)
  18. readPins are read from pin 0 on up.
  19. Example instantiation with port-A pins 0 and 1 connected to Scanner_IOE columns:
  20. const uint8_t PortIOE::DEVICE_ADDR = 0x20; //MCP23S17 address, all 3 ADDR pins are grounded
  21. PortIOE port_A(0);
  22. PortRead_MCP23S17 portRead_A(port_A, 1<<0 | 1<<1 );
  23. Diode orientation
  24. ----------------
  25. Diode orientation is explained in keybrd_library_user_guide.md > Diode orientation
  26. MCP23S17 data sheet
  27. ------------------
  28. http://www.onsemi.com/pub_link/Collateral/MCP23S17-D.PDF
  29. */
  30. class PortRead_MCP23S17 : public PortReadInterface, public PortMCP23S17
  31. {
  32. private:
  33. PortIOE& port;
  34. uint8_t pullUp; //bits, 1 means internal pull-up resistor enabled
  35. const uint8_t readPins; //bits, 1 means internal pull-up resistor enabled
  36. public:
  37. PortRead_MCP23S17(PortIOE& port, const uint8_t readPins)
  38. : port(port), readPins(readPins) {}
  39. void begin(const uint8_t strobeOn);
  40. virtual uint8_t read();
  41. };
  42. #endif