esp32s2_ulp/
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 = "0 - TOUCH_DONE_INT"]
7    TOUCH_DONE_INT = 0,
8    #[doc = "1 - TOUCH_INACTIVE_INT"]
9    TOUCH_INACTIVE_INT = 1,
10    #[doc = "2 - TOUCH_ACTIVE_INT"]
11    TOUCH_ACTIVE_INT = 2,
12    #[doc = "3 - SARADC1_DONE_INT"]
13    SARADC1_DONE_INT = 3,
14    #[doc = "4 - SARADC2_DONE_INT"]
15    SARADC2_DONE_INT = 4,
16    #[doc = "5 - TSENS_DONE_INT"]
17    TSENS_DONE_INT = 5,
18    #[doc = "6 - RISCV_START_INT"]
19    RISCV_START_INT = 6,
20    #[doc = "7 - SW_INT"]
21    SW_INT = 7,
22    #[doc = "8 - SWD_INT"]
23    SWD_INT = 8,
24}
25#[doc = r" TryFromInterruptError"]
26#[derive(Debug, Copy, Clone)]
27pub struct TryFromInterruptError(());
28impl Interrupt {
29    #[doc = r" Attempt to convert a given value into an `Interrupt`"]
30    #[inline]
31    pub fn try_from(value: u8) -> Result<Self, TryFromInterruptError> {
32        match value {
33            0 => Ok(Interrupt::TOUCH_DONE_INT),
34            1 => Ok(Interrupt::TOUCH_INACTIVE_INT),
35            2 => Ok(Interrupt::TOUCH_ACTIVE_INT),
36            3 => Ok(Interrupt::SARADC1_DONE_INT),
37            4 => Ok(Interrupt::SARADC2_DONE_INT),
38            5 => Ok(Interrupt::TSENS_DONE_INT),
39            6 => Ok(Interrupt::RISCV_START_INT),
40            7 => Ok(Interrupt::SW_INT),
41            8 => Ok(Interrupt::SWD_INT),
42            _ => Err(TryFromInterruptError(())),
43        }
44    }
45}
46#[cfg(feature = "rt")]
47#[macro_export]
48#[doc = r" Assigns a handler to an interrupt"]
49#[doc = r""]
50#[doc = r" This macro takes two arguments: the name of an interrupt and the path to the"]
51#[doc = r" function that will be used as the handler of that interrupt. That function"]
52#[doc = r" must have signature `fn()`."]
53#[doc = r""]
54#[doc = r" Optionally, a third argument may be used to declare interrupt local data."]
55#[doc = r" The handler will have exclusive access to these *local* variables on each"]
56#[doc = r" invocation. If the third argument is used then the signature of the handler"]
57#[doc = r" function must be `fn(&mut $NAME::Locals)` where `$NAME` is the first argument"]
58#[doc = r" passed to the macro."]
59#[doc = r""]
60#[doc = r" # Example"]
61#[doc = r""]
62#[doc = r" ``` ignore"]
63#[doc = r" interrupt!(TIM2, periodic);"]
64#[doc = r""]
65#[doc = r" fn periodic() {"]
66#[doc = r#"     print!(".");"#]
67#[doc = r" }"]
68#[doc = r""]
69#[doc = r" interrupt!(TIM3, tick, locals: {"]
70#[doc = r"     tick: bool = false;"]
71#[doc = r" });"]
72#[doc = r""]
73#[doc = r" fn tick(locals: &mut TIM3::Locals) {"]
74#[doc = r"     locals.tick = !locals.tick;"]
75#[doc = r""]
76#[doc = r"     if locals.tick {"]
77#[doc = r#"         println!("Tick");"#]
78#[doc = r"     } else {"]
79#[doc = r#"         println!("Tock");"#]
80#[doc = r"     }"]
81#[doc = r" }"]
82#[doc = r" ```"]
83macro_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 () ; } } }