Balboa32U4 library
Static Public Member Functions | List of all members
FastGPIO::Pin< pin > Class Template Reference

#include <FastGPIO.h>

Static Public Member Functions

static void setOutputLow () __attribute__((always_inline))
 Configures the pin to be an output driving low. More...
 
static void setOutputHigh () __attribute__((always_inline))
 Configures the pin to be an output driving high. More...
 
static void setOutputToggle () __attribute__((always_inline))
 Configures the pin to be an output and toggles it.
 
static void setOutput (bool value) __attribute__((always_inline))
 Sets the pin as an output. More...
 
static void setOutputValueLow () __attribute__((always_inline))
 Sets the output value of the pin to 0. More...
 
static void setOutputValueHigh () __attribute__((always_inline))
 Sets the output value of the pin to 1. More...
 
static void setOutputValueToggle () __attribute__((always_inline))
 Toggles the output value of the pin. More...
 
static void setOutputValue (bool value) __attribute__((always_inline))
 Sets the output value of the pin. More...
 
static void setInput () __attribute__((always_inline))
 Sets a pin to be a digital input with the internal pull-up resistor disabled.
 
static void setInputPulledUp () __attribute__((always_inline))
 Sets a pin to be a digital input with the internal pull-up resistor enabled.
 
static bool isInputHigh () __attribute__((always_inline))
 Reads the input value of the pin. More...
 
static bool isOutput () __attribute__((always_inline))
 Returns 1 if the pin is configured as an output. More...
 
static bool isOutputValueHigh () __attribute__((always_inline))
 Returns the output value of the pin. More...
 
static uint8_t getState ()
 Returns the full 2-bit state of the pin. More...
 
static void setState (uint8_t state)
 Sets the full 2-bit state of the pin. More...
 

Detailed Description

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

Template Parameters
pinThe pin number

The FastGPIO::Pin class provides static functions for manipulating pins. This class can only be used if the pin number is known at compile time, which means it does not come from a variable that might change and it does not come from the result of a complicated calculation.

Here is some example code showing how to use this class to blink an LED:

#include <FastGPIO.h>
#define LED_PIN 13
void setup() {
}
void loop() {
delay(500);
delay(500);
}

Definition at line 217 of file FastGPIO.h.

Member Function Documentation

◆ getState()

template<uint8_t pin>
static uint8_t FastGPIO::Pin< pin >::getState ( )
inlinestatic

Returns the full 2-bit state of the pin.

Bit 0 of this function's return value is the pin's output value. Bit 1 of the return value is the pin direction; a value of 1 means output. All the other bits are zero.

Definition at line 396 of file FastGPIO.h.

◆ isInputHigh()

template<uint8_t pin>
static bool FastGPIO::Pin< pin >::isInputHigh ( )
inlinestatic

Reads the input value of the pin.

Returns
0 if the pin is low, 1 if the pin is high.

Definition at line 352 of file FastGPIO.h.

◆ isOutput()

template<uint8_t pin>
static bool FastGPIO::Pin< pin >::isOutput ( )
inlinestatic

Returns 1 if the pin is configured as an output.

Returns
1 if the pin is an output, 0 if it is an input.

Definition at line 374 of file FastGPIO.h.

◆ isOutputValueHigh()

template<uint8_t pin>
static bool FastGPIO::Pin< pin >::isOutputValueHigh ( )
inlinestatic

Returns the output value of the pin.

This is mainly intended to be called on pins that have been configured an an output. If it is called on an input pin, the return value indicates whether the pull-up resistor is enabled or not.

Definition at line 385 of file FastGPIO.h.

◆ setOutput()

template<uint8_t pin>
static void FastGPIO::Pin< pin >::setOutput ( bool  value)
inlinestatic

Sets the pin as an output.

Parameters
valueShould be 0, LOW, or false to drive the pin low. Should be 1, HIGH, or true to drive the pin high.

The PORT bit is set before the DDR bit to ensure that the output is not accidentally driven to the wrong value during the transition.

Definition at line 260 of file FastGPIO.h.

◆ setOutputHigh()

template<uint8_t pin>
static void FastGPIO::Pin< pin >::setOutputHigh ( )
inlinestatic

Configures the pin to be an output driving high.

This is equivalent to calling setOutput with an argument of 1, but it has a simpler implementation which means it is more likely to be compiled down to just 2 assembly instructions.

Definition at line 238 of file FastGPIO.h.

◆ setOutputLow()

template<uint8_t pin>
static void FastGPIO::Pin< pin >::setOutputLow ( )
inlinestatic

Configures the pin to be an output driving low.

This is equivalent to calling setOutput with an argument of 0, but it has a simpler implementation which means it is more likely to be compiled down to just 2 assembly instructions.

Definition at line 226 of file FastGPIO.h.

◆ setOutputValue()

template<uint8_t pin>
static void FastGPIO::Pin< pin >::setOutputValue ( bool  value)
inlinestatic

Sets the output value of the pin.

Parameters
valueShould be 0, LOW, or false to drive the pin low. Should be 1, HIGH, or true to drive the pin high.

This is mainly intended to be used on pins that have already been configured as an output.

If this function is used on an input pin, it has the effect of toggling setting the state of the input pin's pull-up resistor.

Definition at line 318 of file FastGPIO.h.

◆ setOutputValueHigh()

template<uint8_t pin>
static void FastGPIO::Pin< pin >::setOutputValueHigh ( )
inlinestatic

Sets the output value of the pin to 1.

This is mainly intended to be used on pins that have already been configured as an output in order to make the output drive low.

If this is used on an input pin, it has the effect of enabling the input pin's pull-up resistor.

Definition at line 287 of file FastGPIO.h.

◆ setOutputValueLow()

template<uint8_t pin>
static void FastGPIO::Pin< pin >::setOutputValueLow ( )
inlinestatic

Sets the output value of the pin to 0.

This is mainly intended to be used on pins that have already been configured as an output in order to make the output drive low.

If this is used on an input pin, it has the effect of disabling the input pin's pull-up resistor.

Definition at line 274 of file FastGPIO.h.

◆ setOutputValueToggle()

template<uint8_t pin>
static void FastGPIO::Pin< pin >::setOutputValueToggle ( )
inlinestatic

Toggles the output value of the pin.

This is mainly intended to be used on pins that have already been configured as an output. If the pin was driving low, this function changes it to drive high. If the pin was driving high, this function changes it to drive low.

If this function is used on an input pin, it has the effect of toggling the state of the input pin's pull-up resistor.

Definition at line 302 of file FastGPIO.h.

◆ setState()

template<uint8_t pin>
static void FastGPIO::Pin< pin >::setState ( uint8_t  state)
inlinestatic

Sets the full 2-bit state of the pin.

Parameters
stateThe state of the pin, as returns from getState. All bits other than bits 0 and 1 are ignored.

Sometimes this function will need to change both the PORT bit (which specifies the output value) and the DDR bit (which specifies whether the pin is an output). If the DDR bit is getting set to 0, this function changes DDR first, and if it is getting set to 1, this function changes DDR last. This guarantees that the intermediate pin state is always an input state.

Definition at line 428 of file FastGPIO.h.


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