Provides an interface to configure and efficiently use GPIOs.
More...
|
#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) |
|
|
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...
|
|
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.
Value:
#define GET_DIO_PORT(dio)
Definition at line 189 of file pios_dio.h.
#define _DIO_PRELUDE_RET |
( |
|
s | ) |
|
Value:
#define GET_DIO_PORT(dio)
Definition at line 184 of file pios_dio.h.
#define DIO_BASE ( (uintptr_t) GPIOA ) |
#define DIO_MAKE_TAG |
( |
|
port, |
|
|
|
pin |
|
) |
| ((uintptr_t) ((DIO_PORT_OFFSET(port) << 16) | ((uint16_t) (pin)))) |
#define DIO_NULL ((uintptr_t) 0) |
#define DIO_PORT_OFFSET |
( |
|
port | ) |
(((uintptr_t) (port)) - DIO_BASE) |
#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 { \
__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) |
#define GET_DIO_PORT |
( |
|
dio | ) |
( (GPIO_TypeDef *) (((dio) >> 16) + DIO_BASE) ) |
#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)) |
Enumerator |
---|
DIO_PIN_INPUT |
|
DIO_PIN_OUTPUT |
|
DIO_PIN_ALTFUNC |
|
DIO_PIN_ANALOG |
|
Definition at line 71 of file pios_dio.h.
Enumerator |
---|
DIO_PULL_NONE |
|
DIO_PULL_UP |
|
DIO_PULL_DOWN |
|
Definition at line 78 of file pios_dio.h.
Sets an output GPIO high.
- Parameters
-
[in] | t | The GPIO specifier tag |
Definition at line 194 of file pios_dio.h.
Sets an output GPIO low.
- Parameters
-
[in] | t | The GPIO specifier tag |
Definition at line 205 of file pios_dio.h.
Reads a GPIO logical value.
- Parameters
-
[in] | t | The GPIO specifier tag |
- Return values
-
True | if the GPIO is high; otherwise low. |
Definition at line 407 of file pios_dio.h.
Configures a GPIO as alternate function input.
- Parameters
-
[in] | t | The GPIO specifier tag (created with e.g. GPIOA_DIO(3) ) |
[in] | alt_func | The alternate function specifier. |
[in] | pull | Pullup/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] | t | The GPIO specifier tag (created with e.g. GPIOA_DIO(3) ) |
[in] | alt_func | The alternate function specifier. |
[in] | open_collector | true for open-collector + pull-up semantics |
[in] | dio_drive_strength | The drive strength to use for the GPIO |
Definition at line 271 of file pios_dio.h.
Configures a GPIO as analog. Disables pullups/pulldowns, etc.
- Parameters
-
[in] | t | The GPIO specifier tag (created with e.g. GPIOA_DIO(3) ) |
Definition at line 320 of file pios_dio.h.
Configures a GPIO as an input.
- Parameters
-
[in] | t | The GPIO specifier tag (created with e.g. GPIOA_DIO(3) ) |
[in] | pull | Pullup/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] | t | The GPIO specifier tag (created with e.g. GPIOA_DIO(3) ) |
[in] | open_collector | true for open-collector + pull-up semantics |
[in] | dio_drive_strength | The drive strength to use for the GPIO |
[in] | first_value | Whether it should be initially driven high or low. |
Definition at line 334 of file pios_dio.h.
Toggles an output GPIO to the opposite level.
- Parameters
-
[in] | t | The 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] | t | The GPIO specifier tag |
[in] | high | Whether the GPIO should be high. |
Definition at line 216 of file pios_dio.h.