From 618929939f90832ac44d63db8c69fe4cd01dd023 Mon Sep 17 00:00:00 2001 From: GBA bot Date: Sat, 1 Jan 2022 23:15:14 +0000 Subject: [PATCH] Document the Gba struct --- agb/src/lib.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/agb/src/lib.rs b/agb/src/lib.rs index 3b97356..1ab5a93 100644 --- a/agb/src/lib.rs +++ b/agb/src/lib.rs @@ -59,14 +59,57 @@ fn panic_implementation(info: &core::panic::PanicInfo) -> ! { static mut GBASINGLE: single::Singleton = single::Singleton::new(unsafe { Gba::single_new() }); +/// The Gba struct is used to control access to the Game Boy Advance's hardware in a way which makes it the +/// borrow checker's responsibility to ensure no clashes of global resources. +/// +/// This is typically created once at the start of the main function and then the various fields are used +/// to ensure mutually exclusive use of the various hardware registers. It provides a gateway into the main +/// usage of `agb` library. +/// +/// # Panics +/// +/// Calling this twice will panic. +/// +/// # Examples +/// +/// ``` +/// #![no_std] +/// #![no_main] +/// +/// extern crate agb; +/// +/// use agb::Gba; +/// +/// #[agb::entry] +/// fn main() -> ! { +/// let mut gba = Gba::new(); +/// +/// // Do whatever you need to do with gba +/// +/// loop {} +/// } +/// ``` +#[non_exhaustive] pub struct Gba { + /// Manages access to the Game Boy Advance's display hardware pub display: display::Display, + /// Manages access to the Game Boy Advance's beeps and boops sound hardware as part of the + /// original Game Boy's sound chip (the DMG). pub sound: sound::dmg::Sound, + /// Manages access to the Game Boy Advance's direct sound mixer for playing raw wav files. pub mixer: sound::mixer::MixerController, + /// Manages access to the Game Boy Advance's 4 timers. pub timers: timer::TimerController, } impl Gba { + /// Creates a new instance of the Gba struct. + /// + /// Note that you can only create 1 instance, and trying to create a second will panic. + /// + /// # Panics + /// + /// Panics if you try to create the second instance. pub fn new() -> Self { unsafe { GBASINGLE.take() } }