25#include "../functors.h"
26#include "../i2c_device.h"
27#include "../i2c_device_utilities.h"
39 template<
typename MANAGER>
46 template<u
int8_t REGISTER,
typename T = u
int8_t,
typename FUNCTOR = functor::Identity<T>>
48 template<u
int8_t REGISTER,
typename T = u
int8_t,
typename FUNCTOR = functor::Identity<T>>
50 template<
typename T, uint8_t... REGISTERS>
53 static constexpr uint8_t compute_address(uint8_t address)
55 return uint8_t((uint8_t(BASE_ADDRESS) | uint8_t(address & 0x07U)) << 1);
59 static constexpr const uint8_t BASE_ADDRESS = 0x20;
62 static constexpr const uint8_t IODIR = 0x00;
63 static constexpr const uint8_t IPOL = 0x01;
65 static constexpr const uint8_t GPINTEN = 0x02;
66 static constexpr const uint8_t DEFVAL = 0x03;
67 static constexpr const uint8_t INTCON = 0x04;
69 static constexpr const uint8_t IOCON = 0x05;
71 static constexpr const uint8_t GPPU = 0x06;
73 static constexpr const uint8_t INTF = 0x07;
74 static constexpr const uint8_t INTCAP = 0x08;
76 static constexpr const uint8_t GPIO = 0x09;
77 static constexpr const uint8_t OLAT = 0x0A;
80 static constexpr const uint8_t IOCON_SEQOP =
bits::BV8(5);
81 static constexpr const uint8_t IOCON_DISSLW =
bits::BV8(4);
82 static constexpr const uint8_t IOCON_HAEN =
bits::BV8(3);
83 static constexpr const uint8_t IOCON_ODR =
bits::BV8(2);
84 static constexpr const uint8_t IOCON_INTPOL =
bits::BV8(1);
90 using RES_TYPE = uint8_t;
106 :
PARENT{manager, compute_address(address),
i2c::I2C_FAST, true} {}
168 :
PARENT{direction, polarity, pullup} {}
218 :
PARENT{int_pins, ref, compare_ref} {}
396 return this->
template sync_write<BeginFuture, InterruptPolarity>(interrupt_polarity);
460 return this->
template sync_write<SetValuesFuture>(value);
474 return get_value<GetValuesFuture>();
489 return get_value<InterruptFlagsFuture>();
506 return get_value<CapturedValuesFuture>();
510 template<
typename F> uint8_t get_value()
513 this->
template sync_read<F>(value);
519 return this->
write(byte_count,
false,
true);
I2C device driver for Microchip MCP23008 support.
uint8_t interrupt_flags()
Get the pins that generated the latest interrupt on the port of the MCP23008 chip.
int values(GetValuesFuture &future)
Get levels of pins on the port of this MCP23008 chip.
int configure_interrupts(ConfigureInterruptsFuture &future)
Configure interrupts on the port of this MCP23008 chip.
int values(SetValuesFuture &future)
Set output levels of output pins on the port of this MCP23008 chip.
bool begin(InterruptPolarity interrupt_polarity=InterruptPolarity::ACTIVE_HIGH)
Initialize the chip before operation.
uint8_t values()
Get levels of pins on the port of this MCP23008 chip.
int configure_gpio(ConfigureGPIOFuture &future)
Configure GPIO on the port of this MCP23008 chip.
MCP23008(MANAGER &manager, uint8_t address)
Create a new device driver for an MCP23008 chip.
uint8_t captured_values()
Get captured levels, at the time an interrupt was triggered, of pins on the port of this MCP23008 chi...
int interrupt_flags(InterruptFlagsFuture &future)
Get the pins that generated the latest interrupt on the port of the MCP23008 chip.
bool values(uint8_t value)
Set output levels of output pins on the port of this MCP23008 chip.
bool configure_interrupts(uint8_t int_pins, uint8_t ref=0, uint8_t compare_ref=0)
Configure interrupts on the port of this MCP23008 chip.
int begin(BeginFuture &future)
Initialize the chip before operation.
int captured_values(CapturedValuesFuture &future)
Get captured levels, at the time an interrupt was triggered, of pins on the port of this MCP23008 chi...
bool configure_gpio(uint8_t direction, uint8_t pullup=0, uint8_t polarity=0)
Configure GPIO on the port of this MCP23008 chip.
Base class for all I2C devices.
static constexpr I2CLightCommand write(uint8_t write_count=0, bool finish_future=false, bool stop=false)
Build a write I2CLightCommand that can be later pushed to the I2C Manager for proper handling.
int async_write(F &future, bool stop=true)
Helper method that asynchronously launches I2C commands for a simple Future performing only one write...
int async_multi_write(F &future, bool stop=true)
Helper method that asynchronously launches I2C commands for a simple Future performing several regist...
MANAGER MANAGER
the type of I2C Manager that can handle this device.
int async_read(F &future, bool stop=true)
Helper method that asynchronously launches I2C commands for a simple Future performing one write foll...
Light atomic I2C command as prepared by an I2C device.
Generic Future that can be used to read an I2C device register.
Generic Future that can be used to write to several I2C device registers.
Generic Future that can be used to write to an I2C device register.
API to handle the MCP23008/23017 chips (8 & 16-Bit I/O Expanders with I2C interface).
static constexpr uint8_t BV8(uint8_t bit)
Create a uint8_t bitmask for the given bit number.
Defines the API for MCP23008/MCP23017 chips support.
InterruptPolarity
The polarity of the MCP23008/MCP23017 INT pins.
@ ACTIVE_HIGH
The INT pins shall be active high, ie they are low by default, and changed to high when an interrupt ...
Contains the API around Future implementation.
@ READY
The status of a Future once its output value has been fully set by a provider.
Define API to define and manage I2C devices.