Program Listing for File mcp23017.hh
↰ Return to documentation for file (include/mcp23017/mcp23017.hh
)
#ifndef IPLO_MCP23017_HH
#define IPLO_MCP23017_HH
#include <cstdint>
#include "i2c_bus/i2c.hh"
#include "iplo/iplo.hh"
#include "mcp230xx/mcp230xx.hh"
namespace iplo {
class MCP23017 : public MCP230XX {
enum MCP23017Port : std::uint8_t {
DDRA = 0,
DDRB = 1,
};
enum MCP23017Registers : std::uint8_t {
DDR_A = 0x00,
DDR_B = 0x01,
POL_A = 0x02,
POL_B = 0x03,
GPINTEN_A = 0x04,
GPINTEN_B = 0x05,
DEFVAL_A = 0x06,
DEFVAL_B = 0x07,
INTCON_A = 0x08,
INTCON_B = 0x09,
IOCR = 0x0A,
IOCR2 = 0x0B,
PUR_A = 0x0C,
PUR_B = 0x0D,
INTF_A = 0x0E,
INTF_B = 0x0F,
INTCAP_A = 0x10,
INTCAP_B = 0x11,
GPIO_A = 0x12,
GPIO_B = 0x13,
OLAT_A = 0x14,
OLAT_B = 0x15,
};
public:
static const std::uint8_t PINS = 16;
MCP23017(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(MCP23017Port port, std::uint8_t value);
bool digitalWrite8(MCP23017Port port, std::uint8_t value);
std::uint8_t digitalRead8(MCP23017Port port);
bool setPolarity8(MCP23017Port port, std::uint8_t mask);
bool getPolarity8(MCP23017Port port, std::uint8_t& mask);
bool setPullUp8(MCP23017Port port, std::uint8_t mask);
bool getPullUp8(MCP23017Port port, std::uint8_t& mask);
bool pinMode16(std::uint16_t value);
bool digitalWrite16(std::uint16_t value);
std::uint16_t digitalRead16();
bool setPolarity16(std::uint16_t mask);
bool getPolarity16(std::uint16_t& mask);
bool setPullUp16(std::uint16_t mask);
bool getPullUp16(std::uint16_t& mask);
std::uint16_t readAll() override;
static std::uint8_t extractPinValue(std::uint16_t registerValue, std::uint8_t pin);
};
} /* namespace iplo */
#endif /* IPLO_MCP23017_HH */