esp32c6_lp/
interrupt.rs

1#[doc = r"Enumeration of all the interrupts."]
2#[cfg_attr(feature = "defmt", derive(defmt::Format))]
3#[derive(Copy, Clone, Debug, PartialEq, Eq)]
4#[repr(u16)]
5pub enum Interrupt {
6    #[doc = "7 - LP_TIMER"]
7    LP_TIMER = 7,
8    #[doc = "13 - PMU"]
9    PMU = 13,
10    #[doc = "16 - LP_UART"]
11    LP_UART = 16,
12    #[doc = "17 - LP_I2C"]
13    LP_I2C = 17,
14    #[doc = "18 - LP_WDT"]
15    LP_WDT = 18,
16    #[doc = "19 - LP_PERI_TIMEOUT"]
17    LP_PERI_TIMEOUT = 19,
18    #[doc = "20 - LP_APM_M0"]
19    LP_APM_M0 = 20,
20    #[doc = "21 - LP_APM_M1"]
21    LP_APM_M1 = 21,
22}
23#[doc = r" TryFromInterruptError"]
24#[derive(Debug, Copy, Clone)]
25pub struct TryFromInterruptError(());
26impl Interrupt {
27    #[doc = r" Attempt to convert a given value into an `Interrupt`"]
28    #[inline]
29    pub fn try_from(value: u8) -> Result<Self, TryFromInterruptError> {
30        match value {
31            7 => Ok(Interrupt::LP_TIMER),
32            13 => Ok(Interrupt::PMU),
33            16 => Ok(Interrupt::LP_UART),
34            17 => Ok(Interrupt::LP_I2C),
35            18 => Ok(Interrupt::LP_WDT),
36            19 => Ok(Interrupt::LP_PERI_TIMEOUT),
37            20 => Ok(Interrupt::LP_APM_M0),
38            21 => Ok(Interrupt::LP_APM_M1),
39            _ => Err(TryFromInterruptError(())),
40        }
41    }
42}
43#[cfg(feature = "rt")]
44#[macro_export]
45#[doc = r" Assigns a handler to an interrupt"]
46#[doc = r""]
47#[doc = r" This macro takes two arguments: the name of an interrupt and the path to the"]
48#[doc = r" function that will be used as the handler of that interrupt. That function"]
49#[doc = r" must have signature `fn()`."]
50#[doc = r""]
51#[doc = r" Optionally, a third argument may be used to declare interrupt local data."]
52#[doc = r" The handler will have exclusive access to these *local* variables on each"]
53#[doc = r" invocation. If the third argument is used then the signature of the handler"]
54#[doc = r" function must be `fn(&mut $NAME::Locals)` where `$NAME` is the first argument"]
55#[doc = r" passed to the macro."]
56#[doc = r""]
57#[doc = r" # Example"]
58#[doc = r""]
59#[doc = r" ``` ignore"]
60#[doc = r" interrupt!(TIM2, periodic);"]
61#[doc = r""]
62#[doc = r" fn periodic() {"]
63#[doc = r#"     print!(".");"#]
64#[doc = r" }"]
65#[doc = r""]
66#[doc = r" interrupt!(TIM3, tick, locals: {"]
67#[doc = r"     tick: bool = false;"]
68#[doc = r" });"]
69#[doc = r""]
70#[doc = r" fn tick(locals: &mut TIM3::Locals) {"]
71#[doc = r"     locals.tick = !locals.tick;"]
72#[doc = r""]
73#[doc = r"     if locals.tick {"]
74#[doc = r#"         println!("Tick");"#]
75#[doc = r"     } else {"]
76#[doc = r#"         println!("Tock");"#]
77#[doc = r"     }"]
78#[doc = r" }"]
79#[doc = r" ```"]
80macro_rules ! interrupt { ($ NAME : ident , $ path : path , locals : { $ ($ lvar : ident : $ lty : ty = $ lval : expr ;) * }) => { # [allow (non_snake_case)] mod $ NAME { pub struct Locals { $ (pub $ lvar : $ lty ,) * } } # [allow (non_snake_case)] # [no_mangle] pub extern "C" fn $ NAME () { let _ = $ crate :: interrupt :: Interrupt :: $ NAME ; static mut LOCALS : self :: $ NAME :: Locals = self :: $ NAME :: Locals { $ ($ lvar : $ lval ,) * } ; let f : fn (& mut self :: $ NAME :: Locals) = $ path ; f (unsafe { & mut LOCALS }) ; } } ; ($ NAME : ident , $ path : path) => { # [allow (non_snake_case)] # [no_mangle] pub extern "C" fn $ NAME () { let _ = $ crate :: interrupt :: Interrupt :: $ NAME ; let f : fn () = $ path ; f () ; } } }