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.cpp 984B

123456789101112131415161718192021222324252627
  1. #include "PortRead_MCP23S17.h"
  2. /* begin() is called from Scanner_IOE::begin().
  3. Configures read pins to input with pullup enabled.
  4. */
  5. void PortRead_MCP23S17::begin(const uint8_t strobeOn)
  6. {
  7. if (strobeOn == LOW) //if active low, use internal pull-up resistors
  8. {
  9. pullUp = readPins;
  10. }
  11. else //active high requires external pull-down resistors
  12. {
  13. pullUp = 0;
  14. }
  15. transfer(port.DEVICE_ADDR << 1, port.num, readPins); //write, configure IODIR, 0=output, 1=input
  16. transfer(port.DEVICE_ADDR << 1, port.num + 0x0C, pullUp); //write, configure GPPU,
  17. //0=pull-up disabled, 1=pull-up enabled
  18. }
  19. /* read() returns portState. Only portState pins with pull resistors are valid.
  20. */
  21. uint8_t PortRead_MCP23S17::read()
  22. {
  23. return transfer( (port.DEVICE_ADDR << 1) | 1, port.num + 0x12, 0); //read from GPIO
  24. }