From 82274ec616ebb9745819fbdd72ab7f499bff0626 Mon Sep 17 00:00:00 2001 From: coskunergan Date: Thu, 13 Mar 2025 12:02:02 +0300 Subject: [PATCH 1/2] zephyr-build: fix DTS parser for Windows The zephyr-build DTS parser fails on Windows, due to the "\r\n" whitespace used on that platform. Accept the "\r" in addition to the "\n" to allow it to parse successfully. Fixes: #68 See: https://github.com/zephyrproject-rtos/zephyr-lang-rust/issues/68 Signed-off-by: coskun ergan --- zephyr-build/src/devicetree/dts.pest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zephyr-build/src/devicetree/dts.pest b/zephyr-build/src/devicetree/dts.pest index 8a521580..5db1b95f 100644 --- a/zephyr-build/src/devicetree/dts.pest +++ b/zephyr-build/src/devicetree/dts.pest @@ -74,4 +74,4 @@ nodename = @{ (ASCII_ALPHANUMERIC | "_" | "," | "." | "?" | "-" | "@" | "#")+ } -WHITESPACE = _{ " " | "\n" | "\t" } +WHITESPACE = _{ " " | "\r" | "\n" | "\t" } From 830b748f2f4a5ecf107d2fdd985f69df10cfb435 Mon Sep 17 00:00:00 2001 From: coskunergan Date: Sat, 12 Apr 2025 00:48:48 +0300 Subject: [PATCH 2/2] zephyr-build: add aux_display support and fixed the gpio interrupt for stm32 series. The zephyr-build parser was missing aux_display support, which was included and used in a demo; https://github.com/coskunergan/zephyr_rust_demo Signed-off-by: coskun ergan --- zephyr-sys/build.rs | 1 + zephyr-sys/wrapper.h | 2 +- zephyr/src/device/gpio.rs | 11 ++++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/zephyr-sys/build.rs b/zephyr-sys/build.rs index 05c6e942..4a9c5e0c 100644 --- a/zephyr-sys/build.rs +++ b/zephyr-sys/build.rs @@ -76,6 +76,7 @@ fn main() -> Result<()> { .derive_copy(false) .allowlist_function("k_.*") .allowlist_function("gpio_.*") + .allowlist_function("auxdisplay_.*") .allowlist_function("flash_.*") .allowlist_item("GPIO_.*") .allowlist_item("FLASH_.*") diff --git a/zephyr-sys/wrapper.h b/zephyr-sys/wrapper.h index 98bb9571..4b4ae040 100644 --- a/zephyr-sys/wrapper.h +++ b/zephyr-sys/wrapper.h @@ -42,7 +42,7 @@ extern int errno; #include #include #include - +#include /* * bindgen will only output #defined constants that resolve to simple numbers. These are some * symbols that we want exported that, at least in some situations, are more complex, usually with a diff --git a/zephyr/src/device/gpio.rs b/zephyr/src/device/gpio.rs index f0e52c8a..48b914fe 100644 --- a/zephyr/src/device/gpio.rs +++ b/zephyr/src/device/gpio.rs @@ -31,7 +31,7 @@ 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, + gpio_pin_interrupt_configure_dt, gpio_port_pins_t, GPIO_INT_EDGE_FALLING, GPIO_INT_EDGE_RISING, ZR_GPIO_INT_MODE_DISABLE_ONLY, }; @@ -212,14 +212,19 @@ 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 => GPIO_INT_EDGE_FALLING/*GPIO_INT_LEVEL_LOW*/, + 1 => GPIO_INT_EDGE_RISING/*GPIO_INT_LEVEL_HIGH*/, _ => unreachable!(), }; unsafe { gpio_pin_interrupt_configure_dt(&self.pin.pin, mode); + if self.level == zephyr_sys::gpio_pin_get_raw(self.pin.pin.port,self.pin.pin.pin) as u8 { + let cb = self.pin.data.callback.get(); + GpioStatic::callback_handler(self.pin.pin.port, cb, 1 << self.pin.pin.pin); + } + // Before sleeping, check if it fired, to avoid having to pend if it already // happened. if self.pin.data.has_fired(self.pin.pin.pin) {