RBControl
Library for the RB3201-RBControl board with the ESP32 by RoboticsBrno.
Adafruit_MCP23017.h
Go to the documentation of this file.
1 /***************************************************
2  This is a library for the MCP23017 i2c port expander
3 
4  These displays use I2C to communicate, 2 pins are required to
5  interface
6  Adafruit invests time and resources providing this open source code,
7  please support Adafruit and open-source hardware by purchasing
8  products from Adafruit!
9 
10  Written by Limor Fried/Ladyada for Adafruit Industries.
11  BSD license, all text above must be included in any redistribution
12  ****************************************************/
13 
14 #ifndef _Adafruit_MCP23017_H_
15 #define _Adafruit_MCP23017_H_
16 
17 #include <driver/i2c.h>
18 #include <mutex>
19 #include <stdint.h>
20 
25 public:
26  Adafruit_MCP23017(uint8_t addr, i2c_port_t port, gpio_num_t sda, gpio_num_t scl);
28 
29  void pinMode(uint8_t p, uint8_t d);
30  void digitalWrite(uint8_t p, uint8_t d);
31  void pullUp(uint8_t p, uint8_t d);
32  uint8_t digitalRead(uint8_t p);
33 
34  void writeGPIOAB(uint16_t);
35  uint16_t readGPIOAB();
36  uint8_t readGPIO(uint8_t b);
37 
38  void setupInterrupts(uint8_t mirroring, uint8_t open, uint8_t polarity);
39  uint8_t getLastInterruptPin();
40  uint8_t getLastInterruptPinValue();
41 
42 private:
43  uint8_t bitForPin(uint8_t pin);
44  uint8_t regForPin(uint8_t pin, uint8_t portAaddr, uint8_t portBaddr);
45 
46  uint8_t readRegister(uint8_t addr);
47  void writeRegister(uint8_t addr, uint8_t value);
48 
53  void updateRegisterBit(uint8_t p, uint8_t pValue, uint8_t portAaddr, uint8_t portBaddr);
54 
55  uint8_t m_i2caddr;
56  i2c_port_t m_port;
57  gpio_num_t m_sda;
58  gpio_num_t m_scl;
59 
60  std::mutex m_mutex;
61 };
62 
63 #endif
Controls the expander pins.
Definition: Adafruit_MCP23017.h:24
uint8_t getLastInterruptPin()
Definition: Adafruit_MCP23017.cpp:299
uint8_t digitalRead(uint8_t p)
Definition: Adafruit_MCP23017.cpp:264
uint16_t readGPIOAB()
Definition: Adafruit_MCP23017.cpp:164
Adafruit_MCP23017(uint8_t addr, i2c_port_t port, gpio_num_t sda, gpio_num_t scl)
Definition: Adafruit_MCP23017.cpp:131
uint8_t readGPIO(uint8_t b)
Definition: Adafruit_MCP23017.cpp:198
void writeGPIOAB(uint16_t)
Definition: Adafruit_MCP23017.cpp:228
void digitalWrite(uint8_t p, uint8_t d)
Definition: Adafruit_MCP23017.cpp:242
void pinMode(uint8_t p, uint8_t d)
Definition: Adafruit_MCP23017.cpp:157
void pullUp(uint8_t p, uint8_t d)
Definition: Adafruit_MCP23017.cpp:260
~Adafruit_MCP23017()
Definition: Adafruit_MCP23017.cpp:151
uint8_t getLastInterruptPinValue()
Definition: Adafruit_MCP23017.cpp:318
void setupInterrupts(uint8_t mirroring, uint8_t open, uint8_t polarity)
Definition: Adafruit_MCP23017.cpp:281