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 1.2KB

123456789101112131415161718192021222324252627282930313233343536
  1. #include "PortRead_MCP23S17.h"
  2. /* begin() is called from Scanner_IOE::begin().
  3. Configures port to to read (input with pullup enabled).
  4. */
  5. void PortRead_MCP23S17::begin(const uint8_t strobeOn)
  6. {
  7. if (strobeOn == LOW) //if active low
  8. {
  9. pullUp = readPins;
  10. }
  11. else
  12. {
  13. pullUp = 0;
  14. }
  15. push(port.DEVICE_ADDR << 1, port.num, readPins); //write, configure IODIR, 0=output, 1=input
  16. push(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.
  20. Only portState bits of readPins are valid.
  21. */
  22. uint8_t PortRead_MCP23S17::read()
  23. {
  24. uint8_t portState; //bit wise
  25. digitalWrite(SS, LOW); //enable Slave Select
  26. SPI.transfer( (port.DEVICE_ADDR << 1) | 1); //read command
  27. SPI.transfer(port.num + 0x12); //GPIO register address to read data from
  28. portState = SPI.transfer(0); //save the data (0 is dummy data to send)
  29. digitalWrite(SS, HIGH); //disable Slave Select
  30. return portState;
  31. }