Skip to content

Commit

Permalink
Merge pull request #20936 from maribu/drivers/periph_gpio/gpio_read/bool
Browse files Browse the repository at this point in the history
drivers/periph_gpio: let gpio_read() return bool
  • Loading branch information
maribu authored Oct 24, 2024
2 parents ae36fa4 + 7d1313b commit ba83fef
Show file tree
Hide file tree
Showing 32 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion cpu/atmega_common/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ int gpio_init(gpio_t pin, gpio_mode_t mode)
return 0;
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
return (_SFR_MEM8(atmega_pin_addr(pin)) & (1 << atmega_pin_num(pin)));
}
Expand Down
2 changes: 1 addition & 1 deletion cpu/atxmega/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void gpio_irq_disable(gpio_t pin)
}
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
PORT_t *port = _port_addr(pin);
uint8_t pin_mask = _pin_mask(pin);
Expand Down
2 changes: 1 addition & 1 deletion cpu/cc2538/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ int gpio_init(gpio_t pin, gpio_mode_t mode)
return 0;
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
return (int)(gpio(pin)->DATA & _pin_mask(pin));
}
Expand Down
2 changes: 1 addition & 1 deletion cpu/cc26xx_cc13xx/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int gpio_init(gpio_t pin, gpio_mode_t mode)
return 0;
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
if (GPIO->DOE & (1 << pin)) {
return (GPIO->DOUT >> pin) & 1;
Expand Down
2 changes: 1 addition & 1 deletion cpu/efm32/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int gpio_init(gpio_t pin, gpio_mode_t mode)
return 0;
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
return GPIO_PinInGet(_port_num(pin), _pin_num(pin));
}
Expand Down
4 changes: 2 additions & 2 deletions cpu/esp32/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ static gpio_hal_context_t _gpio_hal_ctx = {
*/
static BITFIELD(_output, GPIO_PIN_NUMOF);

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
assert(pin < GPIO_PIN_NUMOF);

Expand Down Expand Up @@ -394,7 +394,7 @@ void gpio_toggle(gpio_t pin)

#else /* IS_USED(MODULE_ESP_IDF_GPIO_HAL) */

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
assert(pin < GPIO_PIN_NUMOF);

Expand Down
2 changes: 1 addition & 1 deletion cpu/esp8266/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void gpio_irq_disable (gpio_t pin)
}
#endif /* MODULE_PERIPH_GPIO_IRQ */

int gpio_read (gpio_t pin)
bool gpio_read (gpio_t pin)
{
CHECK_PARAM_RET(pin < GPIO_PIN_NUMOF, -1);

Expand Down
2 changes: 1 addition & 1 deletion cpu/fe310/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int gpio_init(gpio_t pin, gpio_mode_t mode)
return 0;
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
return (GPIO_REG(GPIO_INPUT_VAL) & (1 << pin)) ? 1 : 0;
}
Expand Down
2 changes: 1 addition & 1 deletion cpu/gd32v/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void gpio_init_analog(gpio_t pin)
*pin_reg &= ~(0xfl << (4 * (pin_num - ((pin_num >= 8) * 8))));
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
GPIO_Type *port = _port(pin);
unsigned pin_num = _pin_num(pin);
Expand Down
2 changes: 1 addition & 1 deletion cpu/kinetis/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ void gpio_init_port(gpio_t pin, uint32_t pcr)
#endif /* KINETIS_HAVE_PCR */
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
if (gpio(pin)->PDDR & (1 << pin_num(pin))) {
return (gpio(pin)->PDOR & (1 << pin_num(pin))) ? 1 : 0;
Expand Down
2 changes: 1 addition & 1 deletion cpu/lm4f120/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int gpio_init(gpio_t pin, gpio_mode_t mode)
return 0;
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
const uint8_t port_num = _port_num(pin);
const uint32_t port_addr = _port_base[port_num];
Expand Down
2 changes: 1 addition & 1 deletion cpu/lpc1768/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int gpio_init(gpio_t pin, gpio_mode_t mode)
return 0;
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
LPC_GPIO_TypeDef *base = _base(pin);

Expand Down
2 changes: 1 addition & 1 deletion cpu/lpc23xx/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int gpio_init_mux(unsigned pin, unsigned mux)
return 0;
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
unsigned _pin = pin & 31;
unsigned port = pin >> 5;
Expand Down
2 changes: 1 addition & 1 deletion cpu/msp430/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void gpio_periph_mode(gpio_t pin, bool enable)
}
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
msp430_port_t *port = _port(pin);
if (port->DIR & _pin_mask(pin)) {
Expand Down
2 changes: 1 addition & 1 deletion cpu/native/periph/gpio_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ int gpio_init(gpio_t pin, gpio_mode_t mode)
return 0;
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
struct gpiohandle_data data;

Expand Down
2 changes: 1 addition & 1 deletion cpu/native/periph/gpio_mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ __attribute__((weak)) void gpio_irq_disable(gpio_t pin)
(void) pin;
}

__attribute__((weak)) int gpio_read(gpio_t pin) {
__attribute__((weak)) bool gpio_read(gpio_t pin) {
if (pin) {
return pin->value;
}
Expand Down
2 changes: 1 addition & 1 deletion cpu/nrf5x_common/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ int gpio_init(gpio_t pin, gpio_mode_t mode)
return 0;
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
if (port(pin)->DIR & (1 << pin_num(pin))) {
return (port(pin)->OUT & (1 << pin_num(pin))) ? 1 : 0;
Expand Down
2 changes: 1 addition & 1 deletion cpu/qn908x/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void gpio_irq_disable(gpio_t pin)

#endif /* defined(MODULE_PERIPH_GPIO_IRQ) */

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
return ((GPIO_T_ADDR(pin)->DATA) >> GPIO_T_PIN(pin)) & 1u;
}
Expand Down
2 changes: 1 addition & 1 deletion cpu/rpx0xx/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int gpio_init(gpio_t pin, gpio_mode_t mode)
return 0;
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
if (SIO->GPIO_OE & (1LU << pin)) {
/* pin is output: */
Expand Down
2 changes: 1 addition & 1 deletion cpu/sam0_common/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ int gpio_init(gpio_t pin, gpio_mode_t mode)
return 0;
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
PortGroup *port;
int mask = _pin_mask(pin);
Expand Down
2 changes: 1 addition & 1 deletion cpu/sam3/periph/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void gpio_irq_disable(gpio_t pin)
NVIC_DisableIRQ((1 << (_port_num(pin) + PIOA_IRQn)));
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
Pio *port = _port(pin);
int pin_num = _pin_num(pin);
Expand Down
2 changes: 1 addition & 1 deletion cpu/stm32/periph/gpio_all.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void gpio_irq_disable(gpio_t pin)
EXTI_REG_IMR &= ~(1 << _pin_num(pin));
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
return (_port(pin)->IDR & (1 << _pin_num(pin)));
}
Expand Down
2 changes: 1 addition & 1 deletion cpu/stm32/periph/gpio_f1.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void gpio_init_analog(gpio_t pin)
*(uint32_t *)(&_port(pin)->CRL + (pin_num >= 8)) &= ~(0xfl << (4 * (pin_num - ((pin_num >= 8) * 8))));

Check warning on line 145 in cpu/stm32/periph/gpio_f1.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
GPIO_TypeDef *port = _port(pin);
int pin_num = _pin_num(pin);
Expand Down
2 changes: 1 addition & 1 deletion drivers/dht/dht.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static void _wait_for_level(gpio_t pin, bool expected, uint32_t start)
/* Calls to ztimer_now() can be relatively slow on low end platforms.
* Mixing in a busy down-counting loop solves issues e.g. on AVR boards. */
uint8_t pre_timeout = 0;
while (((bool)gpio_read(pin) != expected) && (++pre_timeout
while ((gpio_read(pin) != expected) && (++pre_timeout
|| ztimer_now(ZTIMER_USEC) < start + SPIN_TIMEOUT)) {}
}

Expand Down
4 changes: 2 additions & 2 deletions drivers/epd_bw_spi/epd_bw_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static void epd_bw_spi_cmd_start(epd_bw_spi_params_t *p, uint8_t cmd, bool cont)
{
DEBUG("[epd_bw_spi] cmd_start: command 0x%02x\n", cmd);
if (gpio_is_valid(p->busy_pin)) {
while ((bool)gpio_read(p->busy_pin) == p->busy_value) {}
while (gpio_read(p->busy_pin) == p->busy_value) {}
}
gpio_clear(p->dc_pin);
spi_transfer_byte(p->spi, p->cs_pin, cont, (uint8_t)cmd);
Expand All @@ -52,7 +52,7 @@ static void epd_bw_spi_wait(epd_bw_spi_params_t *p, uint32_t msec)
{
if (gpio_is_valid(p->busy_pin)) {
DEBUG("[epd_bw_spi] wait: for busy bin\n");
while ((bool)gpio_read(p->busy_pin) == p->busy_value) {}
while (gpio_read(p->busy_pin) == p->busy_value) {}
}
else {
DEBUG("[epd_bw_spi] wait: for %" PRIu32 " milliseconds\n", msec);
Expand Down
6 changes: 3 additions & 3 deletions drivers/include/periph/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ void gpio_irq_disable(gpio_t pin);
*
* @param[in] pin the pin to read
*
* @return 0 when pin is LOW
* @return >0 for HIGH
* @retval false pin is LOW
* @retval true pin is HIGH
*/
int gpio_read(gpio_t pin);
bool gpio_read(gpio_t pin);

/**
* @brief Set the given pin to HIGH
Expand Down
2 changes: 1 addition & 1 deletion drivers/lm75/lm75.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ int lm75_get_os_pin(lm75_t *dev, bool *os_pin_state) {
return LM75_ERROR;
}

*os_pin_state = !!gpio_read(dev->lm75_params.gpio_alarm) == dev->lm75_params.polarity;
*os_pin_state = gpio_read(dev->lm75_params.gpio_alarm) == dev->lm75_params.polarity;
return LM75_SUCCESS;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/rust-async/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/rust-gcoap/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/rust-hello-world/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sys/rust_riotmodules_standalone/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/rust_minimal/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ba83fef

Please sign in to comment.