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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 "PortIOE.h"
  8. #include "Scanner_IOE.h"
  9. /* One MCP23S17 I/O expander port connected to matrix columns.
  10. This class has Slave Select hardcoded to Arduino Pin 10.
  11. Arduino Pin 10 avoids the speed penalty of digitalWrite.
  12. Instantiation
  13. ------------
  14. readPins parameter is port's bitwise pin configuration
  15. 1=configure as input (for pins connected to column)
  16. 0=configure as output (for LED or not connected to a column)
  17. readPins are read from pin 0 on up.
  18. Example instantiation with port-A pins 0 and 1 connected to Scanner_IOE columns:
  19. const uint8_t PortIOE::DEVICE_ADDR = 0x20; //MCP23S17 address, all 3 ADDR pins are grounded
  20. PortIOE port_A(0);
  21. PortRead_MCP23S17 portRead_A(port_A, 1<<0 | 1<<1 );
  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 PortRead_MCP23S17 : public PortReadInterface
  30. {
  31. private:
  32. PortIOE& port;
  33. uint8_t pullUp; //bitwise, 1 means internal pull-up resistor enabled
  34. const uint8_t readPins; //bitwise, 1 means internal pull-up resistor enabled
  35. public:
  36. PortRead_MCP23S17(PortIOE& port, const uint8_t readPins)
  37. : port(port), readPins(readPins) {}
  38. void begin(const uint8_t strobeOn);
  39. virtual uint8_t read();
  40. };
  41. #endif