From 913b262d9f12c1dbf69ddae22e35578afd1668f3 Mon Sep 17 00:00:00 2001 From: Luke Else Date: Thu, 16 Nov 2023 13:19:20 +0000 Subject: [PATCH] Created initial config for setting up GPIO pin interrupts --- src/main.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main.rs b/src/main.rs index 1cc6b38..20ff5b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,12 +2,15 @@ use esp_idf_hal::{ self, + gpio::*, i2c::{I2cConfig, I2cDriver}, prelude::Peripherals, units::Hertz, }; use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported +use std::sync::atomic::{AtomicBool, Ordering}; + mod error; use error::Error; @@ -42,6 +45,16 @@ fn main() -> Result<(), Error> { let i2c = I2cDriver::new(peripherals.i2c0, sda, scl, &config).map_err(|err| Error::EspError(err))?; + // Setup GPIO interrupts + static FLAG: AtomicBool = AtomicBool::new(false); + let mut interrupt_button_handle = PinDriver::input(pins.gpio9).unwrap(); + + interrupt_button_handle.set_pull(Pull::Up); + interrupt_button_handle.set_interrupt_type(InterruptType::NegEdge); + unsafe { + interrupt_button_handle.subscribe(app_state_interrupt); + } + // Prepare components for processing let mut gps: GPS = GPS::new(peripherals.uart0, gps_rx)?; let mut display: Display = @@ -65,3 +78,7 @@ fn main() -> Result<(), Error> { display.draw(text.as_str())? } } + +fn app_state_interrupt() { + println!("inteerrupt"); +}