Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Added MCP23018 class with support for OUTPUT_PULLUP in pinMode.
  • Loading branch information
totalretribution committed Mar 7, 2025
commit 831b73d342d415ff57bd4a85f6cd53b134c0123e
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);
}
25 changes: 25 additions & 0 deletions src/Adafruit_MCP23X18.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*!
* @file Adafruit_MCP23X18.h
*/

#ifndef __ADAFRUIT_MCP23X18_H__
#define __ADAFRUIT_MCP23X18_H__

#include "Adafruit_MCP23X17.h"

#define OUTPUT_PULLUP 4

/**************************************************************************/
/*!
@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
Loading