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

MCP23017 main class [詳解]

#include <Adafruit_MCP23017.h>

公開メンバ関数

void begin (uint8_t addr)
 
void begin (void)
 
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)

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

引数
addrSelected address

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

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

◆ begin() [2/2]

void Adafruit_MCP23017::begin ( void  )

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

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

135 { begin(0); }

◆ digitalRead()

uint8_t Adafruit_MCP23017::digitalRead ( uint8_t  pin)

Reads the specified pin

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

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

235  {
236  uint8_t bit = bitForPin(pin);
237  uint8_t regAddr = regForPin(pin, MCP23017_GPIOA, MCP23017_GPIOB);
238  return (readRegister(regAddr) >> bit) & 0x1;
239 }
#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.cpp205 行目に定義があります。

205  {
206  uint8_t gpio;
207  uint8_t bit = bitForPin(pin);
208 
209  // read the current GPIO output latches
210  uint8_t regAddr = regForPin(pin, MCP23017_OLATA, MCP23017_OLATB);
211  gpio = readRegister(regAddr);
212 
213  // set the pin and direction
214  bitWrite(gpio, bit, d);
215 
216  // write the new GPIO
217  regAddr = regForPin(pin, MCP23017_GPIOA, MCP23017_GPIOB);
218  writeRegister(regAddr, gpio);
219 }
#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.cpp299 行目に定義があります。

299  {
300  uint8_t intf;
301 
302  // try port A
303  intf = readRegister(MCP23017_INTFA);
304  for (int i = 0; i < 8; i++)
305  if (bitRead(intf, i))
306  return i;
307 
308  // try port B
309  intf = readRegister(MCP23017_INTFB);
310  for (int i = 0; i < 8; i++)
311  if (bitRead(intf, i))
312  return i + 8;
313 
314  return MCP23017_INT_ERR;
315 }
#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.cpp320 行目に定義があります。

320  {
321  uint8_t intPin = getLastInterruptPin();
322  if (intPin != MCP23017_INT_ERR) {
323  uint8_t intcapreg = regForPin(intPin, MCP23017_INTCAPA, MCP23017_INTCAPB);
324  uint8_t bit = bitForPin(intPin);
325  return (readRegister(intcapreg) >> bit) & (0x01);
326  }
327 
328  return MCP23017_INT_ERR;
329 }
#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.cpp142 行目に定義があります。

142  {
143  updateRegisterBit(p, (d == INPUT), MCP23017_IODIRA, MCP23017_IODIRB);
144 }
#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.cpp226 行目に定義があります。

226  {
227  updateRegisterBit(p, d, MCP23017_GPPUA, MCP23017_GPPUB);
228 }
#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.cpp173 行目に定義があります。

173  {
174 
175  // read the current GPIO output latches
176  Wire.beginTransmission(MCP23017_ADDRESS | i2caddr);
177  if (b == 0)
178  wiresend(MCP23017_GPIOA);
179  else {
180  wiresend(MCP23017_GPIOB);
181  }
182  Wire.endTransmission();
183 
184  Wire.requestFrom(MCP23017_ADDRESS | i2caddr, 1);
185  return wirerecv();
186 }
#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.cpp150 行目に定義があります。

150  {
151  uint16_t ba = 0;
152  uint8_t a;
153 
154  // read the current GPIO output latches
155  Wire.beginTransmission(MCP23017_ADDRESS | i2caddr);
156  wiresend(MCP23017_GPIOA);
157  Wire.endTransmission();
158 
159  Wire.requestFrom(MCP23017_ADDRESS | i2caddr, 2);
160  a = wirerecv();
161  ba = wirerecv();
162  ba <<= 8;
163  ba |= a;
164 
165  return ba;
166 }
#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.cpp278 行目に定義があります。

278  {
279 
280  // set the pin interrupt control (0 means change, 1 means compare against
281  // given value);
282  updateRegisterBit(pin, (mode != CHANGE), MCP23017_INTCONA, MCP23017_INTCONB);
283  // if the mode is not CHANGE, we need to set up a default value, different
284  // value triggers interrupt
285 
286  // In a RISING interrupt the default value is 0, interrupt is triggered when
287  // the pin goes to 1. In a FALLING interrupt the default value is 1, interrupt
288  // is triggered when pin goes to 0.
289  updateRegisterBit(pin, (mode == FALLING), MCP23017_DEFVALA, MCP23017_DEFVALB);
290 
291  // enable the pin for interrupt
292  updateRegisterBit(pin, HIGH, MCP23017_GPINTENA, MCP23017_GPINTENB);
293 }
#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.cpp251 行目に定義があります。

252  {
253  // configure the port A
254  uint8_t ioconfValue = readRegister(MCP23017_IOCONA);
255  bitWrite(ioconfValue, 6, mirroring);
256  bitWrite(ioconfValue, 2, openDrain);
257  bitWrite(ioconfValue, 1, polarity);
258  writeRegister(MCP23017_IOCONA, ioconfValue);
259 
260  // Configure the port B
261  ioconfValue = readRegister(MCP23017_IOCONB);
262  bitWrite(ioconfValue, 6, mirroring);
263  bitWrite(ioconfValue, 2, openDrain);
264  bitWrite(ioconfValue, 1, polarity);
265  writeRegister(MCP23017_IOCONB, ioconfValue);
266 }
#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.cpp192 行目に定義があります。

192  {
193  Wire.beginTransmission(MCP23017_ADDRESS | i2caddr);
194  wiresend(MCP23017_GPIOA);
195  wiresend(ba & 0xFF);
196  wiresend(ba >> 8);
197  Wire.endTransmission();
198 }
#define MCP23017_ADDRESS
MCP23017 Address
#define MCP23017_GPIOA
General purpose I/O port register A

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