Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/periph_gpio: let gpio_read() return bool #20936

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
return 0;
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
return (int)(gpio(pin)->DATA & _pin_mask(pin));
}
Expand Down Expand Up @@ -169,7 +169,7 @@

/* configure the active flank(s) */
gpio(pin)->IS &= ~_pin_mask(pin);
switch(flank) {

Check warning on line 172 in cpu/cc2538/periph/gpio.c

View workflow job for this annotation

GitHub Actions / static-tests

keyword 'switch' not followed by a single space
case GPIO_FALLING:
gpio(pin)->IBE &= ~_pin_mask(pin);
gpio(pin)->IEV &= ~_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 @@ -38,7 +38,7 @@
int gpio_init(gpio_t pin, gpio_mode_t mode)
{
if ((unsigned int)pin > 31)
return -1;

Check warning on line 41 in cpu/cc26xx_cc13xx/periph/gpio.c

View workflow job for this annotation

GitHub Actions / static-tests

full block {} expected in the control structure

/* enable peripherals power domain */
if (!power_is_domain_enabled(POWER_DOMAIN_PERIPHERALS)) {
Expand All @@ -56,7 +56,7 @@
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 Expand Up @@ -96,7 +96,7 @@
{
int init = gpio_init(pin, mode);
if (init != 0)
return init;

Check warning on line 99 in cpu/cc26xx_cc13xx/periph/gpio.c

View workflow job for this annotation

GitHub Actions / static-tests

full block {} expected in the control structure

NVIC_EnableIRQ(EDGE_DETECT_IRQN);

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 @@ -42,7 +42,7 @@

/*
* IOMUX to GPIO mapping
* source https://www.espressif.com/sites/default/files/documentation/0d-esp8266_pin_list_release_15-11-2014.xlsx

Check warning on line 45 in cpu/esp8266/periph/gpio.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
*/

const uint8_t _gpio_to_iomux[] = { 12, 5, 13, 4, 14, 15, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3 };
Expand Down Expand Up @@ -237,7 +237,7 @@
}
#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 @@
return 0;
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
unsigned _pin = pin & 31;
unsigned port = pin >> 5;
Expand Down Expand Up @@ -209,7 +209,7 @@
if (_state_index == 0xff) {
_state_index = bf_get_unset(_gpio_config_bitfield, GPIO_NUM_ISR);
_gpio_isr_map[isr_map_entry] = _state_index;
DEBUG("gpio_init_int(): pin has state_index=%i isr_map_entry=%i\n", _state_index, isr_map_entry);

Check warning on line 212 in cpu/lpc23xx/periph/gpio.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
}

if (_state_index == 0xff) {
Expand Down Expand Up @@ -242,7 +242,7 @@
_gpio_configure(pin, flank & GPIO_RISING, flank & GPIO_FALLING);

/* activate irq */
INTWAKE |= GPIO0WAKE | GPIO2WAKE; /* allow GPIO to wake up from power down */

Check warning on line 245 in cpu/lpc23xx/periph/gpio.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
install_irq(GPIO_INT, &GPIO_IRQHandler, IRQP_GPIO); /* install irq handler */

return 0;
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 @@
return 0;
}

int gpio_read(gpio_t pin)
bool gpio_read(gpio_t pin)
{
PortGroup *port;
int mask = _pin_mask(pin);
Expand Down Expand Up @@ -244,10 +244,10 @@
#ifdef CPU_COMMON_SAMD21
#define EIC_SYNC() while (_EIC->STATUS.reg & EIC_STATUS_SYNCBUSY)
#else
#define EIC_SYNC() while (_EIC->SYNCBUSY.reg & EIC_SYNCBUSY_ENABLE)

Check warning on line 247 in cpu/sam0_common/periph/gpio.c

View workflow job for this annotation

GitHub Actions / static-tests

full block {} expected in the control structure
#endif

static int _exti(gpio_t pin)

Check warning on line 250 in cpu/sam0_common/periph/gpio.c

View workflow job for this annotation

GitHub Actions / static-tests

full block {} expected in the control structure
{
unsigned port_num = ((pin >> 7) & 0x03);

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 @@ -116,7 +116,7 @@
/* For input modes, ODR controls pull up settings */
if (gpio_mode_is_input(mode)) {
if (mode == GPIO_IN_PU)
port->ODR |= 1 << pin_num;

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

View workflow job for this annotation

GitHub Actions / static-tests

full block {} expected in the control structure
else
port->ODR &= ~(1 << pin_num);
}
Expand All @@ -142,10 +142,10 @@

/* map the pin as analog input */
int pin_num = _pin_num(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.

Loading