Skip to content

Added MCP23018 class with support for Pullup on Output #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/Adafruit_MCP23X18.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*!
* @file Adafruit_MCP23X18.cpp
*/

#include "Adafruit_MCP23X18.h"

/**************************************************************************/
/*!
@brief default ctor.
*/
/**************************************************************************/
Adafruit_MCP23X18::Adafruit_MCP23X18() { pinCount = 16; }

/**************************************************************************/
/*!
@brief Configures the specified pin to behave either as an input or an
output.
@param pin the Arduino pin number to set the mode of
@param mode INPUT, OUTPUT, or INPUT_PULLUP
*/
/**************************************************************************/
void Adafruit_MCP23X18::pinMode(uint8_t pin, uint8_t mode) {
Adafruit_BusIO_Register IODIR(i2c_dev, spi_dev, MCP23XXX_SPIREG,
getRegister(MCP23XXX_IODIR, MCP_PORT(pin)));
Adafruit_BusIO_Register GPPU(i2c_dev, spi_dev, MCP23XXX_SPIREG,
getRegister(MCP23XXX_GPPU, MCP_PORT(pin)));
Adafruit_BusIO_RegisterBits dir_bit(&IODIR, 1, pin % 8);
Adafruit_BusIO_RegisterBits pullup_bit(&GPPU, 1, pin % 8);

dir_bit.write((mode == OUTPUT) ? 0 : 1);
pullup_bit.write((mode == INPUT_PULLUP || mode == OUTPUT_PULLUP) ? 1 : 0);
}
24 changes: 24 additions & 0 deletions src/Adafruit_MCP23X18.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*!
* @file Adafruit_MCP23X18.h
*/

#ifndef __ADAFRUIT_MCP23X18_H__
#define __ADAFRUIT_MCP23X18_H__

#include "Adafruit_MCP23X17.h"

#define OUTPUT_PULLUP 4 //!< Additional define for Output with Pullup

/**************************************************************************/
/*!
@brief Class for MCP23018 I2C and MCP23S18 SPI variants.
*/
/**************************************************************************/
class Adafruit_MCP23X18 : public Adafruit_MCP23X17 {
public:
Adafruit_MCP23X18();

void pinMode(uint8_t pin, uint8_t mode);
};

#endif