Zumo32U4 library
Public Attributes | List of all members
FastGPIO::PinLoan< pin > Class Template Reference

#include <FastGPIO.h>

Public Attributes

uint8_t state
 The state of the pin as returned from FastGPIO::Pin::getState. More...
 

Detailed Description

template<uint8_t pin>
class FastGPIO::PinLoan< pin >

This class saves the state of the specified pin in its constructor when it is created, and restores the pin to that state in its destructor. This can be very useful if a pin is being used for multiple purposes. It allows you to write code that temporarily changes the state of the pin and is guaranteed to restore the state later.

For example, if you were controlling both a button and an LED using a single pin and you wanted to see if the button was pressed without affecting the LED, you could write:

bool buttonIsPressed()
{
_delay_us(10);
}
static void setInputPulledUp() __attribute__((always_inline))
Sets a pin to be a digital input with the internal pull-up resistor enabled.
Definition: FastGPIO.h:400
static bool isInputHigh() __attribute__((always_inline))
Reads the input value of the pin.
Definition: FastGPIO.h:410

This is equivalent to:

bool buttonIsPressed()
{
_delay_us(10);
return value;
}
static void setState(uint8_t state)
Sets the full 2-bit state of the pin.
Definition: FastGPIO.h:486
static uint8_t getState()
Returns the full 2-bit state of the pin.
Definition: FastGPIO.h:454
uint8_t state
The state of the pin as returned from FastGPIO::Pin::getState.
Definition: FastGPIO.h:546

Definition at line 542 of file FastGPIO.h.

Constructor & Destructor Documentation

◆ PinLoan()

template<uint8_t pin>
FastGPIO::PinLoan< pin >::PinLoan ( )
inline

Definition at line 548 of file FastGPIO.h.

◆ ~PinLoan()

template<uint8_t pin>
FastGPIO::PinLoan< pin >::~PinLoan ( )
inline

Definition at line 553 of file FastGPIO.h.

Member Data Documentation

◆ state

template<uint8_t pin>
uint8_t FastGPIO::PinLoan< pin >::state

The state of the pin as returned from FastGPIO::Pin::getState.

Definition at line 546 of file FastGPIO.h.


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