From 4627f66caad1c8f7366b85bb298bc6af5d2d7b82 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 22 Oct 2024 16:28:58 +0200 Subject: [PATCH] drivers/periph/gpio: make gpio_write() take a bool --- cpu/atmega_common/periph/gpio.c | 2 +- cpu/atxmega/periph/gpio.c | 2 +- cpu/cc2538/periph/gpio.c | 2 +- cpu/cc26xx_cc13xx/periph/gpio.c | 2 +- cpu/efm32/periph/gpio.c | 2 +- cpu/esp32/periph/gpio.c | 4 ++-- cpu/esp8266/periph/gpio.c | 2 +- cpu/fe310/periph/gpio.c | 2 +- cpu/gd32v/periph/gpio.c | 2 +- cpu/kinetis/periph/gpio.c | 2 +- cpu/lm4f120/periph/gpio.c | 2 +- cpu/lpc1768/periph/gpio.c | 2 +- cpu/lpc23xx/periph/gpio.c | 6 +++--- cpu/msp430/periph/gpio.c | 2 +- cpu/native/periph/gpio_linux.c | 2 +- cpu/native/periph/gpio_mock.c | 2 +- cpu/nrf5x_common/periph/gpio.c | 2 +- cpu/qn908x/periph/gpio.c | 2 +- cpu/rpx0xx/periph/gpio.c | 2 +- cpu/sam0_common/periph/gpio.c | 2 +- cpu/sam3/periph/gpio.c | 2 +- cpu/stm32/periph/gpio_all.c | 2 +- cpu/stm32/periph/gpio_f1.c | 2 +- drivers/include/periph/gpio.h | 3 ++- 24 files changed, 28 insertions(+), 27 deletions(-) diff --git a/cpu/atmega_common/periph/gpio.c b/cpu/atmega_common/periph/gpio.c index 8ae427fc1c..b59a1f703e 100644 --- a/cpu/atmega_common/periph/gpio.c +++ b/cpu/atmega_common/periph/gpio.c @@ -179,7 +179,7 @@ void gpio_toggle(gpio_t pin) } } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { if (value) { gpio_set(pin); diff --git a/cpu/atxmega/periph/gpio.c b/cpu/atxmega/periph/gpio.c index d672ff2a24..8f67990e05 100644 --- a/cpu/atxmega/periph/gpio.c +++ b/cpu/atxmega/periph/gpio.c @@ -306,7 +306,7 @@ void gpio_toggle(gpio_t pin) } } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { DEBUG("gpio_write pin = 0x%04x, value = 0x%02x \n", pin, value); diff --git a/cpu/cc2538/periph/gpio.c b/cpu/cc2538/periph/gpio.c index b7849c0609..861810d4f9 100644 --- a/cpu/cc2538/periph/gpio.c +++ b/cpu/cc2538/periph/gpio.c @@ -142,7 +142,7 @@ void gpio_toggle(gpio_t pin) gpio(pin)->DATA ^= _pin_mask(pin); } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { if (value) { gpio(pin)->DATA |= _pin_mask(pin); diff --git a/cpu/cc26xx_cc13xx/periph/gpio.c b/cpu/cc26xx_cc13xx/periph/gpio.c index 74fd13f1fa..82847bb194 100644 --- a/cpu/cc26xx_cc13xx/periph/gpio.c +++ b/cpu/cc26xx_cc13xx/periph/gpio.c @@ -81,7 +81,7 @@ void gpio_toggle(gpio_t pin) GPIO->DOUTTGL = (1 << pin); } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { if (value) { GPIO->DOUTSET = (1 << pin); diff --git a/cpu/efm32/periph/gpio.c b/cpu/efm32/periph/gpio.c index 01cb037ead..589c7adf3e 100644 --- a/cpu/efm32/periph/gpio.c +++ b/cpu/efm32/periph/gpio.c @@ -93,7 +93,7 @@ void gpio_toggle(gpio_t pin) GPIO_PinOutToggle(_port_num(pin), _pin_num(pin)); } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { if (value) { GPIO_PinOutSet(_port_num(pin), _pin_num(pin)); diff --git a/cpu/esp32/periph/gpio.c b/cpu/esp32/periph/gpio.c index cb1b70569e..9050f011f1 100644 --- a/cpu/esp32/periph/gpio.c +++ b/cpu/esp32/periph/gpio.c @@ -351,7 +351,7 @@ int gpio_read(gpio_t pin) return value; } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { DEBUG("%s gpio=%u val=%d\n", __func__, pin, value); assert(pin < GPIO_PIN_NUMOF); @@ -412,7 +412,7 @@ int gpio_read(gpio_t pin) return value; } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { DEBUG("%s gpio=%u val=%d\n", __func__, pin, value); assert(pin < GPIO_PIN_NUMOF); diff --git a/cpu/esp8266/periph/gpio.c b/cpu/esp8266/periph/gpio.c index 1644670965..d94f3ab8d7 100644 --- a/cpu/esp8266/periph/gpio.c +++ b/cpu/esp8266/periph/gpio.c @@ -249,7 +249,7 @@ int gpio_read (gpio_t pin) return (GPIO.IN & BIT(pin)) ? 1 : 0; } -void gpio_write (gpio_t pin, int value) +void gpio_write (gpio_t pin, bool value) { DEBUG("%s: %d %d\n", __func__, pin, value); diff --git a/cpu/fe310/periph/gpio.c b/cpu/fe310/periph/gpio.c index 3f3d790c05..c923b8e3e1 100644 --- a/cpu/fe310/periph/gpio.c +++ b/cpu/fe310/periph/gpio.c @@ -111,7 +111,7 @@ void gpio_toggle(gpio_t pin) __ATOMIC_RELAXED); } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { if (value) { _set_pin_reg(GPIO_OUTPUT_VAL, pin); diff --git a/cpu/gd32v/periph/gpio.c b/cpu/gd32v/periph/gpio.c index 36ce51f474..f15ed83669 100644 --- a/cpu/gd32v/periph/gpio.c +++ b/cpu/gd32v/periph/gpio.c @@ -195,7 +195,7 @@ void gpio_toggle(gpio_t pin) } } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { if (value) { gpio_set(pin); diff --git a/cpu/kinetis/periph/gpio.c b/cpu/kinetis/periph/gpio.c index 1b674be68b..df62aa6f89 100644 --- a/cpu/kinetis/periph/gpio.c +++ b/cpu/kinetis/periph/gpio.c @@ -272,7 +272,7 @@ void gpio_toggle(gpio_t pin) gpio(pin)->PTOR = (1 << pin_num(pin)); } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { if (value) { gpio(pin)->PSOR = (1 << pin_num(pin)); diff --git a/cpu/lm4f120/periph/gpio.c b/cpu/lm4f120/periph/gpio.c index 1970ea071e..7d158616a7 100644 --- a/cpu/lm4f120/periph/gpio.c +++ b/cpu/lm4f120/periph/gpio.c @@ -157,7 +157,7 @@ void gpio_toggle(gpio_t pin) } } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { if (value) { gpio_set(pin); diff --git a/cpu/lpc1768/periph/gpio.c b/cpu/lpc1768/periph/gpio.c index ba2775eb06..75b3217c50 100644 --- a/cpu/lpc1768/periph/gpio.c +++ b/cpu/lpc1768/periph/gpio.c @@ -120,7 +120,7 @@ void gpio_toggle(gpio_t pin) base->FIOPIN ^= (1 << _pin(pin)); } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { LPC_GPIO_TypeDef *base = _base(pin); diff --git a/cpu/lpc23xx/periph/gpio.c b/cpu/lpc23xx/periph/gpio.c index dadad5911b..88033646c9 100644 --- a/cpu/lpc23xx/periph/gpio.c +++ b/cpu/lpc23xx/periph/gpio.c @@ -133,13 +133,13 @@ void gpio_toggle(gpio_t dev) } } -void gpio_write(gpio_t dev, int value) +void gpio_write(gpio_t pin, bool value) { if (value) { - gpio_set(dev); + gpio_set(pin); } else { - gpio_clear(dev); + gpio_clear(pin); } } diff --git a/cpu/msp430/periph/gpio.c b/cpu/msp430/periph/gpio.c index 2629e906d5..af1ea5ec8c 100644 --- a/cpu/msp430/periph/gpio.c +++ b/cpu/msp430/periph/gpio.c @@ -138,7 +138,7 @@ void gpio_toggle(gpio_t pin) _port(pin)->OD ^= _pin_mask(pin); } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { if (value) { _port(pin)->OD |= _pin_mask(pin); diff --git a/cpu/native/periph/gpio_linux.c b/cpu/native/periph/gpio_linux.c index f9424d77d4..a554628d97 100644 --- a/cpu/native/periph/gpio_linux.c +++ b/cpu/native/periph/gpio_linux.c @@ -210,7 +210,7 @@ void gpio_toggle(gpio_t pin) _set(pin, !gpio_read(pin)); } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { _set(pin, value); } diff --git a/cpu/native/periph/gpio_mock.c b/cpu/native/periph/gpio_mock.c index 3e75755eea..a335f2ddec 100644 --- a/cpu/native/periph/gpio_mock.c +++ b/cpu/native/periph/gpio_mock.c @@ -92,7 +92,7 @@ __attribute__((weak)) void gpio_toggle(gpio_t pin) { } } -__attribute__((weak)) void gpio_write(gpio_t pin, int value) { +__attribute__((weak)) void gpio_write(gpio_t pin, bool value) { if (pin) { pin->value = value; } diff --git a/cpu/nrf5x_common/periph/gpio.c b/cpu/nrf5x_common/periph/gpio.c index 0f762a8802..2ede21d588 100644 --- a/cpu/nrf5x_common/periph/gpio.c +++ b/cpu/nrf5x_common/periph/gpio.c @@ -151,7 +151,7 @@ void gpio_toggle(gpio_t pin) port(pin)->OUT ^= (1 << pin_num(pin)); } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { if (value) { port(pin)->OUTSET = (1 << pin_num(pin)); diff --git a/cpu/qn908x/periph/gpio.c b/cpu/qn908x/periph/gpio.c index 1ed86b4e7b..761eefbf37 100644 --- a/cpu/qn908x/periph/gpio.c +++ b/cpu/qn908x/periph/gpio.c @@ -232,7 +232,7 @@ void gpio_toggle(gpio_t pin) base->OUTENSET = out_clr & dataout; } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { if (value) { gpio_set(pin); diff --git a/cpu/rpx0xx/periph/gpio.c b/cpu/rpx0xx/periph/gpio.c index 96afefd06b..f8ec327404 100644 --- a/cpu/rpx0xx/periph/gpio.c +++ b/cpu/rpx0xx/periph/gpio.c @@ -131,7 +131,7 @@ void gpio_toggle(gpio_t pin) SIO->GPIO_OUT_XOR = 1LU << pin; } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { if (value) { gpio_set(pin); diff --git a/cpu/sam0_common/periph/gpio.c b/cpu/sam0_common/periph/gpio.c index 7d58b950da..5fd7ed2057 100644 --- a/cpu/sam0_common/periph/gpio.c +++ b/cpu/sam0_common/periph/gpio.c @@ -230,7 +230,7 @@ void gpio_toggle(gpio_t pin) _port_iobus(pin)->OUTTGL.reg = _pin_mask(pin); } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { if (value) { _port_iobus(pin)->OUTSET.reg = _pin_mask(pin); diff --git a/cpu/sam3/periph/gpio.c b/cpu/sam3/periph/gpio.c index ccf2e7ae65..4edee67e3d 100644 --- a/cpu/sam3/periph/gpio.c +++ b/cpu/sam3/periph/gpio.c @@ -225,7 +225,7 @@ void gpio_toggle(gpio_t pin) } } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { if (value) { _port(pin)->PIO_SODR = (1 << _pin_num(pin)); diff --git a/cpu/stm32/periph/gpio_all.c b/cpu/stm32/periph/gpio_all.c index 24ea499d8b..f7403b463f 100644 --- a/cpu/stm32/periph/gpio_all.c +++ b/cpu/stm32/periph/gpio_all.c @@ -227,7 +227,7 @@ void gpio_toggle(gpio_t pin) } } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { if (value) { gpio_set(pin); diff --git a/cpu/stm32/periph/gpio_f1.c b/cpu/stm32/periph/gpio_f1.c index a53f0da7d6..18359fa137 100644 --- a/cpu/stm32/periph/gpio_f1.c +++ b/cpu/stm32/periph/gpio_f1.c @@ -180,7 +180,7 @@ void gpio_toggle(gpio_t pin) } } -void gpio_write(gpio_t pin, int value) +void gpio_write(gpio_t pin, bool value) { if (value) { _port(pin)->BSRR = (1 << _pin_num(pin)); diff --git a/drivers/include/periph/gpio.h b/drivers/include/periph/gpio.h index ae78be931f..8a07104984 100644 --- a/drivers/include/periph/gpio.h +++ b/drivers/include/periph/gpio.h @@ -76,6 +76,7 @@ #define PERIPH_GPIO_H #include +#include #include "periph_cpu.h" #include "periph_conf.h" @@ -258,7 +259,7 @@ void gpio_toggle(gpio_t pin); * @param[in] pin the pin to set * @param[in] value value to set the pin to, 0 for LOW, HIGH otherwise */ -void gpio_write(gpio_t pin, int value); +void gpio_write(gpio_t pin, bool value); /** * @brief Test if a GPIO pin is equal to another GPIO pin