From 12f3d8ad40408a3436e578b482d0231656e76d3f Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Wed, 5 Apr 2023 20:44:15 +0200 Subject: [PATCH 1/3] Ask for mut references in Channel --- ctru-rs/src/services/ndsp/mod.rs | 34 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/ctru-rs/src/services/ndsp/mod.rs b/ctru-rs/src/services/ndsp/mod.rs index 1a1c981..fa93cf6 100644 --- a/ctru-rs/src/services/ndsp/mod.rs +++ b/ctru-rs/src/services/ndsp/mod.rs @@ -128,7 +128,7 @@ impl Ndsp { impl Channel<'_> { /// Reset the channel - pub fn reset(&self) { + pub fn reset(&mut self) { unsafe { ctru_sys::ndspChnReset(self.id.into()) }; } @@ -165,28 +165,28 @@ impl Channel<'_> { } /// Pause or un-pause the channel's playback. - pub fn set_paused(&self, state: bool) { + pub fn set_paused(&mut self, state: bool) { unsafe { ctru_sys::ndspChnSetPaused(self.id.into(), state) }; } /// Set the channel's output format. /// Change this setting based on the used sample's format. - pub fn set_format(&self, format: AudioFormat) { + pub fn set_format(&mut self, format: AudioFormat) { unsafe { ctru_sys::ndspChnSetFormat(self.id.into(), format.into()) }; } /// Set the channel's interpolation mode. - pub fn set_interpolation(&self, interp_type: InterpolationType) { + pub fn set_interpolation(&mut self, interp_type: InterpolationType) { unsafe { ctru_sys::ndspChnSetInterp(self.id.into(), interp_type.into()) }; } /// Set the channel's volume mix. - pub fn set_mix(&self, mix: &AudioMix) { + pub fn set_mix(&mut self, mix: &AudioMix) { unsafe { ctru_sys::ndspChnSetMix(self.id.into(), mix.as_raw().as_ptr().cast_mut()) } } /// Set the channel's rate of sampling. - pub fn set_sample_rate(&self, rate: f32) { + pub fn set_sample_rate(&mut self, rate: f32) { unsafe { ctru_sys::ndspChnSetRate(self.id.into(), rate) }; } @@ -195,7 +195,7 @@ impl Channel<'_> { // We suggest using other wave formats when developing homebrew applications. /// Clear the wave buffer queue and stop playback. - pub fn clear_queue(&self) { + pub fn clear_queue(&mut self) { unsafe { ctru_sys::ndspChnWaveBufClear(self.id.into()) }; } @@ -206,7 +206,7 @@ impl Channel<'_> { /// /// `libctru` expects the user to manually keep the info data (in this case [Wave]) alive during playback. /// To ensure safety, checks within [Wave] will clear the whole channel queue if any queued [Wave] is dropped prematurely. - pub fn queue_wave(&self, wave: &mut Wave) -> std::result::Result<(), NdspError> { + pub fn queue_wave(&mut self, wave: &mut Wave) -> std::result::Result<(), NdspError> { match wave.status() { WaveStatus::Playing | WaveStatus::Queued => return Err(NdspError::WaveBusy(self.id)), _ => (), @@ -225,7 +225,7 @@ impl Channel<'_> { /// Refer to [libctru](https://libctru.devkitpro.org/channel_8h.html#a1da3b363c2edfd318c92276b527daae6) for more info. impl Channel<'_> { /// Enables/disables monopole filters. - pub fn iir_mono_set_enabled(&self, enable: bool) { + pub fn iir_mono_set_enabled(&mut self, enable: bool) { unsafe { ctru_sys::ndspChnIirMonoSetEnable(self.id.into(), enable) }; } @@ -234,7 +234,7 @@ impl Channel<'_> { /// # Notes /// /// This is a lower quality filter than the Biquad alternative. - pub fn iir_mono_set_params_high_pass_filter(&self, cut_off_freq: f32) { + pub fn iir_mono_set_params_high_pass_filter(&mut self, cut_off_freq: f32) { unsafe { ctru_sys::ndspChnIirMonoSetParamsHighPassFilter(self.id.into(), cut_off_freq) }; } @@ -243,38 +243,38 @@ impl Channel<'_> { /// # Notes /// /// This is a lower quality filter than the Biquad alternative. - pub fn iir_mono_set_params_low_pass_filter(&self, cut_off_freq: f32) { + pub fn iir_mono_set_params_low_pass_filter(&mut self, cut_off_freq: f32) { unsafe { ctru_sys::ndspChnIirMonoSetParamsLowPassFilter(self.id.into(), cut_off_freq) }; } /// Enables/disables biquad filters. - pub fn iir_biquad_set_enabled(&self, enable: bool) { + pub fn iir_biquad_set_enabled(&mut self, enable: bool) { unsafe { ctru_sys::ndspChnIirBiquadSetEnable(self.id.into(), enable) }; } /// Sets the biquad to be a high pass filter. - pub fn iir_biquad_set_params_high_pass_filter(&self, cut_off_freq: f32, quality: f32) { + pub fn iir_biquad_set_params_high_pass_filter(&mut self, cut_off_freq: f32, quality: f32) { unsafe { ctru_sys::ndspChnIirBiquadSetParamsHighPassFilter(self.id.into(), cut_off_freq, quality) }; } /// Sets the biquad to be a low pass filter. - pub fn iir_biquad_set_params_low_pass_filter(&self, cut_off_freq: f32, quality: f32) { + pub fn iir_biquad_set_params_low_pass_filter(&mut self, cut_off_freq: f32, quality: f32) { unsafe { ctru_sys::ndspChnIirBiquadSetParamsLowPassFilter(self.id.into(), cut_off_freq, quality) }; } /// Sets the biquad to be a notch filter. - pub fn iir_biquad_set_params_notch_filter(&self, notch_freq: f32, quality: f32) { + pub fn iir_biquad_set_params_notch_filter(&mut self, notch_freq: f32, quality: f32) { unsafe { ctru_sys::ndspChnIirBiquadSetParamsNotchFilter(self.id.into(), notch_freq, quality) }; } /// Sets the biquad to be a band pass filter. - pub fn iir_biquad_set_params_band_pass_filter(&self, mid_freq: f32, quality: f32) { + pub fn iir_biquad_set_params_band_pass_filter(&mut self, mid_freq: f32, quality: f32) { unsafe { ctru_sys::ndspChnIirBiquadSetParamsBandPassFilter(self.id.into(), mid_freq, quality) }; @@ -282,7 +282,7 @@ impl Channel<'_> { /// Sets the biquad to be a peaking equalizer. pub fn iir_biquad_set_params_peaking_equalizer( - &self, + &mut self, central_freq: f32, quality: f32, gain: f32, From 1e4002604f37fb850cccb68b3dc3e20cea75585c Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Wed, 5 Apr 2023 20:58:23 +0200 Subject: [PATCH 2/3] Fixed mutability for all modules --- ctru-rs/src/services/apt.rs | 2 +- ctru-rs/src/services/cam.rs | 2 +- ctru-rs/src/services/fs.rs | 20 ++++++++++---------- ctru-rs/src/services/gfx.rs | 6 +++--- ctru-rs/src/services/hid.rs | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ctru-rs/src/services/apt.rs b/ctru-rs/src/services/apt.rs index 2096a70..aa1dd28 100644 --- a/ctru-rs/src/services/apt.rs +++ b/ctru-rs/src/services/apt.rs @@ -14,7 +14,7 @@ impl Apt { unsafe { ctru_sys::aptMainLoop() } } - pub fn set_app_cpu_time_limit(&self, percent: u32) -> crate::Result<()> { + pub fn set_app_cpu_time_limit(&mut self, percent: u32) -> crate::Result<()> { unsafe { ResultCode(ctru_sys::APT_SetAppCpuTimeLimit(percent))?; Ok(()) diff --git a/ctru-rs/src/services/cam.rs b/ctru-rs/src/services/cam.rs index 520e3e2..52ce926 100644 --- a/ctru-rs/src/services/cam.rs +++ b/ctru-rs/src/services/cam.rs @@ -354,7 +354,7 @@ pub trait Camera { /// The new width will be `trim_width / 2` to the left and right of the center. /// The new height will be `trim_height / 2` above and below the center. fn set_trimming_params_center( - &self, + &mut self, trim_width: i16, trim_height: i16, cam_width: i16, diff --git a/ctru-rs/src/services/fs.rs b/ctru-rs/src/services/fs.rs index 45f9efb..9364bb6 100644 --- a/ctru-rs/src/services/fs.rs +++ b/ctru-rs/src/services/fs.rs @@ -310,7 +310,7 @@ impl Fs { } /// Returns a handle to the SDMC (memory card) Archive. - pub fn sdmc(&self) -> crate::Result { + pub fn sdmc(&mut self) -> crate::Result { unsafe { let mut handle = 0; let id = ArchiveID::Sdmc; @@ -384,7 +384,7 @@ impl File { /// let sdmc_archive = fs.sdmc().unwrap(); /// let mut f = File::create(&sdmc_archive, "/foo.txt").unwrap(); /// ``` - pub fn create>(arch: &Archive, path: P) -> IoResult { + pub fn create>(arch: &mut Archive, path: P) -> IoResult { OpenOptions::new() .write(true) .create(true) @@ -588,11 +588,11 @@ impl OpenOptions { /// * Invalid combinations of open options. /// /// [`Archive`]: struct.Archive.html - pub fn open>(&self, path: P) -> IoResult { + pub fn open>(&mut self, path: P) -> IoResult { self._open(path.as_ref(), self.open_flags()) } - fn _open(&self, path: &Path, flags: FsOpen) -> IoResult { + fn _open(&mut self, path: &Path, flags: FsOpen) -> IoResult { unsafe { let mut file_handle = 0; let path = to_utf16(path); @@ -706,7 +706,7 @@ impl<'a> DirEntry<'a> { /// but is not limited to just these cases: /// /// * User lacks permissions to create directory at `path` -pub fn create_dir>(arch: &Archive, path: P) -> IoResult<()> { +pub fn create_dir>(arch: &mut Archive, path: P) -> IoResult<()> { unsafe { let path = to_utf16(path.as_ref()); let fs_path = ctru_sys::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); @@ -732,7 +732,7 @@ pub fn create_dir>(arch: &Archive, path: P) -> IoResult<()> { /// /// * If any directory in the path specified by `path` does not already exist /// and it could not be created otherwise. -pub fn create_dir_all>(arch: &Archive, path: P) -> IoResult<()> { +pub fn create_dir_all>(arch: &mut Archive, path: P) -> IoResult<()> { let path = path.as_ref(); let mut dir = PathBuf::new(); let mut result = Ok(()); @@ -768,7 +768,7 @@ pub fn metadata>(arch: &Archive, path: P) -> IoResult { /// /// * The user lacks permissions to remove the directory at the provided path. /// * The directory isn't empty. -pub fn remove_dir>(arch: &Archive, path: P) -> IoResult<()> { +pub fn remove_dir>(arch: &mut Archive, path: P) -> IoResult<()> { unsafe { let path = to_utf16(path.as_ref()); let fs_path = ctru_sys::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); @@ -786,7 +786,7 @@ pub fn remove_dir>(arch: &Archive, path: P) -> IoResult<()> { /// # Errors /// /// see `file::remove_file` and `fs::remove_dir` -pub fn remove_dir_all>(arch: &Archive, path: P) -> IoResult<()> { +pub fn remove_dir_all>(arch: &mut Archive, path: P) -> IoResult<()> { unsafe { let path = to_utf16(path.as_ref()); let fs_path = ctru_sys::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); @@ -838,7 +838,7 @@ pub fn read_dir>(arch: &Archive, path: P) -> IoResult { /// /// * path points to a directory. /// * The user lacks permissions to remove the file. -pub fn remove_file>(arch: &Archive, path: P) -> IoResult<()> { +pub fn remove_file>(arch: &mut Archive, path: P) -> IoResult<()> { unsafe { let path = to_utf16(path.as_ref()); let fs_path = ctru_sys::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); @@ -861,7 +861,7 @@ pub fn remove_file>(arch: &Archive, path: P) -> IoResult<()> { /// /// * from does not exist. /// * The user lacks permissions to view contents. -pub fn rename(arch: &Archive, from: P, to: Q) -> IoResult<()> +pub fn rename(arch: &mut Archive, from: P, to: Q) -> IoResult<()> where P: AsRef, Q: AsRef, diff --git a/ctru-rs/src/services/gfx.rs b/ctru-rs/src/services/gfx.rs index 40d4740..5b71978 100644 --- a/ctru-rs/src/services/gfx.rs +++ b/ctru-rs/src/services/gfx.rs @@ -163,21 +163,21 @@ impl Gfx { } /// Flushes the current framebuffers - pub fn flush_buffers(&self) { + pub fn flush_buffers(&mut 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) { + pub fn swap_buffers(&mut 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) { + pub fn swap_buffers_gpu(&mut self) { unsafe { ctru_sys::gfxSwapBuffersGpu() }; } diff --git a/ctru-rs/src/services/hid.rs b/ctru-rs/src/services/hid.rs index 26b034f..31dd4d9 100644 --- a/ctru-rs/src/services/hid.rs +++ b/ctru-rs/src/services/hid.rs @@ -71,7 +71,7 @@ impl Hid { /// Scans the HID service for all user input occurring on the current /// frame. This function should be called on every frame when polling /// for user input. - pub fn scan_input(&self) { + pub fn scan_input(&mut self) { unsafe { ctru_sys::hidScanInput() }; } From 8e3017b725bfef1afa89fbd3aedc77f44bbd094f Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Wed, 5 Apr 2023 21:05:45 +0200 Subject: [PATCH 3/3] Fix examples --- ctru-rs/examples/audio-filters.rs | 4 ++-- ctru-rs/examples/buttons.rs | 2 +- ctru-rs/examples/camera-image.rs | 2 +- ctru-rs/examples/file-explorer.rs | 8 ++++---- ctru-rs/examples/futures-basic.rs | 2 +- ctru-rs/examples/futures-tokio.rs | 2 +- ctru-rs/examples/gfx-3d-mode.rs | 2 +- ctru-rs/examples/gfx-wide-mode.rs | 2 +- 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 | 2 +- ctru-rs/examples/system-configuration.rs | 2 +- ctru-rs/examples/thread-basic.rs | 2 +- ctru-rs/examples/thread-info.rs | 2 +- ctru-rs/examples/thread-locals.rs | 2 +- ctru-rs/examples/time-rtc.rs | 2 +- ctru-rs/examples/title-info.rs | 2 +- ctru-rs/src/lib.rs | 2 +- ctru-rs/src/services/gfx.rs | 6 +++--- ctru-rs/src/test_runner.rs | 2 +- 27 files changed, 33 insertions(+), 33 deletions(-) diff --git a/ctru-rs/examples/audio-filters.rs b/ctru-rs/examples/audio-filters.rs index 3dd0e34..327ede4 100644 --- a/ctru-rs/examples/audio-filters.rs +++ b/ctru-rs/examples/audio-filters.rs @@ -38,7 +38,7 @@ fn main() { ctru::use_panic_handler(); let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let hid = Hid::init().expect("Couldn't obtain HID controller"); + let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let apt = Apt::init().expect("Couldn't obtain APT controller"); let _console = Console::init(gfx.top_screen.borrow_mut()); @@ -73,7 +73,7 @@ fn main() { // This line isn't needed since the default NDSP configuration already sets the output mode to `Stereo` ndsp.set_output_mode(OutputMode::Stereo); - let channel_zero = ndsp.channel(0).unwrap(); + let mut channel_zero = ndsp.channel(0).unwrap(); channel_zero.set_interpolation(InterpolationType::Linear); channel_zero.set_sample_rate(SAMPLE_RATE as f32); channel_zero.set_format(AudioFormat::PCM16Stereo); diff --git a/ctru-rs/examples/buttons.rs b/ctru-rs/examples/buttons.rs index 1cc5355..39f24d9 100644 --- a/ctru-rs/examples/buttons.rs +++ b/ctru-rs/examples/buttons.rs @@ -4,7 +4,7 @@ fn main() { ctru::use_panic_handler(); let apt = Apt::init().unwrap(); - let hid = Hid::init().unwrap(); + let mut hid = Hid::init().unwrap(); let gfx = Gfx::init().unwrap(); let console = Console::init(gfx.top_screen.borrow_mut()); diff --git a/ctru-rs/examples/camera-image.rs b/ctru-rs/examples/camera-image.rs index 4303c2c..46a96d4 100644 --- a/ctru-rs/examples/camera-image.rs +++ b/ctru-rs/examples/camera-image.rs @@ -17,7 +17,7 @@ fn main() { ctru::use_panic_handler(); let apt = Apt::init().expect("Failed to initialize Apt service."); - let hid = Hid::init().expect("Failed to initialize Hid service."); + let mut hid = Hid::init().expect("Failed to initialize Hid service."); let gfx = Gfx::init().expect("Failed to initialize GFX service."); gfx.top_screen.borrow_mut().set_double_buffering(true); diff --git a/ctru-rs/examples/file-explorer.rs b/ctru-rs/examples/file-explorer.rs index 527595c..5b256c9 100644 --- a/ctru-rs/examples/file-explorer.rs +++ b/ctru-rs/examples/file-explorer.rs @@ -12,18 +12,18 @@ fn main() { ctru::use_panic_handler(); let apt = Apt::init().unwrap(); - let hid = Hid::init().unwrap(); + let mut hid = Hid::init().unwrap(); let gfx = Gfx::init().unwrap(); #[cfg(all(feature = "romfs", romfs_exists))] let _romfs = ctru::services::romfs::RomFS::init().unwrap(); - FileExplorer::init(&apt, &hid, &gfx).run(); + FileExplorer::init(&apt, &mut hid, &gfx).run(); } struct FileExplorer<'a> { apt: &'a Apt, - hid: &'a Hid, + hid: &'a mut Hid, gfx: &'a Gfx, console: Console<'a>, path: PathBuf, @@ -32,7 +32,7 @@ struct FileExplorer<'a> { } impl<'a> FileExplorer<'a> { - fn init(apt: &'a Apt, hid: &'a Hid, gfx: &'a Gfx) -> Self { + fn init(apt: &'a Apt, hid: &'a mut Hid, gfx: &'a Gfx) -> Self { let mut top_screen = gfx.top_screen.borrow_mut(); top_screen.set_wide_mode(true); let console = Console::init(top_screen); diff --git a/ctru-rs/examples/futures-basic.rs b/ctru-rs/examples/futures-basic.rs index bfcf053..ee2e3be 100644 --- a/ctru-rs/examples/futures-basic.rs +++ b/ctru-rs/examples/futures-basic.rs @@ -16,7 +16,7 @@ fn main() { ctru::use_panic_handler(); let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let hid = Hid::init().expect("Couldn't obtain HID controller"); + let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let apt = Apt::init().expect("Couldn't obtain APT controller"); let _console = Console::init(gfx.top_screen.borrow_mut()); diff --git a/ctru-rs/examples/futures-tokio.rs b/ctru-rs/examples/futures-tokio.rs index 48edc14..cbb446d 100644 --- a/ctru-rs/examples/futures-tokio.rs +++ b/ctru-rs/examples/futures-tokio.rs @@ -9,7 +9,7 @@ fn main() { ctru::use_panic_handler(); let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let hid = Hid::init().expect("Couldn't obtain HID controller"); + let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let apt = Apt::init().expect("Couldn't obtain APT controller"); let _console = Console::init(gfx.top_screen.borrow_mut()); diff --git a/ctru-rs/examples/gfx-3d-mode.rs b/ctru-rs/examples/gfx-3d-mode.rs index ca47c09..13b4d3c 100644 --- a/ctru-rs/examples/gfx-3d-mode.rs +++ b/ctru-rs/examples/gfx-3d-mode.rs @@ -13,7 +13,7 @@ fn main() { ctru::use_panic_handler(); let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let hid = Hid::init().expect("Couldn't obtain HID controller"); + let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let apt = Apt::init().expect("Couldn't obtain APT controller"); let _console = Console::init(gfx.bottom_screen.borrow_mut()); diff --git a/ctru-rs/examples/gfx-wide-mode.rs b/ctru-rs/examples/gfx-wide-mode.rs index 80f73b1..f781c89 100644 --- a/ctru-rs/examples/gfx-wide-mode.rs +++ b/ctru-rs/examples/gfx-wide-mode.rs @@ -4,7 +4,7 @@ fn main() { ctru::use_panic_handler(); let apt = Apt::init().unwrap(); - let hid = Hid::init().unwrap(); + let mut hid = Hid::init().unwrap(); let gfx = Gfx::init().unwrap(); let mut console = Console::init(gfx.top_screen.borrow_mut()); diff --git a/ctru-rs/examples/graphics-bitmap.rs b/ctru-rs/examples/graphics-bitmap.rs index 6ed90e1..ebbf53e 100644 --- a/ctru-rs/examples/graphics-bitmap.rs +++ b/ctru-rs/examples/graphics-bitmap.rs @@ -18,7 +18,7 @@ fn main() { ctru::use_panic_handler(); let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let hid = Hid::init().expect("Couldn't obtain HID controller"); + let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let apt = Apt::init().expect("Couldn't obtain APT controller"); let _console = Console::init(gfx.top_screen.borrow_mut()); diff --git a/ctru-rs/examples/hashmaps.rs b/ctru-rs/examples/hashmaps.rs index e6b9619..87ad8be 100644 --- a/ctru-rs/examples/hashmaps.rs +++ b/ctru-rs/examples/hashmaps.rs @@ -9,7 +9,7 @@ fn main() { // This generator is only active when activating the `PS` service. // This service is automatically initialized. let apt = Apt::init().unwrap(); - let hid = Hid::init().unwrap(); + let mut hid = Hid::init().unwrap(); let gfx = Gfx::init().unwrap(); let _console = Console::init(gfx.top_screen.borrow_mut()); diff --git a/ctru-rs/examples/hello-both-screens.rs b/ctru-rs/examples/hello-both-screens.rs index 601027f..7395967 100644 --- a/ctru-rs/examples/hello-both-screens.rs +++ b/ctru-rs/examples/hello-both-screens.rs @@ -4,7 +4,7 @@ fn main() { ctru::use_panic_handler(); let apt = Apt::init().unwrap(); - let hid = Hid::init().unwrap(); + let mut hid = Hid::init().unwrap(); let gfx = Gfx::init().unwrap(); // Start a console on the top screen diff --git a/ctru-rs/examples/hello-world.rs b/ctru-rs/examples/hello-world.rs index d61a7bc..697ec7c 100644 --- a/ctru-rs/examples/hello-world.rs +++ b/ctru-rs/examples/hello-world.rs @@ -6,7 +6,7 @@ fn main() { ctru::use_panic_handler(); let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let hid = Hid::init().expect("Couldn't obtain HID controller"); + let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let apt = Apt::init().expect("Couldn't obtain APT controller"); let _console = Console::init(gfx.top_screen.borrow_mut()); diff --git a/ctru-rs/examples/linear-memory.rs b/ctru-rs/examples/linear-memory.rs index a44a35f..b3afced 100644 --- a/ctru-rs/examples/linear-memory.rs +++ b/ctru-rs/examples/linear-memory.rs @@ -7,7 +7,7 @@ fn main() { ctru::use_panic_handler(); let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let hid = Hid::init().expect("Couldn't obtain HID controller"); + let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let apt = Apt::init().expect("Couldn't obtain APT controller"); let _console = Console::init(gfx.top_screen.borrow_mut()); diff --git a/ctru-rs/examples/mii-selector.rs b/ctru-rs/examples/mii-selector.rs index 7488c0c..ef7d7d3 100644 --- a/ctru-rs/examples/mii-selector.rs +++ b/ctru-rs/examples/mii-selector.rs @@ -5,7 +5,7 @@ fn main() { ctru::use_panic_handler(); let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let hid = Hid::init().expect("Couldn't obtain HID controller"); + let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let apt = Apt::init().expect("Couldn't obtain APT controller"); let _console = Console::init(gfx.top_screen.borrow_mut()); diff --git a/ctru-rs/examples/network-sockets.rs b/ctru-rs/examples/network-sockets.rs index db750bc..ca2d163 100644 --- a/ctru-rs/examples/network-sockets.rs +++ b/ctru-rs/examples/network-sockets.rs @@ -9,7 +9,7 @@ fn main() { let gfx = Gfx::init().unwrap(); let _console = Console::init(gfx.top_screen.borrow_mut()); - let hid = Hid::init().unwrap(); + let mut hid = Hid::init().unwrap(); let apt = Apt::init().unwrap(); println!("\nlibctru sockets demo\n"); diff --git a/ctru-rs/examples/output-3dslink.rs b/ctru-rs/examples/output-3dslink.rs index 61731d2..1fe0c6a 100644 --- a/ctru-rs/examples/output-3dslink.rs +++ b/ctru-rs/examples/output-3dslink.rs @@ -14,7 +14,7 @@ fn main() { ctru::use_panic_handler(); let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let hid = Hid::init().expect("Couldn't obtain HID controller"); + let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let apt = Apt::init().expect("Couldn't obtain APT controller"); let mut soc = Soc::init().expect("Couldn't obtain SOC controller"); diff --git a/ctru-rs/examples/romfs.rs b/ctru-rs/examples/romfs.rs index f52fff3..c729c32 100644 --- a/ctru-rs/examples/romfs.rs +++ b/ctru-rs/examples/romfs.rs @@ -4,7 +4,7 @@ fn main() { ctru::use_panic_handler(); let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let hid = Hid::init().expect("Couldn't obtain HID controller"); + let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let apt = Apt::init().expect("Couldn't obtain APT controller"); let _console = Console::init(gfx.top_screen.borrow_mut()); diff --git a/ctru-rs/examples/software-keyboard.rs b/ctru-rs/examples/software-keyboard.rs index 5f65be4..954fdd0 100644 --- a/ctru-rs/examples/software-keyboard.rs +++ b/ctru-rs/examples/software-keyboard.rs @@ -5,7 +5,7 @@ fn main() { ctru::use_panic_handler(); let apt = Apt::init().unwrap(); - let hid = Hid::init().unwrap(); + let mut hid = Hid::init().unwrap(); let gfx = Gfx::init().unwrap(); let _console = Console::init(gfx.top_screen.borrow_mut()); diff --git a/ctru-rs/examples/system-configuration.rs b/ctru-rs/examples/system-configuration.rs index 49787ee..cd81a02 100644 --- a/ctru-rs/examples/system-configuration.rs +++ b/ctru-rs/examples/system-configuration.rs @@ -5,7 +5,7 @@ fn main() { ctru::use_panic_handler(); let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let hid = Hid::init().expect("Couldn't obtain HID controller"); + let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let apt = Apt::init().expect("Couldn't obtain APT controller"); let cfgu = Cfgu::init().expect("Couldn't obtain CFGU controller"); let _console = Console::init(gfx.top_screen.borrow_mut()); diff --git a/ctru-rs/examples/thread-basic.rs b/ctru-rs/examples/thread-basic.rs index a6c3a6b..73be659 100644 --- a/ctru-rs/examples/thread-basic.rs +++ b/ctru-rs/examples/thread-basic.rs @@ -9,7 +9,7 @@ fn main() { ctru::use_panic_handler(); let apt = Apt::init().unwrap(); - let hid = Hid::init().unwrap(); + let mut hid = Hid::init().unwrap(); let gfx = Gfx::init().unwrap(); let _console = Console::init(gfx.top_screen.borrow_mut()); diff --git a/ctru-rs/examples/thread-info.rs b/ctru-rs/examples/thread-info.rs index 06e2864..968e858 100644 --- a/ctru-rs/examples/thread-info.rs +++ b/ctru-rs/examples/thread-info.rs @@ -10,7 +10,7 @@ fn main() { ctru::use_panic_handler(); let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let hid = Hid::init().expect("Couldn't obtain HID controller"); + let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let apt = Apt::init().expect("Couldn't obtain APT controller"); let _console = Console::init(gfx.top_screen.borrow_mut()); diff --git a/ctru-rs/examples/thread-locals.rs b/ctru-rs/examples/thread-locals.rs index 70f2aaa..09e2082 100644 --- a/ctru-rs/examples/thread-locals.rs +++ b/ctru-rs/examples/thread-locals.rs @@ -14,7 +14,7 @@ fn main() { let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); gfx.top_screen.borrow_mut().set_wide_mode(true); - let hid = Hid::init().expect("Couldn't obtain HID controller"); + let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let apt = Apt::init().expect("Couldn't obtain APT controller"); let _console = Console::init(gfx.top_screen.borrow_mut()); diff --git a/ctru-rs/examples/time-rtc.rs b/ctru-rs/examples/time-rtc.rs index a229105..86db923 100644 --- a/ctru-rs/examples/time-rtc.rs +++ b/ctru-rs/examples/time-rtc.rs @@ -4,7 +4,7 @@ fn main() { ctru::use_panic_handler(); let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let hid = Hid::init().expect("Couldn't obtain HID controller"); + let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let apt = Apt::init().expect("Couldn't obtain APT controller"); let _console = Console::init(gfx.top_screen.borrow_mut()); diff --git a/ctru-rs/examples/title-info.rs b/ctru-rs/examples/title-info.rs index c904e96..a18534e 100644 --- a/ctru-rs/examples/title-info.rs +++ b/ctru-rs/examples/title-info.rs @@ -6,7 +6,7 @@ fn main() { ctru::use_panic_handler(); let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); - let hid = Hid::init().expect("Couldn't obtain HID controller"); + let mut hid = Hid::init().expect("Couldn't obtain HID controller"); let apt = Apt::init().expect("Couldn't obtain APT controller"); let am = Am::init().expect("Couldn't obtain AM controller"); let top_screen = Console::init(gfx.top_screen.borrow_mut()); diff --git a/ctru-rs/src/lib.rs b/ctru-rs/src/lib.rs index e733d5a..2073fe3 100644 --- a/ctru-rs/src/lib.rs +++ b/ctru-rs/src/lib.rs @@ -55,7 +55,7 @@ fn panic_hook_setup() { println!("\nPress SELECT to exit the software"); match Hid::init() { - Ok(hid) => loop { + Ok(mut hid) => loop { hid.scan_input(); let keys = hid.keys_down(); if keys.contains(KeyPad::SELECT) { diff --git a/ctru-rs/src/services/gfx.rs b/ctru-rs/src/services/gfx.rs index 5b71978..40d4740 100644 --- a/ctru-rs/src/services/gfx.rs +++ b/ctru-rs/src/services/gfx.rs @@ -163,21 +163,21 @@ impl Gfx { } /// Flushes the current framebuffers - pub fn flush_buffers(&mut self) { + 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(&mut self) { + 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(&mut self) { + pub fn swap_buffers_gpu(&self) { unsafe { ctru_sys::gfxSwapBuffersGpu() }; } diff --git a/ctru-rs/src/test_runner.rs b/ctru-rs/src/test_runner.rs index 1f0698f..6f157e3 100644 --- a/ctru-rs/src/test_runner.rs +++ b/ctru-rs/src/test_runner.rs @@ -13,7 +13,7 @@ use crate::prelude::*; /// panic is just treated the same as any normal application panic). pub(crate) fn run(tests: &[&TestDescAndFn]) { let gfx = Gfx::init().unwrap(); - let hid = Hid::init().unwrap(); + let mut hid = Hid::init().unwrap(); let apt = Apt::init().unwrap(); let mut top_screen = gfx.top_screen.borrow_mut();