From ae90fc3e6e8294b6bdf2caf3c21553f27332c4fe Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Thu, 6 Apr 2023 11:22:23 +0200 Subject: [PATCH] Derive traits and Screen changes --- ctru-rs/examples/audio-filters.rs | 4 -- ctru-rs/examples/buttons.rs | 3 -- ctru-rs/examples/camera-image.rs | 17 ++++---- ctru-rs/examples/file-explorer.rs | 2 - ctru-rs/examples/futures-basic.rs | 2 - ctru-rs/examples/futures-tokio.rs | 2 - ctru-rs/examples/gfx-3d-mode.rs | 4 -- ctru-rs/examples/gfx-wide-mode.rs | 4 +- ctru-rs/examples/graphics-bitmap.rs | 4 +- ctru-rs/examples/hashmaps.rs | 2 - ctru-rs/examples/hello-both-screens.rs | 2 - ctru-rs/examples/hello-world.rs | 3 -- ctru-rs/examples/linear-memory.rs | 3 -- ctru-rs/examples/mii-selector.rs | 3 -- ctru-rs/examples/output-3dslink.rs | 3 -- ctru-rs/examples/romfs.rs | 3 -- ctru-rs/examples/software-keyboard.rs | 2 - ctru-rs/examples/system-configuration.rs | 3 -- ctru-rs/examples/thread-basic.rs | 2 - ctru-rs/examples/thread-info.rs | 4 +- ctru-rs/examples/thread-locals.rs | 2 - ctru-rs/examples/time-rtc.rs | 4 -- ctru-rs/examples/title-info.rs | 4 -- ctru-rs/src/applets/mii_selector.rs | 44 ++++++++++---------- ctru-rs/src/applets/swkbd.rs | 9 ++-- ctru-rs/src/console.rs | 4 ++ ctru-rs/src/services/am.rs | 1 + ctru-rs/src/services/cam.rs | 25 ++++++------ ctru-rs/src/services/cfgu.rs | 6 +-- ctru-rs/src/services/fs.rs | 14 +++---- ctru-rs/src/services/gfx.rs | 52 ++++++++++++------------ ctru-rs/src/services/gspgpu.rs | 4 +- ctru-rs/src/services/hid.rs | 3 +- ctru-rs/src/services/ndsp/mod.rs | 10 ++--- ctru-rs/src/services/ndsp/wave.rs | 2 +- ctru-rs/src/services/ps.rs | 4 +- ctru-rs/src/services/sslc.rs | 11 ----- ctru-rs/src/test_runner.rs | 2 - 38 files changed, 104 insertions(+), 169 deletions(-) diff --git a/ctru-rs/examples/audio-filters.rs b/ctru-rs/examples/audio-filters.rs index e425793..3ef76a6 100644 --- a/ctru-rs/examples/audio-filters.rs +++ b/ctru-rs/examples/audio-filters.rs @@ -154,10 +154,6 @@ fn main() { altern = !altern; } - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); - //Wait for VBlank gfx.wait_for_vblank(); } diff --git a/ctru-rs/examples/buttons.rs b/ctru-rs/examples/buttons.rs index 5645915..8bba6c7 100644 --- a/ctru-rs/examples/buttons.rs +++ b/ctru-rs/examples/buttons.rs @@ -63,9 +63,6 @@ fn main() { // Save our current key presses for the next frame old_keys = keys; - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); gfx.wait_for_vblank(); } } diff --git a/ctru-rs/examples/camera-image.rs b/ctru-rs/examples/camera-image.rs index 88526be..8f67b47 100644 --- a/ctru-rs/examples/camera-image.rs +++ b/ctru-rs/examples/camera-image.rs @@ -20,11 +20,10 @@ fn main() { let mut hid = Hid::new().expect("Failed to initialize Hid service."); let gfx = Gfx::new().expect("Failed to initialize GFX service."); - gfx.top_screen.borrow_mut().set_double_buffering(true); - gfx.top_screen - .borrow_mut() - .set_framebuffer_format(FramebufferFormat::Rgb565); - gfx.bottom_screen.borrow_mut().set_double_buffering(false); + let mut top_screen = gfx.top_screen.borrow_mut(); + top_screen.set_double_buffering(true); + top_screen.set_framebuffer_format(FramebufferFormat::Rgb565); + let _console = Console::new(gfx.bottom_screen.borrow_mut()); let mut keys_down; @@ -88,13 +87,15 @@ fn main() { rotate_image_to_screen( &buf, - gfx.top_screen.borrow_mut().raw_framebuffer().ptr, + top_screen.raw_framebuffer().ptr, WIDTH, HEIGHT, ); - gfx.flush_buffers(); - gfx.swap_buffers(); + // We will only flush the "camera" screen, since the other screen is handled by `Console` + top_screen.flush_buffer(); + top_screen.swap_buffers(); + gfx.wait_for_vblank(); } } diff --git a/ctru-rs/examples/file-explorer.rs b/ctru-rs/examples/file-explorer.rs index 8a3d639..6d30590 100644 --- a/ctru-rs/examples/file-explorer.rs +++ b/ctru-rs/examples/file-explorer.rs @@ -68,8 +68,6 @@ impl<'a> FileExplorer<'a> { self.get_input_and_run(Self::set_exact_path); } - self.gfx.flush_buffers(); - self.gfx.swap_buffers(); self.gfx.wait_for_vblank(); } } diff --git a/ctru-rs/examples/futures-basic.rs b/ctru-rs/examples/futures-basic.rs index cb6a804..c41245c 100644 --- a/ctru-rs/examples/futures-basic.rs +++ b/ctru-rs/examples/futures-basic.rs @@ -68,8 +68,6 @@ fn main() { frame_count = 0; } - gfx.flush_buffers(); - gfx.swap_buffers(); gfx.wait_for_vblank(); } } diff --git a/ctru-rs/examples/futures-tokio.rs b/ctru-rs/examples/futures-tokio.rs index e42e9e9..986e930 100644 --- a/ctru-rs/examples/futures-tokio.rs +++ b/ctru-rs/examples/futures-tokio.rs @@ -63,8 +63,6 @@ fn main() { break; } - gfx.flush_buffers(); - gfx.swap_buffers(); gfx.wait_for_vblank(); } } diff --git a/ctru-rs/examples/gfx-3d-mode.rs b/ctru-rs/examples/gfx-3d-mode.rs index c5b194c..8603a64 100644 --- a/ctru-rs/examples/gfx-3d-mode.rs +++ b/ctru-rs/examples/gfx-3d-mode.rs @@ -61,10 +61,6 @@ fn main() { buf.copy_from(IMAGE.as_ptr(), IMAGE.len()); } - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); - //Wait for VBlank gfx.wait_for_vblank(); } diff --git a/ctru-rs/examples/gfx-wide-mode.rs b/ctru-rs/examples/gfx-wide-mode.rs index 53da6ea..0acf1b2 100644 --- a/ctru-rs/examples/gfx-wide-mode.rs +++ b/ctru-rs/examples/gfx-wide-mode.rs @@ -26,9 +26,7 @@ fn main() { console = Console::new(gfx.top_screen.borrow_mut()); println!("Press A to enable/disable wide screen mode."); } - - gfx.flush_buffers(); - gfx.swap_buffers(); + gfx.wait_for_vblank(); } } diff --git a/ctru-rs/examples/graphics-bitmap.rs b/ctru-rs/examples/graphics-bitmap.rs index 55d4903..4beacea 100644 --- a/ctru-rs/examples/graphics-bitmap.rs +++ b/ctru-rs/examples/graphics-bitmap.rs @@ -48,8 +48,8 @@ fn main() { } // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); + bottom_screen.flush_buffer(); + bottom_screen.swap_buffers(); //Wait for VBlank gfx.wait_for_vblank(); diff --git a/ctru-rs/examples/hashmaps.rs b/ctru-rs/examples/hashmaps.rs index e3726eb..7d4d8c4 100644 --- a/ctru-rs/examples/hashmaps.rs +++ b/ctru-rs/examples/hashmaps.rs @@ -21,8 +21,6 @@ fn main() { println!("{map:#?}"); while apt.main_loop() { - gfx.flush_buffers(); - gfx.swap_buffers(); gfx.wait_for_vblank(); hid.scan_input(); diff --git a/ctru-rs/examples/hello-both-screens.rs b/ctru-rs/examples/hello-both-screens.rs index fa2e16d..f2007f1 100644 --- a/ctru-rs/examples/hello-both-screens.rs +++ b/ctru-rs/examples/hello-both-screens.rs @@ -27,8 +27,6 @@ fn main() { println!("\x1b[29;16HPress Start to exit"); while apt.main_loop() { - gfx.flush_buffers(); - gfx.swap_buffers(); gfx.wait_for_vblank(); hid.scan_input(); diff --git a/ctru-rs/examples/hello-world.rs b/ctru-rs/examples/hello-world.rs index 345ee2e..a92cb90 100644 --- a/ctru-rs/examples/hello-world.rs +++ b/ctru-rs/examples/hello-world.rs @@ -29,9 +29,6 @@ fn main() { if hid.keys_down().contains(KeyPad::START) { break; } - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); //Wait for VBlank gfx.wait_for_vblank(); diff --git a/ctru-rs/examples/linear-memory.rs b/ctru-rs/examples/linear-memory.rs index 2373941..e6c18dc 100644 --- a/ctru-rs/examples/linear-memory.rs +++ b/ctru-rs/examples/linear-memory.rs @@ -37,9 +37,6 @@ fn main() { if hid.keys_down().contains(KeyPad::START) { break; } - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); //Wait for VBlank gfx.wait_for_vblank(); diff --git a/ctru-rs/examples/mii-selector.rs b/ctru-rs/examples/mii-selector.rs index 9ef86f6..d489e07 100644 --- a/ctru-rs/examples/mii-selector.rs +++ b/ctru-rs/examples/mii-selector.rs @@ -33,9 +33,6 @@ fn main() { if hid.keys_down().contains(KeyPad::START) { break; } - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); //Wait for VBlank gfx.wait_for_vblank(); diff --git a/ctru-rs/examples/output-3dslink.rs b/ctru-rs/examples/output-3dslink.rs index 5649e6e..8314efa 100644 --- a/ctru-rs/examples/output-3dslink.rs +++ b/ctru-rs/examples/output-3dslink.rs @@ -33,9 +33,6 @@ fn main() { if hid.keys_down().contains(KeyPad::START) { break; } - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); //Wait for VBlank gfx.wait_for_vblank(); diff --git a/ctru-rs/examples/romfs.rs b/ctru-rs/examples/romfs.rs index f92d81d..1138203 100644 --- a/ctru-rs/examples/romfs.rs +++ b/ctru-rs/examples/romfs.rs @@ -36,9 +36,6 @@ fn main() { if hid.keys_down().contains(KeyPad::START) { break; } - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); //Wait for VBlank gfx.wait_for_vblank(); diff --git a/ctru-rs/examples/software-keyboard.rs b/ctru-rs/examples/software-keyboard.rs index 77e877a..39b5549 100644 --- a/ctru-rs/examples/software-keyboard.rs +++ b/ctru-rs/examples/software-keyboard.rs @@ -12,8 +12,6 @@ fn main() { println!("Press A to enter some text or press Start to quit"); while apt.main_loop() { - gfx.flush_buffers(); - gfx.swap_buffers(); gfx.wait_for_vblank(); hid.scan_input(); diff --git a/ctru-rs/examples/system-configuration.rs b/ctru-rs/examples/system-configuration.rs index cb1e00f..001233d 100644 --- a/ctru-rs/examples/system-configuration.rs +++ b/ctru-rs/examples/system-configuration.rs @@ -22,9 +22,6 @@ fn main() { if hid.keys_down().contains(KeyPad::START) { break; } - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); //Wait for VBlank gfx.wait_for_vblank(); diff --git a/ctru-rs/examples/thread-basic.rs b/ctru-rs/examples/thread-basic.rs index cc494f6..33a8ea9 100644 --- a/ctru-rs/examples/thread-basic.rs +++ b/ctru-rs/examples/thread-basic.rs @@ -34,8 +34,6 @@ fn main() { } while apt.main_loop() { - gfx.flush_buffers(); - gfx.swap_buffers(); gfx.wait_for_vblank(); hid.scan_input(); diff --git a/ctru-rs/examples/thread-info.rs b/ctru-rs/examples/thread-info.rs index 9ab04fe..2316f16 100644 --- a/ctru-rs/examples/thread-info.rs +++ b/ctru-rs/examples/thread-info.rs @@ -44,9 +44,7 @@ fn main() { if hid.keys_down().contains(KeyPad::KEY_START) { break; } - - gfx.flush_buffers(); - gfx.swap_buffers(); + gfx.wait_for_vblank(); } } diff --git a/ctru-rs/examples/thread-locals.rs b/ctru-rs/examples/thread-locals.rs index d2a5e3e..80d8508 100644 --- a/ctru-rs/examples/thread-locals.rs +++ b/ctru-rs/examples/thread-locals.rs @@ -61,8 +61,6 @@ fn main() { break; } - gfx.flush_buffers(); - gfx.swap_buffers(); gfx.wait_for_vblank(); } } diff --git a/ctru-rs/examples/time-rtc.rs b/ctru-rs/examples/time-rtc.rs index 66c9a63..377fd5c 100644 --- a/ctru-rs/examples/time-rtc.rs +++ b/ctru-rs/examples/time-rtc.rs @@ -36,10 +36,6 @@ fn main() { println!("\x1b[1;1H{hours:0>2}:{minutes:0>2}:{seconds:0>2}"); println!("{weekday} {month} {day} {year}"); - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); - //Wait for VBlank gfx.wait_for_vblank(); } diff --git a/ctru-rs/examples/title-info.rs b/ctru-rs/examples/title-info.rs index 07ba9f4..fee5cb6 100644 --- a/ctru-rs/examples/title-info.rs +++ b/ctru-rs/examples/title-info.rs @@ -106,10 +106,6 @@ fn main() { refresh = false; } - // Flush and swap framebuffers - gfx.flush_buffers(); - gfx.swap_buffers(); - //Wait for VBlank gfx.wait_for_vblank(); } diff --git a/ctru-rs/src/applets/mii_selector.rs b/ctru-rs/src/applets/mii_selector.rs index 69175a2..e7d0559 100644 --- a/ctru-rs/src/applets/mii_selector.rs +++ b/ctru-rs/src/applets/mii_selector.rs @@ -8,14 +8,14 @@ use std::ffi::CString; /// Index of a Mii used to configure some parameters of the Mii Selector /// Can be either a single index, or _all_ Miis -#[derive(Debug, Clone)] -pub enum MiiConfigIndex { +#[derive(Debug, Clone, Copy, Eq, PartialEq)] +pub enum MiiIndex { Index(u32), All, } /// The type of a Mii with their respective data -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Eq, PartialEq)] pub enum MiiType { Guest { index: u32, name: String }, User, @@ -54,7 +54,7 @@ pub struct MiiSelector { /// Return value from a MiiSelector's launch #[non_exhaustive] #[derive(Clone, Debug)] -pub struct MiiSelectorReturn { +pub struct SelectionResult { pub mii_data: MiiData, pub is_mii_selected: bool, pub mii_type: MiiType, @@ -62,7 +62,7 @@ pub struct MiiSelectorReturn { /// Error type for the Mii selector #[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub enum MiiLaunchError { +pub enum LaunchError { InvalidChecksum, } @@ -94,40 +94,40 @@ impl MiiSelector { } /// Whitelist a guest Mii - pub fn whitelist_guest_mii(&mut self, mii_index: MiiConfigIndex) { + pub fn whitelist_guest_mii(&mut self, mii_index: MiiIndex) { let index = match mii_index { - MiiConfigIndex::Index(i) => i, - MiiConfigIndex::All => ctru_sys::MIISELECTOR_GUESTMII_SLOTS, + MiiIndex::Index(i) => i, + MiiIndex::All => ctru_sys::MIISELECTOR_GUESTMII_SLOTS, }; unsafe { ctru_sys::miiSelectorWhitelistGuestMii(self.config.as_mut(), index) } } /// Blacklist a guest Mii - pub fn blacklist_guest_mii(&mut self, mii_index: MiiConfigIndex) { + pub fn blacklist_guest_mii(&mut self, mii_index: MiiIndex) { let index = match mii_index { - MiiConfigIndex::Index(i) => i, - MiiConfigIndex::All => ctru_sys::MIISELECTOR_GUESTMII_SLOTS, + MiiIndex::Index(i) => i, + MiiIndex::All => ctru_sys::MIISELECTOR_GUESTMII_SLOTS, }; unsafe { ctru_sys::miiSelectorBlacklistGuestMii(self.config.as_mut(), index) } } /// Whitelist a user Mii - pub fn whitelist_user_mii(&mut self, mii_index: MiiConfigIndex) { + pub fn whitelist_user_mii(&mut self, mii_index: MiiIndex) { let index = match mii_index { - MiiConfigIndex::Index(i) => i, - MiiConfigIndex::All => ctru_sys::MIISELECTOR_USERMII_SLOTS, + MiiIndex::Index(i) => i, + MiiIndex::All => ctru_sys::MIISELECTOR_USERMII_SLOTS, }; unsafe { ctru_sys::miiSelectorWhitelistUserMii(self.config.as_mut(), index) } } /// Blacklist a user Mii - pub fn blacklist_user_mii(&mut self, mii_index: MiiConfigIndex) { + pub fn blacklist_user_mii(&mut self, mii_index: MiiIndex) { let index = match mii_index { - MiiConfigIndex::Index(i) => i, - MiiConfigIndex::All => ctru_sys::MIISELECTOR_USERMII_SLOTS, + MiiIndex::Index(i) => i, + MiiIndex::All => ctru_sys::MIISELECTOR_USERMII_SLOTS, }; unsafe { ctru_sys::miiSelectorBlacklistUserMii(self.config.as_mut(), index) } @@ -143,24 +143,24 @@ impl MiiSelector { /// Launch the Mii Selector. /// Returns an error when the checksum of the Mii is invalid. - pub fn launch(&mut self) -> Result { + pub fn launch(&mut self) -> Result { let mut return_val = Box::::default(); unsafe { ctru_sys::miiSelectorLaunch(self.config.as_mut(), return_val.as_mut()) } if unsafe { ctru_sys::miiSelectorChecksumIsValid(return_val.as_mut()) } { Ok((*return_val).into()) } else { - Err(MiiLaunchError::InvalidChecksum) + Err(LaunchError::InvalidChecksum) } } } -impl From for MiiSelectorReturn { +impl From for SelectionResult { fn from(ret: ctru_sys::MiiSelectorReturn) -> Self { let raw_mii_data = ret.mii; let mut guest_mii_name = ret.guest_mii_name; - MiiSelectorReturn { + SelectionResult { mii_data: raw_mii_data.into(), is_mii_selected: ret.no_mii_selected == 0, mii_type: if ret.guest_mii_index != 0xFFFFFFFF { @@ -179,7 +179,7 @@ impl From for MiiSelectorReturn { } } -impl From for MiiConfigIndex { +impl From for MiiIndex { fn from(v: u32) -> Self { Self::Index(v) } diff --git a/ctru-rs/src/applets/swkbd.rs b/ctru-rs/src/applets/swkbd.rs index 178a86e..8f4aab6 100644 --- a/ctru-rs/src/applets/swkbd.rs +++ b/ctru-rs/src/applets/swkbd.rs @@ -7,6 +7,7 @@ use std::iter::once; use std::str; /// An instance of the software keyboard. +#[derive(Clone)] pub struct Swkbd { state: Box, } @@ -18,7 +19,7 @@ pub struct Swkbd { /// Numpad is a number pad. /// Western is a text keyboard without japanese symbols (only applies to JPN systems). For other /// systems it's the same as a Normal keyboard. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum Kind { Normal = ctru_sys::SWKBD_TYPE_NORMAL, @@ -28,7 +29,7 @@ pub enum Kind { } /// Represents which button the user pressed to close the software keyboard. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum Button { Left = ctru_sys::SWKBD_BUTTON_LEFT, @@ -37,7 +38,7 @@ pub enum Button { } /// Error type for the software keyboard. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(i32)] pub enum Error { InvalidInput = ctru_sys::SWKBD_INVALID_INPUT, @@ -51,7 +52,7 @@ pub enum Error { } /// Restrictions on keyboard input -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum ValidInput { Anything = ctru_sys::SWKBD_ANYTHING, diff --git a/ctru-rs/src/console.rs b/ctru-rs/src/console.rs index 73d3952..1891492 100644 --- a/ctru-rs/src/console.rs +++ b/ctru-rs/src/console.rs @@ -16,6 +16,10 @@ impl<'screen> Console<'screen> { /// Initialize a console on the chosen screen, overwriting whatever was on the screen /// previously (including other consoles). The new console is automatically selected for /// printing. + /// + /// # Notes + /// + /// [Console] automatically takes care of flushing and swapping buffers for its screen when printing. pub fn new(screen: RefMut<'screen, dyn Screen>) -> Self { let mut context = Box::::default(); diff --git a/ctru-rs/src/services/am.rs b/ctru-rs/src/services/am.rs index 6fcee8c..70bd151 100644 --- a/ctru-rs/src/services/am.rs +++ b/ctru-rs/src/services/am.rs @@ -6,6 +6,7 @@ use std::mem::MaybeUninit; #[derive(Copy, Clone, Debug)] #[repr(transparent)] pub struct TitleInfo(ctru_sys::AM_TitleEntry); + impl TitleInfo { pub fn id(&self) -> u64 { self.0.titleID diff --git a/ctru-rs/src/services/cam.rs b/ctru-rs/src/services/cam.rs index 261dbd3..4a06421 100644 --- a/ctru-rs/src/services/cam.rs +++ b/ctru-rs/src/services/cam.rs @@ -21,7 +21,7 @@ pub struct Cam { } /// Flag to pass to [Camera::flip_image] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum FlipMode { None = ctru_sys::FLIP_NONE, @@ -31,7 +31,7 @@ pub enum FlipMode { } /// Flag to pass to [Camera::set_view_size] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum ViewSize { TopLCD = ctru_sys::SIZE_CTR_TOP_LCD, @@ -48,7 +48,7 @@ pub enum ViewSize { } /// Flag to pass to [Camera::set_frame_rate] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum FrameRate { Fps15 = ctru_sys::FRAME_RATE_15, @@ -68,7 +68,7 @@ pub enum FrameRate { /// Flag to pass to [Camera::set_white_balance] or /// [Camera::set_white_balance_without_base_up] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum WhiteBalance { /// Normal @@ -86,7 +86,7 @@ pub enum WhiteBalance { } /// Flag to pass to [Camera::set_photo_mode] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum PhotoMode { Normal = ctru_sys::PHOTO_MODE_NORMAL, @@ -97,7 +97,7 @@ pub enum PhotoMode { } /// Flag to pass to [Camera::set_effect] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum Effect { None = ctru_sys::EFFECT_NONE, @@ -109,7 +109,7 @@ pub enum Effect { } /// Flag to pass to [Camera::set_contrast] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum Contrast { /// OFF @@ -121,7 +121,7 @@ pub enum Contrast { } /// Flag to pass to [Camera::set_lens_correction] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum LensCorrection { Off = ctru_sys::LENS_CORRECTION_DARK, @@ -130,7 +130,7 @@ pub enum LensCorrection { } /// Flag to pass to [Camera::set_output_format] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum OutputFormat { Yuv422 = ctru_sys::OUTPUT_YUV_422, @@ -138,7 +138,7 @@ pub enum OutputFormat { } /// Flag to pass to [Cam::play_shutter_sound] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum ShutterSound { Normal = ctru_sys::SHUTTER_SOUND_TYPE_NORMAL, @@ -169,6 +169,7 @@ impl TryFrom for FramebufferFormat { } /// Struct containing coordinates passed to [Camera::set_trimming_params]. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct TrimmingParams { x_start: i16, y_start: i16, @@ -193,11 +194,11 @@ impl TrimmingParams { } /// Represents data used by the camera to calibrate image quality -#[derive(Default)] +#[derive(Default, Clone, Copy, Debug)] pub struct ImageQualityCalibrationData(pub ctru_sys::CAMU_ImageQualityCalibrationData); /// Represents data used by the camera to calibrate image quality when using both outward cameras -#[derive(Default)] +#[derive(Default, Clone, Copy, Debug)] pub struct StereoCameraCalibrationData(pub ctru_sys::CAMU_StereoCameraCalibrationData); /// Represents the camera on the inside of the 3DS diff --git a/ctru-rs/src/services/cfgu.rs b/ctru-rs/src/services/cfgu.rs index 90edf44..62052eb 100644 --- a/ctru-rs/src/services/cfgu.rs +++ b/ctru-rs/src/services/cfgu.rs @@ -4,7 +4,7 @@ use crate::error::ResultCode; -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum Region { Japan = ctru_sys::CFG_REGION_JPN, @@ -16,7 +16,7 @@ pub enum Region { Taiwan = ctru_sys::CFG_REGION_TWN, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum Language { Japanese = ctru_sys::CFG_LANGUAGE_JP, @@ -33,7 +33,7 @@ pub enum Language { TraditionalChinese = ctru_sys::CFG_LANGUAGE_TW, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum SystemModel { Model3DS = ctru_sys::CFG_MODEL_3DS, diff --git a/ctru-rs/src/services/fs.rs b/ctru-rs/src/services/fs.rs index e59b02b..ccc4267 100644 --- a/ctru-rs/src/services/fs.rs +++ b/ctru-rs/src/services/fs.rs @@ -23,17 +23,13 @@ bitflags! { const FS_OPEN_WRITE = 2; const FS_OPEN_CREATE = 4; } -} -bitflags! { #[derive(Default)] struct FsWrite: u32 { const FS_WRITE_FLUSH = 1; const FS_WRITE_UPDATE_TIME = 256; } -} - -bitflags! { + #[derive(Default)] struct FsAttribute: u32 { const FS_ATTRIBUTE_DIRECTORY = 1; @@ -43,7 +39,7 @@ bitflags! { } } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum FsMediaType { Nand = ctru_sys::MEDIATYPE_NAND, @@ -51,7 +47,7 @@ pub enum FsMediaType { GameCard = ctru_sys::MEDIATYPE_GAME_CARD, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum PathType { Invalid = ctru_sys::PATH_INVALID, @@ -61,7 +57,7 @@ pub enum PathType { UTF16 = ctru_sys::PATH_UTF16, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum ArchiveID { RomFS = ctru_sys::ARCHIVE_ROMFS, @@ -252,7 +248,7 @@ pub struct Metadata { /// .open("foo.txt") /// .unwrap(); /// ``` -#[derive(Clone, Default)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub struct OpenOptions { read: bool, write: bool, diff --git a/ctru-rs/src/services/gfx.rs b/ctru-rs/src/services/gfx.rs index 87be464..a4c5c17 100644 --- a/ctru-rs/src/services/gfx.rs +++ b/ctru-rs/src/services/gfx.rs @@ -55,6 +55,23 @@ pub trait Screen: private::Sealed { unsafe { ctru_sys::gfxSetDoubleBuffering(self.as_raw(), enabled) } } + /// Swaps the video buffers. + /// + /// This should be used even if double buffering is disabled. + fn flush_buffer(&mut self) { + let framebuffer = self.raw_framebuffer(); + + // Flush the data array. `self.raw_framebuffer` should get the correct parameters for all kinds of screens + unsafe { ctru_sys::GSPGPU_FlushDataCache(framebuffer.ptr.cast(), (framebuffer.height * framebuffer.width).into()) }; + } + + /// Swaps the video buffers. + /// + /// This should be used even if double buffering is disabled. + fn swap_buffers(&mut self) { + unsafe { ctru_sys::gfxScreenSwapBuffers(self.side().into(), true) }; + } + /// Gets the framebuffer format fn framebuffer_format(&self) -> FramebufferFormat { unsafe { ctru_sys::gfxGetScreenFormat(self.as_raw()) }.into() @@ -103,7 +120,7 @@ pub struct RawFrameBuffer<'screen> { screen: PhantomData<&'screen mut dyn Screen>, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] /// Side of top screen framebuffer /// @@ -128,6 +145,13 @@ pub struct Gfx { static GFX_ACTIVE: Mutex = Mutex::new(0); impl Gfx { + /// Creates a new [Gfx] instance with default init values + /// It's the same as calling: + /// `Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false)` + pub fn new() -> Result { + Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false) + } + /// Initialize the Gfx module with the chosen framebuffer formats for the top and bottom /// screens /// @@ -155,32 +179,6 @@ impl Gfx { }) } - /// Creates a new [Gfx] instance with default init values - /// It's the same as calling: - /// `Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false)` - pub fn new() -> Result { - Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false) - } - - /// Flushes the current framebuffers - pub fn flush_buffers(&self) { - unsafe { ctru_sys::gfxFlushBuffers() }; - } - - /// Swaps the framebuffers and sets the gsp state - /// - /// Use this function when working with software rendering - pub fn swap_buffers(&self) { - unsafe { ctru_sys::gfxSwapBuffers() }; - } - - /// Swaps the framebuffers without manipulating the gsp state - /// - /// Use this function when working with GPU rendering - pub fn swap_buffers_gpu(&self) { - unsafe { ctru_sys::gfxSwapBuffersGpu() }; - } - /// Waits for the vertical blank interrupt /// /// Use this to synchronize your application with the refresh rate of the LCD screens diff --git a/ctru-rs/src/services/gspgpu.rs b/ctru-rs/src/services/gspgpu.rs index 234c088..9f9219c 100644 --- a/ctru-rs/src/services/gspgpu.rs +++ b/ctru-rs/src/services/gspgpu.rs @@ -1,6 +1,6 @@ //! GSPGPU service -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum Event { Psc0 = ctru_sys::GSPGPU_EVENT_PSC0, @@ -13,7 +13,7 @@ pub enum Event { } /// Framebuffer formats supported by the 3DS -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum FramebufferFormat { /// RGBA8. 4 bytes per pixel diff --git a/ctru-rs/src/services/hid.rs b/ctru-rs/src/services/hid.rs index 9577f42..2db0d23 100644 --- a/ctru-rs/src/services/hid.rs +++ b/ctru-rs/src/services/hid.rs @@ -8,7 +8,6 @@ use crate::error::ResultCode; bitflags::bitflags! { /// A set of flags corresponding to the button and directional pad /// inputs on the 3DS - #[derive(Default)] pub struct KeyPad: u32 { const A = ctru_sys::KEY_A; const B = ctru_sys::KEY_B; @@ -48,9 +47,11 @@ bitflags::bitflags! { pub struct Hid(()); /// Represents user input to the touchscreen. +#[derive(Debug, Clone, Copy)] pub struct TouchPosition(ctru_sys::touchPosition); /// Represents the current position of the 3DS circle pad. +#[derive(Debug, Clone, Copy)] pub struct CirclePosition(ctru_sys::circlePosition); /// Initializes the HID service. diff --git a/ctru-rs/src/services/ndsp/mod.rs b/ctru-rs/src/services/ndsp/mod.rs index 3fff3b8..8f67b1b 100644 --- a/ctru-rs/src/services/ndsp/mod.rs +++ b/ctru-rs/src/services/ndsp/mod.rs @@ -14,7 +14,7 @@ use std::sync::Mutex; const NUMBER_OF_CHANNELS: u8 = 24; -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum OutputMode { Mono = ctru_sys::NDSP_OUTPUT_MONO, @@ -22,7 +22,7 @@ pub enum OutputMode { Surround = ctru_sys::NDSP_OUTPUT_SURROUND, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum AudioFormat { PCM8Mono = ctru_sys::NDSP_FORMAT_MONO_PCM8, @@ -32,12 +32,12 @@ pub enum AudioFormat { } /// Representation of volume mix for a channel. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq)] pub struct AudioMix { raw: [f32; 12], } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u32)] pub enum InterpolationType { Polyphase = ctru_sys::NDSP_INTERP_POLYPHASE, @@ -45,7 +45,7 @@ pub enum InterpolationType { None = ctru_sys::NDSP_INTERP_NONE, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum NdspError { /// Channel ID InvalidChannel(u8), diff --git a/ctru-rs/src/services/ndsp/wave.rs b/ctru-rs/src/services/ndsp/wave.rs index a47c113..feff4cd 100644 --- a/ctru-rs/src/services/ndsp/wave.rs +++ b/ctru-rs/src/services/ndsp/wave.rs @@ -11,7 +11,7 @@ pub struct Wave { played_on_channel: Option, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(u8)] /// Enum representing the playback status of a [Wave]. pub enum WaveStatus { diff --git a/ctru-rs/src/services/ps.rs b/ctru-rs/src/services/ps.rs index a14f2c4..1d5bd69 100644 --- a/ctru-rs/src/services/ps.rs +++ b/ctru-rs/src/services/ps.rs @@ -6,6 +6,7 @@ use crate::error::ResultCode; use crate::Result; +#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(u32)] pub enum AESAlgorithm { CbcEnc = ctru_sys::PS_ALGORITHM_CBC_ENC, @@ -16,6 +17,7 @@ pub enum AESAlgorithm { CcmDec = ctru_sys::PS_ALGORITHM_CCM_DEC, } +#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(u32)] pub enum AESKeyType { Keyslot0D = ctru_sys::PS_KEYSLOT_0D, @@ -56,7 +58,7 @@ impl Ps { pub fn generate_random_bytes(&self, out: &mut [u8]) -> crate::Result<()> { ResultCode(unsafe { - ctru_sys::PS_GenerateRandomBytes(out as *mut _ as *mut _, out.len()) + ctru_sys::PS_GenerateRandomBytes(out.as_mut_ptr().cast(), out.len()) })?; Ok(()) } diff --git a/ctru-rs/src/services/sslc.rs b/ctru-rs/src/services/sslc.rs index 405fb9b..341155f 100644 --- a/ctru-rs/src/services/sslc.rs +++ b/ctru-rs/src/services/sslc.rs @@ -14,17 +14,6 @@ impl SslC { Ok(SslC(())) } } - - /// Fill `buf` with `buf.len()` random bytes - pub fn generate_random_data(&self, buf: &mut [u8]) -> crate::Result<()> { - unsafe { - ResultCode(ctru_sys::sslcGenerateRandomData( - buf.as_ptr() as _, - buf.len() as u32, - ))?; - Ok(()) - } - } } impl Drop for SslC { diff --git a/ctru-rs/src/test_runner.rs b/ctru-rs/src/test_runner.rs index 713e0e6..97aa5f4 100644 --- a/ctru-rs/src/test_runner.rs +++ b/ctru-rs/src/test_runner.rs @@ -39,8 +39,6 @@ pub(crate) fn run(tests: &[&TestDescAndFn]) { println!("Press START to exit."); while apt.main_loop() { - gfx.flush_buffers(); - gfx.swap_buffers(); gfx.wait_for_vblank(); hid.scan_input();