avr-classes
|
The core project contains a bunch of classes that can be used to manipulate the AVR's GPIO pins. The two main types of components to distinguish here are Ports and Pins.
Ports implement one of the port interfaces (InputPort, OutputPort, GpioPort) which allows them to read or write an 8 bit value. The prototype of such ports are the GPIO ports built into the AVR (e.g. HAM32A::PortA).
Pins implement one of the pin interfaces (InputPin, OutputPin, GpioPin) which allows them to read or write a boolean value. A pin can be located on a compatible port (e.g. an InputPin on an InputPort or on a GpioPort, but not on an OutputPort).
While the heavy usage of interfaces makes the GPIO classes rather expensive in terms of RAM (due to the virtual method tables), the classes also are highly combinable. Example:
Additionally the classes VirtualInputPort and VirtualOutputPort allow to form ports using pins that are located virtually anywhere. This is especially useful when interfacing external hardware while not having consecutive pins on a real port left. But don't expect big data throughput from such virtual ports. Internally the virtual ports use the PinArray template class which allows even larger ports than 8 bit.
For using external interrupts ExternalInterrupt and its derived classes exist. These classes manage the external interrupts only, to control the underlying pin a separate instance of a GpioPortPin is required.
Summary of interfaces and classes
Interface | Description |
---|---|
InputPin | Pin that can get a boolean value |
OutputPin | Pin that can set a boolean value |
GpioPin | Pin that can be input and output, supports configuration of direction and internal pullup resistors |
InputPort | Port that can get an 8 bit value (or parts, controlled by a bit mask) |
OutputPort | Port that can set an 8 bit value (or parts, controlled by a bit mask) |
GpioPort | Port that can be input and output, supports configuration of direction and internal pullup resistors |
Class | Description |
---|---|
InputPortPin | Input pin located on a device that implements the InputPort interface |
OutputPortPin | Output pin located on a device that implements the OutputPort interface |
GpioPortPin | Bi-directional pin located on a device that implements the GpioPort interface |
PinArray | Template class forming port-like pin sequences that can be physically located anywhere |
VirtualInputPort | Convenience wrapper of PinArray forming an 8 bit port that implements the InputPort interface |
VirtualOutputPort | Convenience wrapper of PinArray forming an 8 bit port that implements the OutputPort interface |