modm API documentation
modm::GpioExpander Class Reference

#include <modm/architecture/interface/gpio_expander.hpp>

Inheritance diagram for modm::GpioExpander:
modm::mcp23x17< Transport > modm::pca8574< I2cMaster > modm::pca9535< I2cMaster >

Public Typedefs

using PortType = uint8_t
 
typedef modm::Flags< Pin, PortTypePins
 Use type-safe flags container for the pins.
 

Public Member Functions

modm::ResumableResult< bool > setOutput (Pins pins)
 Sets one or more pins to output.
 
modm::ResumableResult< bool > set (Pins pins)
 
modm::ResumableResult< bool > reset (Pins pins)
 
modm::ResumableResult< bool > toggle (Pins pins)
 
modm::ResumableResult< bool > set (Pins pins, bool value)
 
bool isSet (Pin pin) const
 Returns the set logical output state of the pin.
 
modm::Gpio::Direction getDirection (Pin pin) const
 returns direction of one pin at run-time
 
modm::ResumableResult< bool > setInput (Pins pins)
 Sets one or more pins to input.
 
bool read (Pins pins) const
 
modm::ResumableResult< bool > readInput ()
 Reads the inputs and buffers them.
 
modm::ResumableResult< bool > writePort (PortType data)
 
modm::ResumableResult< bool > readPort (PortType &data)
 Reads the entire port, buffers them and outputs the result to data.
 
Pins getDirections () const
 Returns the direction bits: 0 for Input, 1 for Output.
 
Pins getOutputs () const
 Returns the output bits: 0 for low, 1 for high.
 
Pins getInputs () const
 Returns the input bits: 0 for low, 1 for high.
 

Static Public Member Functions

static constexpr uint8_t indexFromPin (Pin pin)
 

Static Public Attributes

static constexpr uint8_t width
 

Detailed Description

Interface of an IO expander driver.

All IO expander driver should implement this interface, so that they can be wrapped into modm::GpioExpanderPin and modm::GpioExpanderPort.

The interface is almost identical to an GPIO pin, except multiple pins can be set at once.

Note
The driver must buffer the expanders IO registers. This means at least the direction, output and input values should be buffered so that a read-modify-write can be performed on SRAM and then only one write is performed on the bus instead of a read and write!
Warning
The read() function does not perform a read bus access, but operates on the buffered result of readInput(). This allows a capture-and-evaluate approach, which is especially useful for reducing bus traffic and necessary for sampling all pins at the same time for modm::GpioExpanderPort.
See also
modm::GpioExpanderPin
modm::GpioExpanderPort
modm::GpioIO
Author
Niklas Hauser

Member Typedef Documentation

This contains the underlying type that can hold the bits of the entire port. This value is implementation defined, it may also be uint16_t.

Member Function Documentation

static constexpr uint8_t modm::GpioExpander::indexFromPin ( Pin  pin)
staticconstexpr

Returns the index of the pin as a constexpr function. The mapping is implementation defined, however, as an implementation hint when using a bit mask, you should use modm::leftmostBit()

bool modm::GpioExpander::read ( Pins  pins) const

Returns true if all pins have a high level

Warning
This function operates on the buffered input read. You have to call readInput() to update the result.
modm::ResumableResult<bool> modm::GpioExpander::reset ( Pins  pins)

Resets one or more pins to logic low

Warning
only modifies pins that have previously been set to output!
modm::ResumableResult<bool> modm::GpioExpander::set ( Pins  pins)

Sets one or more pins to logic high

Warning
only modifies pins that have previously been set to output!
modm::ResumableResult<bool> modm::GpioExpander::set ( Pins  pins,
bool  value 
)

sets one or more pins to high or low level

Warning
only modifies pins that have previously been set to output!
modm::ResumableResult<bool> modm::GpioExpander::toggle ( Pins  pins)

Toggles one or more pins

Warning
only modifies pins that have previously been set to output!
modm::ResumableResult<bool> modm::GpioExpander::writePort ( PortType  data)

Writes data to the entire port

Warning
only modifies pins that have previously been set to output!

Member Data Documentation

constexpr uint8_t modm::GpioExpander::width
staticconstexpr

This holds the width of the port as number of bits and can be used in drivers to assert the correct requirements


The documentation for this class was generated from the following file: