Program Listing for File mcp230xx.hh

Return to documentation for file (include/mcp230xx/mcp230xx.hh)

#ifndef IPLO_MCP230XX_HH
#define IPLO_MCP230XX_HH

#include <cstdint>

#include "i2c_bus/i2c.hh"
#include "iplo/iplo.hh"

namespace iplo {

class MCP230XX {
protected:
    std::uint8_t _address{};
    std::uint8_t _error{};
    I2C& _bus;
    bool writeRegister(std::uint8_t reg, uint8_t value);

    std::uint8_t readRegister(uint8_t reg);

public:
    MCP230XX(I2C& bus, std::uint8_t address) : _bus(bus), _address(address), _error(OK){};

    virtual bool begin() = 0;

    virtual bool isConnected() = 0;

    virtual bool pinMode(std::uint8_t pin, PinMode mode) = 0;

    virtual bool digitalWrite(std::uint8_t pin, std::uint8_t value) = 0;

    virtual std::uint8_t digitalRead(std::uint8_t pin) = 0;

    virtual bool setPolarity(std::uint8_t pin, bool reversed) = 0;

    virtual bool getPolarity(std::uint8_t pin, bool& reversed) = 0;

    virtual bool setPullUp(std::uint8_t pin, bool pullUp) = 0;

    virtual bool getPullUp(std::uint8_t pin, bool& pullUp) = 0;

    virtual std::uint16_t readAll() = 0;

    int lastError();
};

} /* namespace iplo */

#endif /* IPLO_MCP230XX_HH */