Program Listing for File mcp23008.hh

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

#ifndef IPLO_MCP23008_HH
#define IPLO_MCP23008_HH

#include <cstdint>

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

namespace iplo {

class MCP23008 : public MCP230XX {
    enum MCP23008Registers : std::uint8_t {
        DDR_A = 0x00,
        POL_A = 0x01,
        GPINTEN_A = 0x02,
        DEFVAL_A = 0x03,
        INTCON_A = 0x04,
        IOCR = 0x05,
        PUR_A = 0x06,
        INTF_A = 0x07,
        INTCAP_A = 0x08,
        GPIO_A = 0x09,
        OLAT_A = 0x0A,
    };

public:
    static const std::uint8_t PINS = 8;
    MCP23008(I2C& bus, std::uint8_t address);

    bool begin() override;

    bool isConnected() override;

    bool pinMode(std::uint8_t pin, PinMode mode) override;

    bool digitalWrite(std::uint8_t pin, std::uint8_t value) override;

    std::uint8_t digitalRead(std::uint8_t pin) override;

    bool setPolarity(std::uint8_t pin, bool reversed) override;

    bool getPolarity(std::uint8_t pin, bool& reversed) override;

    bool setPullUp(std::uint8_t pin, bool pullUp) override;

    bool getPullUp(std::uint8_t pin, bool& pullUp) override;

    bool pinMode8(std::uint8_t value);

    bool digitalWrite8(std::uint8_t value);

    std::uint8_t digitalRead8();

    bool setPolarity8(std::uint8_t mask);

    bool getPolarity8(std::uint8_t& mask);

    bool setPullUp8(std::uint8_t mask);

    bool getPullUp8(std::uint8_t& mask);

    std::uint16_t readAll() override;

    static std::uint8_t extractPinValue(std::uint8_t registerValue, std::uint8_t pin);
};

} /* namespace iplo */

#endif /* IPLO_MCP23008_HH */