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

3
ctru-rs/examples/buttons.rs

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2
ctru-rs/examples/hashmaps.rs

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

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

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

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

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

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

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

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

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

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

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

3
ctru-rs/examples/romfs.rs

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

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

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

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

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

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

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

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

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

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

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

4
ctru-rs/examples/time-rtc.rs

@ -36,10 +36,6 @@ fn main() { @@ -36,10 +36,6 @@ fn main() {
println!("\x1b[1;1H{hours:0>2}:{minutes:0>2}:{seconds:0>2}");
println!("{weekday} {month} {day} {year}");
// Flush and swap framebuffers
gfx.flush_buffers();
gfx.swap_buffers();
//Wait for VBlank
gfx.wait_for_vblank();
}

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

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

44
ctru-rs/src/applets/mii_selector.rs

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

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

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

4
ctru-rs/src/console.rs

@ -16,6 +16,10 @@ impl<'screen> Console<'screen> { @@ -16,6 +16,10 @@ impl<'screen> Console<'screen> {
/// Initialize a console on the chosen screen, overwriting whatever was on the screen
/// previously (including other consoles). The new console is automatically selected for
/// printing.
///
/// # Notes
///
/// [Console] automatically takes care of flushing and swapping buffers for its screen when printing.
pub fn new(screen: RefMut<'screen, dyn Screen>) -> Self {
let mut context = Box::<PrintConsole>::default();

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

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

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

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

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

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

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

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

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

@ -55,6 +55,23 @@ pub trait Screen: private::Sealed { @@ -55,6 +55,23 @@ pub trait Screen: private::Sealed {
unsafe { ctru_sys::gfxSetDoubleBuffering(self.as_raw(), enabled) }
}
/// Swaps the video buffers.
///
/// This should be used even if double buffering is disabled.
fn flush_buffer(&mut self) {
let framebuffer = self.raw_framebuffer();
// Flush the data array. `self.raw_framebuffer` should get the correct parameters for all kinds of screens
unsafe { ctru_sys::GSPGPU_FlushDataCache(framebuffer.ptr.cast(), (framebuffer.height * framebuffer.width).into()) };
}
/// Swaps the video buffers.
///
/// This should be used even if double buffering is disabled.
fn swap_buffers(&mut self) {
unsafe { ctru_sys::gfxScreenSwapBuffers(self.side().into(), true) };
}
/// Gets the framebuffer format
fn framebuffer_format(&self) -> FramebufferFormat {
unsafe { ctru_sys::gfxGetScreenFormat(self.as_raw()) }.into()
@ -103,7 +120,7 @@ pub struct RawFrameBuffer<'screen> { @@ -103,7 +120,7 @@ pub struct RawFrameBuffer<'screen> {
screen: PhantomData<&'screen mut dyn Screen>,
}
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)]
/// Side of top screen framebuffer
///
@ -128,6 +145,13 @@ pub struct Gfx { @@ -128,6 +145,13 @@ pub struct Gfx {
static GFX_ACTIVE: Mutex<usize> = Mutex::new(0);
impl Gfx {
/// Creates a new [Gfx] instance with default init values
/// It's the same as calling:
/// `Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false)`
pub fn new() -> Result<Self> {
Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false)
}
/// Initialize the Gfx module with the chosen framebuffer formats for the top and bottom
/// screens
///
@ -155,32 +179,6 @@ impl Gfx { @@ -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
///
/// 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 @@ @@ -1,6 +1,6 @@
//! GSPGPU service
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)]
pub enum Event {
Psc0 = ctru_sys::GSPGPU_EVENT_PSC0,
@ -13,7 +13,7 @@ pub enum Event { @@ -13,7 +13,7 @@ pub enum Event {
}
/// Framebuffer formats supported by the 3DS
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)]
pub enum FramebufferFormat {
/// RGBA8. 4 bytes per pixel

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

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

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

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

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

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

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

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

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

@ -14,17 +14,6 @@ impl SslC { @@ -14,17 +14,6 @@ impl SslC {
Ok(SslC(()))
}
}
/// Fill `buf` with `buf.len()` random bytes
pub fn generate_random_data(&self, buf: &mut [u8]) -> crate::Result<()> {
unsafe {
ResultCode(ctru_sys::sslcGenerateRandomData(
buf.as_ptr() as _,
buf.len() as u32,
))?;
Ok(())
}
}
}
impl Drop for SslC {

2
ctru-rs/src/test_runner.rs

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

Loading…
Cancel
Save