From c3df8af69f738199b99739849c41b0986ee101e7 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Wed, 29 Mar 2023 20:06:40 +0200 Subject: [PATCH 01/18] Folder restructuring and slight changes to gspgpu --- ctru-rs/examples/camera-image.rs | 2 +- ctru-rs/examples/file-explorer.rs | 2 +- ctru-rs/examples/gfx-3d-mode.rs | 2 +- ctru-rs/examples/graphics-bitmap.rs | 2 +- ctru-rs/examples/romfs.rs | 2 +- ctru-rs/src/console.rs | 2 +- ctru-rs/src/lib.rs | 20 -------------------- ctru-rs/src/prelude.rs | 3 +-- ctru-rs/src/{ => services}/gfx.rs | 2 +- ctru-rs/src/services/gspgpu.rs | 28 +++++++++++++++------------- ctru-rs/src/services/mod.rs | 20 ++++++++++++++++++++ ctru-rs/src/{ => services}/romfs.rs | 2 ++ ctru-rs/src/test_runner.rs | 5 +---- 13 files changed, 46 insertions(+), 46 deletions(-) rename ctru-rs/src/{ => services}/gfx.rs (99%) rename ctru-rs/src/{ => services}/romfs.rs (97%) diff --git a/ctru-rs/examples/camera-image.rs b/ctru-rs/examples/camera-image.rs index b46b591..7922f20 100644 --- a/ctru-rs/examples/camera-image.rs +++ b/ctru-rs/examples/camera-image.rs @@ -1,6 +1,6 @@ -use ctru::gfx::Screen; use ctru::prelude::*; use ctru::services::cam::{Cam, CamOutputFormat, CamShutterSoundType, CamSize, Camera}; +use ctru::services::gfx::Screen; use ctru::services::gspgpu::FramebufferFormat; use std::time::Duration; diff --git a/ctru-rs/examples/file-explorer.rs b/ctru-rs/examples/file-explorer.rs index 74a94eb..3bfeadc 100644 --- a/ctru-rs/examples/file-explorer.rs +++ b/ctru-rs/examples/file-explorer.rs @@ -16,7 +16,7 @@ fn main() { let gfx = Gfx::init().unwrap(); #[cfg(all(feature = "romfs", romfs_exists))] - let _romfs = ctru::romfs::RomFS::init().unwrap(); + let _romfs = ctru::services::romfs::RomFS::init().unwrap(); FileExplorer::init(&apt, &hid, &gfx).run(); } diff --git a/ctru-rs/examples/gfx-3d-mode.rs b/ctru-rs/examples/gfx-3d-mode.rs index dfdc028..171838b 100644 --- a/ctru-rs/examples/gfx-3d-mode.rs +++ b/ctru-rs/examples/gfx-3d-mode.rs @@ -1,5 +1,5 @@ -use ctru::gfx::{Screen, Side, TopScreen3D}; use ctru::prelude::*; +use ctru::services::gfx::{Screen, Side, TopScreen3D}; /// See `graphics-bitmap.rs` for details on how the image is generated. /// diff --git a/ctru-rs/examples/graphics-bitmap.rs b/ctru-rs/examples/graphics-bitmap.rs index b6842f1..5421e9b 100644 --- a/ctru-rs/examples/graphics-bitmap.rs +++ b/ctru-rs/examples/graphics-bitmap.rs @@ -1,5 +1,5 @@ -use ctru::gfx::Screen as _; use ctru::prelude::*; +use ctru::services::gfx::Screen; /// Ferris image taken from and scaled down to 320x240px. /// To regenerate the data, you will need to install `imagemagick` and run this diff --git a/ctru-rs/examples/romfs.rs b/ctru-rs/examples/romfs.rs index 45a7add..965cb6d 100644 --- a/ctru-rs/examples/romfs.rs +++ b/ctru-rs/examples/romfs.rs @@ -13,7 +13,7 @@ fn main() { // This never fails as `ctru-rs` examples inherit all of the `ctru` features, // but it might if a normal user application wasn't setup correctly if #[cfg(all(feature = "romfs", romfs_exists))] { - let _romfs = ctru::romfs::RomFS::init().unwrap(); + let _romfs = ctru::services::romfs::RomFS::init().unwrap(); let f = std::fs::read_to_string("romfs:/test-file.txt").unwrap(); println!("Contents of test-file.txt: \n{f}\n"); diff --git a/ctru-rs/src/console.rs b/ctru-rs/src/console.rs index cfd15ea..c0a8765 100644 --- a/ctru-rs/src/console.rs +++ b/ctru-rs/src/console.rs @@ -3,7 +3,7 @@ use std::default::Default; use ctru_sys::{consoleClear, consoleInit, consoleSelect, consoleSetWindow, PrintConsole}; -use crate::gfx::Screen; +use crate::services::gfx::Screen; static mut EMPTY_CONSOLE: PrintConsole = unsafe { const_zero::const_zero!(PrintConsole) }; diff --git a/ctru-rs/src/lib.rs b/ctru-rs/src/lib.rs index 8dd8abf..2db6c22 100644 --- a/ctru-rs/src/lib.rs +++ b/ctru-rs/src/lib.rs @@ -62,31 +62,11 @@ fn panic_hook_setup() { pub mod applets; pub mod console; pub mod error; -pub mod gfx; pub mod linear; pub mod mii; pub mod prelude; pub mod services; -cfg_if::cfg_if! { - if #[cfg(all(feature = "romfs", romfs_exists))] { - pub mod romfs; - } else { - pub mod romfs { - //! The RomFS folder has not been detected and/or the `romfs` feature has not been enabled. - //! - //! Configure the path in Cargo.toml (the default path is "romfs"). Paths are relative to the - //! `CARGO_MANIFEST_DIR` environment variable, which is the directory containing the manifest of - //! your package. - //! - //! ```toml - //! [package.metadata.cargo-3ds] - //! romfs_dir = "romfs" - //! ``` - } - } -} - #[cfg(test)] mod test_runner; diff --git a/ctru-rs/src/prelude.rs b/ctru-rs/src/prelude.rs index 27196f9..74faa41 100644 --- a/ctru-rs/src/prelude.rs +++ b/ctru-rs/src/prelude.rs @@ -1,3 +1,2 @@ pub use crate::console::Console; -pub use crate::gfx::Gfx; -pub use crate::services::{hid::KeyPad, soc::Soc, Apt, Hid}; +pub use crate::services::{gfx::Gfx, hid::KeyPad, soc::Soc, Apt, Hid}; diff --git a/ctru-rs/src/gfx.rs b/ctru-rs/src/services/gfx.rs similarity index 99% rename from ctru-rs/src/gfx.rs rename to ctru-rs/src/services/gfx.rs index fd439a0..457f94d 100644 --- a/ctru-rs/src/gfx.rs +++ b/ctru-rs/src/services/gfx.rs @@ -57,7 +57,7 @@ pub trait Screen: private::Sealed { /// Gets the framebuffer format fn get_framebuffer_format(&self) -> FramebufferFormat { - unsafe { ctru_sys::gfxGetScreenFormat(self.as_raw()).into() } + unsafe { ctru_sys::gfxGetScreenFormat(self.as_raw()) }.into() } /// Change the framebuffer format diff --git a/ctru-rs/src/services/gspgpu.rs b/ctru-rs/src/services/gspgpu.rs index 1357fad..73fb77d 100644 --- a/ctru-rs/src/services/gspgpu.rs +++ b/ctru-rs/src/services/gspgpu.rs @@ -3,29 +3,31 @@ use std::convert::From; #[derive(Copy, Clone, Debug)] +#[repr(u32)] pub enum Event { - Psc0, - Psc1, - VBlank0, - VBlank1, - PPF, - P3D, - DMA, + Psc0 = ctru_sys::GSPGPU_EVENT_PSC0, + Psc1 = ctru_sys::GSPGPU_EVENT_PSC1, + VBlank0 = ctru_sys::GSPGPU_EVENT_VBlank0, + VBlank1 = ctru_sys::GSPGPU_EVENT_VBlank1, + PPF = ctru_sys::GSPGPU_EVENT_PPF, + P3D = ctru_sys::GSPGPU_EVENT_P3D, + DMA = ctru_sys::GSPGPU_EVENT_DMA, } -/// The different framebuffer formats supported by the 3DS +/// Framebuffer formats supported by the 3DS #[derive(Copy, Clone, Debug)] +#[repr(u32)] pub enum FramebufferFormat { /// RGBA8. 4 bytes per pixel - Rgba8, + Rgba8 = ctru_sys::GSP_RGBA8_OES, /// BGR8. 3 bytes per pixel - Bgr8, + Bgr8 = ctru_sys::GSP_BGR8_OES, /// RGB565. 2 bytes per pixel - Rgb565, + Rgb565 = ctru_sys::GSP_RGB565_OES, /// RGB5A1. 2 bytes per pixel - Rgb5A1, + Rgb5A1 = ctru_sys::GSP_RGB5_A1_OES, /// RGBA4. 2 bytes per pixel - Rgba4, + Rgba4 = ctru_sys::GSP_RGBA4_OES, } impl FramebufferFormat { diff --git a/ctru-rs/src/services/mod.rs b/ctru-rs/src/services/mod.rs index 5abf93a..6b9e115 100644 --- a/ctru-rs/src/services/mod.rs +++ b/ctru-rs/src/services/mod.rs @@ -10,6 +10,7 @@ pub mod apt; pub mod cam; pub mod cfgu; pub mod fs; +pub mod gfx; pub mod gspgpu; pub mod hid; pub mod ndsp; @@ -18,6 +19,25 @@ mod reference; pub mod soc; pub mod sslc; +cfg_if::cfg_if! { + if #[cfg(all(feature = "romfs", romfs_exists))] { + pub mod romfs; + } else { + pub mod romfs { + //! The RomFS folder has not been detected and/or the `romfs` feature has not been enabled. + //! + //! Configure the path in Cargo.toml (the default path is "romfs"). Paths are relative to the + //! `CARGO_MANIFEST_DIR` environment variable, which is the directory containing the manifest of + //! your package. + //! + //! ```toml + //! [package.metadata.cargo-3ds] + //! romfs_dir = "romfs" + //! ``` + } + } +} + pub use self::apt::Apt; pub use self::hid::Hid; diff --git a/ctru-rs/src/romfs.rs b/ctru-rs/src/services/romfs.rs similarity index 97% rename from ctru-rs/src/romfs.rs rename to ctru-rs/src/services/romfs.rs index e601898..fd022e8 100644 --- a/ctru-rs/src/romfs.rs +++ b/ctru-rs/src/services/romfs.rs @@ -1,3 +1,5 @@ +//! Read-Only Memory FileSystem +//! //! This module only gets compiled if the configured RomFS directory is found and the `romfs` //! feature is enabled. //! diff --git a/ctru-rs/src/test_runner.rs b/ctru-rs/src/test_runner.rs index 8b3f117..00634f6 100644 --- a/ctru-rs/src/test_runner.rs +++ b/ctru-rs/src/test_runner.rs @@ -6,10 +6,7 @@ use std::io; use test::{ColorConfig, OutputFormat, TestDescAndFn, TestFn, TestOpts}; -use crate::console::Console; -use crate::gfx::Gfx; -use crate::services::hid::{Hid, KeyPad}; -use crate::services::Apt; +use crate::prelude::*; /// A custom runner to be used with `#[test_runner]`. This simple implementation /// runs all tests in series, "failing" on the first one to panic (really, the From 43b83b53565360d6fcb5f93ca0bfaecbda976fa9 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Wed, 29 Mar 2023 21:02:00 +0200 Subject: [PATCH 02/18] More modules starndardised --- ctru-rs/examples/audio-filters.rs | 10 ++-- ctru-rs/examples/buttons.rs | 10 ++-- ctru-rs/examples/camera-image.rs | 4 +- ctru-rs/examples/file-explorer.rs | 12 ++--- ctru-rs/examples/gfx-3d-mode.rs | 4 +- ctru-rs/examples/gfx-wide-mode.rs | 4 +- ctru-rs/examples/graphics-bitmap.rs | 2 +- ctru-rs/examples/hashmaps.rs | 2 +- ctru-rs/examples/hello-both-screens.rs | 2 +- ctru-rs/examples/hello-world.rs | 2 +- ctru-rs/examples/linear-memory.rs | 2 +- ctru-rs/examples/mii-selector.rs | 2 +- ctru-rs/examples/network-sockets.rs | 2 +- ctru-rs/examples/output-3dslink.rs | 2 +- ctru-rs/examples/romfs.rs | 2 +- ctru-rs/examples/software-keyboard.rs | 4 +- ctru-rs/examples/system-configuration.rs | 2 +- ctru-rs/examples/time-rtc.rs | 2 +- ctru-rs/examples/title-info.rs | 8 ++-- ctru-rs/src/lib.rs | 6 +-- ctru-rs/src/services/fs.rs | 58 ++++++++++++------------ ctru-rs/src/services/hid.rs | 56 +++++++++++------------ ctru-rs/src/services/ps.rs | 32 ++++++------- ctru-rs/src/services/soc.rs | 8 +++- ctru-rs/src/services/sslc.rs | 4 +- ctru-rs/src/test_runner.rs | 2 +- 26 files changed, 126 insertions(+), 118 deletions(-) diff --git a/ctru-rs/examples/audio-filters.rs b/ctru-rs/examples/audio-filters.rs index 616b8d4..8c11799 100644 --- a/ctru-rs/examples/audio-filters.rs +++ b/ctru-rs/examples/audio-filters.rs @@ -102,23 +102,23 @@ fn main() { hid.scan_input(); let keys_down = hid.keys_down(); - if keys_down.contains(KeyPad::KEY_START) { + if keys_down.contains(KeyPad::START) { break; } // break in order to return to hbmenu - if keys_down.intersects(KeyPad::KEY_DOWN) { + if keys_down.intersects(KeyPad::DOWN) { note = note.saturating_sub(1); - } else if keys_down.intersects(KeyPad::KEY_UP) { + } else if keys_down.intersects(KeyPad::UP) { note = std::cmp::min(note + 1, NOTEFREQ.len() - 1); } let mut update_params = false; - if keys_down.intersects(KeyPad::KEY_LEFT) { + if keys_down.intersects(KeyPad::LEFT) { filter -= 1; filter = filter.rem_euclid(filter_names.len() as _); update_params = true; - } else if keys_down.intersects(KeyPad::KEY_RIGHT) { + } else if keys_down.intersects(KeyPad::RIGHT) { filter += 1; filter = filter.rem_euclid(filter_names.len() as _); diff --git a/ctru-rs/examples/buttons.rs b/ctru-rs/examples/buttons.rs index c8f9f71..1cc5355 100644 --- a/ctru-rs/examples/buttons.rs +++ b/ctru-rs/examples/buttons.rs @@ -42,19 +42,19 @@ fn main() { // You can also use the .bits() method to do direct comparisons on // the underlying bits - if keys.contains(KeyPad::KEY_A) { + if keys.contains(KeyPad::A) { println!("You held A!"); } - if keys.bits() & KeyPad::KEY_B.bits() != 0 { + if keys.bits() & KeyPad::B.bits() != 0 { println!("You held B!"); } - if keys.contains(KeyPad::KEY_X | KeyPad::KEY_Y) { + if keys.contains(KeyPad::X | KeyPad::Y) { println!("You held X and Y!"); } - if keys.intersects(KeyPad::KEY_L | KeyPad::KEY_R | KeyPad::KEY_ZL | KeyPad::KEY_ZR) { + if keys.intersects(KeyPad::L | KeyPad::R | KeyPad::ZL | KeyPad::ZR) { println!("You held a shoulder button!"); } - if keys.intersects(KeyPad::KEY_START) { + if keys.intersects(KeyPad::START) { println!("See ya!"); break; } diff --git a/ctru-rs/examples/camera-image.rs b/ctru-rs/examples/camera-image.rs index 7922f20..7559275 100644 --- a/ctru-rs/examples/camera-image.rs +++ b/ctru-rs/examples/camera-image.rs @@ -65,11 +65,11 @@ fn main() { hid.scan_input(); keys_down = hid.keys_down(); - if keys_down.contains(KeyPad::KEY_START) { + if keys_down.contains(KeyPad::START) { break; } - if keys_down.contains(KeyPad::KEY_R) { + if keys_down.contains(KeyPad::R) { println!("Capturing new image"); let camera = &mut cam.outer_right_cam; diff --git a/ctru-rs/examples/file-explorer.rs b/ctru-rs/examples/file-explorer.rs index 3bfeadc..88de947 100644 --- a/ctru-rs/examples/file-explorer.rs +++ b/ctru-rs/examples/file-explorer.rs @@ -56,15 +56,15 @@ impl<'a> FileExplorer<'a> { self.hid.scan_input(); let input = self.hid.keys_down(); - if input.contains(KeyPad::KEY_START) { + if input.contains(KeyPad::START) { break; - } else if input.contains(KeyPad::KEY_B) && self.path.components().count() > 1 { + } else if input.contains(KeyPad::B) && self.path.components().count() > 1 { self.path.pop(); self.console.clear(); self.print_menu(); - } else if input.contains(KeyPad::KEY_A) { + } else if input.contains(KeyPad::A) { self.get_input_and_run(Self::set_next_path); - } else if input.contains(KeyPad::KEY_X) { + } else if input.contains(KeyPad::X) { self.get_input_and_run(Self::set_exact_path); } @@ -147,11 +147,11 @@ impl<'a> FileExplorer<'a> { self.hid.scan_input(); let input = self.hid.keys_down(); - if input.contains(KeyPad::KEY_A) { + if input.contains(KeyPad::A) { break; } - if input.contains(KeyPad::KEY_START) { + if input.contains(KeyPad::START) { self.running = false; return; } diff --git a/ctru-rs/examples/gfx-3d-mode.rs b/ctru-rs/examples/gfx-3d-mode.rs index 171838b..da7150a 100644 --- a/ctru-rs/examples/gfx-3d-mode.rs +++ b/ctru-rs/examples/gfx-3d-mode.rs @@ -31,7 +31,7 @@ fn main() { //Scan all the inputs. This should be done once for each frame hid.scan_input(); - if hid.keys_down().contains(KeyPad::KEY_START) { + if hid.keys_down().contains(KeyPad::START) { break; } @@ -44,7 +44,7 @@ fn main() { right_buf.ptr.copy_from(ZERO.as_ptr(), ZERO.len()); } - if hid.keys_down().contains(KeyPad::KEY_A) { + if hid.keys_down().contains(KeyPad::A) { // flip which buffer we're writing to current_side = match current_side { Side::Left => Side::Right, diff --git a/ctru-rs/examples/gfx-wide-mode.rs b/ctru-rs/examples/gfx-wide-mode.rs index 2d25f7f..ae263cd 100644 --- a/ctru-rs/examples/gfx-wide-mode.rs +++ b/ctru-rs/examples/gfx-wide-mode.rs @@ -13,11 +13,11 @@ fn main() { while apt.main_loop() { hid.scan_input(); - if hid.keys_down().contains(KeyPad::KEY_START) { + if hid.keys_down().contains(KeyPad::START) { break; } - if hid.keys_down().contains(KeyPad::KEY_A) { + if hid.keys_down().contains(KeyPad::A) { drop(console); let wide_mode = gfx.top_screen.borrow().get_wide_mode(); diff --git a/ctru-rs/examples/graphics-bitmap.rs b/ctru-rs/examples/graphics-bitmap.rs index 5421e9b..e2b7def 100644 --- a/ctru-rs/examples/graphics-bitmap.rs +++ b/ctru-rs/examples/graphics-bitmap.rs @@ -43,7 +43,7 @@ fn main() { //Scan all the inputs. This should be done once for each frame hid.scan_input(); - if hid.keys_down().contains(KeyPad::KEY_START) { + if hid.keys_down().contains(KeyPad::START) { break; } diff --git a/ctru-rs/examples/hashmaps.rs b/ctru-rs/examples/hashmaps.rs index 42efee2..e6b9619 100644 --- a/ctru-rs/examples/hashmaps.rs +++ b/ctru-rs/examples/hashmaps.rs @@ -26,7 +26,7 @@ fn main() { gfx.wait_for_vblank(); hid.scan_input(); - if hid.keys_down().contains(KeyPad::KEY_START) { + if hid.keys_down().contains(KeyPad::START) { break; } } diff --git a/ctru-rs/examples/hello-both-screens.rs b/ctru-rs/examples/hello-both-screens.rs index 38934d3..601027f 100644 --- a/ctru-rs/examples/hello-both-screens.rs +++ b/ctru-rs/examples/hello-both-screens.rs @@ -32,7 +32,7 @@ fn main() { gfx.wait_for_vblank(); hid.scan_input(); - if hid.keys_down().contains(KeyPad::KEY_START) { + if hid.keys_down().contains(KeyPad::START) { break; } } diff --git a/ctru-rs/examples/hello-world.rs b/ctru-rs/examples/hello-world.rs index 910813a..d61a7bc 100644 --- a/ctru-rs/examples/hello-world.rs +++ b/ctru-rs/examples/hello-world.rs @@ -26,7 +26,7 @@ fn main() { //Scan all the inputs. This should be done once for each frame hid.scan_input(); - if hid.keys_down().contains(KeyPad::KEY_START) { + if hid.keys_down().contains(KeyPad::START) { break; } // Flush and swap framebuffers diff --git a/ctru-rs/examples/linear-memory.rs b/ctru-rs/examples/linear-memory.rs index 440e62b..a44a35f 100644 --- a/ctru-rs/examples/linear-memory.rs +++ b/ctru-rs/examples/linear-memory.rs @@ -34,7 +34,7 @@ fn main() { //Scan all the inputs. This should be done once for each frame hid.scan_input(); - if hid.keys_down().contains(KeyPad::KEY_START) { + if hid.keys_down().contains(KeyPad::START) { break; } // Flush and swap framebuffers diff --git a/ctru-rs/examples/mii-selector.rs b/ctru-rs/examples/mii-selector.rs index 84115b6..7488c0c 100644 --- a/ctru-rs/examples/mii-selector.rs +++ b/ctru-rs/examples/mii-selector.rs @@ -30,7 +30,7 @@ fn main() { //Scan all the inputs. This should be done once for each frame hid.scan_input(); - if hid.keys_down().contains(KeyPad::KEY_START) { + if hid.keys_down().contains(KeyPad::START) { break; } // Flush and swap framebuffers diff --git a/ctru-rs/examples/network-sockets.rs b/ctru-rs/examples/network-sockets.rs index e53ef42..db750bc 100644 --- a/ctru-rs/examples/network-sockets.rs +++ b/ctru-rs/examples/network-sockets.rs @@ -61,7 +61,7 @@ fn main() { } hid.scan_input(); - if hid.keys_down().contains(KeyPad::KEY_START) { + if hid.keys_down().contains(KeyPad::START) { break; }; } diff --git a/ctru-rs/examples/output-3dslink.rs b/ctru-rs/examples/output-3dslink.rs index 2d6b147..61731d2 100644 --- a/ctru-rs/examples/output-3dslink.rs +++ b/ctru-rs/examples/output-3dslink.rs @@ -30,7 +30,7 @@ fn main() { //Scan all the inputs. This should be done once for each frame hid.scan_input(); - if hid.keys_down().contains(KeyPad::KEY_START) { + if hid.keys_down().contains(KeyPad::START) { break; } // Flush and swap framebuffers diff --git a/ctru-rs/examples/romfs.rs b/ctru-rs/examples/romfs.rs index 965cb6d..f52fff3 100644 --- a/ctru-rs/examples/romfs.rs +++ b/ctru-rs/examples/romfs.rs @@ -33,7 +33,7 @@ fn main() { //Scan all the inputs. This should be done once for each frame hid.scan_input(); - if hid.keys_down().contains(KeyPad::KEY_START) { + if hid.keys_down().contains(KeyPad::START) { break; } // Flush and swap framebuffers diff --git a/ctru-rs/examples/software-keyboard.rs b/ctru-rs/examples/software-keyboard.rs index 0415b10..ffa096c 100644 --- a/ctru-rs/examples/software-keyboard.rs +++ b/ctru-rs/examples/software-keyboard.rs @@ -18,7 +18,7 @@ fn main() { hid.scan_input(); - if hid.keys_down().contains(KeyPad::KEY_A) { + if hid.keys_down().contains(KeyPad::A) { // Prepares a software keyboard with two buttons: One to cancel input and one // to accept it. You can also use `Swkbd::init()` to launch the keyboard in different // configurations. @@ -37,7 +37,7 @@ fn main() { } } - if hid.keys_down().contains(KeyPad::KEY_START) { + if hid.keys_down().contains(KeyPad::START) { break; } } diff --git a/ctru-rs/examples/system-configuration.rs b/ctru-rs/examples/system-configuration.rs index 284e3f1..fde7d18 100644 --- a/ctru-rs/examples/system-configuration.rs +++ b/ctru-rs/examples/system-configuration.rs @@ -19,7 +19,7 @@ fn main() { //Scan all the inputs. This should be done once for each frame hid.scan_input(); - if hid.keys_down().contains(KeyPad::KEY_START) { + if hid.keys_down().contains(KeyPad::START) { break; } // Flush and swap framebuffers diff --git a/ctru-rs/examples/time-rtc.rs b/ctru-rs/examples/time-rtc.rs index b7ff399..a229105 100644 --- a/ctru-rs/examples/time-rtc.rs +++ b/ctru-rs/examples/time-rtc.rs @@ -16,7 +16,7 @@ fn main() { // Scan all the inputs. This should be done once for each frame hid.scan_input(); - if hid.keys_down().contains(KeyPad::KEY_START) { + if hid.keys_down().contains(KeyPad::START) { break; } diff --git a/ctru-rs/examples/title-info.rs b/ctru-rs/examples/title-info.rs index 1f5654f..6dd39a6 100644 --- a/ctru-rs/examples/title-info.rs +++ b/ctru-rs/examples/title-info.rs @@ -35,10 +35,10 @@ fn main() { //Scan all the inputs. This should be done once for each frame hid.scan_input(); - if hid.keys_down().contains(KeyPad::KEY_START) { + if hid.keys_down().contains(KeyPad::START) { break; } - if hid.keys_down().contains(KeyPad::KEY_SELECT) { + if hid.keys_down().contains(KeyPad::SELECT) { refresh = true; offset = 0; use_nand = !use_nand; @@ -46,12 +46,12 @@ fn main() { let cur_list = if use_nand { &nand_list } else { &sd_list }; - if hid.keys_down().intersects(KeyPad::KEY_DOWN) { + if hid.keys_down().intersects(KeyPad::DOWN) { if offset + 1 < cur_list.len() { offset = offset + 1; refresh = true; } - } else if hid.keys_down().intersects(KeyPad::KEY_UP) { + } else if hid.keys_down().intersects(KeyPad::UP) { if offset > 0 { offset = offset - 1; refresh = true; diff --git a/ctru-rs/src/lib.rs b/ctru-rs/src/lib.rs index 2db6c22..bcd60e0 100644 --- a/ctru-rs/src/lib.rs +++ b/ctru-rs/src/lib.rs @@ -15,10 +15,10 @@ extern crate pthread_3ds; #[cfg(feature = "big-stack")] static __stacksize__: usize = 2 * 1024 * 1024; // 2MB -/// Activate ´ctru-rs´' default panic handler. +/// Activate the default panic handler. /// /// With this implementation, the main thread will stop and try to print debug info to an available [console::Console]. -/// In case it fails to find an active [console::Console], the program will just exit. +/// In case it fails to find an active [console::Console] the program will just exit. /// /// # Notes /// @@ -48,7 +48,7 @@ fn panic_hook_setup() { Ok(hid) => loop { hid.scan_input(); let keys = hid.keys_down(); - if keys.contains(KeyPad::KEY_SELECT) { + if keys.contains(KeyPad::SELECT) { break; } }, diff --git a/ctru-rs/src/services/fs.rs b/ctru-rs/src/services/fs.rs index 6cd3728..f53b24c 100644 --- a/ctru-rs/src/services/fs.rs +++ b/ctru-rs/src/services/fs.rs @@ -1,7 +1,7 @@ //! Filesystem service //! //! This module contains basic methods to manipulate the contents of the 3DS's filesystem. -//! Only the SD card is currently supported. +//! Only the SD card is currently supported. You should prefer using `std::fs`. use bitflags::bitflags; use std::ffi::OsString; @@ -52,38 +52,40 @@ pub enum FsMediaType { } #[derive(Copy, Clone, Debug)] +#[repr(u32)] pub enum PathType { - Invalid, - Empty, - Binary, - ASCII, - UTF16, + Invalid = ctru_sys::PATH_INVALID, + Empty = ctru_sys::PATH_EMPTY, + Binary = ctru_sys::PATH_BINARY, + ASCII = ctru_sys::PATH_ASCII, + UTF16 = ctru_sys::PATH_UTF16, } #[derive(Copy, Clone, Debug)] +#[repr(u32)] pub enum ArchiveID { - RomFS, - Savedata, - Extdata, - SharedExtdata, - SystemSavedata, - Sdmc, - SdmcWriteOnly, - BossExtdata, - CardSpiFS, - ExtDataAndBossExtdata, - SystemSaveData2, - NandRW, - NandRO, - NandROWriteAccess, - SaveDataAndContent, - SaveDataAndContent2, - NandCtrFS, - TwlPhoto, - NandTwlFS, - GameCardSavedata, - UserSavedata, - DemoSavedata, + RomFS = ctru_sys::ARCHIVE_ROMFS, + Savedata = ctru_sys::ARCHIVE_ROMFS, + Extdata = ctru_sys::ARCHIVE_ROMFS, + SharedExtdata = ctru_sys::ARCHIVE_ROMFS, + SystemSavedata = ctru_sys::ARCHIVE_ROMFS, + Sdmc = ctru_sys::ARCHIVE_ROMFS, + SdmcWriteOnly = ctru_sys::ARCHIVE_ROMFS, + BossExtdata = ctru_sys::ARCHIVE_ROMFS, + CardSpiFS = ctru_sys::ARCHIVE_ROMFS, + ExtDataAndBossExtdata = ctru_sys::ARCHIVE_ROMFS, + SystemSaveData2 = ctru_sys::ARCHIVE_ROMFS, + NandRW = ctru_sys::ARCHIVE_ROMFS, + NandRO = ctru_sys::ARCHIVE_ROMFS, + NandROWriteAccess = ctru_sys::ARCHIVE_ROMFS, + SaveDataAndContent = ctru_sys::ARCHIVE_ROMFS, + SaveDataAndContent2 = ctru_sys::ARCHIVE_ROMFS, + NandCtrFS = ctru_sys::ARCHIVE_ROMFS, + TwlPhoto = ctru_sys::ARCHIVE_ROMFS, + NandTwlFS = ctru_sys::ARCHIVE_ROMFS, + GameCardSavedata = ctru_sys::ARCHIVE_ROMFS, + UserSavedata = ctru_sys::ARCHIVE_ROMFS, + DemoSavedata = ctru_sys::ARCHIVE_ROMFS, } /// Represents the filesystem service. No file IO can be performed diff --git a/ctru-rs/src/services/hid.rs b/ctru-rs/src/services/hid.rs index 6aacf3a..26b034f 100644 --- a/ctru-rs/src/services/hid.rs +++ b/ctru-rs/src/services/hid.rs @@ -10,34 +10,34 @@ bitflags::bitflags! { /// inputs on the 3DS #[derive(Default)] pub struct KeyPad: u32 { - const KEY_A = 1u32 << 0; - const KEY_B = 1u32 << 1; - const KEY_SELECT = 1u32 << 2; - const KEY_START = 1u32 << 3; - const KEY_DRIGHT = 1u32 << 4; - const KEY_DLEFT = 1u32 << 5; - const KEY_DUP = 1u32 << 6; - const KEY_DDOWN = 1u32 << 7; - const KEY_R = 1u32 << 8; - const KEY_L = 1u32 << 9; - const KEY_X = 1u32 << 10; - const KEY_Y = 1u32 << 11; - const KEY_ZL = 1u32 << 14; - const KEY_ZR = 1u32 << 15; - const KEY_TOUCH = 1u32 << 20; - const KEY_CSTICK_RIGHT = 1u32 << 24; - const KEY_CSTICK_LEFT = 1u32 << 25; - const KEY_CSTICK_UP = 1u32 << 26; - const KEY_CSTICK_DOWN = 1u32 << 27; - const KEY_CPAD_RIGHT = 1u32 << 28; - const KEY_CPAD_LEFT = 1u32 << 29; - const KEY_CPAD_UP = 1u32 << 30; - const KEY_CPAD_DOWN = 1u32 << 31; - // convenience catch-all for the dpad and cpad - const KEY_UP = KeyPad::KEY_DUP.bits | KeyPad::KEY_CPAD_UP.bits; - const KEY_DOWN = KeyPad::KEY_DDOWN.bits | KeyPad::KEY_CPAD_DOWN.bits; - const KEY_LEFT = KeyPad::KEY_DLEFT.bits | KeyPad::KEY_CPAD_LEFT.bits; - const KEY_RIGHT = KeyPad::KEY_DRIGHT.bits | KeyPad::KEY_CPAD_RIGHT.bits; + const A = ctru_sys::KEY_A; + const B = ctru_sys::KEY_B; + const SELECT = ctru_sys::KEY_SELECT; + const START = ctru_sys::KEY_START; + const DRIGHT = ctru_sys::KEY_DRIGHT; + const DLEFT = ctru_sys::KEY_DLEFT; + const DUP = ctru_sys::KEY_DUP; + const DDOWN = ctru_sys::KEY_DDOWN; + const R = ctru_sys::KEY_R; + const L = ctru_sys::KEY_L; + const X = ctru_sys::KEY_X; + const Y = ctru_sys::KEY_Y; + const ZL = ctru_sys::KEY_ZL; + const ZR = ctru_sys::KEY_ZR; + const TOUCH = ctru_sys::KEY_TOUCH; + const CSTICK_RIGHT = ctru_sys::KEY_CSTICK_RIGHT; + const CSTICK_LEFT = ctru_sys::KEY_CSTICK_LEFT; + const CSTICK_UP = ctru_sys::KEY_CSTICK_UP; + const CSTICK_DOWN = ctru_sys::KEY_CSTICK_DOWN; + const CPAD_RIGHT = ctru_sys::KEY_CPAD_RIGHT; + const CPAD_LEFT = ctru_sys::KEY_CPAD_LEFT; + const CPAD_UP = ctru_sys::KEY_CPAD_UP; + const CPAD_DOWN = ctru_sys::KEY_CPAD_DOWN; + // Convenience catch-all for the dpad and cpad + const UP = KeyPad::DUP.bits() | KeyPad::CPAD_UP.bits(); + const DOWN = KeyPad::DDOWN.bits() | KeyPad::CPAD_DOWN.bits(); + const LEFT = KeyPad::DLEFT.bits() | KeyPad::CPAD_LEFT.bits(); + const RIGHT = KeyPad::DRIGHT.bits() | KeyPad::CPAD_RIGHT.bits(); } } diff --git a/ctru-rs/src/services/ps.rs b/ctru-rs/src/services/ps.rs index 79ebcd7..8795b32 100644 --- a/ctru-rs/src/services/ps.rs +++ b/ctru-rs/src/services/ps.rs @@ -8,26 +8,26 @@ use crate::Result; #[repr(u32)] pub enum AESAlgorithm { - CbcEnc, - CbcDec, - CtrEnc, - CtrDec, - CcmEnc, - CcmDec, + CbcEnc = ctru_sys::PS_ALGORITHM_CBC_ENC, + CbcDec = ctru_sys::PS_ALGORITHM_CBC_DEC, + CtrEnc = ctru_sys::PS_ALGORITHM_CTR_ENC, + CtrDec = ctru_sys::PS_ALGORITHM_CTR_DEC, + CcmEnc = ctru_sys::PS_ALGORITHM_CCM_ENC, + CcmDec = ctru_sys::PS_ALGORITHM_CCM_DEC, } #[repr(u32)] pub enum AESKeyType { - Keyslot0D, - Keyslot2D, - Keyslot31, - Keyslot38, - Keyslot32, - Keyslot39Dlp, - Keyslot2E, - KeyslotInvalid, - Keyslot36, - Keyslot39Nfc, + Keyslot0D = ctru_sys::PS_KEYSLOT_0D, + Keyslot2D = ctru_sys::PS_KEYSLOT_2D, + Keyslot2E = ctru_sys::PS_KEYSLOT_2E, + Keyslot31 = ctru_sys::PS_KEYSLOT_31, + Keyslot32 = ctru_sys::PS_KEYSLOT_32, + Keyslot36 = ctru_sys::PS_KEYSLOT_36, + Keyslot38 = ctru_sys::PS_KEYSLOT_38, + Keyslot39Dlp = ctru_sys::PS_KEYSLOT_39_DLP, + Keyslot39Nfc = ctru_sys::PS_KEYSLOT_39_NFC, + KeyslotInvalid = ctru_sys::PS_KEYSLOT_INVALID, } pub struct Ps(()); diff --git a/ctru-rs/src/services/soc.rs b/ctru-rs/src/services/soc.rs index aecd889..2b7ae7d 100644 --- a/ctru-rs/src/services/soc.rs +++ b/ctru-rs/src/services/soc.rs @@ -1,3 +1,5 @@ +//! Network Socket + use libc::memalign; use std::net::Ipv4Addr; use std::sync::Mutex; @@ -6,8 +8,10 @@ use crate::error::ResultCode; use crate::services::ServiceReference; use crate::Error; -/// Soc service. Initializing this service will enable the use of network sockets and utilities -/// such as those found in `std::net`. The service will be closed when this struct is is dropped. +/// Network socket service +/// +/// Initializing this service will enable the use of network sockets and utilities +/// such as those found in `std::net`. The service will close once this struct gets dropped. pub struct Soc { _service_handler: ServiceReference, sock_3dslink: libc::c_int, diff --git a/ctru-rs/src/services/sslc.rs b/ctru-rs/src/services/sslc.rs index aa4d26f..99eb456 100644 --- a/ctru-rs/src/services/sslc.rs +++ b/ctru-rs/src/services/sslc.rs @@ -1,3 +1,5 @@ +//! SSLC (TLS) service + // TODO: Implement remaining functions use crate::error::ResultCode; @@ -5,7 +7,7 @@ use crate::error::ResultCode; pub struct SslC(()); impl SslC { - /// Initialize sslc + /// Initialize the service pub fn init() -> crate::Result { unsafe { ResultCode(ctru_sys::sslcInit(0))?; diff --git a/ctru-rs/src/test_runner.rs b/ctru-rs/src/test_runner.rs index 00634f6..1f0698f 100644 --- a/ctru-rs/src/test_runner.rs +++ b/ctru-rs/src/test_runner.rs @@ -44,7 +44,7 @@ pub(crate) fn run(tests: &[&TestDescAndFn]) { gfx.wait_for_vblank(); hid.scan_input(); - if hid.keys_down().contains(KeyPad::KEY_START) { + if hid.keys_down().contains(KeyPad::START) { break; } } From 7688644fe17b39ea3dc07d8e8c1b35d0fe3f7692 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Thu, 30 Mar 2023 18:21:52 +0200 Subject: [PATCH 03/18] CAM renaming/fixing with build problems --- ctru-rs/src/services/cam.rs | 258 ++++++++++++++++-------------------- ctru-rs/src/services/soc.rs | 2 +- 2 files changed, 118 insertions(+), 142 deletions(-) diff --git a/ctru-rs/src/services/cam.rs b/ctru-rs/src/services/cam.rs index 7f96ebd..4ce97c8 100644 --- a/ctru-rs/src/services/cam.rs +++ b/ctru-rs/src/services/cam.rs @@ -1,11 +1,10 @@ -//! CAM service +//! Camera service //! -//! The CAM service provides access to the cameras. Cameras can return 2D images -//! in the form of byte vectors which can be used for display or other usages. +//! The CAM service provides access to the cameras. Cameras can return images +//! in the form of byte vectors which can be displayed or used in other ways. use crate::error::{Error, ResultCode}; use crate::services::gspgpu::FramebufferFormat; -use bitflags::bitflags; use ctru_sys::Handle; use std::time::Duration; @@ -21,177 +20,154 @@ pub struct Cam { pub both_outer_cams: BothOutwardCam, } -bitflags! { - /// A set of flags to be passed to [Camera::flip_image] - #[derive(Default)] - pub struct CamFlip: u32 { - const NONE = ctru_sys::FLIP_NONE; - const HORIZONTAL = ctru_sys::FLIP_HORIZONTAL; - const VERTICAL = ctru_sys::FLIP_VERTICAL; - const REVERSE = ctru_sys::FLIP_REVERSE; - } +/// Flag to pass to [Camera::flip_image] +#[derive(Default)] +#[repr(u32)] +pub enum FlipMode { + None = ctru_sys::FLIP_NONE, + Horizontal = ctru_sys::FLIP_HORIZONTAL, + Vertical = ctru_sys::FLIP_VERTICAL, + Reverse = ctru_sys::FLIP_REVERSE, } -bitflags! { - /// A set of flags to be passed to [Camera::set_view_size] - #[derive(Default)] - pub struct CamSize: u32 { - const VGA = ctru_sys::SIZE_VGA; - const QVGA = ctru_sys::SIZE_QVGA; - const QQVGA = ctru_sys::SIZE_QQVGA; - const CIF = ctru_sys::SIZE_CIF; - const QCIF = ctru_sys::SIZE_QCIF; - const DS_LCD = ctru_sys::SIZE_DS_LCD; - const DS_LCD_X4 = ctru_sys::SIZE_DS_LCDx4; - const CTR_TOP_LCD = ctru_sys::SIZE_CTR_TOP_LCD; - const CTR_BOTTOM_LCD = ctru_sys::SIZE_CTR_BOTTOM_LCD; - } +/// Flag to pass to [Camera::set_view_size] +#[repr(u32)] +pub enum PictureSize { + Vga = ctru_sys::SIZE_VGA, + QVga = ctru_sys::SIZE_QVGA, + QQVga = ctru_sys::SIZE_QQVGA, + Cif = ctru_sys::SIZE_CIF, + QCif = ctru_sys::SIZE_QCIF, + DS = ctru_sys::SIZE_DS_LCD, + DSX4 = ctru_sys::SIZE_DS_LCDx4, + TopLCD = ctru_sys::SIZE_CTR_TOP_LCD, + BottomLCD = ctru_sys::SIZE_CTR_BOTTOM_LCD, } -bitflags! { - /// A set of flags to be passed to [Camera::set_frame_rate] - #[derive(Default)] - pub struct CamFrameRate: u32 { - const RATE_15 = ctru_sys::FRAME_RATE_15; - const RATE_15_TO_5 = ctru_sys::FRAME_RATE_15_TO_5; - const RATE_15_TO_2 = ctru_sys::FRAME_RATE_15_TO_2; - const RATE_10 = ctru_sys::FRAME_RATE_10; - const RATE_8_5 = ctru_sys::FRAME_RATE_8_5; - const RATE_5 = ctru_sys::FRAME_RATE_5; - const RATE_20 = ctru_sys::FRAME_RATE_20; - const RATE_20_TO_5 = ctru_sys::FRAME_RATE_20_TO_5; - const RATE_30 = ctru_sys::FRAME_RATE_30; - const RATE_30_TO_5 = ctru_sys::FRAME_RATE_30_TO_5; - const RATE_15_TO_10 = ctru_sys::FRAME_RATE_15_TO_10; - const RATE_20_TO_10 = ctru_sys::FRAME_RATE_20_TO_10; - const RATE_30_TO_10 = ctru_sys::FRAME_RATE_30_TO_10; - } +/// Flag to pass to [Camera::set_frame_rate] +#[repr(u32)] +pub enum FrameRate { + Fps15 = ctru_sys::FRAME_RATE_15, + Fps15To5 = ctru_sys::FRAME_RATE_15_TO_5, + Fps15To2 = ctru_sys::FRAME_RATE_15_TO_2, + Fps10 = ctru_sys::FRAME_RATE_10, + Fps8_5 = ctru_sys::FRAME_RATE_8_5, + Fps5 = ctru_sys::FRAME_RATE_5, + Fps20 = ctru_sys::FRAME_RATE_20, + Fps20To5 = ctru_sys::FRAME_RATE_20_TO_5, + Fps30 = ctru_sys::FRAME_RATE_30, + Fps30To5 = ctru_sys::FRAME_RATE_30_TO_5, + Fps15To10 = ctru_sys::FRAME_RATE_15_TO_10, + Fps20To10 = ctru_sys::FRAME_RATE_20_TO_10, + Fps30To10 = ctru_sys::FRAME_RATE_30_TO_10, } -bitflags! { - /// A set of flags to be passed to [Camera::set_white_balance] or - /// [Camera::set_white_balance_without_base_up] - #[derive(Default)] - pub struct CamWhiteBalance: u32 { - const AUTO = ctru_sys::WHITE_BALANCE_AUTO; - const BALANCE_3200K = ctru_sys::WHITE_BALANCE_3200K; - const BALANCE_4150K = ctru_sys::WHITE_BALANCE_4150K; - const BALANCE_5200K = ctru_sys::WHITE_BALANCE_5200K; - const BALANCE_6000K = ctru_sys::WHITE_BALANCE_6000K; - const BALANCE_7000K = ctru_sys::WHITE_BALANCE_7000K; - - const NORMAL = ctru_sys::WHITE_BALANCE_NORMAL; - const TUNGSTEN = ctru_sys::WHITE_BALANCE_TUNGSTEN; - const WHITE_FLUORESCENT_LIGHT = ctru_sys::WHITE_BALANCE_WHITE_FLUORESCENT_LIGHT; - const DAYLIGHT = ctru_sys::WHITE_BALANCE_DAYLIGHT; - const CLOUDY = ctru_sys::WHITE_BALANCE_CLOUDY; - const HORIZON = ctru_sys::WHITE_BALANCE_HORIZON; - const SHADE = ctru_sys::WHITE_BALANCE_SHADE; - } +/// Flag to pass to [Camera::set_white_balance] or +/// [Camera::set_white_balance_without_base_up] +#[repr(u32)] +pub enum WhiteBalance { + Auto = ctru_sys::WHITE_BALANCE_AUTO, + Type3200K = ctru_sys::WHITE_BALANCE_3200K, + Type4150K = ctru_sys::WHITE_BALANCE_4150K, + Type5200K = ctru_sys::WHITE_BALANCE_5200K, + Type6000K = ctru_sys::WHITE_BALANCE_6000K, + Type7000K = ctru_sys::WHITE_BALANCE_7000K, + + Normal = ctru_sys::WHITE_BALANCE_NORMAL, + Tungsten = ctru_sys::WHITE_BALANCE_TUNGSTEN, + FluorescentLight = ctru_sys::WHITE_BALANCE_WHITE_FLUORESCENT_LIGHT, + Daylight = ctru_sys::WHITE_BALANCE_DAYLIGHT, + Cloudy = ctru_sys::WHITE_BALANCE_CLOUDY, + Horizon = ctru_sys::WHITE_BALANCE_HORIZON, + Shade = ctru_sys::WHITE_BALANCE_SHADE, } -bitflags! { - /// A set of flags to be passed to [Camera::set_photo_mode] - #[derive(Default)] - pub struct CamPhotoMode: u32 { - const NORMAL = ctru_sys::PHOTO_MODE_NORMAL; - const PORTRAIT = ctru_sys::PHOTO_MODE_PORTRAIT; - const LANDSCAPE = ctru_sys::PHOTO_MODE_LANDSCAPE; - const NIGHTVIEW = ctru_sys::PHOTO_MODE_NIGHTVIEW; - const LETTER = ctru_sys::PHOTO_MODE_LETTER; - } +/// Flag to pass to [Camera::set_photo_mode] +#[repr(u32)] +pub enum PhotoMode { + Normal = ctru_sys::PHOTO_MODE_NORMAL, + Portrait = ctru_sys::PHOTO_MODE_PORTRAIT, + Landscape = ctru_sys::PHOTO_MODE_LANDSCAPE, + Nightview = ctru_sys::PHOTO_MODE_NIGHTVIEW, + Letter = ctru_sys::PHOTO_MODE_LETTER, } -bitflags! { - /// A set of flags to be passed to [Camera::set_effect] - #[derive(Default)] - pub struct CamEffect: u32 { - const NONE = ctru_sys::EFFECT_NONE; - const MONO = ctru_sys::EFFECT_MONO; - const SEPIA = ctru_sys::EFFECT_SEPIA; - const NEGATIVE = ctru_sys::EFFECT_NEGATIVE; - const NEGAFILM = ctru_sys::EFFECT_NEGAFILM; - const SEPIA01 = ctru_sys::EFFECT_SEPIA01; - } +/// Flag to pass to [Camera::set_effect] +#[repr(u32)] +pub enum Effect { + None = ctru_sys::EFFECT_NONE, + Mono = ctru_sys::EFFECT_MONO, + Sepia = ctru_sys::EFFECT_SEPIA, + Negative = ctru_sys::EFFECT_NEGATIVE, + Negafilm = ctru_sys::EFFECT_NEGAFILM, + Sepia01 = ctru_sys::EFFECT_SEPIA01, } -bitflags! { - /// A set of flags to be passed to [Camera::set_contrast] - #[derive(Default)] - pub struct CamContrast: u32 { - const PATTERN_01 = ctru_sys::CONTRAST_PATTERN_01; - const PATTERN_02 = ctru_sys::CONTRAST_PATTERN_02; - const PATTERN_03 = ctru_sys::CONTRAST_PATTERN_03; - const PATTERN_04 = ctru_sys::CONTRAST_PATTERN_04; - const PATTERN_05 = ctru_sys::CONTRAST_PATTERN_05; - const PATTERN_06 = ctru_sys::CONTRAST_PATTERN_06; - const PATTERN_07 = ctru_sys::CONTRAST_PATTERN_07; - const PATTERN_08 = ctru_sys::CONTRAST_PATTERN_08; - const PATTERN_09 = ctru_sys::CONTRAST_PATTERN_09; - const PATTERN_10 = ctru_sys::CONTRAST_PATTERN_10; - const PATTERN_11 = ctru_sys::CONTRAST_PATTERN_11; - - const LOW = ctru_sys::CONTRAST_LOW; - const NORMAL = ctru_sys::CONTRAST_NORMAL; - const HIGH = ctru_sys::CONTRAST_HIGH; - } +/// Flag to pass to [Camera::set_contrast] +#[repr(u32)] +pub enum Contrast { + Pattern01 = ctru_sys::CONTRAST_PATTERN_01, + Pattern02 = ctru_sys::CONTRAST_PATTERN_02, + Pattern03 = ctru_sys::CONTRAST_PATTERN_03, + Pattern04 = ctru_sys::CONTRAST_PATTERN_04, + Pattern05 = ctru_sys::CONTRAST_PATTERN_05, + Pattern06 = ctru_sys::CONTRAST_PATTERN_06, + Pattern07 = ctru_sys::CONTRAST_PATTERN_07, + Pattern08 = ctru_sys::CONTRAST_PATTERN_08, + Pattern09 = ctru_sys::CONTRAST_PATTERN_09, + Pattern10 = ctru_sys::CONTRAST_PATTERN_10, + Pattern11 = ctru_sys::CONTRAST_PATTERN_11, + + Low = ctru_sys::CONTRAST_LOW, + Normal = ctru_sys::CONTRAST_NORMAL, + High = ctru_sys::CONTRAST_HIGH, } -bitflags! { - /// A set of flags to be passed to [Camera::set_lens_correction] - #[derive(Default)] - pub struct CamLensCorrection: u32 { - const OFF = ctru_sys::LENS_CORRECTION_OFF; - const ON_70 = ctru_sys::LENS_CORRECTION_ON_70; - const ON_90 = ctru_sys::LENS_CORRECTION_ON_90; +/// Flag to pass to [Camera::set_lens_correction] +#[repr(u32)] +pub enum LensCorrection { + Off = ctru_sys::LENS_CORRECTION_DARK, + Normal = ctru_sys::LENS_CORRECTION_NORMAL, + Bright = ctru_sys::LENS_CORRECTION_BRIGHT, +} - const DARK = ctru_sys::LENS_CORRECTION_DARK; - const NORMAL = ctru_sys::LENS_CORRECTION_NORMAL; - const BRIGHT = ctru_sys::LENS_CORRECTION_BRIGHT; - } +/// Flag to pass to [Camera::set_output_format] +#[repr(u32)] +pub enum OutputFormat { + Yuv422 = ctru_sys::OUTPUT_YUV_422, + Rgb565 = ctru_sys::OUTPUT_RGB_565, } -bitflags! { - /// A set of flags to be passed to [Camera::set_output_format] - #[derive(Default)] - pub struct CamOutputFormat: u32 { - const YUV_422 = ctru_sys::OUTPUT_YUV_422; - const RGB_565 = ctru_sys::OUTPUT_RGB_565; - } +/// Flag to pass to [Cam::play_shutter_sound] +#[repr(u32)] +pub enum ShutterSound { + Normal = ctru_sys::SHUTTER_SOUND_TYPE_NORMAL, + Movie = ctru_sys::SHUTTER_SOUND_TYPE_MOVIE, + MovieEnd = ctru_sys::SHUTTER_SOUND_TYPE_MOVIE_END, } -impl TryFrom for CamOutputFormat { +impl TryFrom for OutputFormat { type Error = (); fn try_from(value: FramebufferFormat) -> Result { match value { - FramebufferFormat::Rgb565 => Ok(CamOutputFormat::RGB_565), + FramebufferFormat::Rgb565 => Ok(OutputFormat::RGB_565), _ => Err(()), } } } -impl TryFrom for FramebufferFormat { +impl TryFrom for FramebufferFormat { type Error = (); - fn try_from(value: CamOutputFormat) -> Result { + fn try_from(value: OutputFormat) -> Result { match value { - CamOutputFormat::RGB_565 => Ok(FramebufferFormat::Rgb565), + OutputFormat::Rgb565 => Ok(FramebufferFormat::Rgb565), _ => Err(()), } } } -bitflags! { - /// A set of flags to be passed to [Cam::play_shutter_sound] - #[derive(Default)] - pub struct CamShutterSoundType: u32 { - const NORMAL = ctru_sys::SHUTTER_SOUND_TYPE_NORMAL; - const MOVIE = ctru_sys::SHUTTER_SOUND_TYPE_MOVIE; - const MOVIE_END = ctru_sys::SHUTTER_SOUND_TYPE_MOVIE_END; - } -} - /// Struct containing coordinates passed to [Camera::set_trimming_params]. pub struct CamTrimmingParams { x_start: i16, @@ -806,8 +782,8 @@ impl Cam { } } - /// Plays the specified sound based on the [CamShutterSoundType] argument - pub fn play_shutter_sound(&self, sound: CamShutterSoundType) -> crate::Result<()> { + /// Plays the specified sound based on the [ShutterSound] argument + pub fn play_shutter_sound(&self, sound: ShutterSound) -> crate::Result<()> { unsafe { ResultCode(ctru_sys::CAMU_PlayShutterSound(sound.bits()))?; Ok(()) diff --git a/ctru-rs/src/services/soc.rs b/ctru-rs/src/services/soc.rs index 2b7ae7d..c5df066 100644 --- a/ctru-rs/src/services/soc.rs +++ b/ctru-rs/src/services/soc.rs @@ -9,7 +9,7 @@ use crate::services::ServiceReference; use crate::Error; /// Network socket service -/// +/// /// Initializing this service will enable the use of network sockets and utilities /// such as those found in `std::net`. The service will close once this struct gets dropped. pub struct Soc { From ad11818d1f5ebc588b4065375d53b2c392fa75f6 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Thu, 30 Mar 2023 20:09:28 +0200 Subject: [PATCH 04/18] Fixed compiler errors for CAM --- ctru-rs/src/services/cam.rs | 127 ++++++++++++++++++------------------ 1 file changed, 62 insertions(+), 65 deletions(-) diff --git a/ctru-rs/src/services/cam.rs b/ctru-rs/src/services/cam.rs index 4ce97c8..3d05089 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(Default)] +#[derive(Copy, Clone, Debug)] #[repr(u32)] pub enum FlipMode { None = ctru_sys::FLIP_NONE, @@ -31,20 +31,24 @@ pub enum FlipMode { } /// Flag to pass to [Camera::set_view_size] +#[derive(Copy, Clone, Debug)] #[repr(u32)] -pub enum PictureSize { +pub enum ViewSize { + TopLCD = ctru_sys::SIZE_CTR_TOP_LCD, + /// Equivalent to QVga + BottomLCD = ctru_sys::SIZE_CTR_BOTTOM_LCD, Vga = ctru_sys::SIZE_VGA, - QVga = ctru_sys::SIZE_QVGA, QQVga = ctru_sys::SIZE_QQVGA, Cif = ctru_sys::SIZE_CIF, QCif = ctru_sys::SIZE_QCIF, + /// Nintendo DS Screen DS = ctru_sys::SIZE_DS_LCD, + /// Nintendo DS Screen x4 DSX4 = ctru_sys::SIZE_DS_LCDx4, - TopLCD = ctru_sys::SIZE_CTR_TOP_LCD, - BottomLCD = ctru_sys::SIZE_CTR_BOTTOM_LCD, } /// Flag to pass to [Camera::set_frame_rate] +#[derive(Copy, Clone, Debug)] #[repr(u32)] pub enum FrameRate { Fps15 = ctru_sys::FRAME_RATE_15, @@ -64,25 +68,25 @@ pub enum FrameRate { /// Flag to pass to [Camera::set_white_balance] or /// [Camera::set_white_balance_without_base_up] +#[derive(Copy, Clone, Debug)] #[repr(u32)] pub enum WhiteBalance { + /// Normal Auto = ctru_sys::WHITE_BALANCE_AUTO, + /// Tungsten Type3200K = ctru_sys::WHITE_BALANCE_3200K, + /// Fluorescent Light Type4150K = ctru_sys::WHITE_BALANCE_4150K, + /// Daylight Type5200K = ctru_sys::WHITE_BALANCE_5200K, + /// Cloudy/Horizon Type6000K = ctru_sys::WHITE_BALANCE_6000K, + ///Shade Type7000K = ctru_sys::WHITE_BALANCE_7000K, - - Normal = ctru_sys::WHITE_BALANCE_NORMAL, - Tungsten = ctru_sys::WHITE_BALANCE_TUNGSTEN, - FluorescentLight = ctru_sys::WHITE_BALANCE_WHITE_FLUORESCENT_LIGHT, - Daylight = ctru_sys::WHITE_BALANCE_DAYLIGHT, - Cloudy = ctru_sys::WHITE_BALANCE_CLOUDY, - Horizon = ctru_sys::WHITE_BALANCE_HORIZON, - Shade = ctru_sys::WHITE_BALANCE_SHADE, } /// Flag to pass to [Camera::set_photo_mode] +#[derive(Copy, Clone, Debug)] #[repr(u32)] pub enum PhotoMode { Normal = ctru_sys::PHOTO_MODE_NORMAL, @@ -93,6 +97,7 @@ pub enum PhotoMode { } /// Flag to pass to [Camera::set_effect] +#[derive(Copy, Clone, Debug)] #[repr(u32)] pub enum Effect { None = ctru_sys::EFFECT_NONE, @@ -104,26 +109,16 @@ pub enum Effect { } /// Flag to pass to [Camera::set_contrast] +#[derive(Copy, Clone, Debug)] #[repr(u32)] pub enum Contrast { - Pattern01 = ctru_sys::CONTRAST_PATTERN_01, - Pattern02 = ctru_sys::CONTRAST_PATTERN_02, - Pattern03 = ctru_sys::CONTRAST_PATTERN_03, - Pattern04 = ctru_sys::CONTRAST_PATTERN_04, - Pattern05 = ctru_sys::CONTRAST_PATTERN_05, - Pattern06 = ctru_sys::CONTRAST_PATTERN_06, - Pattern07 = ctru_sys::CONTRAST_PATTERN_07, - Pattern08 = ctru_sys::CONTRAST_PATTERN_08, - Pattern09 = ctru_sys::CONTRAST_PATTERN_09, - Pattern10 = ctru_sys::CONTRAST_PATTERN_10, - Pattern11 = ctru_sys::CONTRAST_PATTERN_11, - Low = ctru_sys::CONTRAST_LOW, Normal = ctru_sys::CONTRAST_NORMAL, High = ctru_sys::CONTRAST_HIGH, } /// Flag to pass to [Camera::set_lens_correction] +#[derive(Copy, Clone, Debug)] #[repr(u32)] pub enum LensCorrection { Off = ctru_sys::LENS_CORRECTION_DARK, @@ -132,6 +127,7 @@ pub enum LensCorrection { } /// Flag to pass to [Camera::set_output_format] +#[derive(Copy, Clone, Debug)] #[repr(u32)] pub enum OutputFormat { Yuv422 = ctru_sys::OUTPUT_YUV_422, @@ -139,6 +135,7 @@ pub enum OutputFormat { } /// Flag to pass to [Cam::play_shutter_sound] +#[derive(Copy, Clone, Debug)] #[repr(u32)] pub enum ShutterSound { Normal = ctru_sys::SHUTTER_SOUND_TYPE_NORMAL, @@ -151,7 +148,7 @@ impl TryFrom for OutputFormat { fn try_from(value: FramebufferFormat) -> Result { match value { - FramebufferFormat::Rgb565 => Ok(OutputFormat::RGB_565), + FramebufferFormat::Rgb565 => Ok(OutputFormat::Rgb565), _ => Err(()), } } @@ -169,19 +166,19 @@ impl TryFrom for FramebufferFormat { } /// Struct containing coordinates passed to [Camera::set_trimming_params]. -pub struct CamTrimmingParams { +pub struct TrimmingParams { x_start: i16, y_start: i16, x_end: i16, y_end: i16, } -impl CamTrimmingParams { +impl TrimmingParams { /// Creates a new [CamTrimmingParams] and guarantees the start coordinates are less than or /// equal to the end coordinates. /// /// `x_start <= x_end && y_start <= y_end` - pub fn new(x_start: i16, y_start: i16, x_end: i16, y_end: i16) -> CamTrimmingParams { + pub fn new(x_start: i16, y_start: i16, x_end: i16, y_end: i16) -> TrimmingParams { assert!(x_start <= x_end && y_start <= y_end); Self { x_start, @@ -312,8 +309,8 @@ pub trait Camera { } } - /// Sets trimming parameters based on coordinates specified inside a [CamTrimmingParams] - fn set_trimming_params(&mut self, params: CamTrimmingParams) -> crate::Result<()> { + /// Sets trimming parameters based on coordinates specified inside a [TrimmingParams] + fn set_trimming_params(&mut self, params: TrimmingParams) -> crate::Result<()> { unsafe { ResultCode(ctru_sys::CAMU_SetTrimmingParams( self.port_as_raw(), @@ -326,8 +323,8 @@ pub trait Camera { } } - /// Returns the set [CamTrimmingParams] from the camera - fn get_trimming_params(&self) -> crate::Result { + /// Returns the [TrimmingParams] set + fn get_trimming_params(&self) -> crate::Result { unsafe { let mut x_start = 0; let mut y_start = 0; @@ -341,7 +338,7 @@ pub trait Camera { self.port_as_raw(), ))?; - Ok(CamTrimmingParams { + Ok(TrimmingParams { x_start, y_start, x_end, @@ -380,27 +377,27 @@ pub trait Camera { } } - /// Sets the white balance mod of the camera based on the passed [CamWhiteBalance] argument - fn set_white_balance(&mut self, white_balance: CamWhiteBalance) -> crate::Result<()> { + /// Sets the white balance mod of the camera based on the passed [WhiteBalance] argument + fn set_white_balance(&mut self, white_balance: WhiteBalance) -> crate::Result<()> { unsafe { ResultCode(ctru_sys::CAMU_SetWhiteBalance( self.camera_as_raw(), - white_balance.bits(), + white_balance as u32, ))?; Ok(()) } } - /// Sets the white balance mode of the camera based on the passed [CamWhiteBalance] argument + /// Sets the white balance mode of the camera based on the passed [WhiteBalance] argument // TODO: Explain base up fn set_white_balance_without_base_up( &mut self, - white_balance: CamWhiteBalance, + white_balance: WhiteBalance, ) -> crate::Result<()> { unsafe { ResultCode(ctru_sys::CAMU_SetWhiteBalanceWithoutBaseUp( self.camera_as_raw(), - white_balance.bits(), + white_balance as u32, ))?; Ok(()) } @@ -460,12 +457,12 @@ pub trait Camera { } } - /// Sets the flip direction of the camera's image based on the passed [CamFlip] argument - fn flip_image(&mut self, flip: CamFlip) -> crate::Result<()> { + /// Sets the flip direction of the camera's image based on the passed [FlipMode] argument + fn flip_image(&mut self, flip: FlipMode) -> crate::Result<()> { unsafe { ResultCode(ctru_sys::CAMU_FlipImage( self.camera_as_raw(), - flip.bits(), + flip as u32, ctru_sys::CONTEXT_A, ))?; Ok(()) @@ -506,82 +503,82 @@ pub trait Camera { } } - /// Sets the view size of the camera based on the passed [CamSize] argument. - fn set_view_size(&mut self, size: CamSize) -> crate::Result<()> { + /// Sets the view size of the camera based on the passed [ViewSize] argument. + fn set_view_size(&mut self, size: ViewSize) -> crate::Result<()> { unsafe { ResultCode(ctru_sys::CAMU_SetSize( self.camera_as_raw(), - size.bits(), + size as u32, ctru_sys::CONTEXT_A, ))?; Ok(()) } } - /// Sets the frame rate of the camera based on the passed [CamFrameRate] argument. - fn set_frame_rate(&mut self, frame_rate: CamFrameRate) -> crate::Result<()> { + /// Sets the frame rate of the camera based on the passed [FrameRate] argument. + fn set_frame_rate(&mut self, frame_rate: FrameRate) -> crate::Result<()> { unsafe { ResultCode(ctru_sys::CAMU_SetFrameRate( self.camera_as_raw(), - frame_rate.bits(), + frame_rate as u32, ))?; Ok(()) } } - /// Sets the photo mode of the camera based on the passed [CamPhotoMode] argument. - fn set_photo_mode(&mut self, photo_mode: CamPhotoMode) -> crate::Result<()> { + /// Sets the photo mode of the camera based on the passed [PhotoMode] argument. + fn set_photo_mode(&mut self, photo_mode: PhotoMode) -> crate::Result<()> { unsafe { ResultCode(ctru_sys::CAMU_SetPhotoMode( self.camera_as_raw(), - photo_mode.bits(), + photo_mode as u32, ))?; Ok(()) } } - /// Sets the effect of the camera based on the passed [CamEffect] argument. + /// Sets the effect of the camera based on the passed [Effect] argument. /// /// Multiple effects can be set at once by combining the bitflags of [CamEffect] - fn set_effect(&mut self, effect: CamEffect) -> crate::Result<()> { + fn set_effect(&mut self, effect: Effect) -> crate::Result<()> { unsafe { ResultCode(ctru_sys::CAMU_SetEffect( self.camera_as_raw(), - effect.bits(), + effect as u32, ctru_sys::CONTEXT_A, ))?; Ok(()) } } - /// Sets the contrast of the camera based on the passed [CamContrast] argument. - fn set_contrast(&mut self, contrast: CamContrast) -> crate::Result<()> { + /// Sets the contrast of the camera based on the passed [Contrast] argument. + fn set_contrast(&mut self, contrast: Contrast) -> crate::Result<()> { unsafe { ResultCode(ctru_sys::CAMU_SetContrast( self.camera_as_raw(), - contrast.bits(), + contrast as u32, ))?; Ok(()) } } - /// Sets the lens correction of the camera based on the passed [CamLensCorrection] argument. - fn set_lens_correction(&mut self, lens_correction: CamLensCorrection) -> crate::Result<()> { + /// Sets the lens correction of the camera based on the passed [LensCorrection] argument. + fn set_lens_correction(&mut self, lens_correction: LensCorrection) -> crate::Result<()> { unsafe { ResultCode(ctru_sys::CAMU_SetLensCorrection( self.camera_as_raw(), - lens_correction.bits(), + lens_correction as u32, ))?; Ok(()) } } - /// Sets the output format of the camera based on the passed [CamOutputFormat] argument. - fn set_output_format(&mut self, format: CamOutputFormat) -> crate::Result<()> { + /// Sets the output format of the camera based on the passed [OutputFormat] argument. + fn set_output_format(&mut self, format: OutputFormat) -> crate::Result<()> { unsafe { ResultCode(ctru_sys::CAMU_SetOutputFormat( self.camera_as_raw(), - format.bits(), + format as u32, ctru_sys::CONTEXT_A, ))?; Ok(()) @@ -785,7 +782,7 @@ impl Cam { /// Plays the specified sound based on the [ShutterSound] argument pub fn play_shutter_sound(&self, sound: ShutterSound) -> crate::Result<()> { unsafe { - ResultCode(ctru_sys::CAMU_PlayShutterSound(sound.bits()))?; + ResultCode(ctru_sys::CAMU_PlayShutterSound(sound as u32))?; Ok(()) } } From 2e6039c1b85de8fa32c4e05f23ed5f63f0f63b45 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Thu, 30 Mar 2023 20:12:43 +0200 Subject: [PATCH 05/18] Fixed ArchiveID struct --- ctru-rs/src/services/fs.rs | 42 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/ctru-rs/src/services/fs.rs b/ctru-rs/src/services/fs.rs index f53b24c..c89fec2 100644 --- a/ctru-rs/src/services/fs.rs +++ b/ctru-rs/src/services/fs.rs @@ -65,27 +65,27 @@ pub enum PathType { #[repr(u32)] pub enum ArchiveID { RomFS = ctru_sys::ARCHIVE_ROMFS, - Savedata = ctru_sys::ARCHIVE_ROMFS, - Extdata = ctru_sys::ARCHIVE_ROMFS, - SharedExtdata = ctru_sys::ARCHIVE_ROMFS, - SystemSavedata = ctru_sys::ARCHIVE_ROMFS, - Sdmc = ctru_sys::ARCHIVE_ROMFS, - SdmcWriteOnly = ctru_sys::ARCHIVE_ROMFS, - BossExtdata = ctru_sys::ARCHIVE_ROMFS, - CardSpiFS = ctru_sys::ARCHIVE_ROMFS, - ExtDataAndBossExtdata = ctru_sys::ARCHIVE_ROMFS, - SystemSaveData2 = ctru_sys::ARCHIVE_ROMFS, - NandRW = ctru_sys::ARCHIVE_ROMFS, - NandRO = ctru_sys::ARCHIVE_ROMFS, - NandROWriteAccess = ctru_sys::ARCHIVE_ROMFS, - SaveDataAndContent = ctru_sys::ARCHIVE_ROMFS, - SaveDataAndContent2 = ctru_sys::ARCHIVE_ROMFS, - NandCtrFS = ctru_sys::ARCHIVE_ROMFS, - TwlPhoto = ctru_sys::ARCHIVE_ROMFS, - NandTwlFS = ctru_sys::ARCHIVE_ROMFS, - GameCardSavedata = ctru_sys::ARCHIVE_ROMFS, - UserSavedata = ctru_sys::ARCHIVE_ROMFS, - DemoSavedata = ctru_sys::ARCHIVE_ROMFS, + Savedata = ctru_sys::ARCHIVE_SAVEDATA, + Extdata = ctru_sys::ARCHIVE_EXTDATA, + SharedExtdata = ctru_sys::ARCHIVE_SHARED_EXTDATA, + SystemSavedata = ctru_sys::ARCHIVE_SYSTEM_SAVEDATA, + Sdmc = ctru_sys::ARCHIVE_SDMC, + SdmcWriteOnly = ctru_sys::ARCHIVE_SDMC_WRITE_ONLY, + BossExtdata = ctru_sys::ARCHIVE_BOSS_EXTDATA, + CardSpiFS = ctru_sys::ARCHIVE_CARD_SPIFS, + ExtDataAndBossExtdata = ctru_sys::ARCHIVE_EXTDATA_AND_BOSS_EXTDATA, + SystemSaveData2 = ctru_sys::ARCHIVE_SYSTEM_SAVEDATA2, + NandRW = ctru_sys::ARCHIVE_NAND_RW, + NandRO = ctru_sys::ARCHIVE_NAND_RO, + NandROWriteAccess = ctru_sys::ARCHIVE_NAND_RO_WRITE_ACCESS, + SaveDataAndContent = ctru_sys::ARCHIVE_SAVEDATA_AND_CONTENT, + SaveDataAndContent2 = ctru_sys::ARCHIVE_SAVEDATA_AND_CONTENT2, + NandCtrFS = ctru_sys::ARCHIVE_NAND_CTR_FS, + TwlPhoto = ctru_sys::ARCHIVE_TWL_PHOTO, + NandTwlFS = ctru_sys::ARCHIVE_NAND_TWL_FS, + GameCardSavedata = ctru_sys::ARCHIVE_GAMECARD_SAVEDATA, + UserSavedata = ctru_sys::ARCHIVE_USER_SAVEDATA, + DemoSavedata = ctru_sys::ARCHIVE_DEMO_SAVEDATA, } /// Represents the filesystem service. No file IO can be performed From bcfd0fd84c3428c8dbfc137be6d4d5d989fc02c3 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Thu, 30 Mar 2023 20:14:51 +0200 Subject: [PATCH 06/18] Update CAM example --- ctru-rs/examples/camera-image.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ctru-rs/examples/camera-image.rs b/ctru-rs/examples/camera-image.rs index 7559275..a852830 100644 --- a/ctru-rs/examples/camera-image.rs +++ b/ctru-rs/examples/camera-image.rs @@ -1,5 +1,5 @@ use ctru::prelude::*; -use ctru::services::cam::{Cam, CamOutputFormat, CamShutterSoundType, CamSize, Camera}; +use ctru::services::cam::{Cam, OutputFormat, ShutterSound, ViewSize, Camera}; use ctru::services::gfx::Screen; use ctru::services::gspgpu::FramebufferFormat; @@ -37,10 +37,10 @@ fn main() { let camera = &mut cam.outer_right_cam; camera - .set_view_size(CamSize::CTR_TOP_LCD) + .set_view_size(ViewSize::TopLCD) .expect("Failed to set camera size"); camera - .set_output_format(CamOutputFormat::RGB_565) + .set_output_format(OutputFormat::Rgb565) .expect("Failed to set camera output format"); camera .set_noise_filter(true) @@ -83,7 +83,7 @@ fn main() { ) .expect("Failed to take picture"); - cam.play_shutter_sound(CamShutterSoundType::NORMAL) + cam.play_shutter_sound(ShutterSound::Normal) .expect("Failed to play shutter sound"); rotate_image_to_screen( From fd7afb6e3c119002b21cdcfeb6891441702cc883 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Fri, 31 Mar 2023 14:03:42 +0200 Subject: [PATCH 07/18] Fixed enums in SWKBD --- ctru-rs/examples/camera-image.rs | 2 +- ctru-rs/src/applets/swkbd.rs | 106 +++++++++++++++++++------------ 2 files changed, 68 insertions(+), 40 deletions(-) diff --git a/ctru-rs/examples/camera-image.rs b/ctru-rs/examples/camera-image.rs index a852830..41aa9f3 100644 --- a/ctru-rs/examples/camera-image.rs +++ b/ctru-rs/examples/camera-image.rs @@ -1,5 +1,5 @@ use ctru::prelude::*; -use ctru::services::cam::{Cam, OutputFormat, ShutterSound, ViewSize, Camera}; +use ctru::services::cam::{Cam, Camera, OutputFormat, ShutterSound, ViewSize}; use ctru::services::gfx::Screen; use ctru::services::gspgpu::FramebufferFormat; diff --git a/ctru-rs/src/applets/swkbd.rs b/ctru-rs/src/applets/swkbd.rs index 976bdec..19db774 100644 --- a/ctru-rs/src/applets/swkbd.rs +++ b/ctru-rs/src/applets/swkbd.rs @@ -19,68 +19,72 @@ pub struct Swkbd { /// 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)] +#[repr(u32)] pub enum Kind { - Normal, - Qwerty, - Numpad, - Western, + Normal = ctru_sys::SWKBD_TYPE_NORMAL, + Qwerty = ctru_sys::SWKBD_TYPE_QWERTY, + Numpad = ctru_sys::SWKBD_TYPE_NUMPAD, + Western = ctru_sys::SWKBD_TYPE_WESTERN, } /// Represents which button the user pressed to close the software keyboard. #[derive(Copy, Clone, Debug)] +#[repr(u32)] pub enum Button { - Left, - Middle, - Right, + Left = ctru_sys::SWKBD_BUTTON_LEFT, + Middle = ctru_sys::SWKBD_BUTTON_MIDDLE, + Right = ctru_sys::SWKBD_BUTTON_RIGHT, } /// Error type for the software keyboard. #[derive(Copy, Clone, Debug)] +#[repr(i32)] pub enum Error { - InvalidInput, - OutOfMem, - HomePressed, - ResetPressed, - PowerPressed, - ParentalOk, - ParentalFail, - BannedInput, + InvalidInput = ctru_sys::SWKBD_INVALID_INPUT, + OutOfMem = ctru_sys::SWKBD_OUTOFMEM, + HomePressed = ctru_sys::SWKBD_HOMEPRESSED, + ResetPressed = ctru_sys::SWKBD_RESETPRESSED, + PowerPressed = ctru_sys::SWKBD_POWERPRESSED, + ParentalOk = ctru_sys::SWKBD_PARENTAL_OK, + ParentalFail = ctru_sys::SWKBD_PARENTAL_FAIL, + BannedInput = ctru_sys::SWKBD_BANNED_INPUT, } /// Restrictions on keyboard input #[derive(Copy, Clone, Debug)] +#[repr(u32)] pub enum ValidInput { - Anything, - NotEmpty, - NotEmptyNotBlank, - NotBlank, - FixedLen, + Anything = ctru_sys::SWKBD_ANYTHING, + NotEmpty = ctru_sys::SWKBD_NOTEMPTY, + NotEmptyNotBlank = ctru_sys::SWKBD_NOTEMPTY_NOTBLANK, + NotBlank = ctru_sys::SWKBD_NOTBLANK, + FixedLen = ctru_sys::SWKBD_FIXEDLEN, } bitflags! { /// Keyboard feature flags pub struct Features: u32 { - const PARENTAL_PIN = 1 << 0; - const DARKEN_TOP_SCREEN = 1 << 1; - const PREDICTIVE_INPUT = 1 << 2; - const MULTILINE = 1 << 3; - const FIXED_WIDTH = 1 << 4; - const ALLOW_HOME = 1 << 5; - const ALLOW_RESET = 1 << 6; - const ALLOW_POWER = 1 << 7; - const DEFAULT_QWERTY = 1 << 8; + const ParentalPin = ctru_sys::SWKBD_PARENTAL; + const DarkenTopScreen = ctru_sys::SWKBD_DARKEN_TOP_SCREEN; + const PredictiveInput = ctru_sys::SWKBD_PREDICTIVE_INPUT; + const Multiline = ctru_sys::SWKBD_MULTILINE; + const FixedWidth = ctru_sys::SWKBD_FIXED_WIDTH; + const AllowHome = ctru_sys::SWKBD_ALLOW_HOME; + const AllowReset = ctru_sys::SWKBD_ALLOW_RESET; + const AllowPower = ctru_sys::SWKBD_ALLOW_POWER; + const DefaultQwerty = ctru_sys::SWKBD_DEFAULT_QWERTY; } } bitflags! { /// Keyboard input filtering flags pub struct Filters: u32 { - const DIGITS = 1 << 0; - const AT = 1 << 1; - const PERCENT = 1 << 2; - const BACKSLASH = 1 << 3; - const PROFANITY = 1 << 4; - const CALLBACK = 1 << 5; + const DIGITS = ctru_sys::SWKBD_FILTER_DIGITS; + const AT = ctru_sys::SWKBD_FILTER_AT; + const PERCENT = ctru_sys::SWKBD_FILTER_PERCENT; + const BACKSLASH = ctru_sys::SWKBD_FILTER_BACKSLASH; + const PROFANITY = ctru_sys::SWKBD_FILTER_PROFANITY; + const CALLBACK = ctru_sys::SWKBD_FILTER_CALLBACK; } } @@ -90,7 +94,7 @@ impl Swkbd { pub fn init(keyboard_type: Kind, num_buttons: i32) -> Self { unsafe { let mut state = Box::::default(); - swkbdInit(state.as_mut(), keyboard_type as u32, num_buttons, -1); + swkbdInit(state.as_mut(), keyboard_type.into(), num_buttons, -1); Swkbd { state } } } @@ -123,7 +127,7 @@ impl Swkbd { /// this software keyboard. /// /// If the buffer is too small to contain the entire sequence received from the keyboard, - /// the output will be truncated but should still be well-formed UTF-8 + /// the output will be truncated but should still be well-formed UTF-8. pub fn get_bytes(&mut self, buf: &mut [u8]) -> Result { unsafe { match swkbdInputText(self.state.as_mut(), buf.as_mut_ptr(), buf.len()) { @@ -143,7 +147,7 @@ impl Swkbd { /// Configures input validation for this keyboard pub fn set_validation(&mut self, validation: ValidInput, filters: Filters) { - self.state.valid_input = validation as i32; + self.state.valid_input = validation.into(); self.state.filter_flags = filters.bits; } @@ -173,7 +177,7 @@ impl Swkbd { let nul_terminated: String = text.chars().chain(once('\0')).collect(); swkbdSetButton( self.state.as_mut(), - button as u32, + button.into(), nul_terminated.as_ptr(), submit, ); @@ -210,3 +214,27 @@ impl Default for Swkbd { Swkbd::init(Kind::Normal, 2) } } + +impl From for u32 { + fn from(value: Kind) -> Self { + value as u32 + } +} + +impl From