Skip to content

zephyr-build: add aux_display support and fixed the gpio interrupt for stm32 series. #90

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions zephyr-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ fn main() -> Result<()> {
.derive_copy(false)
.allowlist_function("k_.*")
.allowlist_function("gpio_.*")
.allowlist_function("auxdisplay_.*")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your editor seems to be inserting tabs instead of spaces. It does seem to suggest that cargo fmt doesn't process the build.rs file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from that, does auxdisplay have anything to do with this PR?

.allowlist_function("flash_.*")
.allowlist_item("GPIO_.*")
.allowlist_item("FLASH_.*")
Expand Down
2 changes: 1 addition & 1 deletion zephyr-sys/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extern int errno;
#include <zephyr/logging/log.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/drivers/flash.h>

#include <zephyr/drivers/auxdisplay.h>
/*
* 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
Expand Down
11 changes: 8 additions & 3 deletions zephyr/src/device/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although the STM32 devices do not have level triggered interrupts, we don't want to remove support for them from targets that do. The async interface is actually really racy with edge triggered interrupts, and will pretty readily end up missing an edge and not firing again.

Honestly, I think supporting wake from stm32 is going to be a bit more work. We can't just have something attach an edge trigger, but would need to leave it attached, to track the state.

ZR_GPIO_INT_MODE_DISABLE_ONLY,
};

Expand Down Expand Up @@ -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) {
Expand Down
Loading