AVRTools
A Library for the AVR ATmega328 and ATmega2560 Microcontrollers
Classes | Macros | Enumerations | Functions
GpioPinMacros.h File Reference

This file contains the primary macros for naming and manipulating GPIO pin names. More...

#include <avr/io.h>
Include dependency graph for GpioPinMacros.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  GpioPinVariable
 This class defines a type that can encode a GPIO pin as a variable. Read the section on GPIO Pin Variables to understand how to use this class. More...
 

Macros

#define GpioPin(portLtr, pinNbr)
 Primary macro-function for defining a GPIO pin name. More...
 
#define GpioPinAnalog(portLtr, pinNbr, adcNbr)
 Secondary macro-function for defining a GPIO pin name for GPIO pins that support analog conversion. More...
 
#define GpioPinPwm(portLtr, pinNbr, timer, chan)
 Secondary macro-function for defining a GPIO pin name for GPIO pins that support PWM output. More...
 
#define isGpioPinModeOutput(pinName)
 Test if the mode of the GPIO pin is output (i.e., the corresponding DDRn bit is set). More...
 
#define isGpioPinModeInput(pinName)
 Test if the mode of the GPIO pin is input (i.e., the corresponding DDRn is clear). More...
 
#define setGpioPinModeOutput(pinName)
 Set the mode of the GPIO pin to output (i.e., set the corresponding DDRn bit). More...
 
#define setGpioPinModeInput(pinName)
 Set the mode of the GPIO pin to input (i.e., clear the corresponding DDRn and PORTn bits). More...
 
#define setGpioPinModeInputPullup(pinName)
 Set the mode of the GPIO pin to input with pullup (i.e., clear the corresponding DDRn bit and set the PORTn bit). More...
 
#define readGpioPinDigital(pinName)
 Read the value of the GPIO pin (i.e., return the value of correspoinding the PINn bit). More...
 
#define writeGpioPinDigital(pinName, val)
 Write a value the GPIO pin (i.e., set or clear the correspoinding the PORTn bit). More...
 
#define setGpioPinHigh(pinName)
 Write a 1 to the GPIO pin (i.e., set the correspoinding the PORTn bit). More...
 
#define setGpioPinLow(pinName)
 Write a 0 the GPIO pin (i.e., clear the correspoinding the PORTn bit). More...
 
#define getGpioDDR(pinName)
 Get the DDRn corresponding to this GPIO pin. More...
 
#define getGpioPORT(pinName)
 Get the PORTn corresponding to this GPIO pin. More...
 
#define getGpioPIN(pinName)
 Get the bit number corresponding to this GPIO pin. More...
 
#define getGpioMASK(pinName)
 Get the bit mask corresponding to this GPIO pin. More...
 
#define getGpioADC(pinName)
 Get the ADC channel corresponding to this GPIO pin, assuming it is an ADC capable GPIO pin. More...
 
#define getGpioOCR(pinName)
 Get the OCR register corresponding to this GPIO pin, assuming it is a PWM capable GPIO pin. More...
 
#define getGpioCOM(pinName)
 Get the COM bit name corresponding to this GPIO pin, assuming it is a PWM capable GPIO pin. More...
 
#define getGpioTCCR(pinName)
 Get the TCCR register corresponding to this GPIO pin, assuming it is a PWM capable GPIO pin. More...
 
#define makeGpioVarFromGpioPin(pinName)
 Create a GPIO pin variable of type GpioPinVariable from a GPIO pin macro. More...
 
#define makeGpioVarFromGpioPinAnalog(pinName)
 Create a GPIO pin variable of type GpioPinVariable that can be used for analog-to-digital reading from a GPIO pin macro. More...
 
#define makeGpioVarFromGpioPinPwm(pinName)
 Create a GPIO pin variable of type GpioPinVariable that can be used for PWM from a GPIO pin macro. More...
 

Enumerations

enum  { kDigitalLow = 0, kDigitalHigh = 1 }
 Constants for digital values representing LOW and HIGH. More...
 

Functions

bool isGpioPinModeOutputV (const GpioPinVariable &pinVar)
 Test if the mode of the GPIO pin is output (i.e., the corresponding DDRn bit is set). More...
 
bool isGpioPinModeInputV (const GpioPinVariable &pinVar)
 Test if the mode of the GPIO pin is input (i.e., the corresponding DDRn is clear). More...
 
void setGpioPinModeOutputV (const GpioPinVariable &pinVar)
 Set the mode of the GPIO pin to output (i.e., set the corresponding DDRn bit). More...
 
void setGpioPinModeInputV (const GpioPinVariable &pinVar)
 Set the mode of the GPIO pin to input (i.e., clear the corresponding DDRn and PORTn bits). More...
 
void setGpioPinModeInputPullupV (const GpioPinVariable &pinVar)
 Set the mode of the GPIO pin to input with pullup (i.e., clear the corresponding DDRn bit and set the PORTn bit). More...
 
bool readGpioPinDigitalV (const GpioPinVariable &pinVar)
 Read the value of the GPIO pin (i.e., return the value of correspoinding the PINn bit). More...
 
void writeGpioPinDigitalV (const GpioPinVariable &pinVar, bool value)
 Write a value the GPIO pin (i.e., set or clear the correspoinding the PORTn bit). More...
 
void setGpioPinHighV (const GpioPinVariable &pinVar)
 Write a 1 to the GPIO pin (i.e., set the correspoinding the PORTn bit). More...
 
void setGpioPinLowV (const GpioPinVariable &pinVar)
 Write a 0 to the GPIO pin (i.e., clear the correspoinding the PORTn bit). More...
 

Detailed Description

This file contains the primary macros for naming and manipulating GPIO pin names.

Normally you do not include this file directly. Instead include either ArduinoPins.h, which will automatically include this file.

Macro Definition Documentation

§ getGpioADC

#define getGpioADC (   pinName)

Get the ADC channel corresponding to this GPIO pin, assuming it is an ADC capable GPIO pin.

Returns
a number between 0-7 (for ATmega328) or between 0-15 (for ATmega2560).

§ getGpioCOM

#define getGpioCOM (   pinName)

Get the COM bit name corresponding to this GPIO pin, assuming it is a PWM capable GPIO pin.

Returns
a COMn[A/B]1 bit name (e.g., COM2B1)

§ getGpioDDR

#define getGpioDDR (   pinName)

Get the DDRn corresponding to this GPIO pin.

Returns
a DDRn register name (e.g., DDRB)

§ getGpioMASK

#define getGpioMASK (   pinName)

Get the bit mask corresponding to this GPIO pin.

Returns
a byte-sized bitmask

§ getGpioOCR

#define getGpioOCR (   pinName)

Get the OCR register corresponding to this GPIO pin, assuming it is a PWM capable GPIO pin.

Returns
a OCRn[A/B] register name (e.g., OCR2B)

§ getGpioPIN

#define getGpioPIN (   pinName)

Get the bit number corresponding to this GPIO pin.

Returns
a number between 0 and 7

§ getGpioPORT

#define getGpioPORT (   pinName)

Get the PORTn corresponding to this GPIO pin.

Returns
a PORTn register name (e.g., PORTB)

§ getGpioTCCR

#define getGpioTCCR (   pinName)

Get the TCCR register corresponding to this GPIO pin, assuming it is a PWM capable GPIO pin.

Returns
a TCCTn[A/B] register name (e.g., TCCR2B)

§ GpioPin

#define GpioPin (   portLtr,
  pinNbr 
)

Primary macro-function for defining a GPIO pin name.

  • portLtr an uppercase letter identifying the port (e.g., A, B, C, ...) the GPIO pin belongs to.
  • pinNbr a number between 0 and 7 identifying the bit on that port that corresponds to the GPIO pin.

§ GpioPinAnalog

#define GpioPinAnalog (   portLtr,
  pinNbr,
  adcNbr 
)

Secondary macro-function for defining a GPIO pin name for GPIO pins that support analog conversion.

  • portLtr an uppercase letter identifying the port (e.g., A, B, C, ...) the GPIO pin belongs to.
  • pinNbr a number between 0 and 7 identifying the bit on that port that corresponds to the GPIO pin.
  • adcNbr a number representing the ADC converter channel corresponding to this GPIO pin (0-7 for ArduinoUno; 0-15 for ArduinoMega)

§ GpioPinPwm

#define GpioPinPwm (   portLtr,
  pinNbr,
  timer,
  chan 
)

Secondary macro-function for defining a GPIO pin name for GPIO pins that support PWM output.

  • portLtr an uppercase letter identifying the port (e.g., A, B, C, ...) the GPIO pin belongs to.
  • pinNbr a number between 0 and 7 identifying the bit on that port that corresponds to the GPIO pin.
  • timer a number representing the timer number associated with the PWM function on this GPIO pin.
  • chan a letter (A, B, or C) representing the channel on the timer associated with the PWM function on this GPIO pin.

§ isGpioPinModeInput

#define isGpioPinModeInput (   pinName)

Test if the mode of the GPIO pin is input (i.e., the corresponding DDRn is clear).

§ isGpioPinModeOutput

#define isGpioPinModeOutput (   pinName)

Test if the mode of the GPIO pin is output (i.e., the corresponding DDRn bit is set).

§ makeGpioVarFromGpioPin

#define makeGpioVarFromGpioPin (   pinName)

Create a GPIO pin variable of type GpioPinVariable from a GPIO pin macro.

Returns
a GpioPinVariable.

§ makeGpioVarFromGpioPinAnalog

#define makeGpioVarFromGpioPinAnalog (   pinName)

Create a GPIO pin variable of type GpioPinVariable that can be used for analog-to-digital reading from a GPIO pin macro.

Returns
a GpioPinVariable that can be used for analog-to-digital reading.

§ makeGpioVarFromGpioPinPwm

#define makeGpioVarFromGpioPinPwm (   pinName)

Create a GPIO pin variable of type GpioPinVariable that can be used for PWM from a GPIO pin macro.

Returns
a GpioPinVariable that can be used for PWM.

§ readGpioPinDigital

#define readGpioPinDigital (   pinName)

Read the value of the GPIO pin (i.e., return the value of correspoinding the PINn bit).

Returns
0 (false) or a non-zero (true) value

§ setGpioPinHigh

#define setGpioPinHigh (   pinName)

Write a 1 to the GPIO pin (i.e., set the correspoinding the PORTn bit).

§ setGpioPinLow

#define setGpioPinLow (   pinName)

Write a 0 the GPIO pin (i.e., clear the correspoinding the PORTn bit).

§ setGpioPinModeInput

#define setGpioPinModeInput (   pinName)

Set the mode of the GPIO pin to input (i.e., clear the corresponding DDRn and PORTn bits).

§ setGpioPinModeInputPullup

#define setGpioPinModeInputPullup (   pinName)

Set the mode of the GPIO pin to input with pullup (i.e., clear the corresponding DDRn bit and set the PORTn bit).

§ setGpioPinModeOutput

#define setGpioPinModeOutput (   pinName)

Set the mode of the GPIO pin to output (i.e., set the corresponding DDRn bit).

§ writeGpioPinDigital

#define writeGpioPinDigital (   pinName,
  val 
)

Write a value the GPIO pin (i.e., set or clear the correspoinding the PORTn bit).

  • pinName a GPIO pin name macro generated by either GpioPin(), GpioPinAnalog(), or GpioPinPwm().
  • val the value to be written: 0 means to clear the GPIO pin; any other value means to set it.

Enumeration Type Documentation

§ anonymous enum

anonymous enum

Constants for digital values representing LOW and HIGH.

Enumerator
kDigitalLow 

Value representing digital LOW.

kDigitalHigh 

Value representing digital HIGH.

Function Documentation

§ isGpioPinModeInputV()

bool isGpioPinModeInputV ( const GpioPinVariable pinVar)
inline

Test if the mode of the GPIO pin is input (i.e., the corresponding DDRn is clear).

§ isGpioPinModeOutputV()

bool isGpioPinModeOutputV ( const GpioPinVariable pinVar)
inline

Test if the mode of the GPIO pin is output (i.e., the corresponding DDRn bit is set).

§ readGpioPinDigitalV()

bool readGpioPinDigitalV ( const GpioPinVariable pinVar)
inline

Read the value of the GPIO pin (i.e., return the value of correspoinding the PINn bit).

Returns
0 (false) or 1 (true)

§ setGpioPinHighV()

void setGpioPinHighV ( const GpioPinVariable pinVar)
inline

Write a 1 to the GPIO pin (i.e., set the correspoinding the PORTn bit).

§ setGpioPinLowV()

void setGpioPinLowV ( const GpioPinVariable pinVar)
inline

Write a 0 to the GPIO pin (i.e., clear the correspoinding the PORTn bit).

§ setGpioPinModeInputPullupV()

void setGpioPinModeInputPullupV ( const GpioPinVariable pinVar)
inline

Set the mode of the GPIO pin to input with pullup (i.e., clear the corresponding DDRn bit and set the PORTn bit).

§ setGpioPinModeInputV()

void setGpioPinModeInputV ( const GpioPinVariable pinVar)
inline

Set the mode of the GPIO pin to input (i.e., clear the corresponding DDRn and PORTn bits).

§ setGpioPinModeOutputV()

void setGpioPinModeOutputV ( const GpioPinVariable pinVar)
inline

Set the mode of the GPIO pin to output (i.e., set the corresponding DDRn bit).

§ writeGpioPinDigitalV()

void writeGpioPinDigitalV ( const GpioPinVariable pinVar,
bool  value 
)
inline

Write a value the GPIO pin (i.e., set or clear the correspoinding the PORTn bit).

  • pinVar a GPIO pin variable of type GpioPinVariable.
  • val the value to be written: 0 means to clear the GPIO pin; any other value means to set it.