dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages

Provides an interface to configure and efficiently use GPIOs. More...

Macros

#define DIO_NULL   ((uintptr_t) 0)
 
#define DIO_BASE   ( (uintptr_t) GPIOA )
 
#define DIO_PORT_OFFSET(port)   (((uintptr_t) (port)) - DIO_BASE)
 
#define DIO_MAKE_TAG(port, pin)   ((uintptr_t) ((DIO_PORT_OFFSET(port) << 16) | ((uint16_t) (pin))))
 
#define GPIOA_DIO(pin_num)   DIO_MAKE_TAG(GPIOA, 1<<(pin_num))
 
#define GPIOB_DIO(pin_num)   DIO_MAKE_TAG(GPIOB, 1<<(pin_num))
 
#define GPIOC_DIO(pin_num)   DIO_MAKE_TAG(GPIOC, 1<<(pin_num))
 
#define GPIOD_DIO(pin_num)   DIO_MAKE_TAG(GPIOD, 1<<(pin_num))
 
#define GPIOE_DIO(pin_num)   DIO_MAKE_TAG(GPIOE, 1<<(pin_num))
 
#define GPIOF_DIO(pin_num)   DIO_MAKE_TAG(GPIOF, 1<<(pin_num))
 
#define GET_DIO_PORT(dio)   ( (GPIO_TypeDef *) (((dio) >> 16) + DIO_BASE) )
 
#define GET_DIO_PIN(dio)   ((dio) & 0xffff)
 
#define _DIO_PRELUDE_RET(s)
 
#define _DIO_PRELUDE
 
#define DIO_SETREGS_FOURWIDE(reglow, reghigh, idx, val)
 
#define DIO_SETREG_TWOWIDE(reg, idx, val)
 
#define DIO_SETREG_ONEWIDE(reg, idx, val)
 

Typedefs

typedef uintptr_t dio_tag_t
 

Enumerations

enum  dio_pin_function { DIO_PIN_INPUT = 0, DIO_PIN_OUTPUT = 1, DIO_PIN_ALTFUNC = 2, DIO_PIN_ANALOG = 3 }
 
enum  dio_pull { DIO_PULL_NONE = 0, DIO_PULL_UP, DIO_PULL_DOWN }
 

Functions

static void dio_set_altfunc_output (dio_tag_t t, int alt_func, bool open_collector, enum dio_drive_strength strength)
 Configures a GPIO as alternate function output. More...
 
static void dio_set_altfunc_input (dio_tag_t t, int alt_func, enum dio_pull pull)
 Configures a GPIO as alternate function input. More...
 
static void dio_set_analog (dio_tag_t t)
 Configures a GPIO as analog. Disables pullups/pulldowns, etc. More...
 
static void dio_set_output (dio_tag_t t, bool open_collector, enum dio_drive_strength strength, bool first_value)
 Configures a GPIO as an output. More...
 
static void dio_toggle (dio_tag_t t)
 Toggles an output GPIO to the opposite level. More...
 
static void dio_high (dio_tag_t t)
 Sets an output GPIO high. More...
 
static void dio_low (dio_tag_t t)
 Sets an output GPIO low. More...
 
static void dio_write (dio_tag_t t, bool high)
 Sets an output GPIO to a chosen logical level. More...
 
static void dio_set_input (dio_tag_t t, enum dio_pull pull)
 Configures a GPIO as an input. More...
 
static bool dio_read (dio_tag_t t)
 Reads a GPIO logical value. More...
 

Detailed Description

Provides an interface to configure and efficiently use GPIOs.

DIO holds a GPIO specifier (bank, pin) in a pointer-width integer. Inline functions in this module provide an efficient interface by which to set/reset/toggle/read the GPIO.

Partially inspired by the iotag subsystem in CleanFlight/BetaFlight.

To use this module, first store a GPIO into a dio_tag_t – e.g.

dio_tag_t t = GPIOA_DIO(4);

for pin A4 on STM32. Then use the below functions to access it.

Macro Definition Documentation

#define _DIO_PRELUDE
Value:
if (t == DIO_NULL) { return; } \
GPIO_TypeDef * gp = GET_DIO_PORT(t); \
uint16_t pin = GET_DIO_PIN(t);
#define GET_DIO_PIN(dio)
Definition: pios_dio.h:182
#define GET_DIO_PORT(dio)
Definition: pios_dio.h:180
#define DIO_NULL
Definition: pios_dio.h:86

Definition at line 189 of file pios_dio.h.

#define _DIO_PRELUDE_RET (   s)
Value:
if (t == DIO_NULL) { return (s); } \
GPIO_TypeDef * gp = GET_DIO_PORT(t); \
uint16_t pin = GET_DIO_PIN(t);
#define GET_DIO_PIN(dio)
Definition: pios_dio.h:182
#define GET_DIO_PORT(dio)
Definition: pios_dio.h:180
#define DIO_NULL
Definition: pios_dio.h:86

Definition at line 184 of file pios_dio.h.

#define DIO_BASE   ( (uintptr_t) GPIOA )

Definition at line 167 of file pios_dio.h.

#define DIO_MAKE_TAG (   port,
  pin 
)    ((uintptr_t) ((DIO_PORT_OFFSET(port) << 16) | ((uint16_t) (pin))))

Definition at line 171 of file pios_dio.h.

#define DIO_NULL   ((uintptr_t) 0)

Definition at line 86 of file pios_dio.h.

#define DIO_PORT_OFFSET (   port)    (((uintptr_t) (port)) - DIO_BASE)

Definition at line 169 of file pios_dio.h.

#define DIO_SETREG_ONEWIDE (   reg,
  idx,
  val 
)
Value:
do { \
int __pos = (idx); \
(reg) = ((reg) & ~(1 << (__pos))) | ( (val) << __pos); \
} while (0)

Definition at line 252 of file pios_dio.h.

#define DIO_SETREG_TWOWIDE (   reg,
  idx,
  val 
)
Value:
do { \
int __pos = (idx); \
(reg) = ((reg) & ~(3 << (__pos * 2))) | ( (val) << (__pos * 2)); \
} while (0)

Definition at line 246 of file pios_dio.h.

#define DIO_SETREGS_FOURWIDE (   reglow,
  reghigh,
  idx,
  val 
)
Value:
do { \
int __pos = (idx); \
if (__pos >= 8) { \
__pos -= 8; \
(reghigh) = ((reghigh) & ~(15 << (__pos * 4))) | ( (val) << (__pos * 4)); \
} else { \
(reglow) = ((reglow) & ~(15 << (__pos * 4))) | ( (val) << (__pos * 4)); \
} \
} while (0)
if(BaroAltitudeHandle()!=NULL)

Definition at line 235 of file pios_dio.h.

#define GET_DIO_PIN (   dio)    ((dio) & 0xffff)

Definition at line 182 of file pios_dio.h.

#define GET_DIO_PORT (   dio)    ( (GPIO_TypeDef *) (((dio) >> 16) + DIO_BASE) )

Definition at line 180 of file pios_dio.h.

#define GPIOA_DIO (   pin_num)    DIO_MAKE_TAG(GPIOA, 1<<(pin_num))

Definition at line 173 of file pios_dio.h.

#define GPIOB_DIO (   pin_num)    DIO_MAKE_TAG(GPIOB, 1<<(pin_num))

Definition at line 174 of file pios_dio.h.

#define GPIOC_DIO (   pin_num)    DIO_MAKE_TAG(GPIOC, 1<<(pin_num))

Definition at line 175 of file pios_dio.h.

#define GPIOD_DIO (   pin_num)    DIO_MAKE_TAG(GPIOD, 1<<(pin_num))

Definition at line 176 of file pios_dio.h.

#define GPIOE_DIO (   pin_num)    DIO_MAKE_TAG(GPIOE, 1<<(pin_num))

Definition at line 177 of file pios_dio.h.

#define GPIOF_DIO (   pin_num)    DIO_MAKE_TAG(GPIOF, 1<<(pin_num))

Definition at line 178 of file pios_dio.h.

Typedef Documentation

typedef uintptr_t dio_tag_t

Definition at line 84 of file pios_dio.h.

Enumeration Type Documentation

Enumerator
DIO_PIN_INPUT 
DIO_PIN_OUTPUT 
DIO_PIN_ALTFUNC 
DIO_PIN_ANALOG 

Definition at line 71 of file pios_dio.h.

enum dio_pull
Enumerator
DIO_PULL_NONE 
DIO_PULL_UP 
DIO_PULL_DOWN 

Definition at line 78 of file pios_dio.h.

Function Documentation

static void dio_high ( dio_tag_t  t)
inlinestatic

Sets an output GPIO high.

Parameters
[in]tThe GPIO specifier tag

Definition at line 194 of file pios_dio.h.

static void dio_low ( dio_tag_t  t)
inlinestatic

Sets an output GPIO low.

Parameters
[in]tThe GPIO specifier tag

Definition at line 205 of file pios_dio.h.

static bool dio_read ( dio_tag_t  t)
inlinestatic

Reads a GPIO logical value.

Parameters
[in]tThe GPIO specifier tag
Return values
Trueif the GPIO is high; otherwise low.

Definition at line 407 of file pios_dio.h.

static void dio_set_altfunc_input ( dio_tag_t  t,
int  alt_func,
enum dio_pull  pull 
)
inlinestatic

Configures a GPIO as alternate function input.

Parameters
[in]tThe GPIO specifier tag (created with e.g. GPIOA_DIO(3) )
[in]alt_funcThe alternate function specifier.
[in]pullPullup/Pulldown configuration.

Definition at line 299 of file pios_dio.h.

static void dio_set_altfunc_output ( dio_tag_t  t,
int  alt_func,
bool  open_collector,
enum dio_drive_strength  strength 
)
inlinestatic

Configures a GPIO as alternate function output.

Parameters
[in]tThe GPIO specifier tag (created with e.g. GPIOA_DIO(3) )
[in]alt_funcThe alternate function specifier.
[in]open_collectortrue for open-collector + pull-up semantics
[in]dio_drive_strengthThe drive strength to use for the GPIO

Definition at line 271 of file pios_dio.h.

static void dio_set_analog ( dio_tag_t  t)
inlinestatic

Configures a GPIO as analog. Disables pullups/pulldowns, etc.

Parameters
[in]tThe GPIO specifier tag (created with e.g. GPIOA_DIO(3) )

Definition at line 320 of file pios_dio.h.

static void dio_set_input ( dio_tag_t  t,
enum dio_pull  pull 
)
inlinestatic

Configures a GPIO as an input.

Parameters
[in]tThe GPIO specifier tag (created with e.g. GPIOA_DIO(3) )
[in]pullPullup/Pulldown configuration.

Definition at line 376 of file pios_dio.h.

static void dio_set_output ( dio_tag_t  t,
bool  open_collector,
enum dio_drive_strength  strength,
bool  first_value 
)
inlinestatic

Configures a GPIO as an output.

Parameters
[in]tThe GPIO specifier tag (created with e.g. GPIOA_DIO(3) )
[in]open_collectortrue for open-collector + pull-up semantics
[in]dio_drive_strengthThe drive strength to use for the GPIO
[in]first_valueWhether it should be initially driven high or low.

Definition at line 334 of file pios_dio.h.

static void dio_toggle ( dio_tag_t  t)
inlinestatic

Toggles an output GPIO to the opposite level.

Parameters
[in]tThe GPIO specifier tag

Definition at line 225 of file pios_dio.h.

static void dio_write ( dio_tag_t  t,
bool  high 
)
inlinestatic

Sets an output GPIO to a chosen logical level.

Parameters
[in]tThe GPIO specifier tag
[in]highWhether the GPIO should be high.

Definition at line 216 of file pios_dio.h.