AdafruitMCP23017ArduinoLibrary  1.2.0
公開メンバ関数 | 全メンバ一覧
Adafruit_MCP23017 クラス

MCP23017 main class [詳解]

#include <Adafruit_MCP23017.h>

公開メンバ関数

void begin (uint8_t addr, TwoWire *theWire=&Wire)
 
void begin (TwoWire *theWire=&Wire)
 
void pinMode (uint8_t p, uint8_t d)
 
void digitalWrite (uint8_t p, uint8_t d)
 Writes to a pin on the MCP23017 [詳解]
 
void pullUp (uint8_t p, uint8_t d)
 Enables the pull-up resistor on the specified pin [詳解]
 
uint8_t digitalRead (uint8_t p)
 Reads the specified pin [詳解]
 
void writeGPIOAB (uint16_t)
 
uint16_t readGPIOAB ()
 
uint8_t readGPIO (uint8_t b)
 
void setupInterrupts (uint8_t mirroring, uint8_t open, uint8_t polarity)
 
void setupInterruptPin (uint8_t p, uint8_t mode)
 
uint8_t getLastInterruptPin ()
 Gets the last interrupt pin [詳解]
 
uint8_t getLastInterruptPinValue ()
 Gets the value of the last interrupt pin [詳解]
 

詳解

MCP23017 main class

Adafruit_MCP23017.h24 行目に定義があります。

関数詳解

◆ begin() [1/2]

void Adafruit_MCP23017::begin ( uint8_t  addr,
TwoWire *  theWire = &Wire 
)

Initializes the MCP23017 given its HW selected address, see datasheet for Address selection.

引数
addrSelected address
theWirethe I2C object to use, defaults to &Wire

Adafruit_MCP23017.cpp118 行目に定義があります。

118  {
119  if (addr > 7) {
120  addr = 7;
121  }
122  i2caddr = addr;
123  _wire = theWire;
124 
125  _wire->begin();
126 
127  // set defaults!
128  // all inputs on port A and B
129  writeRegister(MCP23017_IODIRA, 0xff);
130  writeRegister(MCP23017_IODIRB, 0xff);
131 }
#define MCP23017_IODIRB
I/O direction register B
#define MCP23017_IODIRA
I/O direction register A

◆ begin() [2/2]

void Adafruit_MCP23017::begin ( TwoWire *  theWire = &Wire)

Initializes the default MCP23017, with 000 for the configurable part of the address

引数
theWirethe I2C object to use, defaults to &Wire

Adafruit_MCP23017.cpp138 行目に定義があります。

138 { begin(0, theWire); }
void begin(uint8_t addr, TwoWire *theWire=&Wire)

◆ digitalRead()

uint8_t Adafruit_MCP23017::digitalRead ( uint8_t  pin)

Reads the specified pin

引数
pinPin to read
戻り値
Value of the pin

Adafruit_MCP23017.cpp238 行目に定義があります。

238  {
239  uint8_t bit = bitForPin(pin);
240  uint8_t regAddr = regForPin(pin, MCP23017_GPIOA, MCP23017_GPIOB);
241  return (readRegister(regAddr) >> bit) & 0x1;
242 }
#define MCP23017_GPIOA
General purpose I/O port register A
#define MCP23017_GPIOB
General purpose I/O port register B

◆ digitalWrite()

void Adafruit_MCP23017::digitalWrite ( uint8_t  pin,
uint8_t  d 
)

Writes to a pin on the MCP23017

引数
pinPin to write to
dWhat to write to the pin

Adafruit_MCP23017.cpp208 行目に定義があります。

208  {
209  uint8_t gpio;
210  uint8_t bit = bitForPin(pin);
211 
212  // read the current GPIO output latches
213  uint8_t regAddr = regForPin(pin, MCP23017_OLATA, MCP23017_OLATB);
214  gpio = readRegister(regAddr);
215 
216  // set the pin and direction
217  bitWrite(gpio, bit, d);
218 
219  // write the new GPIO
220  regAddr = regForPin(pin, MCP23017_GPIOA, MCP23017_GPIOB);
221  writeRegister(regAddr, gpio);
222 }
#define MCP23017_GPIOA
General purpose I/O port register A
#define MCP23017_OLATB
Output latch register 0 B
#define MCP23017_OLATA
Output latch register 0 A
#define MCP23017_GPIOB
General purpose I/O port register B

◆ getLastInterruptPin()

uint8_t Adafruit_MCP23017::getLastInterruptPin ( )

Gets the last interrupt pin

戻り値
Returns the last interrupt pin

Adafruit_MCP23017.cpp302 行目に定義があります。

302  {
303  uint8_t intf;
304 
305  // try port A
306  intf = readRegister(MCP23017_INTFA);
307  for (int i = 0; i < 8; i++)
308  if (bitRead(intf, i))
309  return i;
310 
311  // try port B
312  intf = readRegister(MCP23017_INTFB);
313  for (int i = 0; i < 8; i++)
314  if (bitRead(intf, i))
315  return i + 8;
316 
317  return MCP23017_INT_ERR;
318 }
#define MCP23017_INT_ERR
Interrupt error
#define MCP23017_INTFB
Interrupt flag register B
#define MCP23017_INTFA
Interrupt flag register A

◆ getLastInterruptPinValue()

uint8_t Adafruit_MCP23017::getLastInterruptPinValue ( )

Gets the value of the last interrupt pin

戻り値
Returns the value of the last interrupt pin

Adafruit_MCP23017.cpp323 行目に定義があります。

323  {
324  uint8_t intPin = getLastInterruptPin();
325  if (intPin != MCP23017_INT_ERR) {
326  uint8_t intcapreg = regForPin(intPin, MCP23017_INTCAPA, MCP23017_INTCAPB);
327  uint8_t bit = bitForPin(intPin);
328  return (readRegister(intcapreg) >> bit) & (0x01);
329  }
330 
331  return MCP23017_INT_ERR;
332 }
#define MCP23017_INTCAPA
Interrupt captured value for port register A
#define MCP23017_INT_ERR
Interrupt error
#define MCP23017_INTCAPB
Interrupt captured value for port register B
uint8_t getLastInterruptPin()
Gets the last interrupt pin

◆ pinMode()

void Adafruit_MCP23017::pinMode ( uint8_t  p,
uint8_t  d 
)

Sets the pin mode to either INPUT or OUTPUT

引数
pPin to set
dMode to set the pin

Adafruit_MCP23017.cpp145 行目に定義があります。

145  {
146  updateRegisterBit(p, (d == INPUT), MCP23017_IODIRA, MCP23017_IODIRB);
147 }
#define MCP23017_IODIRB
I/O direction register B
#define MCP23017_IODIRA
I/O direction register A

◆ pullUp()

void Adafruit_MCP23017::pullUp ( uint8_t  p,
uint8_t  d 
)

Enables the pull-up resistor on the specified pin

引数
pPin to set
dValue to set the pin

Adafruit_MCP23017.cpp229 行目に定義があります。

229  {
230  updateRegisterBit(p, d, MCP23017_GPPUA, MCP23017_GPPUB);
231 }
#define MCP23017_GPPUA
GPIO pull-up resistor register A
#define MCP23017_GPPUB
GPIO pull-up resistor register B

◆ readGPIO()

uint8_t Adafruit_MCP23017::readGPIO ( uint8_t  b)

Read a single port, A or B, and return its current 8 bit value.

引数
bDecided what gpio to use. Should be 0 for GPIOA, and 1 for GPIOB.
戻り値
Returns the b bit value of the port

Adafruit_MCP23017.cpp176 行目に定義があります。

176  {
177 
178  // read the current GPIO output latches
179  _wire->beginTransmission(MCP23017_ADDRESS | i2caddr);
180  if (b == 0)
181  wiresend(MCP23017_GPIOA, _wire);
182  else {
183  wiresend(MCP23017_GPIOB, _wire);
184  }
185  _wire->endTransmission();
186 
187  _wire->requestFrom(MCP23017_ADDRESS | i2caddr, 1);
188  return wirerecv(_wire);
189 }
#define MCP23017_ADDRESS
MCP23017 Address
#define MCP23017_GPIOA
General purpose I/O port register A
#define MCP23017_GPIOB
General purpose I/O port register B

◆ readGPIOAB()

uint16_t Adafruit_MCP23017::readGPIOAB ( )

Reads all 16 pins (port A and B) into a single 16 bits variable.

戻り値
Returns the 16 bit variable representing all 16 pins

Adafruit_MCP23017.cpp153 行目に定義があります。

153  {
154  uint16_t ba = 0;
155  uint8_t a;
156 
157  // read the current GPIO output latches
158  _wire->beginTransmission(MCP23017_ADDRESS | i2caddr);
159  wiresend(MCP23017_GPIOA, _wire);
160  _wire->endTransmission();
161 
162  _wire->requestFrom(MCP23017_ADDRESS | i2caddr, 2);
163  a = wirerecv(_wire);
164  ba = wirerecv(_wire);
165  ba <<= 8;
166  ba |= a;
167 
168  return ba;
169 }
#define MCP23017_ADDRESS
MCP23017 Address
#define MCP23017_GPIOA
General purpose I/O port register A

◆ setupInterruptPin()

void Adafruit_MCP23017::setupInterruptPin ( uint8_t  pin,
uint8_t  mode 
)

Set's up a pin for interrupt. uses arduino MODEs: CHANGE, FALLING, RISING.

Note that the interrupt condition finishes when you read the information about the port / value that caused the interrupt or you read the port itself. Check the datasheet can be confusing.

引数
pinPin to set
modeMode to set the pin

Adafruit_MCP23017.cpp281 行目に定義があります。

281  {
282 
283  // set the pin interrupt control (0 means change, 1 means compare against
284  // given value);
285  updateRegisterBit(pin, (mode != CHANGE), MCP23017_INTCONA, MCP23017_INTCONB);
286  // if the mode is not CHANGE, we need to set up a default value, different
287  // value triggers interrupt
288 
289  // In a RISING interrupt the default value is 0, interrupt is triggered when
290  // the pin goes to 1. In a FALLING interrupt the default value is 1, interrupt
291  // is triggered when pin goes to 0.
292  updateRegisterBit(pin, (mode == FALLING), MCP23017_DEFVALA, MCP23017_DEFVALB);
293 
294  // enable the pin for interrupt
295  updateRegisterBit(pin, HIGH, MCP23017_GPINTENA, MCP23017_GPINTENB);
296 }
#define MCP23017_GPINTENB
Interrupt-on-change pins B
#define MCP23017_DEFVALA
Default value register A
#define MCP23017_GPINTENA
Interrupt-on-change pins A
#define MCP23017_DEFVALB
Default value register B
#define MCP23017_INTCONA
Interrupt-on-change control register A
#define MCP23017_INTCONB
Interrupt-on-change control register B

◆ setupInterrupts()

void Adafruit_MCP23017::setupInterrupts ( uint8_t  mirroring,
uint8_t  openDrain,
uint8_t  polarity 
)

Configures the interrupt system. both port A and B are assigned the same configuration.

引数
mirroringMirroring will OR both INTA and INTB pins.
openDrainOpendrain will set the INT pin to value or open drain.
polaritypolarity will set LOW or HIGH on interrupt. Default values after Power On Reset are: (false, false, LOW) If you are connecting the INTA/B pin to arduino 2/3, you should configure the interupt handling as FALLING with the default configuration.

Adafruit_MCP23017.cpp254 行目に定義があります。

255  {
256  // configure the port A
257  uint8_t ioconfValue = readRegister(MCP23017_IOCONA);
258  bitWrite(ioconfValue, 6, mirroring);
259  bitWrite(ioconfValue, 2, openDrain);
260  bitWrite(ioconfValue, 1, polarity);
261  writeRegister(MCP23017_IOCONA, ioconfValue);
262 
263  // Configure the port B
264  ioconfValue = readRegister(MCP23017_IOCONB);
265  bitWrite(ioconfValue, 6, mirroring);
266  bitWrite(ioconfValue, 2, openDrain);
267  bitWrite(ioconfValue, 1, polarity);
268  writeRegister(MCP23017_IOCONB, ioconfValue);
269 }
#define MCP23017_IOCONA
I/O expander configuration register A
#define MCP23017_IOCONB
I/O expander configuration register B

◆ writeGPIOAB()

void Adafruit_MCP23017::writeGPIOAB ( uint16_t  ba)

Writes all the pins in one go. This method is very useful if you are implementing a multiplexed matrix and want to get a decent refresh rate.

Adafruit_MCP23017.cpp195 行目に定義があります。

195  {
196  _wire->beginTransmission(MCP23017_ADDRESS | i2caddr);
197  wiresend(MCP23017_GPIOA, _wire);
198  wiresend(ba & 0xFF, _wire);
199  wiresend(ba >> 8, _wire);
200  _wire->endTransmission();
201 }
#define MCP23017_ADDRESS
MCP23017 Address
#define MCP23017_GPIOA
General purpose I/O port register A

このクラス詳解は次のファイルから抽出されました: