Created initial config for setting up GPIO pin interrupts

This commit is contained in:
Luke Else 2023-11-16 13:19:20 +00:00
parent a2a9abc4b3
commit 913b262d9f

View File

@ -2,12 +2,15 @@
use esp_idf_hal::{ use esp_idf_hal::{
self, self,
gpio::*,
i2c::{I2cConfig, I2cDriver}, i2c::{I2cConfig, I2cDriver},
prelude::Peripherals, prelude::Peripherals,
units::Hertz, units::Hertz,
}; };
use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported 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; mod error;
use error::Error; use error::Error;
@ -42,6 +45,16 @@ fn main() -> Result<(), Error> {
let i2c = let i2c =
I2cDriver::new(peripherals.i2c0, sda, scl, &config).map_err(|err| Error::EspError(err))?; 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 // Prepare components for processing
let mut gps: GPS = GPS::new(peripherals.uart0, gps_rx)?; let mut gps: GPS = GPS::new(peripherals.uart0, gps_rx)?;
let mut display: Display<DisplaySize128x64> = let mut display: Display<DisplaySize128x64> =
@ -65,3 +78,7 @@ fn main() -> Result<(), Error> {
display.draw(text.as_str())? display.draw(text.as_str())?
} }
} }
fn app_state_interrupt() {
println!("inteerrupt");
}