Browse Source

Derive traits and Screen changes

pull/118/head
Andrea Ciliberti 2 years ago
parent
commit
fe29c25c35
  1. 4
      ctru-rs/examples/audio-filters.rs
  2. 3
      ctru-rs/examples/buttons.rs
  3. 17
      ctru-rs/examples/camera-image.rs
  4. 2
      ctru-rs/examples/file-explorer.rs
  5. 2
      ctru-rs/examples/futures-basic.rs
  6. 2
      ctru-rs/examples/futures-tokio.rs
  7. 4
      ctru-rs/examples/gfx-3d-mode.rs
  8. 4
      ctru-rs/examples/gfx-wide-mode.rs
  9. 4
      ctru-rs/examples/graphics-bitmap.rs
  10. 2
      ctru-rs/examples/hashmaps.rs
  11. 2
      ctru-rs/examples/hello-both-screens.rs
  12. 3
      ctru-rs/examples/hello-world.rs
  13. 3
      ctru-rs/examples/linear-memory.rs
  14. 3
      ctru-rs/examples/mii-selector.rs
  15. 3
      ctru-rs/examples/output-3dslink.rs
  16. 3
      ctru-rs/examples/romfs.rs
  17. 2
      ctru-rs/examples/software-keyboard.rs
  18. 3
      ctru-rs/examples/system-configuration.rs
  19. 2
      ctru-rs/examples/thread-basic.rs
  20. 4
      ctru-rs/examples/thread-info.rs
  21. 2
      ctru-rs/examples/thread-locals.rs
  22. 4
      ctru-rs/examples/time-rtc.rs
  23. 4
      ctru-rs/examples/title-info.rs
  24. 44
      ctru-rs/src/applets/mii_selector.rs
  25. 9
      ctru-rs/src/applets/swkbd.rs
  26. 4
      ctru-rs/src/console.rs
  27. 1
      ctru-rs/src/services/am.rs
  28. 25
      ctru-rs/src/services/cam.rs
  29. 6
      ctru-rs/src/services/cfgu.rs
  30. 14
      ctru-rs/src/services/fs.rs
  31. 52
      ctru-rs/src/services/gfx.rs
  32. 4
      ctru-rs/src/services/gspgpu.rs
  33. 3
      ctru-rs/src/services/hid.rs
  34. 10
      ctru-rs/src/services/ndsp/mod.rs
  35. 2
      ctru-rs/src/services/ndsp/wave.rs
  36. 4
      ctru-rs/src/services/ps.rs
  37. 11
      ctru-rs/src/services/sslc.rs
  38. 2
      ctru-rs/src/test_runner.rs

4
ctru-rs/examples/audio-filters.rs

@ -154,10 +154,6 @@ fn main() {
altern = !altern; altern = !altern;
} }
// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();
//Wait for VBlank //Wait for VBlank
gfx.wait_for_vblank(); gfx.wait_for_vblank();
} }

3
ctru-rs/examples/buttons.rs

@ -63,9 +63,6 @@ fn main() {
// Save our current key presses for the next frame // Save our current key presses for the next frame
old_keys = keys; old_keys = keys;
// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank(); gfx.wait_for_vblank();
} }
} }

17
ctru-rs/examples/camera-image.rs

@ -20,11 +20,10 @@ fn main() {
let mut hid = Hid::new().expect("Failed to initialize Hid service."); let mut hid = Hid::new().expect("Failed to initialize Hid service.");
let gfx = Gfx::new().expect("Failed to initialize GFX service."); let gfx = Gfx::new().expect("Failed to initialize GFX service.");
gfx.top_screen.borrow_mut().set_double_buffering(true); let mut top_screen = gfx.top_screen.borrow_mut();
gfx.top_screen top_screen.set_double_buffering(true);
.borrow_mut() top_screen.set_framebuffer_format(FramebufferFormat::Rgb565);
.set_framebuffer_format(FramebufferFormat::Rgb565);
gfx.bottom_screen.borrow_mut().set_double_buffering(false);
let _console = Console::new(gfx.bottom_screen.borrow_mut()); let _console = Console::new(gfx.bottom_screen.borrow_mut());
let mut keys_down; let mut keys_down;
@ -88,13 +87,15 @@ fn main() {
rotate_image_to_screen( rotate_image_to_screen(
&buf, &buf,
gfx.top_screen.borrow_mut().raw_framebuffer().ptr, top_screen.raw_framebuffer().ptr,
WIDTH, WIDTH,
HEIGHT, HEIGHT,
); );
gfx.flush_buffers(); // We will only flush the "camera" screen, since the other screen is handled by `Console`
gfx.swap_buffers(); top_screen.flush_buffer();
top_screen.swap_buffers();
gfx.wait_for_vblank(); gfx.wait_for_vblank();
} }
} }

2
ctru-rs/examples/file-explorer.rs

@ -68,8 +68,6 @@ impl<'a> FileExplorer<'a> {
self.get_input_and_run(Self::set_exact_path); self.get_input_and_run(Self::set_exact_path);
} }
self.gfx.flush_buffers();
self.gfx.swap_buffers();
self.gfx.wait_for_vblank(); self.gfx.wait_for_vblank();
} }
} }

2
ctru-rs/examples/futures-basic.rs

@ -68,8 +68,6 @@ fn main() {
frame_count = 0; frame_count = 0;
} }
gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank(); gfx.wait_for_vblank();
} }
} }

2
ctru-rs/examples/futures-tokio.rs

@ -63,8 +63,6 @@ fn main() {
break; break;
} }
gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank(); gfx.wait_for_vblank();
} }
} }

4
ctru-rs/examples/gfx-3d-mode.rs

@ -61,10 +61,6 @@ fn main() {
buf.copy_from(IMAGE.as_ptr(), IMAGE.len()); buf.copy_from(IMAGE.as_ptr(), IMAGE.len());
} }
// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();
//Wait for VBlank //Wait for VBlank
gfx.wait_for_vblank(); gfx.wait_for_vblank();
} }

4
ctru-rs/examples/gfx-wide-mode.rs

@ -26,9 +26,7 @@ fn main() {
console = Console::new(gfx.top_screen.borrow_mut()); console = Console::new(gfx.top_screen.borrow_mut());
println!("Press A to enable/disable wide screen mode."); println!("Press A to enable/disable wide screen mode.");
} }
gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank(); gfx.wait_for_vblank();
} }
} }

4
ctru-rs/examples/graphics-bitmap.rs

@ -48,8 +48,8 @@ fn main() {
} }
// Flush and swap framebuffers // Flush and swap framebuffers
gfx.flush_buffers(); bottom_screen.flush_buffer();
gfx.swap_buffers(); bottom_screen.swap_buffers();
//Wait for VBlank //Wait for VBlank
gfx.wait_for_vblank(); gfx.wait_for_vblank();

2
ctru-rs/examples/hashmaps.rs

@ -21,8 +21,6 @@ fn main() {
println!("{map:#?}"); println!("{map:#?}");
while apt.main_loop() { while apt.main_loop() {
gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank(); gfx.wait_for_vblank();
hid.scan_input(); hid.scan_input();

2
ctru-rs/examples/hello-both-screens.rs

@ -27,8 +27,6 @@ fn main() {
println!("\x1b[29;16HPress Start to exit"); println!("\x1b[29;16HPress Start to exit");
while apt.main_loop() { while apt.main_loop() {
gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank(); gfx.wait_for_vblank();
hid.scan_input(); hid.scan_input();

3
ctru-rs/examples/hello-world.rs

@ -29,9 +29,6 @@ fn main() {
if hid.keys_down().contains(KeyPad::START) { if hid.keys_down().contains(KeyPad::START) {
break; break;
} }
// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();
//Wait for VBlank //Wait for VBlank
gfx.wait_for_vblank(); gfx.wait_for_vblank();

3
ctru-rs/examples/linear-memory.rs

@ -37,9 +37,6 @@ fn main() {
if hid.keys_down().contains(KeyPad::START) { if hid.keys_down().contains(KeyPad::START) {
break; break;
} }
// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();
//Wait for VBlank //Wait for VBlank
gfx.wait_for_vblank(); gfx.wait_for_vblank();

3
ctru-rs/examples/mii-selector.rs

@ -33,9 +33,6 @@ fn main() {
if hid.keys_down().contains(KeyPad::START) { if hid.keys_down().contains(KeyPad::START) {
break; break;
} }
// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();
//Wait for VBlank //Wait for VBlank
gfx.wait_for_vblank(); gfx.wait_for_vblank();

3
ctru-rs/examples/output-3dslink.rs

@ -33,9 +33,6 @@ fn main() {
if hid.keys_down().contains(KeyPad::START) { if hid.keys_down().contains(KeyPad::START) {
break; break;
} }
// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();
//Wait for VBlank //Wait for VBlank
gfx.wait_for_vblank(); gfx.wait_for_vblank();

3
ctru-rs/examples/romfs.rs

@ -36,9 +36,6 @@ fn main() {
if hid.keys_down().contains(KeyPad::START) { if hid.keys_down().contains(KeyPad::START) {
break; break;
} }
// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();
//Wait for VBlank //Wait for VBlank
gfx.wait_for_vblank(); gfx.wait_for_vblank();

2
ctru-rs/examples/software-keyboard.rs

@ -12,8 +12,6 @@ fn main() {
println!("Press A to enter some text or press Start to quit"); println!("Press A to enter some text or press Start to quit");
while apt.main_loop() { while apt.main_loop() {
gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank(); gfx.wait_for_vblank();
hid.scan_input(); hid.scan_input();

3
ctru-rs/examples/system-configuration.rs

@ -22,9 +22,6 @@ fn main() {
if hid.keys_down().contains(KeyPad::START) { if hid.keys_down().contains(KeyPad::START) {
break; break;
} }
// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();
//Wait for VBlank //Wait for VBlank
gfx.wait_for_vblank(); gfx.wait_for_vblank();

2
ctru-rs/examples/thread-basic.rs

@ -34,8 +34,6 @@ fn main() {
} }
while apt.main_loop() { while apt.main_loop() {
gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank(); gfx.wait_for_vblank();
hid.scan_input(); hid.scan_input();

4
ctru-rs/examples/thread-info.rs

@ -44,9 +44,7 @@ fn main() {
if hid.keys_down().contains(KeyPad::KEY_START) { if hid.keys_down().contains(KeyPad::KEY_START) {
break; break;
} }
gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank(); gfx.wait_for_vblank();
} }
} }

2
ctru-rs/examples/thread-locals.rs

@ -61,8 +61,6 @@ fn main() {
break; break;
} }
gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank(); gfx.wait_for_vblank();
} }
} }

4
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!("\x1b[1;1H{hours:0>2}:{minutes:0>2}:{seconds:0>2}");
println!("{weekday} {month} {day} {year}"); println!("{weekday} {month} {day} {year}");
// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();
//Wait for VBlank //Wait for VBlank
gfx.wait_for_vblank(); gfx.wait_for_vblank();
} }

4
ctru-rs/examples/title-info.rs

@ -106,10 +106,6 @@ fn main() {
refresh = false; refresh = false;
} }
// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();
//Wait for VBlank //Wait for VBlank
gfx.wait_for_vblank(); gfx.wait_for_vblank();
} }

44
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 /// Index of a Mii used to configure some parameters of the Mii Selector
/// Can be either a single index, or _all_ Miis /// Can be either a single index, or _all_ Miis
#[derive(Debug, Clone)] #[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum MiiConfigIndex { pub enum MiiIndex {
Index(u32), Index(u32),
All, All,
} }
/// The type of a Mii with their respective data /// The type of a Mii with their respective data
#[derive(Debug, Clone)] #[derive(Debug, Clone, Eq, PartialEq)]
pub enum MiiType { pub enum MiiType {
Guest { index: u32, name: String }, Guest { index: u32, name: String },
User, User,
@ -54,7 +54,7 @@ pub struct MiiSelector {
/// Return value from a MiiSelector's launch /// Return value from a MiiSelector's launch
#[non_exhaustive] #[non_exhaustive]
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct MiiSelectorReturn { pub struct SelectionResult {
pub mii_data: MiiData, pub mii_data: MiiData,
pub is_mii_selected: bool, pub is_mii_selected: bool,
pub mii_type: MiiType, pub mii_type: MiiType,
@ -62,7 +62,7 @@ pub struct MiiSelectorReturn {
/// Error type for the Mii selector /// Error type for the Mii selector
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum MiiLaunchError { pub enum LaunchError {
InvalidChecksum, InvalidChecksum,
} }
@ -94,40 +94,40 @@ impl MiiSelector {
} }
/// Whitelist a guest Mii /// 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 { let index = match mii_index {
MiiConfigIndex::Index(i) => i, MiiIndex::Index(i) => i,
MiiConfigIndex::All => ctru_sys::MIISELECTOR_GUESTMII_SLOTS, MiiIndex::All => ctru_sys::MIISELECTOR_GUESTMII_SLOTS,
}; };
unsafe { ctru_sys::miiSelectorWhitelistGuestMii(self.config.as_mut(), index) } unsafe { ctru_sys::miiSelectorWhitelistGuestMii(self.config.as_mut(), index) }
} }
/// Blacklist a guest Mii /// 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 { let index = match mii_index {
MiiConfigIndex::Index(i) => i, MiiIndex::Index(i) => i,
MiiConfigIndex::All => ctru_sys::MIISELECTOR_GUESTMII_SLOTS, MiiIndex::All => ctru_sys::MIISELECTOR_GUESTMII_SLOTS,
}; };
unsafe { ctru_sys::miiSelectorBlacklistGuestMii(self.config.as_mut(), index) } unsafe { ctru_sys::miiSelectorBlacklistGuestMii(self.config.as_mut(), index) }
} }
/// Whitelist a user Mii /// 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 { let index = match mii_index {
MiiConfigIndex::Index(i) => i, MiiIndex::Index(i) => i,
MiiConfigIndex::All => ctru_sys::MIISELECTOR_USERMII_SLOTS, MiiIndex::All => ctru_sys::MIISELECTOR_USERMII_SLOTS,
}; };
unsafe { ctru_sys::miiSelectorWhitelistUserMii(self.config.as_mut(), index) } unsafe { ctru_sys::miiSelectorWhitelistUserMii(self.config.as_mut(), index) }
} }
/// Blacklist a user Mii /// 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 { let index = match mii_index {
MiiConfigIndex::Index(i) => i, MiiIndex::Index(i) => i,
MiiConfigIndex::All => ctru_sys::MIISELECTOR_USERMII_SLOTS, MiiIndex::All => ctru_sys::MIISELECTOR_USERMII_SLOTS,
}; };
unsafe { ctru_sys::miiSelectorBlacklistUserMii(self.config.as_mut(), index) } unsafe { ctru_sys::miiSelectorBlacklistUserMii(self.config.as_mut(), index) }
@ -143,24 +143,24 @@ impl MiiSelector {
/// Launch the Mii Selector. /// Launch the Mii Selector.
/// Returns an error when the checksum of the Mii is invalid. /// Returns an error when the checksum of the Mii is invalid.
pub fn launch(&mut self) -> Result<MiiSelectorReturn, MiiLaunchError> { pub fn launch(&mut self) -> Result<SelectionResult, LaunchError> {
let mut return_val = Box::<ctru_sys::MiiSelectorReturn>::default(); let mut return_val = Box::<ctru_sys::MiiSelectorReturn>::default();
unsafe { ctru_sys::miiSelectorLaunch(self.config.as_mut(), return_val.as_mut()) } unsafe { ctru_sys::miiSelectorLaunch(self.config.as_mut(), return_val.as_mut()) }
if unsafe { ctru_sys::miiSelectorChecksumIsValid(return_val.as_mut()) } { if unsafe { ctru_sys::miiSelectorChecksumIsValid(return_val.as_mut()) } {
Ok((*return_val).into()) Ok((*return_val).into())
} else { } else {
Err(MiiLaunchError::InvalidChecksum) Err(LaunchError::InvalidChecksum)
} }
} }
} }
impl From<ctru_sys::MiiSelectorReturn> for MiiSelectorReturn { impl From<ctru_sys::MiiSelectorReturn> for SelectionResult {
fn from(ret: ctru_sys::MiiSelectorReturn) -> Self { fn from(ret: ctru_sys::MiiSelectorReturn) -> Self {
let raw_mii_data = ret.mii; let raw_mii_data = ret.mii;
let mut guest_mii_name = ret.guest_mii_name; let mut guest_mii_name = ret.guest_mii_name;
MiiSelectorReturn { SelectionResult {
mii_data: raw_mii_data.into(), mii_data: raw_mii_data.into(),
is_mii_selected: ret.no_mii_selected == 0, is_mii_selected: ret.no_mii_selected == 0,
mii_type: if ret.guest_mii_index != 0xFFFFFFFF { mii_type: if ret.guest_mii_index != 0xFFFFFFFF {
@ -179,7 +179,7 @@ impl From<ctru_sys::MiiSelectorReturn> for MiiSelectorReturn {
} }
} }
impl From<u32> for MiiConfigIndex { impl From<u32> for MiiIndex {
fn from(v: u32) -> Self { fn from(v: u32) -> Self {
Self::Index(v) Self::Index(v)
} }

9
ctru-rs/src/applets/swkbd.rs

@ -7,6 +7,7 @@ use std::iter::once;
use std::str; use std::str;
/// An instance of the software keyboard. /// An instance of the software keyboard.
#[derive(Clone)]
pub struct Swkbd { pub struct Swkbd {
state: Box<SwkbdState>, state: Box<SwkbdState>,
} }
@ -18,7 +19,7 @@ pub struct Swkbd {
/// Numpad is a number pad. /// Numpad is a number pad.
/// Western is a text keyboard without japanese symbols (only applies to JPN systems). For other /// Western is a text keyboard without japanese symbols (only applies to JPN systems). For other
/// systems it's the same as a Normal keyboard. /// systems it's the same as a Normal keyboard.
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum Kind { pub enum Kind {
Normal = ctru_sys::SWKBD_TYPE_NORMAL, Normal = ctru_sys::SWKBD_TYPE_NORMAL,
@ -28,7 +29,7 @@ pub enum Kind {
} }
/// Represents which button the user pressed to close the software keyboard. /// Represents which button the user pressed to close the software keyboard.
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum Button { pub enum Button {
Left = ctru_sys::SWKBD_BUTTON_LEFT, Left = ctru_sys::SWKBD_BUTTON_LEFT,
@ -37,7 +38,7 @@ pub enum Button {
} }
/// Error type for the software keyboard. /// Error type for the software keyboard.
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(i32)] #[repr(i32)]
pub enum Error { pub enum Error {
InvalidInput = ctru_sys::SWKBD_INVALID_INPUT, InvalidInput = ctru_sys::SWKBD_INVALID_INPUT,
@ -51,7 +52,7 @@ pub enum Error {
} }
/// Restrictions on keyboard input /// Restrictions on keyboard input
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum ValidInput { pub enum ValidInput {
Anything = ctru_sys::SWKBD_ANYTHING, Anything = ctru_sys::SWKBD_ANYTHING,

4
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 /// Initialize a console on the chosen screen, overwriting whatever was on the screen
/// previously (including other consoles). The new console is automatically selected for /// previously (including other consoles). The new console is automatically selected for
/// printing. /// 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 { pub fn new(screen: RefMut<'screen, dyn Screen>) -> Self {
let mut context = Box::<PrintConsole>::default(); let mut context = Box::<PrintConsole>::default();

1
ctru-rs/src/services/am.rs

@ -6,6 +6,7 @@ use std::mem::MaybeUninit;
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
#[repr(transparent)] #[repr(transparent)]
pub struct TitleInfo(ctru_sys::AM_TitleEntry); pub struct TitleInfo(ctru_sys::AM_TitleEntry);
impl TitleInfo { impl TitleInfo {
pub fn id(&self) -> u64 { pub fn id(&self) -> u64 {
self.0.titleID self.0.titleID

25
ctru-rs/src/services/cam.rs

@ -21,7 +21,7 @@ pub struct Cam {
} }
/// Flag to pass to [Camera::flip_image] /// Flag to pass to [Camera::flip_image]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum FlipMode { pub enum FlipMode {
None = ctru_sys::FLIP_NONE, None = ctru_sys::FLIP_NONE,
@ -31,7 +31,7 @@ pub enum FlipMode {
} }
/// Flag to pass to [Camera::set_view_size] /// Flag to pass to [Camera::set_view_size]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum ViewSize { pub enum ViewSize {
TopLCD = ctru_sys::SIZE_CTR_TOP_LCD, TopLCD = ctru_sys::SIZE_CTR_TOP_LCD,
@ -48,7 +48,7 @@ pub enum ViewSize {
} }
/// Flag to pass to [Camera::set_frame_rate] /// Flag to pass to [Camera::set_frame_rate]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum FrameRate { pub enum FrameRate {
Fps15 = ctru_sys::FRAME_RATE_15, Fps15 = ctru_sys::FRAME_RATE_15,
@ -68,7 +68,7 @@ pub enum FrameRate {
/// Flag to pass to [Camera::set_white_balance] or /// Flag to pass to [Camera::set_white_balance] or
/// [Camera::set_white_balance_without_base_up] /// [Camera::set_white_balance_without_base_up]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum WhiteBalance { pub enum WhiteBalance {
/// Normal /// Normal
@ -86,7 +86,7 @@ pub enum WhiteBalance {
} }
/// Flag to pass to [Camera::set_photo_mode] /// Flag to pass to [Camera::set_photo_mode]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum PhotoMode { pub enum PhotoMode {
Normal = ctru_sys::PHOTO_MODE_NORMAL, Normal = ctru_sys::PHOTO_MODE_NORMAL,
@ -97,7 +97,7 @@ pub enum PhotoMode {
} }
/// Flag to pass to [Camera::set_effect] /// Flag to pass to [Camera::set_effect]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum Effect { pub enum Effect {
None = ctru_sys::EFFECT_NONE, None = ctru_sys::EFFECT_NONE,
@ -109,7 +109,7 @@ pub enum Effect {
} }
/// Flag to pass to [Camera::set_contrast] /// Flag to pass to [Camera::set_contrast]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum Contrast { pub enum Contrast {
/// OFF /// OFF
@ -121,7 +121,7 @@ pub enum Contrast {
} }
/// Flag to pass to [Camera::set_lens_correction] /// Flag to pass to [Camera::set_lens_correction]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum LensCorrection { pub enum LensCorrection {
Off = ctru_sys::LENS_CORRECTION_DARK, Off = ctru_sys::LENS_CORRECTION_DARK,
@ -130,7 +130,7 @@ pub enum LensCorrection {
} }
/// Flag to pass to [Camera::set_output_format] /// Flag to pass to [Camera::set_output_format]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum OutputFormat { pub enum OutputFormat {
Yuv422 = ctru_sys::OUTPUT_YUV_422, Yuv422 = ctru_sys::OUTPUT_YUV_422,
@ -138,7 +138,7 @@ pub enum OutputFormat {
} }
/// Flag to pass to [Cam::play_shutter_sound] /// Flag to pass to [Cam::play_shutter_sound]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum ShutterSound { pub enum ShutterSound {
Normal = ctru_sys::SHUTTER_SOUND_TYPE_NORMAL, Normal = ctru_sys::SHUTTER_SOUND_TYPE_NORMAL,
@ -169,6 +169,7 @@ impl TryFrom<OutputFormat> for FramebufferFormat {
} }
/// Struct containing coordinates passed to [Camera::set_trimming_params]. /// Struct containing coordinates passed to [Camera::set_trimming_params].
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct TrimmingParams { pub struct TrimmingParams {
x_start: i16, x_start: i16,
y_start: i16, y_start: i16,
@ -193,11 +194,11 @@ impl TrimmingParams {
} }
/// Represents data used by the camera to calibrate image quality /// 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); pub struct ImageQualityCalibrationData(pub ctru_sys::CAMU_ImageQualityCalibrationData);
/// Represents data used by the camera to calibrate image quality when using both outward cameras /// 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); pub struct StereoCameraCalibrationData(pub ctru_sys::CAMU_StereoCameraCalibrationData);
/// Represents the camera on the inside of the 3DS /// Represents the camera on the inside of the 3DS

6
ctru-rs/src/services/cfgu.rs

@ -4,7 +4,7 @@
use crate::error::ResultCode; use crate::error::ResultCode;
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum Region { pub enum Region {
Japan = ctru_sys::CFG_REGION_JPN, Japan = ctru_sys::CFG_REGION_JPN,
@ -16,7 +16,7 @@ pub enum Region {
Taiwan = ctru_sys::CFG_REGION_TWN, Taiwan = ctru_sys::CFG_REGION_TWN,
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum Language { pub enum Language {
Japanese = ctru_sys::CFG_LANGUAGE_JP, Japanese = ctru_sys::CFG_LANGUAGE_JP,
@ -33,7 +33,7 @@ pub enum Language {
TraditionalChinese = ctru_sys::CFG_LANGUAGE_TW, TraditionalChinese = ctru_sys::CFG_LANGUAGE_TW,
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum SystemModel { pub enum SystemModel {
Model3DS = ctru_sys::CFG_MODEL_3DS, Model3DS = ctru_sys::CFG_MODEL_3DS,

14
ctru-rs/src/services/fs.rs

@ -23,17 +23,13 @@ bitflags! {
const FS_OPEN_WRITE = 2; const FS_OPEN_WRITE = 2;
const FS_OPEN_CREATE = 4; const FS_OPEN_CREATE = 4;
} }
}
bitflags! {
#[derive(Default)] #[derive(Default)]
struct FsWrite: u32 { struct FsWrite: u32 {
const FS_WRITE_FLUSH = 1; const FS_WRITE_FLUSH = 1;
const FS_WRITE_UPDATE_TIME = 256; const FS_WRITE_UPDATE_TIME = 256;
} }
}
bitflags! {
#[derive(Default)] #[derive(Default)]
struct FsAttribute: u32 { struct FsAttribute: u32 {
const FS_ATTRIBUTE_DIRECTORY = 1; const FS_ATTRIBUTE_DIRECTORY = 1;
@ -43,7 +39,7 @@ bitflags! {
} }
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum FsMediaType { pub enum FsMediaType {
Nand = ctru_sys::MEDIATYPE_NAND, Nand = ctru_sys::MEDIATYPE_NAND,
@ -51,7 +47,7 @@ pub enum FsMediaType {
GameCard = ctru_sys::MEDIATYPE_GAME_CARD, GameCard = ctru_sys::MEDIATYPE_GAME_CARD,
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum PathType { pub enum PathType {
Invalid = ctru_sys::PATH_INVALID, Invalid = ctru_sys::PATH_INVALID,
@ -61,7 +57,7 @@ pub enum PathType {
UTF16 = ctru_sys::PATH_UTF16, UTF16 = ctru_sys::PATH_UTF16,
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum ArchiveID { pub enum ArchiveID {
RomFS = ctru_sys::ARCHIVE_ROMFS, RomFS = ctru_sys::ARCHIVE_ROMFS,
@ -234,7 +230,7 @@ pub struct Metadata {
/// .open("foo.txt") /// .open("foo.txt")
/// .unwrap(); /// .unwrap();
/// ``` /// ```
#[derive(Clone, Default)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct OpenOptions { pub struct OpenOptions {
read: bool, read: bool,
write: bool, write: bool,

52
ctru-rs/src/services/gfx.rs

@ -55,6 +55,23 @@ pub trait Screen: private::Sealed {
unsafe { ctru_sys::gfxSetDoubleBuffering(self.as_raw(), enabled) } 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 /// Gets the framebuffer format
fn framebuffer_format(&self) -> FramebufferFormat { fn framebuffer_format(&self) -> FramebufferFormat {
unsafe { ctru_sys::gfxGetScreenFormat(self.as_raw()) }.into() unsafe { ctru_sys::gfxGetScreenFormat(self.as_raw()) }.into()
@ -103,7 +120,7 @@ pub struct RawFrameBuffer<'screen> {
screen: PhantomData<&'screen mut dyn Screen>, screen: PhantomData<&'screen mut dyn Screen>,
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
/// Side of top screen framebuffer /// Side of top screen framebuffer
/// ///
@ -128,6 +145,13 @@ pub struct Gfx {
static GFX_ACTIVE: Mutex<usize> = Mutex::new(0); static GFX_ACTIVE: Mutex<usize> = Mutex::new(0);
impl Gfx { 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<Self> {
Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false)
}
/// Initialize the Gfx module with the chosen framebuffer formats for the top and bottom /// Initialize the Gfx module with the chosen framebuffer formats for the top and bottom
/// screens /// 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<Self> {
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 /// Waits for the vertical blank interrupt
/// ///
/// Use this to synchronize your application with the refresh rate of the LCD screens /// Use this to synchronize your application with the refresh rate of the LCD screens

4
ctru-rs/src/services/gspgpu.rs

@ -1,6 +1,6 @@
//! GSPGPU service //! GSPGPU service
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum Event { pub enum Event {
Psc0 = ctru_sys::GSPGPU_EVENT_PSC0, Psc0 = ctru_sys::GSPGPU_EVENT_PSC0,
@ -13,7 +13,7 @@ pub enum Event {
} }
/// Framebuffer formats supported by the 3DS /// Framebuffer formats supported by the 3DS
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum FramebufferFormat { pub enum FramebufferFormat {
/// RGBA8. 4 bytes per pixel /// RGBA8. 4 bytes per pixel

3
ctru-rs/src/services/hid.rs

@ -8,7 +8,6 @@ use crate::error::ResultCode;
bitflags::bitflags! { bitflags::bitflags! {
/// A set of flags corresponding to the button and directional pad /// A set of flags corresponding to the button and directional pad
/// inputs on the 3DS /// inputs on the 3DS
#[derive(Default)]
pub struct KeyPad: u32 { pub struct KeyPad: u32 {
const A = ctru_sys::KEY_A; const A = ctru_sys::KEY_A;
const B = ctru_sys::KEY_B; const B = ctru_sys::KEY_B;
@ -48,9 +47,11 @@ bitflags::bitflags! {
pub struct Hid(()); pub struct Hid(());
/// Represents user input to the touchscreen. /// Represents user input to the touchscreen.
#[derive(Debug, Clone, Copy)]
pub struct TouchPosition(ctru_sys::touchPosition); pub struct TouchPosition(ctru_sys::touchPosition);
/// Represents the current position of the 3DS circle pad. /// Represents the current position of the 3DS circle pad.
#[derive(Debug, Clone, Copy)]
pub struct CirclePosition(ctru_sys::circlePosition); pub struct CirclePosition(ctru_sys::circlePosition);
/// Initializes the HID service. /// Initializes the HID service.

10
ctru-rs/src/services/ndsp/mod.rs

@ -14,7 +14,7 @@ use std::sync::Mutex;
const NUMBER_OF_CHANNELS: u8 = 24; const NUMBER_OF_CHANNELS: u8 = 24;
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum OutputMode { pub enum OutputMode {
Mono = ctru_sys::NDSP_OUTPUT_MONO, Mono = ctru_sys::NDSP_OUTPUT_MONO,
@ -22,7 +22,7 @@ pub enum OutputMode {
Surround = ctru_sys::NDSP_OUTPUT_SURROUND, Surround = ctru_sys::NDSP_OUTPUT_SURROUND,
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum AudioFormat { pub enum AudioFormat {
PCM8Mono = ctru_sys::NDSP_FORMAT_MONO_PCM8, PCM8Mono = ctru_sys::NDSP_FORMAT_MONO_PCM8,
@ -32,12 +32,12 @@ pub enum AudioFormat {
} }
/// Representation of volume mix for a channel. /// Representation of volume mix for a channel.
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq)]
pub struct AudioMix { pub struct AudioMix {
raw: [f32; 12], raw: [f32; 12],
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum InterpolationType { pub enum InterpolationType {
Polyphase = ctru_sys::NDSP_INTERP_POLYPHASE, Polyphase = ctru_sys::NDSP_INTERP_POLYPHASE,
@ -45,7 +45,7 @@ pub enum InterpolationType {
None = ctru_sys::NDSP_INTERP_NONE, None = ctru_sys::NDSP_INTERP_NONE,
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum NdspError { pub enum NdspError {
/// Channel ID /// Channel ID
InvalidChannel(u8), InvalidChannel(u8),

2
ctru-rs/src/services/ndsp/wave.rs

@ -11,7 +11,7 @@ pub struct Wave {
played_on_channel: Option<u8>, played_on_channel: Option<u8>,
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u8)] #[repr(u8)]
/// Enum representing the playback status of a [Wave]. /// Enum representing the playback status of a [Wave].
pub enum WaveStatus { pub enum WaveStatus {

4
ctru-rs/src/services/ps.rs

@ -6,6 +6,7 @@
use crate::error::ResultCode; use crate::error::ResultCode;
use crate::Result; use crate::Result;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum AESAlgorithm { pub enum AESAlgorithm {
CbcEnc = ctru_sys::PS_ALGORITHM_CBC_ENC, CbcEnc = ctru_sys::PS_ALGORITHM_CBC_ENC,
@ -16,6 +17,7 @@ pub enum AESAlgorithm {
CcmDec = ctru_sys::PS_ALGORITHM_CCM_DEC, CcmDec = ctru_sys::PS_ALGORITHM_CCM_DEC,
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum AESKeyType { pub enum AESKeyType {
Keyslot0D = ctru_sys::PS_KEYSLOT_0D, Keyslot0D = ctru_sys::PS_KEYSLOT_0D,
@ -56,7 +58,7 @@ impl Ps {
pub fn generate_random_bytes(&self, out: &mut [u8]) -> crate::Result<()> { pub fn generate_random_bytes(&self, out: &mut [u8]) -> crate::Result<()> {
ResultCode(unsafe { 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(()) Ok(())
} }

11
ctru-rs/src/services/sslc.rs

@ -14,17 +14,6 @@ impl SslC {
Ok(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 { impl Drop for SslC {

2
ctru-rs/src/test_runner.rs

@ -39,8 +39,6 @@ pub(crate) fn run(tests: &[&TestDescAndFn]) {
println!("Press START to exit."); println!("Press START to exit.");
while apt.main_loop() { while apt.main_loop() {
gfx.flush_buffers();
gfx.swap_buffers();
gfx.wait_for_vblank(); gfx.wait_for_vblank();
hid.scan_input(); hid.scan_input();

Loading…
Cancel
Save