Class MCP23008
Defined in File mcp23008.hh
Inheritance Relationships
Base Type
public iplo::MCP230XX
(Class MCP230XX)
Class Documentation
-
class MCP23008 : public iplo::MCP230XX
Represents MCP23008 electronic IC.
Public Functions
-
virtual bool begin() override
Begin interaction with the device.
Selects device on the I2C bus with address given on creation. Checks if device is connected and initialize it. Disable address increment and set all pins as INPUTS with internal PULLUP.
- Returns:
Status of the device initialization.
-
virtual bool isConnected() override
Checks if device is connected and program can read a byte from it.
- Returns:
Identifier whether device is connected.
-
virtual bool pinMode(std::uint8_t pin, PinMode mode) override
Set pin mode.
Reads whole pin direction register and change only specified pin value.
See also
PinMode
- Parameters:
pin – Number of device pin.
mode – Pin mode. One of the PinMode enum values.
- Returns:
Status of the pin setting.
-
virtual bool digitalWrite(std::uint8_t pin, std::uint8_t value) override
Write HIGH or LOW value to the device pin.
Reads whole register and make copy of that value. Change value of the specified pin and write new value to the register.
- Parameters:
pin – Device pin number.
value – New value of the device pin. Must be one of {0, 1}.
- Returns:
Status of the transmission.
-
virtual std::uint8_t digitalRead(std::uint8_t pin) override
Read specified pin value.
Reads whole register and check for value on given pin.
- Parameters:
pin – Device pin number.
- Returns:
High (1) or Low (0) state of the pin. On failure returns MCP23008Status::INVALID_READ.
-
virtual bool setPolarity(std::uint8_t pin, bool reversed) override
Set pin polarity.
Reads whole register and change only specified pin value.
- Parameters:
pin – Device pin number.
reversed – Identifier if polarity on given pin should be reversed.
- Returns:
Status of the transmission.
-
virtual bool getPolarity(std::uint8_t pin, bool &reversed) override
Read pin polarity and save result to the reversed function parameter.
- Parameters:
pin – Device pin number.
reversed – Variable to store result of the pin polarity.
- Returns:
Status of the transmission.
-
virtual bool setPullUp(std::uint8_t pin, bool pullUp) override
Set pull up on specified device pin.
- Parameters:
pin – Device pin number.
pullUp – Identifier whether to set up pull up on given pin.
- Returns:
Status of the transmission.
-
virtual bool getPullUp(std::uint8_t pin, bool &pullUp) override
Get pull up value in specified pin.
- Parameters:
pin – Device pin number.
pullUp – Variable to store result of pin pull up value.
- Returns:
Status of the transmission.
-
bool pinMode8(std::uint8_t value)
Set mode on all eight pins of the device.
- Parameters:
value – Register mask value.
- Returns:
Status of the transmission.
-
bool digitalWrite8(std::uint8_t value)
Set High or Low state on all device pins.
- Parameters:
value – Register mask value.
- Returns:
Status of the transmission.
-
std::uint8_t digitalRead8()
Read state on all device pins.
- Returns:
Register value for all pins state.
-
bool setPolarity8(std::uint8_t mask)
Set polarity on all device pins.
- Parameters:
mask – Register mask value.
- Returns:
Status of the transmission.
-
bool getPolarity8(std::uint8_t &mask)
Read polarity for all pins.
- Parameters:
mask – Variable to store read register value.
- Returns:
Status of the transmission.
-
bool setPullUp8(std::uint8_t mask)
Set pull up on all device pins.
- Parameters:
mask – Register mask value.
- Returns:
Status of the transmission.
-
bool getPullUp8(std::uint8_t &mask)
Read pull up state on all device pins.
- Parameters:
mask – Variable to store read register value.
- Returns:
Status of the transmission.
-
virtual std::uint16_t readAll() override
Read values on all pins at once.
- Returns:
Value of read pins.
Public Static Functions
-
static std::uint8_t extractPinValue(std::uint8_t registerValue, std::uint8_t pin)
Extract one pin value from whole register value.
- Parameters:
registerValue – Value of the register.
pin – Pin number.
- Returns:
HIGH (1) or LOW (0) state of the given pin.
Public Static Attributes
-
static const std::uint8_t PINS = 8
Number of gpio pins in the IC.
-
virtual bool begin() override