generated from luke-else/esp32-std-template
	Created initial config for setting up GPIO pin interrupts
This commit is contained in:
		
							
								
								
									
										17
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								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<DisplaySize128x64> =
 | 
			
		||||
@@ -65,3 +78,7 @@ fn main() -> Result<(), Error> {
 | 
			
		||||
        display.draw(text.as_str())?
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn app_state_interrupt() {
 | 
			
		||||
    println!("inteerrupt");
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user