Nut/OS  4.10.3
API Reference
porttran.h File Reference

Port translations. More...

#include <cfg/arch.h>
Include dependency graph for porttran.h:

Go to the source code of this file.

Defines

#define GPIO_SET_LO(b)
#define GPIO_SET_HI(b)
#define GPIO_IS_HI(b)
#define GPIO_GET(b)
#define GPIO_ENABLE(b)
#define GPIO_OUTPUT(b)
#define GPIO_INPUT(b)
#define GPIO_PULLUP_ON(b)
#define GPIO_PULLUP_OFF(b)
#define GPIO_FILTER_ON(b)
#define GPIO_FILTER_OFF(b)
#define GPIO_OPENDRAIN(b)
#define GPIO_PUSHPULL(b)

Detailed Description

Port translations.

This header file determines the target specific GPIO register names by a simple configured port identifier. In addition it provides several macros to configure, set, clear or query GPIO bits.

Unlike most other header files, this one may be included several times within a single source file, typically once for each configured identifier.

 #undef GPIO_ID
 #define GPIO_ID MY_PORT1_ID
 #include <cfg/arch/porttran.h>
 static INLINE void MY_PORT1_SET(int bit) { GPIO_SET_HI(bit); }
 static INLINE void MY_PORT1_CLR(int bit) { GPIO_SET_LO(bit); }

 #undef GPIO_ID
 #define GPIO_ID MY_PORT2_ID
 #include <cfg/arch/porttran.h>
 static INLINE void MY_PORT2_SET(int bit) { GPIO_SET_HI(bit); }
 static INLINE void MY_PORT2_CLR(int bit) { GPIO_SET_LO(bit); }

 void Out1(int bit, int val)
 {
   if (val)
     MY_PORT1_SET(bit);
   else
     MY_PORT1_CLR(bit);
 }

 void Toogle2(int bit)
 {
   MY_PORT2_SET(bit);
   MY_PORT2_CLR(bit);
 }

In contrast to the routines in dev/gpio.h, these macros do not require any function call and will therefore produce faster and smaller code. The following macros are currently available:

  • GPIO_SET_LO Sets output low.
  • GPIO_SET_HI Sets output high.
  • GPIO_IS_HI Returns output status.
  • GPIO_GET Returns input status.
  • GPIO_ENABLE Enables GPIO function.
  • GPIO_OUTPUT Configures an output.
  • GPIO_INPUT Configures an input.
  • GPIO_PULLUP_ON Enables input pull-up resistor.
  • GPIO_PULLUP_OFF Disables input pull-up resistor.
  • GPIO_FILTER_ON Enables glitch input filter.
  • GPIO_FILTER_OFF Disables glitch input filter.
  • GPIO_OPENDRAIN Configures open drain output mode.
  • GPIO_PUSHPULL Configures push/pull output mode.
Note:
All listed macros will be available for any port identifier on any target, even if the related function is not available. You should check the target's datasheet.
We use capital letters for the inline attribute to refer to a preprocessor macro. If the compiler doesn't support inlined function, then the macro will be empty. In this case a function call may be used, depending on the compiler's optimization strategy. Even if the compiler supports the inline keyword, it may decide to generate a callable function.

Definition in file porttran.h.