32#include "driver/spi_master.h"
51#define MCP_SPI_FREQ 10000000
52#define MCP_DMACHANNEL 2
55#define MCP_MAXDEVICES 2
84#define MCP_GPINTEN 0x04
85#define MCP_DEFVAL 0x06
86#define MCP_INTCON 0x08
90#define MCP_INTCAP 0x10
96#define MCP_BNK1_IODIR 0x00
97#define MCP_BNK1_IPOL 0x01
98#define MCP_BNK1_GPINTEN 0x02
99#define MCP_BNK1_DEFVAL 0x03
100#define MCP_BNK1_INTCON 0x04
101#define MCP_BNK1_IOCON 0x05
102#define MCP_BNK1_GPPU 0x06
103#define MCP_BNK1_INTF 0x07
104#define MCP_BNK1_INTCAP 0x08
105#define MCP_BNK1_GPIO 0x09
106#define MCP_BNK1_OLAT 0x0A
110#define MCP_IOCON_BANK 0x80
111#define MCP_IOCON_MIRROR 0x40
112#define MCP_IOCON_SEQOP 0x20
113#define MCP_IOCON_DISSLW 0x10
114#define MCP_IOCON_HAEN 0x08
115#define MCP_IOCON_ODR 0x04
116#define MCP_IOCON_INTPOL 0x02
119#define MCP_GPIO2REG(basereg, gpio) ((basereg) + ((gpio) >> 3))
120#define MCP_GPIO2MASK(gpio) (1 << ((gpio) & 7))
176 bool begin(
int MISO = -1,
int MOSI = -1,
int CLK = -1,
int CS = -1,
int CSActiveState = -1,
int host = HSPI_HOST);
230 void writeReg(uint8_t addr, uint8_t value, uint8_t hwAddr = 0);
240 uint8_t
readReg(uint8_t addr, uint8_t hwAddr = 0);
249 void writeReg16(uint8_t addr, uint16_t value, uint8_t hwAddr = 0);
259 uint16_t
readReg16(uint8_t addr, uint8_t hwAddr = 0);
314 void setPortDir(
int port, uint8_t value, uint8_t hwAddr = 0) {
writeReg(MCP_IODIR + port, value, hwAddr); }
371 void writePort(
int port, uint8_t value, uint8_t hwAddr = 0) {
writeReg(MCP_OLAT + port, value, hwAddr); }
386 uint8_t
readPort(
int port, uint8_t hwAddr = 0) {
return readReg(MCP_GPIO + port, hwAddr); }
445 void writeGPIO(
int gpio,
bool value, uint8_t hwAddr = 0);
459 bool readGPIO(
int gpio, uint8_t hwAddr = 0);
541 void writePort(
int port,
void const * buffer,
size_t length, uint8_t hwAddr = 0);
557 void readPort(
int port,
void * buffer,
size_t length, uint8_t hwAddr = 0);
562 bool SPIBegin(
int CSActiveState);
569 spi_host_device_t m_SPIHost;
571 spi_device_handle_t m_SPIDevHandle;
574 uint8_t m_IOCON[MCP_MAXDEVICES];
void configureGPIO(int gpio, MCPDir dir, bool pullup=false, uint8_t hwAddr=0)
Configure a pin direction and pullup.
void setPortInputPolarity(int port, uint8_t value, uint8_t hwAddr=0)
Sets input polarity.
void writeGPIO(int gpio, bool value, uint8_t hwAddr=0)
Sets output status of a pin.
void writePort(int port, uint8_t value, uint8_t hwAddr=0)
Sets status of output pins of specified port.
void enableINTMirroring(bool value, uint8_t hwAddr=0)
Enables/disables INTs pins mirroring.
void setPortDir(int port, uint8_t value, uint8_t hwAddr=0)
Sets port direction.
void writeReg16(uint8_t addr, uint16_t value, uint8_t hwAddr=0)
Writes 16 bit value to two consecutive registers.
uint8_t getPortIntFlags(int port, uint8_t hwAddr=0)
Reads interrupt flags for the specified port.
bool available()
Determines MCP23S17 availability.
uint8_t getPortIntCaptured(int port, uint8_t hwAddr=0)
Reads status of input port when last interrupt has been triggered.
void writePort16(uint16_t value, uint8_t hwAddr=0)
Sets status of output pins of combined port A and B.
uint16_t readPort16(uint8_t hwAddr=0)
Gets status of input pins of combined port A and B.
uint16_t readReg16(uint8_t addr, uint8_t hwAddr=0)
Reads 16 bit value from two consecutive registers.
void writeReg(uint8_t addr, uint8_t value, uint8_t hwAddr=0)
Writes 8 bit value to an internal register.
bool initDevice(uint8_t hwAddr)
Initializes additional MCP23S17 devices connected to the same SPI bus but with a different hardware a...
void setINTActiveHigh(bool value, uint8_t hwAddr=0)
Sets the polarity of the INT pins.
bool getINTActiveHigh(uint8_t hwAddr=0)
Gets the polarity of the INT pins.
void end()
Deinitializes MCP23S17 driver.
bool begin(int MISO=-1, int MOSI=-1, int CLK=-1, int CS=-1, int CSActiveState=-1, int host=HSPI_HOST)
Initializes MCP23S17 driver.
void enableINTOpenDrain(bool value, uint8_t hwAddr=0)
Enables/disables the INT pin open-drain.
uint8_t getPortDir(int port, uint8_t hwAddr=0)
Gets port direction.
uint8_t getPortPullUp(int port, uint8_t hwAddr=0)
Gets port pull-ups.
void enableInterrupt(int gpio, MCPIntTrigger trigger, bool defaultValue=false, uint8_t hwAddr=0)
Enables interrupt on the specific pin.
void enablePortPullUp(int port, uint8_t value, uint8_t hwAddr=0)
Enables/disables port pull-ups.
uint8_t readReg(uint8_t addr, uint8_t hwAddr=0)
Reads 8 bit value from an internal register.
uint8_t readPort(int port, uint8_t hwAddr=0)
Gets status of input pins of specified port.
void disableInterrupt(int gpio, uint8_t hwAddr=0)
Disables any interrupt on the specified pin.
bool readGPIO(int gpio, uint8_t hwAddr=0)
Reads input status of a pin.
This file contains some utility classes and functions.
MCPDir
Represents GPIO directioon.
MCPIntTrigger
Represents interrupt trigger mode.