This commit is contained in:
Corwin 2022-03-21 22:19:07 +00:00
parent f312ff7df8
commit aa0337941a
2 changed files with 17 additions and 1 deletions

View file

@ -227,6 +227,18 @@ fn interrupt_to_root(interrupt: Interrupt) -> &'static InterruptRoot {
} }
#[must_use] #[must_use]
/// Adds an interrupt handler as long as the returned value is alive. The
/// closure takes a [`CriticalSection`] which can be used for mutexes.
///
/// [`CriticalSection`]: bare_metal::CriticalSection
///
/// # Examples
///
/// ```
/// let _a = add_interrupt_handler(Interrupt::VBlank, |_: &CriticalSection| {
/// println!("Woah there! There's been a vblank!");
/// });
/// ```
pub fn add_interrupt_handler<'a>( pub fn add_interrupt_handler<'a>(
interrupt: Interrupt, interrupt: Interrupt,
handler: impl Fn(&CriticalSection) + 'a, handler: impl Fn(&CriticalSection) + 'a,
@ -264,6 +276,10 @@ pub fn add_interrupt_handler<'a>(
do_with_inner(interrupt, inner) do_with_inner(interrupt, inner)
} }
/// How you can access mutexes outside of interrupts by being given a
/// [`CriticalSection`]
///
/// [`CriticalSection`]: bare_metal::CriticalSection
pub fn free<F, R>(f: F) -> R pub fn free<F, R>(f: F) -> R
where where
F: FnOnce(&CriticalSection) -> R, F: FnOnce(&CriticalSection) -> R,

View file

@ -145,7 +145,7 @@ pub mod display;
mod dma; mod dma;
/// Button inputs to the system. /// Button inputs to the system.
pub mod input; pub mod input;
#[doc(hidden)] // hide for now as the implementation in here is unsound /// Interacting with the GBA interrupts
pub mod interrupt; pub mod interrupt;
mod memory_mapped; mod memory_mapped;
/// Implements logging to the mgba emulator. /// Implements logging to the mgba emulator.