Skip to content

zephyr-sys: Handle deflected GPIO constants #104

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

Merged
merged 1 commit into from
Jun 4, 2025
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
6 changes: 3 additions & 3 deletions tests/drivers/gpio-async/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use embassy_time::{Duration, Ticker};
use zephyr::{
device::gpio::{GpioPin, GpioToken},
embassy::Executor,
raw::{GPIO_INPUT, GPIO_OUTPUT_ACTIVE, GPIO_PULL_DOWN},
raw::{GPIO_PULL_DOWN, ZR_GPIO_INPUT, ZR_GPIO_OUTPUT_ACTIVE},
};

use embassy_executor::Spawner;
Expand Down Expand Up @@ -40,9 +40,9 @@ async fn main(spawner: Spawner) {
let mut gpio_token = unsafe { zephyr::device::gpio::GpioToken::get_instance().unwrap() };

unsafe {
col0.configure(&mut gpio_token, GPIO_OUTPUT_ACTIVE);
col0.configure(&mut gpio_token, ZR_GPIO_OUTPUT_ACTIVE);
col0.set(&mut gpio_token, true);
row0.configure(&mut gpio_token, GPIO_INPUT | GPIO_PULL_DOWN);
row0.configure(&mut gpio_token, ZR_GPIO_INPUT | GPIO_PULL_DOWN);
}

loop {
Expand Down
20 changes: 20 additions & 0 deletions zephyr-sys/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ const uint32_t ZR_GPIO_INT_MODE_DISABLE_ONLY = GPIO_INT_MODE_DISABLE_ONLY;
const uint32_t ZR_GPIO_INT_MODE_ENABLE_ONLY = GPIO_INT_MODE_ENABLE_ONLY;
#endif

#define ZR_GPIO(name) \
const uint32_t ZR_ ## name = name

ZR_GPIO(GPIO_INPUT);
ZR_GPIO(GPIO_OUTPUT);
ZR_GPIO(GPIO_OUTPUT_INIT_LOW);
ZR_GPIO(GPIO_OUTPUT_INIT_HIGH);
ZR_GPIO(GPIO_OUTPUT_INIT_LOGICAL);
ZR_GPIO(GPIO_INT_DISABLE);
ZR_GPIO(GPIO_INT_ENABLE);
ZR_GPIO(GPIO_INT_LEVELS_LOGICAL);
ZR_GPIO(GPIO_INT_EDGE);
ZR_GPIO(GPIO_INT_LOW_0);
ZR_GPIO(GPIO_INT_HIGH_1);
ZR_GPIO(GPIO_INT_LEVEL_HIGH);
ZR_GPIO(GPIO_INT_LEVEL_LOW);
ZR_GPIO(GPIO_OUTPUT_ACTIVE);

#undef ZR_GPIO

/*
* Zephyr's irq_lock() and irq_unlock() are macros not inline functions, so we need some inlines to
* access them.
Expand Down
8 changes: 4 additions & 4 deletions zephyr/src/device/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ mod async_io {
use embassy_sync::waitqueue::AtomicWaker;
use zephyr_sys::{
device, gpio_add_callback, gpio_callback, gpio_init_callback, gpio_pin_interrupt_configure,
gpio_pin_interrupt_configure_dt, gpio_port_pins_t, GPIO_INT_LEVEL_HIGH, GPIO_INT_LEVEL_LOW,
ZR_GPIO_INT_MODE_DISABLE_ONLY,
gpio_pin_interrupt_configure_dt, gpio_port_pins_t, ZR_GPIO_INT_LEVEL_HIGH,
ZR_GPIO_INT_LEVEL_LOW, ZR_GPIO_INT_MODE_DISABLE_ONLY,
};

use crate::sync::atomic::{AtomicBool, AtomicU32};
Expand Down Expand Up @@ -212,8 +212,8 @@ mod async_io {
self.pin.data.register(self.pin.pin.pin, cx.waker());

let mode = match self.level {
0 => GPIO_INT_LEVEL_LOW,
1 => GPIO_INT_LEVEL_HIGH,
0 => ZR_GPIO_INT_LEVEL_LOW,
1 => ZR_GPIO_INT_LEVEL_HIGH,
_ => unreachable!(),
};

Expand Down