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

ESP32-P4: Initial GPIO support #1109

Merged
merged 2 commits into from
Jan 23, 2024
Merged

Conversation

bjoernQ
Copy link
Contributor

@bjoernQ bjoernQ commented Jan 23, 2024

This adds initial GPIO support for P4

Can be tested with this

#![no_std]
#![no_main]

use esp32p4_hal::{gpio::IO, peripherals::Peripherals, prelude::*};
use esp_backtrace as _;

#[entry]
fn main() -> ! {
    let peripherals = Peripherals::take();

    let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
    let mut led = io.pins.gpio36.into_push_pull_output();
    let mut button = io.pins.gpio35.into_pull_up_input();

    button.listen(esp32p4_hal::gpio::Event::AnyEdge);

    led.set_high().unwrap();

    loop {
        led.toggle().unwrap();

        // run in debug mode so the busy-loop-wait isn't optimized out
        for _ in 0..500000 {}

        esp_println::println!(
            "blink! state={}, interrupt set = {}",
            button.is_high().unwrap(),
            button.is_interrupt_set()
        );
        button.clear_interrupt();
    }
}

Needs to be run in debug mode b.c. I was a bit too lazy to write a better delay ...

Just connect an LED (or logic analyzer) to GPIO36. Pressing the boot button should show that inputs are working and also interrupt status is set (and cleared after the println)

That FUNC_IN_SEL_OFFSET is because on P4 FUNC_IN_SEL_CFG starts with signal 1

For the future we probably want to support GPIO_INT1..GPIO_INT3 but that's an improvement we can do later

@bjoernQ bjoernQ force-pushed the feature/esp32p4-gpio branch from f2da6e2 to 803330b Compare January 23, 2024 17:12
Copy link
Member

@jessebraham jessebraham left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@jessebraham jessebraham added this pull request to the merge queue Jan 23, 2024
Merged via the queue into esp-rs:main with commit f542eb4 Jan 23, 2024
18 checks passed
@bjoernQ bjoernQ deleted the feature/esp32p4-gpio branch November 26, 2024 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants