IoAbstraction
Public Member Functions | List of all members
BasicIoAbstraction Class Reference

#include <BasicIoAbstraction.h>

Inheritance diagram for BasicIoAbstraction:
AnalogJoystickToButtons DfRobotInputAbstraction LoggingIoAbstraction MockedIoAbstraction MultiIoAbstraction NegatingIoAbstraction PCF8574IoAbstraction ShiftRegisterIoAbstraction ShiftRegisterIoAbstraction165In Standard16BitDevice

Public Member Functions

uint8_t digitalRead (pinid_t p)
 
void digitalWrite (pinid_t p, uint8_t v)
 
uint8_t digitalReadS (pinid_t p)
 
void digitalWriteS (pinid_t p, uint8_t v)
 
void writePortS (pinid_t p, uint8_t v)
 
uint8_t readPortS (pinid_t p)
 
void pinMode (pinid_t pin, uint8_t mode)
 
bool sync ()
 
virtual void pinDirection (pinid_t pin, uint8_t mode)
 
virtual void writeValue (pinid_t pin, uint8_t value)
 
virtual uint8_t readValue (pinid_t pin)
 
virtual void attachInterrupt (pinid_t pin, RawIntHandler interruptHandler, uint8_t mode)
 
virtual bool runLoop ()
 
virtual void writePort (pinid_t pin, uint8_t portVal)
 
virtual uint8_t readPort (pinid_t pin)
 

Detailed Description

This class provides the interface by which all IoAbstractionRef types work. It makes it possible to treat many types of IO in the same way, by providing a standard way of dealing with Arduino pins, shift registers and IO expanders.

As well as providing the standard interface, it also provides the Arduino pin implementation.

Normally, to use an IoAbstraction one would use the helper functions available, for this IoAbstraction the helper function is ioUsingArduino

Member Function Documentation

◆ digitalRead()

uint8_t BasicIoAbstraction::digitalRead ( pinid_t  p)
inline

Reads the current digital state of a pin, HIGH or LOW. Note that for I2C/off-chip devices you need to sync() the device first. This means you can read many pins with one sync!

Parameters
pthe pin to read
Returns
HIGH or LOW

◆ digitalWrite()

void BasicIoAbstraction::digitalWrite ( pinid_t  p,
uint8_t  v 
)
inline

Writes a new digital value for a given pin on the device. For I2C and other offboard devices you'll need to sync() afterwards, or use digitalWriteS if you only need a single write.

Parameters
pthe pin to write
vthe value to write
See also
digitalWriteS

◆ digitalReadS()

uint8_t BasicIoAbstraction::digitalReadS ( pinid_t  p)
inline

Reads the current digital state of a pin, HIGH or LOW. Does a sync() before reading ensuring latest values.

Parameters
pthe pin to read
Returns
HIGH or LOW

◆ digitalWriteS()

void BasicIoAbstraction::digitalWriteS ( pinid_t  p,
uint8_t  v 
)
inline

Writes a new digital value for a given pin on the device. For I2C and other off-chip devices this does sync() after writing. It is useful when only one pin needs to be set. To write more than one pin at once, use the non sync() version and sync() at the end.

Parameters
pthe pin to write
vthe value to write
See also
digitalWrite

◆ writePortS()

void BasicIoAbstraction::writePortS ( pinid_t  p,
uint8_t  v 
)
inline

Write a whole port at once if support by the device. Supported on most Arduino, I2C, Shift registers. It does sync with the device for I2C/off-chip. Use the non 'S' version to optimize writes to off-board chips.

Parameters
pany pin on the port
vthe value for the whole port.

◆ readPortS()

uint8_t BasicIoAbstraction::readPortS ( pinid_t  p)
inline

Reads a whole port at once, and does a sync() with the chip before hand. Use the non 'S' version to optimize writes to off-board chips.

Parameters
pany pin on the port
Returns
the value of the port

◆ pinMode()

void BasicIoAbstraction::pinMode ( pinid_t  pin,
uint8_t  mode 
)
inline

Set the direction of a pin on the device, be careful that the device can support the pin mode you're requesting. It roughly follows the Arduino method.

Parameters
pinthe pin to set the mode for
modethe mode you are requesting, EG OUTPUT, INPUT, INPUT_PULLUP

◆ sync()

bool BasicIoAbstraction::sync ( )
inline

This method is not needed on Arduino pins, but for most serial implementations it causes the device and abstraction to be synced. Returns true if the write call worked, normally true, false indicates error

Returns
true if successful, otherwise false.
See also
runLoop this just calls runLoop, it is a renaming to make the intention clearer.

◆ pinDirection()

virtual void BasicIoAbstraction::pinDirection ( pinid_t  pin,
uint8_t  mode 
)
virtual

sets the pin direction for a pin controlled by this abstraction - as per pinMode

Parameters
pinthe pin to be changed
modethe new mode, as per pinMode (or on Mbed you can use PinMode enum values)

Reimplemented in NegatingIoAbstraction, LoggingIoAbstraction, MockedIoAbstraction, AnalogJoystickToButtons, MPR121IoAbstraction, AW9523IoAbstraction, MCP23017IoAbstraction, PCF8574IoAbstraction, MultiIoAbstraction, ShiftRegisterIoAbstraction165In, ShiftRegisterIoAbstraction, and DfRobotInputAbstraction.

◆ writeValue()

virtual void BasicIoAbstraction::writeValue ( pinid_t  pin,
uint8_t  value 
)
virtual

Writes a value to a pin on this abstraction, as per digitalWrite. For serial devices, may need a sync first.

Parameters
pinthe pin to be written to
valuethe new value such as HIGH / LOW

Reimplemented in NegatingIoAbstraction, LoggingIoAbstraction, MockedIoAbstraction, AnalogJoystickToButtons, Standard16BitDevice, PCF8574IoAbstraction, MultiIoAbstraction, ShiftRegisterIoAbstraction165In, ShiftRegisterIoAbstraction, and DfRobotInputAbstraction.

◆ readValue()

virtual uint8_t BasicIoAbstraction::readValue ( pinid_t  pin)
virtual

Reads a value from a pin for this abstraction as per digitalRead. For serial devices may need a sync first.

Parameters
pinthe pin to be read

Reimplemented in NegatingIoAbstraction, LoggingIoAbstraction, MockedIoAbstraction, AnalogJoystickToButtons, Standard16BitDevice, PCF8574IoAbstraction, MultiIoAbstraction, ShiftRegisterIoAbstraction165In, ShiftRegisterIoAbstraction, and DfRobotInputAbstraction.

◆ attachInterrupt()

virtual void BasicIoAbstraction::attachInterrupt ( pinid_t  pin,
RawIntHandler  interruptHandler,
uint8_t  mode 
)
virtual

Attach an interrupt to this abstraction, regardless of the device location this will perform the required tasks to register the interrupt in the requested mode. Note that not all devices can support all modes, for arduino pins all modes are supported.

Parameters
pinthe pin on this device to be used
intHandlera void function with no parameters, used to handle interrupts. THIS IS A RAW INTERRUPT AND NOT MARSHALLED
modestandard Arduino interrupt modes: CHANGE, RISING, FALLING

Reimplemented in ShiftRegisterIoAbstraction165In, ShiftRegisterIoAbstraction, MPR121IoAbstraction, AW9523IoAbstraction, MCP23017IoAbstraction, PCF8574IoAbstraction, MultiIoAbstraction, NegatingIoAbstraction, LoggingIoAbstraction, and MockedIoAbstraction.

◆ runLoop()

virtual bool BasicIoAbstraction::runLoop ( )
inlinevirtual

This method is not needed on Arduino pins, but for most serial implementations it causes the device and abstraction to be synced. Returns true if the write call worked, normally true, false indicates error

Reimplemented in NegatingIoAbstraction, LoggingIoAbstraction, MockedIoAbstraction, AnalogJoystickToButtons, MPR121IoAbstraction, AW9523IoAbstraction, MCP23017IoAbstraction, PCF8574IoAbstraction, MultiIoAbstraction, ShiftRegisterIoAbstraction165In, ShiftRegisterIoAbstraction, and DfRobotInputAbstraction.

◆ writePort()

virtual void BasicIoAbstraction::writePort ( pinid_t  pin,
uint8_t  portVal 
)
virtual

Writes out a whole port at once, on Arduino pins this is achieved by providing any pin within that port. On Arduino pins you should take care not to use ports that are providing core functions.

Parameters
pinthe pin determines the hardware port to use.
portValthe 8 bit value to write to the port. Use with care.

Reimplemented in MultiIoAbstraction, ShiftRegisterIoAbstraction165In, ShiftRegisterIoAbstraction, NegatingIoAbstraction, LoggingIoAbstraction, MockedIoAbstraction, AnalogJoystickToButtons, DfRobotInputAbstraction, Standard16BitDevice, and PCF8574IoAbstraction.

◆ readPort()

virtual uint8_t BasicIoAbstraction::readPort ( pinid_t  pin)
virtual

Reads a whole port at once, on Arduino pins this is achieved by providing any pin within that port. On Arduino pins you should take care not to use ports that are providing core functions.

Parameters
pinthe pin determines the hardware port to use.
Returns
the 8 bit value read from the port.

Reimplemented in MultiIoAbstraction, ShiftRegisterIoAbstraction165In, ShiftRegisterIoAbstraction, DfRobotInputAbstraction, NegatingIoAbstraction, LoggingIoAbstraction, AnalogJoystickToButtons, Standard16BitDevice, PCF8574IoAbstraction, and MockedIoAbstraction.


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