Browse Source

Fixed typos, nits and small issues

pull/50/head
Andrea Ciliberti 3 years ago
parent
commit
447ef1eaa2
  1. 2
      ctru-rs/examples/buttons.rs
  2. 2
      ctru-rs/examples/file-explorer.rs
  3. 2
      ctru-rs/examples/futures-basic.rs
  4. 2
      ctru-rs/examples/futures-tokio.rs
  5. 2
      ctru-rs/examples/gfx-wide-mode.rs
  6. 2
      ctru-rs/examples/graphics-bitmap.rs
  7. 2
      ctru-rs/examples/hashmaps.rs
  8. 2
      ctru-rs/examples/hello-both-screens.rs
  9. 2
      ctru-rs/examples/hello-world.rs
  10. 2
      ctru-rs/examples/network-sockets.rs
  11. 2
      ctru-rs/examples/romfs.rs
  12. 2
      ctru-rs/examples/software-keyboard.rs
  13. 2
      ctru-rs/examples/thread-basic.rs
  14. 2
      ctru-rs/examples/thread-locals.rs
  15. 2
      ctru-rs/examples/time-rtc.rs
  16. 5
      ctru-rs/src/error.rs
  17. 17
      ctru-rs/src/gfx.rs
  18. 2
      ctru-rs/src/lib.rs
  19. 7
      ctru-rs/src/romfs.rs
  20. 10
      ctru-rs/src/services/apt.rs
  21. 8
      ctru-rs/src/services/fs.rs
  22. 7
      ctru-rs/src/services/hid.rs
  23. 7
      ctru-rs/src/services/soc.rs
  24. 8
      ctru-rs/src/services/sslc.rs
  25. 7
      ctru-rs/src/srv.rs
  26. 2
      ctru-rs/src/test_runner.rs

2
ctru-rs/examples/buttons.rs

@ -8,7 +8,7 @@ fn main() {
ctru::init(); ctru::init();
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let gfx = Gfx::init_default().unwrap(); let gfx = Gfx::init().unwrap();
let console = Console::init(gfx.top_screen.borrow_mut()); let console = Console::init(gfx.top_screen.borrow_mut());
println!("Hi there! Try pressing a button"); println!("Hi there! Try pressing a button");

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

@ -14,7 +14,7 @@ fn main() {
ctru::init(); ctru::init();
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let gfx = Gfx::init_default().unwrap(); let gfx = Gfx::init().unwrap();
#[cfg(all(feature = "romfs", romfs_exists))] #[cfg(all(feature = "romfs", romfs_exists))]
let _romfs = ctru::romfs::RomFS::init().unwrap(); let _romfs = ctru::romfs::RomFS::init().unwrap();

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

@ -13,7 +13,7 @@ use futures::StreamExt;
fn main() { fn main() {
ctru::init(); ctru::init();
let gfx = Gfx::init_default().expect("Couldn't obtaint GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::init().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::init(gfx.top_screen.borrow_mut());

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

@ -6,7 +6,7 @@ use std::time::Duration;
fn main() { fn main() {
ctru::init(); ctru::init();
let gfx = Gfx::init_default().expect("Couldn't obtaint GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::init().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::init(gfx.top_screen.borrow_mut());

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

@ -7,7 +7,7 @@ fn main() {
ctru::init(); ctru::init();
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let gfx = Gfx::init_default().unwrap(); let gfx = Gfx::init().unwrap();
let mut console = Console::init(gfx.top_screen.borrow_mut()); let mut console = Console::init(gfx.top_screen.borrow_mut());
println!("Press A to enable/disable wide screen mode."); println!("Press A to enable/disable wide screen mode.");

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

@ -19,7 +19,7 @@ static IMAGE: &[u8] = include_bytes!("assets/ferris.rgb");
fn main() { fn main() {
ctru::init(); ctru::init();
let gfx = Gfx::init_default().expect("Couldn't obtaint GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::init().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::init(gfx.top_screen.borrow_mut());

2
ctru-rs/examples/hashmaps.rs

@ -12,7 +12,7 @@ fn main() {
ctru::init(); ctru::init();
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let gfx = Gfx::init_default().unwrap(); let gfx = Gfx::init().unwrap();
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::init(gfx.top_screen.borrow_mut());
let mut map = std::collections::HashMap::new(); let mut map = std::collections::HashMap::new();

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

@ -8,7 +8,7 @@ fn main() {
ctru::init(); ctru::init();
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let gfx = Gfx::init_default().unwrap(); let gfx = Gfx::init().unwrap();
// Start a console on the top screen // Start a console on the top screen
let top_screen = Console::init(gfx.top_screen.borrow_mut()); let top_screen = Console::init(gfx.top_screen.borrow_mut());

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

@ -7,7 +7,7 @@ use std::io::BufWriter;
fn main() { fn main() {
ctru::init(); ctru::init();
let gfx = Gfx::init_default().expect("Couldn't obtain GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::init().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::init(gfx.top_screen.borrow_mut());

2
ctru-rs/examples/network-sockets.rs

@ -10,7 +10,7 @@ use std::time::Duration;
fn main() { fn main() {
ctru::init(); ctru::init();
let gfx = Gfx::init_default().unwrap(); let gfx = Gfx::init().unwrap();
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::init(gfx.top_screen.borrow_mut());
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();

2
ctru-rs/examples/romfs.rs

@ -5,7 +5,7 @@ use ctru::services::hid::{Hid, KeyPad};
fn main() { fn main() {
ctru::init(); ctru::init();
let gfx = Gfx::init_default().expect("Couldn't obtaint GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::init().expect("Couldn't obtain APT controller");
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::init(gfx.top_screen.borrow_mut());

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

@ -8,7 +8,7 @@ fn main() {
ctru::init(); ctru::init();
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let gfx = Gfx::default(); let gfx = Gfx::init().unwrap();
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::init(gfx.top_screen.borrow_mut());
println!("Press A to enter some text or press Start to quit"); println!("Press A to enter some text or press Start to quit");

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

@ -11,7 +11,7 @@ fn main() {
ctru::init(); ctru::init();
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let gfx = Gfx::init_default().unwrap(); let gfx = Gfx::init().unwrap();
let _console = Console::init(gfx.top_screen.borrow_mut()); let _console = Console::init(gfx.top_screen.borrow_mut());
let prio = thread::current().priority(); let prio = thread::current().priority();

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

@ -10,7 +10,7 @@ std::thread_local! {
fn main() { fn main() {
ctru::init(); ctru::init();
let gfx = Gfx::init_default().expect("Couldn't obtaint GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
gfx.top_screen.borrow_mut().set_wide_mode(true); gfx.top_screen.borrow_mut().set_wide_mode(true);
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::init().expect("Couldn't obtain APT controller");

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

@ -6,7 +6,7 @@ use ctru::services::hid::{Hid, KeyPad};
fn main() { fn main() {
ctru::init(); ctru::init();
let gfx = Gfx::init_default().expect("Couldn't obtaint GFX controller"); let gfx = Gfx::init().expect("Couldn't obtain GFX controller");
let hid = Hid::init().expect("Couldn't obtain HID controller"); let hid = Hid::init().expect("Couldn't obtain HID controller");
let apt = Apt::init().expect("Couldn't obtain APT controller"); let apt = Apt::init().expect("Couldn't obtain APT controller");

5
ctru-rs/src/error.rs

@ -29,7 +29,10 @@ impl fmt::Debug for Error {
.field("summary", &R_SUMMARY(err)) .field("summary", &R_SUMMARY(err))
.field("level", &R_LEVEL(err)) .field("level", &R_LEVEL(err))
.finish(), .finish(),
Error::ServiceAlreadyActive(service) => write!(f, "Service {service} already active"), Error::ServiceAlreadyActive(service) => f
.debug_tuple("ServiceAlreadyActive")
.field(&String::from(service))
.finish(),
} }
} }
} }

17
ctru-rs/src/gfx.rs

@ -80,8 +80,8 @@ impl Gfx {
/// 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
/// ///
/// Use `Gfx::init_default()` instead of this function to initialize the module with default parameters /// Use `Gfx::init()` instead of this function to initialize the module with default parameters
pub fn init( pub fn with_formats(
top_fb_fmt: FramebufferFormat, top_fb_fmt: FramebufferFormat,
bottom_fb_fmt: FramebufferFormat, bottom_fb_fmt: FramebufferFormat,
use_vram_buffers: bool, use_vram_buffers: bool,
@ -102,9 +102,9 @@ impl Gfx {
} }
/// Creates a new Gfx instance with default init values /// Creates a new Gfx instance with default init values
/// It's the same as calling: `Gfx::init(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false) /// It's the same as calling: `Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false)
pub fn init_default() -> Result<Self> { pub fn init() -> Result<Self> {
Gfx::init(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false) Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false)
} }
/// Flushes the current framebuffers /// Flushes the current framebuffers
@ -216,7 +216,7 @@ impl Drop for Gfx {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ctru_sys::gfxExit() }; unsafe { ctru_sys::gfxExit() };
GFX_ACTIVE.store(false, Ordering::Release); GFX_ACTIVE.store(false, Ordering::SeqCst);
} }
} }
@ -227,6 +227,9 @@ mod tests {
#[test] #[test]
fn gfx_duplicate() { fn gfx_duplicate() {
// We don't need to build a `Gfx` because the test runner has one already // We don't need to build a `Gfx` because the test runner has one already
assert!(Gfx::init_default().is_err()); match Gfx::init() {
Err(Error::ServiceAlreadyActive("Gfx")) => return,
_ => panic!(),
}
} }
} }

2
ctru-rs/src/lib.rs

@ -45,7 +45,7 @@ pub fn init() {
// The problem here is that the `panic_hook` is run _before_ the app cleanup, // The problem here is that the `panic_hook` is run _before_ the app cleanup,
// so an `Hid` stuct may still be alive and thus make the `panic_hook` panic. // so an `Hid` stuct may still be alive and thus make the `panic_hook` panic.
// If that were to happen, the system would have to reboot to properly close the app. // If that were to happen, the system would have to reboot to properly close the app.
// //
// Using `hidInit` is safe when another instance is open, and we can do safe operations afterwards. // Using `hidInit` is safe when another instance is open, and we can do safe operations afterwards.
// The only (probably) unsafe part of this system is the `hidExit`, since in a multithreaded // The only (probably) unsafe part of this system is the `hidExit`, since in a multithreaded
// environment some other threads may still be doing operations on the service // environment some other threads may still be doing operations on the service

7
ctru-rs/src/romfs.rs

@ -43,7 +43,7 @@ impl Drop for RomFS {
let mount_name = CStr::from_bytes_with_nul(b"romfs\0").unwrap(); let mount_name = CStr::from_bytes_with_nul(b"romfs\0").unwrap();
unsafe { ctru_sys::romfsUnmount(mount_name.as_ptr()) }; unsafe { ctru_sys::romfsUnmount(mount_name.as_ptr()) };
ROMFS_ACTIVE.store(false, Ordering::Release); ROMFS_ACTIVE.store(false, Ordering::SeqCst);
} }
} }
@ -55,6 +55,9 @@ mod tests {
fn romfs_duplicate() { fn romfs_duplicate() {
let _romfs = RomFS::init().unwrap(); let _romfs = RomFS::init().unwrap();
assert!(RomFS::init().is_err()); match RomFS::init() {
Err(Error::ServiceAlreadyActive("RomFS")) => return,
_ => panic!(),
}
} }
} }

10
ctru-rs/src/services/apt.rs

@ -40,7 +40,7 @@ impl Drop for Apt {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ctru_sys::aptExit() }; unsafe { ctru_sys::aptExit() };
APT_ACTIVE.store(false, Ordering::Release); APT_ACTIVE.store(false, Ordering::SeqCst);
} }
} }
@ -49,9 +49,11 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn gfx_duplicate() { fn apt_duplicate() {
// We don't need to build a `Apt` because the test runner has one already // We don't need to build a `Apt` because the test runner has one already
assert!(Apt::init().is_err()); match Apt::init() {
Err(Error::ServiceAlreadyActive("Apt")) => return,
_ => panic!(),
}
} }
} }

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

@ -1004,7 +1004,7 @@ impl Drop for Fs {
ctru_sys::fsExit(); ctru_sys::fsExit();
} }
FS_ACTIVE.store(false, Ordering::Release); FS_ACTIVE.store(false, Ordering::SeqCst);
} }
} }
@ -1083,7 +1083,9 @@ mod tests {
fn fs_duplicate() { fn fs_duplicate() {
let _fs = Fs::init().unwrap(); let _fs = Fs::init().unwrap();
assert!(Fs::init().is_err()); match Fs::init() {
Err(Error::ServiceAlreadyActive("Fs")) => return,
_ => panic!(),
}
} }
} }

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

@ -164,7 +164,7 @@ impl Drop for Hid {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ctru_sys::hidExit() }; unsafe { ctru_sys::hidExit() };
HID_ACTIVE.store(false, Ordering::Release); HID_ACTIVE.store(false, Ordering::SeqCst);
} }
} }
@ -175,6 +175,9 @@ mod tests {
#[test] #[test]
fn hid_duplicate() { fn hid_duplicate() {
// We don't need to build a `Hid` because the test runner has one already // We don't need to build a `Hid` because the test runner has one already
assert!(Hid::init().is_err()); match Hid::init() {
Err(Error::ServiceAlreadyActive("Hid")) => return,
_ => panic!(),
}
} }
} }

7
ctru-rs/src/services/soc.rs

@ -61,7 +61,7 @@ impl Drop for Soc {
free(self.soc_mem as *mut _); free(self.soc_mem as *mut _);
} }
SOC_ACTIVE.store(false, Ordering::Release); SOC_ACTIVE.store(false, Ordering::SeqCst);
} }
} }
@ -73,6 +73,9 @@ mod tests {
fn soc_duplicate() { fn soc_duplicate() {
let _soc = Soc::init().unwrap(); let _soc = Soc::init().unwrap();
assert!(Soc::init().is_err()); match Soc::init() {
Err(Error::ServiceAlreadyActive("Soc")) => return,
_ => panic!(),
}
} }
} }

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

@ -40,7 +40,7 @@ impl Drop for SslC {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ctru_sys::sslcExit() }; unsafe { ctru_sys::sslcExit() };
SSLC_ACTIVE.store(false, Ordering::Release); SSLC_ACTIVE.store(false, Ordering::SeqCst);
} }
} }
@ -52,7 +52,9 @@ mod tests {
fn sslc_duplicate() { fn sslc_duplicate() {
let _sslc = SslC::init().unwrap(); let _sslc = SslC::init().unwrap();
assert!(SslC::init().is_err()); match SslC::init() {
Err(Error::ServiceAlreadyActive("SslC")) => return,
_ => panic!(),
}
} }
} }

7
ctru-rs/src/srv.rs

@ -27,7 +27,7 @@ impl Drop for Srv {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ctru_sys::srvExit() }; unsafe { ctru_sys::srvExit() };
SRV_ACTIVE.store(false, Ordering::Release); SRV_ACTIVE.store(false, Ordering::SeqCst);
} }
} }
@ -39,6 +39,9 @@ mod tests {
fn srv_duplicate() { fn srv_duplicate() {
let _srv = Srv::init().unwrap(); let _srv = Srv::init().unwrap();
assert!(Srv::init().is_err()); match Srv::init() {
Err(Error::ServiceAlreadyActive("Srv")) => return,
_ => panic!(),
}
} }
} }

2
ctru-rs/src/test_runner.rs

@ -17,7 +17,7 @@ use crate::services::Apt;
pub(crate) fn run(tests: &[&TestDescAndFn]) { pub(crate) fn run(tests: &[&TestDescAndFn]) {
crate::init(); crate::init();
let gfx = Gfx::init_default().unwrap(); let gfx = Gfx::init().unwrap();
let hid = Hid::init().unwrap(); let hid = Hid::init().unwrap();
let apt = Apt::init().unwrap(); let apt = Apt::init().unwrap();

Loading…
Cancel
Save