modm API documentation
modm::GpioExpanderPort< GpioExpander, expander, StartPin, Width, DataOrder > Class Template Reference

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

Inheritance diagram for modm::GpioExpanderPort< GpioExpander, expander, StartPin, Width, DataOrder >:
modm::GpioPort

Public Types

enum  DataOrder : bool { DataOrder::Normal = false, DataOrder::Reversed = true }
 This enum can be used to reverse the bit order of the Data. More...
 

Static Public Member Functions

static constexpr DataOrder getDataOrder ()
 
static void setOutput ()
 
static void setInput ()
 
static PortType read ()
 
static void write (PortType data)
 
static void toggle ()
 
static void write (PortType data)
 The write data is always right-aligned regardless of physical mapping.
 

Static Public Attributes

static constexpr uint8_t width = Width
 
static constexpr GpioExpanderioExpander = expander
 
static constexpr uint8_t number_of_ports
 

Detailed Description

template<typename GpioExpander, GpioExpander & expander, typename GpioExpander::Pin StartPin, uint8_t Width, GpioPort::DataOrder DataOrder = GpioPort::DataOrder::Normal>
class modm::GpioExpanderPort< GpioExpander, expander, StartPin, Width, DataOrder >

Create an modm::GpioPort compatible interface from any IO-expander conforming to the modm::GpioExpander interface.

This allows the transparent usage of IO Expander ports in classes that require Ports as template arguments. The port access is optimized so that only one write or one read needs to be performed to update the port values. Any port position and width is supported and operates independently from the other IOs on the expander.

Note
For every port access a blocking bus transfer is performed, therefore do not expect these ports to be fast!
Warning
You can also use SoftwareGpioPort to create a port out of individual GpioExpanderPin classes, however, since each pin is individually accessed, this means more bus traffic and a non-atomic write and read of port data! It is strongly recommended to use this optimized class instead!

Usage:

However, instead of using this class like that, prefer using the alias-template types provided by the IO-expander of your choice for better readability:

typedef modm::Pca8574<MyI2cMaster> Expander;
Expander expander;
// a 4bit wide port in the upper nibble
typedef Expander::Port< expander, Expander::Pin::P4, 4 > Data;
// writes 0x50 on the port
Data::write(0x5);

You can reverse the ports bit order in software at runtime, so that data is written or read in reverse bit order when accessing the port:

// a 4bit wide port in the upper nibble with reversed bit order
typedef Expander::Port< expander, Expander::Pin::P4, 4, modm::GpioPort::DataOrder::Reversed > Data;
// writes 0xa0 on the port
Data::write(0x5);
Warning
Access to the IO-expander is blocking and can silently fail! If this is undesirable for you application, you need to write your own wrapper!
Precondition
The IO-expander needs to be initialized externally, if required.
See also
modm::GpioExpander
modm::GpioIO
Template Parameters
GpioExpanderType of class conforming to the modm::GpioExpander interface
expanderinstance of the expander with the selected pin
StartPinstarting pin of the port, physically LSB
Widthwidth of the entire port in bits
DataOrderthe bit order mapping of data
Author
Niklas Hauser

Member Enumeration Documentation

enum modm::GpioPort::DataOrder : bool
inheritedstrong

This enum can be used to reverse the bit order of the Data.

Enum ValuesDocumentation
Normal 

bit order of data is the same as bit order of port

Reversed 

bit order of data is the reverse bit order of port

Member Data Documentation

constexpr uint8_t modm::GpioPort::number_of_ports
inheritedstaticconstexpr

This holds the number of unique platform ports that this implementation accesses. It's always at least 1.


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