From 147b79169c773f0471f1c507603cc5ec94e9ad1c Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Fri, 17 Jan 2020 08:08:21 +0100 Subject: [PATCH] drivers/periph/gpio: add comparison functions The expandable GPIO API requires the comparison of structured GPIO types. This means that inline functions must be used instead of direct comparisons. For the migration process, drivers and other modules must first be changed so that they use the inline comparison functions. --- drivers/include/periph/gpio.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/include/periph/gpio.h b/drivers/include/periph/gpio.h index 8f06b98fe3..961e481438 100644 --- a/drivers/include/periph/gpio.h +++ b/drivers/include/periph/gpio.h @@ -43,6 +43,11 @@ * definitions in `RIOT/boards/ * /include/periph_conf.h` will define the selected * GPIO pin. * + * @warning The scalar GPIO pin type `gpio_t` is deprecated and will be + * replaced by a structured GPIO pin type in a future GPIO API. Therefore, + * don't use the direct comparison of GPIO pins anymore. Instead, use the + * inline comparison functions @ref gpio_is_equal and @ref gpio_is_valid. + * * # (Low-) Power Implications * * On almost all platforms, we can only control the peripheral power state of @@ -253,6 +258,27 @@ void gpio_toggle(gpio_t pin); */ void gpio_write(gpio_t pin, int value); +/** + * @brief Test if a GPIO pin is equal to another GPIO pin + * + * @param[in] gpio1 First GPIO pin to check + * @param[in] gpio2 Second GPIO pin to check + */ +static inline int gpio_is_equal(gpio_t gpio1, gpio_t gpio2) +{ + return (gpio1 == gpio2); +} + +/** + * @brief Test if a GPIO pin is a valid pin and not declared as undefined. + * + * @param[in] gpio GPIO pin to check + */ +static inline int gpio_is_valid(gpio_t gpio) +{ + return (gpio != GPIO_UNDEF); +} + #ifdef __cplusplus } #endif