Dilbert
Firmware for the Dilbert interactive badge.
 All Classes Files Functions Variables Enumerations Macros Pages
Adafruit_MCP23017.h
Go to the documentation of this file.
1 
3 /***************************************************
4  This is a library for the MCP23017 i2c port expander
5 
6  These displays use I2C to communicate, 2 pins are required to
7  interface
8  Adafruit invests time and resources providing this open source code,
9  please support Adafruit and open-source hardware by purchasing
10  products from Adafruit!
11 
12  Written by Limor Fried/Ladyada for Adafruit Industries.
13  BSD license, all text above must be included in any redistribution
14  ****************************************************/
15 
16 #ifndef _Adafruit_MCP23017_H_
17 #define _Adafruit_MCP23017_H_
18 
19 // Don't forget the Wire library
21 public:
22  void begin(uint8_t addr);
23  void begin(void);
24 
25  void pinMode(uint8_t p, uint8_t d);
26  void digitalWrite(uint8_t p, uint8_t d);
27  void pullUp(uint8_t p, uint8_t d);
28  uint8_t digitalRead(uint8_t p);
29 
30  void writeGPIOAB(uint16_t);
31  uint16_t readGPIOAB();
32  uint8_t readGPIO(uint8_t b);
33 
34  void setupInterrupts(uint8_t mirroring, uint8_t open, uint8_t polarity);
35  void setupInterruptPin(uint8_t p, uint8_t mode);
36  uint8_t getLastInterruptPin();
37  uint8_t getLastInterruptPinValue();
38 
39  private:
40  uint8_t i2caddr;
41 
42  uint8_t bitForPin(uint8_t pin);
43  uint8_t regForPin(uint8_t pin, uint8_t portAaddr, uint8_t portBaddr);
44 
45  uint8_t readRegister(uint8_t addr);
46  void writeRegister(uint8_t addr, uint8_t value);
47 
52  void updateRegisterBit(uint8_t p, uint8_t pValue, uint8_t portAaddr, uint8_t portBaddr);
53 
54 };
55 
56 #define MCP23017_ADDRESS 0x20
57 
58 // registers
59 #define MCP23017_IODIRA 0x00
60 #define MCP23017_IPOLA 0x02
61 #define MCP23017_GPINTENA 0x04
62 #define MCP23017_DEFVALA 0x06
63 #define MCP23017_INTCONA 0x08
64 #define MCP23017_IOCONA 0x0A
65 #define MCP23017_GPPUA 0x0C
66 #define MCP23017_INTFA 0x0E
67 #define MCP23017_INTCAPA 0x10
68 #define MCP23017_GPIOA 0x12
69 #define MCP23017_OLATA 0x14
70 
71 
72 #define MCP23017_IODIRB 0x01
73 #define MCP23017_IPOLB 0x03
74 #define MCP23017_GPINTENB 0x05
75 #define MCP23017_DEFVALB 0x07
76 #define MCP23017_INTCONB 0x09
77 #define MCP23017_IOCONB 0x0B
78 #define MCP23017_GPPUB 0x0D
79 #define MCP23017_INTFB 0x0F
80 #define MCP23017_INTCAPB 0x11
81 #define MCP23017_GPIOB 0x13
82 #define MCP23017_OLATB 0x15
83 
84 #define MCP23017_INT_ERR 255
85 
86 #endif
uint8_t readGPIO(uint8_t b)
Definition: Adafruit_MCP23017.cpp:162
void setupInterrupts(uint8_t mirroring, uint8_t open, uint8_t polarity)
Definition: Adafruit_MCP23017.cpp:224
void setupInterruptPin(uint8_t p, uint8_t mode)
Definition: Adafruit_MCP23017.cpp:247
Definition: Adafruit_MCP23017.h:20
void writeGPIOAB(uint16_t)
Definition: Adafruit_MCP23017.cpp:180
void begin(void)
Definition: Adafruit_MCP23017.cpp:126
uint16_t readGPIOAB()
Definition: Adafruit_MCP23017.cpp:140
void pinMode(uint8_t p, uint8_t d)
Definition: Adafruit_MCP23017.cpp:133