Skip to content

Commit 898662c

Browse files
committed
zephyr-sys: Handle deflected GPIO constants
bindgen is willing to perform some simple math when expanding macros, but, does not see through the BIT macro. As a workaround, until we can come up with a better solution, export `ZR_` prefixed versions that are consts so that they will get exported. Unfortunately, this changes the visible exported name (which should be fixed as well) Signed-off-by: David Brown <[email protected]>
1 parent 174ded5 commit 898662c

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

tests/drivers/gpio-async/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use embassy_time::{Duration, Ticker};
99
use zephyr::{
1010
device::gpio::{GpioPin, GpioToken},
1111
embassy::Executor,
12-
raw::{GPIO_INPUT, GPIO_OUTPUT_ACTIVE, GPIO_PULL_DOWN},
12+
raw::{GPIO_PULL_DOWN, ZR_GPIO_INPUT, ZR_GPIO_OUTPUT_ACTIVE},
1313
};
1414

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

4242
unsafe {
43-
col0.configure(&mut gpio_token, GPIO_OUTPUT_ACTIVE);
43+
col0.configure(&mut gpio_token, ZR_GPIO_OUTPUT_ACTIVE);
4444
col0.set(&mut gpio_token, true);
45-
row0.configure(&mut gpio_token, GPIO_INPUT | GPIO_PULL_DOWN);
45+
row0.configure(&mut gpio_token, ZR_GPIO_INPUT | GPIO_PULL_DOWN);
4646
}
4747

4848
loop {

zephyr-sys/wrapper.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,26 @@ const uint32_t ZR_GPIO_INT_MODE_DISABLE_ONLY = GPIO_INT_MODE_DISABLE_ONLY;
6363
const uint32_t ZR_GPIO_INT_MODE_ENABLE_ONLY = GPIO_INT_MODE_ENABLE_ONLY;
6464
#endif
6565

66+
#define ZR_GPIO(name) \
67+
const uint32_t ZR_ ## name = name
68+
69+
ZR_GPIO(GPIO_INPUT);
70+
ZR_GPIO(GPIO_OUTPUT);
71+
ZR_GPIO(GPIO_OUTPUT_INIT_LOW);
72+
ZR_GPIO(GPIO_OUTPUT_INIT_HIGH);
73+
ZR_GPIO(GPIO_OUTPUT_INIT_LOGICAL);
74+
ZR_GPIO(GPIO_INT_DISABLE);
75+
ZR_GPIO(GPIO_INT_ENABLE);
76+
ZR_GPIO(GPIO_INT_LEVELS_LOGICAL);
77+
ZR_GPIO(GPIO_INT_EDGE);
78+
ZR_GPIO(GPIO_INT_LOW_0);
79+
ZR_GPIO(GPIO_INT_HIGH_1);
80+
ZR_GPIO(GPIO_INT_LEVEL_HIGH);
81+
ZR_GPIO(GPIO_INT_LEVEL_LOW);
82+
ZR_GPIO(GPIO_OUTPUT_ACTIVE);
83+
84+
#undef ZR_GPIO
85+
6686
/*
6787
* Zephyr's irq_lock() and irq_unlock() are macros not inline functions, so we need some inlines to
6888
* access them.

zephyr/src/device/gpio.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ mod async_io {
3131
use embassy_sync::waitqueue::AtomicWaker;
3232
use zephyr_sys::{
3333
device, gpio_add_callback, gpio_callback, gpio_init_callback, gpio_pin_interrupt_configure,
34-
gpio_pin_interrupt_configure_dt, gpio_port_pins_t, GPIO_INT_LEVEL_HIGH, GPIO_INT_LEVEL_LOW,
35-
ZR_GPIO_INT_MODE_DISABLE_ONLY,
34+
gpio_pin_interrupt_configure_dt, gpio_port_pins_t, ZR_GPIO_INT_LEVEL_HIGH,
35+
ZR_GPIO_INT_LEVEL_LOW, ZR_GPIO_INT_MODE_DISABLE_ONLY,
3636
};
3737

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

214214
let mode = match self.level {
215-
0 => GPIO_INT_LEVEL_LOW,
216-
1 => GPIO_INT_LEVEL_HIGH,
215+
0 => ZR_GPIO_INT_LEVEL_LOW,
216+
1 => ZR_GPIO_INT_LEVEL_HIGH,
217217
_ => unreachable!(),
218218
};
219219

0 commit comments

Comments
 (0)