35 #ifndef GpioPinMacros_h 36 #define GpioPinMacros_h 66 #define _GpioPin( ddr, port, pin, nbr ) \ 67 ddr, port, pin, nbr, -1, 0, -1, 0 69 #define _GpioPinAnalog( ddr, port, pin, nbr, adc ) \ 70 ddr, port, pin, nbr, adc, 0, -1, 0 72 #define _GpioPinPwm( ddr, port, pin, nbr, ocr, com, tccr ) \ 73 ddr, port, pin, nbr, -1, ocr, com, tccr 75 #define _isGpioPinModeOutput( ddr, port, pin, nbr, adc, ocr, com, tccr ) ( ddr & (1<<nbr) ) 77 #define _isGpioPinModeInput( ddr, port, pin, nbr, adc, ocr, com, tccr ) (!( ddr & (1<<nbr) )) 79 #define _setGpioPinModeOutput( ddr, port, pin, nbr, adc, ocr, com, tccr ) ddr |= (1<<nbr) 81 #define _setGpioPinModeInput( ddr, port, pin, nbr, adc, ocr, com, tccr ) ddr &= ~(1<<nbr), port &= ~(1<<nbr) 83 #define _setGpioPinModeInputPullup( ddr, port, pin, nbr, adc, ocr, com, tccr ) ddr &= ~(1<<nbr), port |= (1<<nbr) 85 #define _readGpioPinDigital( ddr, port, pin, nbr, adc, ocr, com, tccr ) ( pin & (1<<nbr) ) 87 #define _writeGpioPinDigital( ddr, port, pin, nbr, adc, ocr, com, tccr, value ) \ 88 do { if (value) port |= (1<<nbr); else port &= ~(1<<nbr); } while ( 0 ) 90 #define _setGpioPinHigh( ddr, port, pin, nbr, adc, ocr, com, tccr ) port |= (1<<nbr) 92 #define _setGpioPinLow( ddr, port, pin, nbr, adc, ocr, com, tccr ) port &= ~(1<<nbr) 94 #define _getGpioDDR( ddr, port, pin, nbr, adc, ocr, com, tccr ) ddr 96 #define _getGpioPORT( ddr, port, pin, nbr, adc, ocr, com, tccr ) port 98 #define _getGpioPIN( ddr, port, pin, nbr, adc, ocr, com, tccr ) pin 100 #define _getGpioMASK( ddr, port, pin, nbr, adc, ocr, com, tccr ) (1<<nbr) 102 #define _getGpioADC( ddr, port, pin, nbr, adc, ocr, com, tccr ) adc 104 #define _getGpioOCR( ddr, port, pin, nbr, adc, ocr, com, tccr ) ocr 106 #define _getGpioCOM( ddr, port, pin, nbr, adc, ocr, com, tccr ) com 108 #define _getGpioTCCR( ddr, port, pin, nbr, adc, ocr, com, tccr ) tccr 131 #define GpioPin( portLtr, pinNbr ) \ 132 _GpioPin( DDR##portLtr, PORT##portLtr, PIN##portLtr, pinNbr ) 146 #define GpioPinAnalog( portLtr, pinNbr, adcNbr ) \ 147 _GpioPinAnalog( DDR##portLtr, PORT##portLtr, PIN##portLtr, pinNbr, adcNbr ) 161 #define GpioPinPwm( portLtr, pinNbr, timer, chan ) \ 162 _GpioPinPwm( DDR##portLtr, PORT##portLtr, PIN##portLtr, pinNbr, OCR##timer##chan, COM##timer##chan##1, TCCR##timer##A ) 174 #define isGpioPinModeOutput( pinName ) _isGpioPinModeOutput( pinName ) 186 #define isGpioPinModeInput( pinName ) _isGpioPinModeInput( pinName ) 198 #define setGpioPinModeOutput( pinName ) _setGpioPinModeOutput( pinName ) 210 #define setGpioPinModeInput( pinName ) _setGpioPinModeInput( pinName ) 222 #define setGpioPinModeInputPullup( pinName ) _setGpioPinModeInputPullup( pinName ) 236 #define readGpioPinDigital( pinName ) _readGpioPinDigital( pinName ) 248 #define writeGpioPinDigital( pinName, val ) _writeGpioPinDigital( pinName, val ) 260 #define setGpioPinHigh( pinName ) _setGpioPinHigh( pinName ) 272 #define setGpioPinLow( pinName ) _setGpioPinLow( pinName ) 286 #define getGpioDDR( pinName ) _getGpioDDR( pinName ) 300 #define getGpioPORT( pinName ) _getGpioPORT( pinName ) 314 #define getGpioPIN( pinName ) _getGpioPIN( pinName ) 328 #define getGpioMASK( pinName ) _getGpioMASK( pinName ) 342 #define getGpioADC( pinName ) _getGpioADC( pinName ) 356 #define getGpioOCR( pinName ) _getGpioOCR( pinName ) 370 #define getGpioCOM( pinName ) _getGpioCOM( pinName ) 384 #define getGpioTCCR( pinName ) _getGpioTCCR( pinName ) 397 typedef volatile uint8_t* Gpio8Ptr;
398 typedef volatile uint16_t* Gpio16Ptr;
429 : mDdr( 0 ), mPort( 0 ), mPin( 0 ), mOcr( 0 ), mTccr( 0 ), mCom( 0xFF ),
430 mNbr( 0xFF ), mAdc( 0xFF )
434 : mDdr( ddr ), mPort( port ), mPin( pin ), mOcr( 0 ), mTccr( 0 ), mCom( 0xFF ),
435 mNbr( static_cast<uint8_t>(nbr) ), mAdc( 0xFF )
438 GpioPinVariable( Gpio8Ptr ddr, Gpio8Ptr port, Gpio8Ptr pin, int8_t nbr, int8_t adc )
439 : mDdr( ddr ), mPort( port ), mPin( pin ), mOcr( 0 ), mTccr( 0 ), mCom( 0xFF ),
440 mNbr( static_cast<uint8_t>(nbr) ), mAdc( static_cast<uint8_t>(adc) )
444 : mDdr( ddr ), mPort( port ), mPin( pin ), mOcr( ocr ), mTccr( tccr ), mCom( com ),
445 mNbr( static_cast<uint8_t>(nbr) ), mAdc( 0xFF )
497 #define _makeGpioVarFromGpioPin( ddr, port, pin, nbr, adc, ocr, com, tccr ) \ 498 GpioPinVariable( &(ddr), &(port), &(pin), nbr ) 500 #define _makeGpioVarFromGpioPinAnalog( ddr, port, pin, nbr, adc, ocr, com, tccr ) \ 501 GpioPinVariable( &(ddr), &(port), &(pin), nbr, adc ) 503 #define _makeGpioVarFromGpioPinPwm( ddr, port, pin, nbr, adc, ocr, com, tccr ) \ 504 GpioPinVariable( &(ddr), &(port), &(pin), nbr, ocr, tccr, com ) 518 #define makeGpioVarFromGpioPin( pinName ) _makeGpioVarFromGpioPin( pinName ) 531 #define makeGpioVarFromGpioPinAnalog( pinName ) _makeGpioVarFromGpioPinAnalog( pinName ) 544 #define makeGpioVarFromGpioPinPwm( pinName ) _makeGpioVarFromGpioPinPwm( pinName ) 558 return *(pinVar.
ddr()) & ( 1 << pinVar.
bitNbr() );
570 return !( *(pinVar.
ddr()) & ( 1 << pinVar.
bitNbr() ) );
587 *(pinVar.
ddr()) |= (1 << pinVar.
bitNbr() );
603 *(pinVar.
ddr()) &= ~( 1 << pinVar.
bitNbr() );
604 *(pinVar.
port()) &= ~( 1 << pinVar.
bitNbr() );
619 *(pinVar.
ddr()) &= ~( 1 << pinVar.
bitNbr() );
637 return *(pinVar.
pin()) & ( 1 << pinVar.
bitNbr() );
660 *(pinVar.
port()) &= ~( 1 << pinVar.
bitNbr() );
692 *(pinVar.
port()) &= ~( 1 << pinVar.
bitNbr() );
void writeGpioPinDigitalV(const GpioPinVariable &pinVar, bool value)
Write a value the GPIO pin (i.e., set or clear the correspoinding the PORTn bit). ...
Definition: GpioPinMacros.h:652
bool readGpioPinDigitalV(const GpioPinVariable &pinVar)
Read the value of the GPIO pin (i.e., return the value of correspoinding the PINn bit)...
Definition: GpioPinMacros.h:635
void setGpioPinModeInputV(const GpioPinVariable &pinVar)
Set the mode of the GPIO pin to input (i.e., clear the corresponding DDRn and PORTn bits)...
Definition: GpioPinMacros.h:601
bool isGpioPinModeInputV(const GpioPinVariable &pinVar)
Test if the mode of the GPIO pin is input (i.e., the corresponding DDRn is clear).
Definition: GpioPinMacros.h:568
Gpio16Ptr ocr() const
Return a pointer to the OCR register (PWM related).
Definition: GpioPinMacros.h:461
Value representing digital HIGH.
Definition: GpioPinMacros.h:50
Gpio8Ptr pin() const
Return a pointer to the PIN register.
Definition: GpioPinMacros.h:457
void setGpioPinModeOutputV(const GpioPinVariable &pinVar)
Set the mode of the GPIO pin to output (i.e., set the corresponding DDRn bit).
Definition: GpioPinMacros.h:585
uint8_t adcNbr() const
Return the ADC channel number (analog-to-digital related).
Definition: GpioPinMacros.h:477
Gpio8Ptr ddr() const
Return a pointer to the DDR register.
Definition: GpioPinMacros.h:449
void setGpioPinHighV(const GpioPinVariable &pinVar)
Write a 1 to the GPIO pin (i.e., set the correspoinding the PORTn bit).
Definition: GpioPinMacros.h:674
uint8_t bitNbr() const
Return the bit number of this GPIO pin within the DDR, PORT, and PIN registers.
Definition: GpioPinMacros.h:469
Gpio8Ptr tccr() const
Return a pointer to the TCCR register (PWM related).
Definition: GpioPinMacros.h:465
Value representing digital LOW.
Definition: GpioPinMacros.h:49
Gpio8Ptr port() const
Return a pointer to the PORT register.
Definition: GpioPinMacros.h:453
bool isGpioPinModeOutputV(const GpioPinVariable &pinVar)
Test if the mode of the GPIO pin is output (i.e., the corresponding DDRn bit is set).
Definition: GpioPinMacros.h:556
uint8_t com() const
Return the bit number needed for manipulating TCCR register (PWM related).
Definition: GpioPinMacros.h:473
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...
Definition: GpioPinMacros.h:617
This class defines a type that can encode a GPIO pin as a variable. Read the section on GPIO Pin Vari...
Definition: GpioPinMacros.h:424
void setGpioPinLowV(const GpioPinVariable &pinVar)
Write a 0 to the GPIO pin (i.e., clear the correspoinding the PORTn bit).
Definition: GpioPinMacros.h:690