Browse Source

Use ctru_sys crate name instead of libctru, and run cargo fix --edition

Including --edition-idioms.
pull/13/head
AzureMarker 3 years ago
parent
commit
f547addf21
No known key found for this signature in database
GPG Key ID: 47A133F3BF9D03D3
  1. 34
      ctru-rs/src/applets/swkbd.rs
  2. 4
      ctru-rs/src/console.rs
  3. 62
      ctru-rs/src/gfx.rs
  4. 13
      ctru-rs/src/lib.rs
  5. 6
      ctru-rs/src/sdmc.rs
  6. 14
      ctru-rs/src/services/apt.rs
  7. 120
      ctru-rs/src/services/fs.rs
  8. 44
      ctru-rs/src/services/gspgpu.rs
  9. 26
      ctru-rs/src/services/hid.rs
  10. 10
      ctru-rs/src/services/soc.rs
  11. 10
      ctru-rs/src/services/sslc.rs
  12. 6
      ctru-rs/src/srv.rs
  13. 4
      ctru-rs/src/thread.rs

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

@ -1,12 +1,10 @@
use std::convert::TryInto; use ctru_sys::{
use std::iter::once;
use std::str;
use libctru::{
self, swkbdInit, swkbdInputText, swkbdSetButton, swkbdSetFeatures, swkbdSetHintText, SwkbdState, self, swkbdInit, swkbdInputText, swkbdSetButton, swkbdSetFeatures, swkbdSetHintText, SwkbdState,
}; };
use libc; use libc;
use std::convert::TryInto;
use std::iter::once;
use std::str;
/// An instance of the software keyboard. /// An instance of the software keyboard.
pub struct Swkbd { pub struct Swkbd {
@ -133,10 +131,10 @@ impl Swkbd {
buf.as_mut_ptr(), buf.as_mut_ptr(),
buf.len().try_into().unwrap(), buf.len().try_into().unwrap(),
) { ) {
libctru::SWKBD_BUTTON_NONE => Err(self.parse_swkbd_error()), ctru_sys::SWKBD_BUTTON_NONE => Err(self.parse_swkbd_error()),
libctru::SWKBD_BUTTON_LEFT => Ok(Button::Left), ctru_sys::SWKBD_BUTTON_LEFT => Ok(Button::Left),
libctru::SWKBD_BUTTON_MIDDLE => Ok(Button::Middle), ctru_sys::SWKBD_BUTTON_MIDDLE => Ok(Button::Middle),
libctru::SWKBD_BUTTON_RIGHT => Ok(Button::Right), ctru_sys::SWKBD_BUTTON_RIGHT => Ok(Button::Right),
_ => unreachable!(), _ => unreachable!(),
} }
} }
@ -198,14 +196,14 @@ impl Swkbd {
fn parse_swkbd_error(&self) -> Error { fn parse_swkbd_error(&self) -> Error {
match self.state.result { match self.state.result {
libctru::SWKBD_INVALID_INPUT => Error::InvalidInput, ctru_sys::SWKBD_INVALID_INPUT => Error::InvalidInput,
libctru::SWKBD_OUTOFMEM => Error::OutOfMem, ctru_sys::SWKBD_OUTOFMEM => Error::OutOfMem,
libctru::SWKBD_HOMEPRESSED => Error::HomePressed, ctru_sys::SWKBD_HOMEPRESSED => Error::HomePressed,
libctru::SWKBD_RESETPRESSED => Error::ResetPressed, ctru_sys::SWKBD_RESETPRESSED => Error::ResetPressed,
libctru::SWKBD_POWERPRESSED => Error::PowerPressed, ctru_sys::SWKBD_POWERPRESSED => Error::PowerPressed,
libctru::SWKBD_PARENTAL_OK => Error::ParentalOk, ctru_sys::SWKBD_PARENTAL_OK => Error::ParentalOk,
libctru::SWKBD_PARENTAL_FAIL => Error::ParentalFail, ctru_sys::SWKBD_PARENTAL_FAIL => Error::ParentalFail,
libctru::SWKBD_BANNED_INPUT => Error::BannedInput, ctru_sys::SWKBD_BANNED_INPUT => Error::BannedInput,
_ => unreachable!(), _ => unreachable!(),
} }
} }

4
ctru-rs/src/console.rs

@ -1,8 +1,8 @@
use std::default::Default; use std::default::Default;
use libctru::{consoleClear, consoleInit, consoleSelect, consoleSetWindow, PrintConsole}; use ctru_sys::{consoleClear, consoleInit, consoleSelect, consoleSetWindow, PrintConsole};
use gfx::Screen; use crate::gfx::Screen;
pub struct Console { pub struct Console {
context: Box<PrintConsole>, context: Box<PrintConsole>,

62
ctru-rs/src/gfx.rs

@ -3,7 +3,7 @@
use std::default::Default; use std::default::Default;
use std::ops::Drop; use std::ops::Drop;
use services::gspgpu::{self, FramebufferFormat}; use crate::services::gspgpu::{self, FramebufferFormat};
/// A handle to libctru's gfx module. This module is a wrapper around the GSPGPU service that /// A handle to libctru's gfx module. This module is a wrapper around the GSPGPU service that
/// provides helper functions and utilities for software rendering. /// provides helper functions and utilities for software rendering.
@ -37,28 +37,31 @@ impl Gfx {
/// ///
/// Use `Gfx::default()` instead of this function to initialize the module with default parameters /// Use `Gfx::default()` instead of this function to initialize the module with default parameters
pub fn new( pub fn new(
top_fb_fmt: FramebufferFormat, bottom_fb_fmt: FramebufferFormat, use_vram_buffers: bool) -> Self { top_fb_fmt: FramebufferFormat,
unsafe { ::libctru::gfxInit(top_fb_fmt.into(), bottom_fb_fmt.into(), use_vram_buffers); } bottom_fb_fmt: FramebufferFormat,
use_vram_buffers: bool,
) -> Self {
unsafe {
ctru_sys::gfxInit(top_fb_fmt.into(), bottom_fb_fmt.into(), use_vram_buffers);
}
Gfx(()) Gfx(())
} }
/// Enable or disable the 3D stereoscopic effect /// Enable or disable the 3D stereoscopic effect
pub fn set_3d_enabled(&self, enabled: bool) { pub fn set_3d_enabled(&self, enabled: bool) {
unsafe { unsafe { ctru_sys::gfxSet3D(enabled) }
::libctru::gfxSet3D(enabled)
}
} }
/// Enable or disable the wide screen mode (top screen). /// Enable or disable the wide screen mode (top screen).
/// ///
/// This only works when 3D is disabled. /// This only works when 3D is disabled.
pub fn set_wide_mode(&self, enabled: bool) { pub fn set_wide_mode(&self, enabled: bool) {
unsafe { libctru::gfxSetWide(enabled) }; unsafe { ctru_sys::gfxSetWide(enabled) };
} }
/// Get the status of wide screen mode. /// Get the status of wide screen mode.
pub fn get_wide_mode(&self) -> bool { pub fn get_wide_mode(&self) -> bool {
unsafe { libctru::gfxIsWide() } unsafe { ctru_sys::gfxIsWide() }
} }
/// Sets whether to use double buffering. Enabled by default. /// Sets whether to use double buffering. Enabled by default.
@ -66,28 +69,26 @@ impl Gfx {
/// Note that even when double buffering is disabled, one should still use the `swap_buffers` /// Note that even when double buffering is disabled, one should still use the `swap_buffers`
/// method on each frame to keep the gsp configuration up to date /// method on each frame to keep the gsp configuration up to date
pub fn set_double_buffering(&self, screen: Screen, enabled: bool) { pub fn set_double_buffering(&self, screen: Screen, enabled: bool) {
unsafe { unsafe { ctru_sys::gfxSetDoubleBuffering(screen.into(), enabled) }
::libctru::gfxSetDoubleBuffering(screen.into(), enabled)
}
} }
/// Flushes the current framebuffers /// Flushes the current framebuffers
pub fn flush_buffers(&self) { pub fn flush_buffers(&self) {
unsafe { ::libctru::gfxFlushBuffers() }; unsafe { ctru_sys::gfxFlushBuffers() };
} }
/// Swaps the framebuffers and sets the gsp state /// Swaps the framebuffers and sets the gsp state
/// ///
/// Use this function when working with software rendering /// Use this function when working with software rendering
pub fn swap_buffers(&self) { pub fn swap_buffers(&self) {
unsafe { ::libctru::gfxSwapBuffers() }; unsafe { ctru_sys::gfxSwapBuffers() };
} }
/// Swaps the framebuffers without manipulating the gsp state /// Swaps the framebuffers without manipulating the gsp state
/// ///
/// Use this function when working with GPU rendering /// Use this function when working with GPU rendering
pub fn swap_buffers_gpu(&self) { pub fn swap_buffers_gpu(&self) {
unsafe { ::libctru::gfxSwapBuffersGpu() }; unsafe { ctru_sys::gfxSwapBuffersGpu() };
} }
/// Waits for the vertical blank interrupt /// Waits for the vertical blank interrupt
@ -95,17 +96,16 @@ impl Gfx {
/// 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
pub fn wait_for_vblank(&self) { pub fn wait_for_vblank(&self) {
gspgpu::wait_for_event(gspgpu::Event::VBlank0, true); gspgpu::wait_for_event(gspgpu::Event::VBlank0, true);
} }
/// Gets the framebuffer format for a screen /// Gets the framebuffer format for a screen
pub fn get_framebuffer_format(&self, screen: Screen) -> FramebufferFormat { pub fn get_framebuffer_format(&self, screen: Screen) -> FramebufferFormat {
unsafe { ::libctru::gfxGetScreenFormat(screen.into()).into() } unsafe { ctru_sys::gfxGetScreenFormat(screen.into()).into() }
} }
/// Change the framebuffer format for a screen /// Change the framebuffer format for a screen
pub fn set_framebuffer_format(&self, screen: Screen, fmt: FramebufferFormat) { pub fn set_framebuffer_format(&self, screen: Screen, fmt: FramebufferFormat) {
unsafe { ::libctru::gfxSetScreenFormat(screen.into(), fmt.into()) } unsafe { ctru_sys::gfxSetScreenFormat(screen.into(), fmt.into()) }
} }
/// Returns a tuple containing a pointer to the specifified framebuffer (as determined by the /// Returns a tuple containing a pointer to the specifified framebuffer (as determined by the
@ -118,46 +118,42 @@ impl Gfx {
unsafe { unsafe {
let mut width: u16 = 0; let mut width: u16 = 0;
let mut height: u16 = 0; let mut height: u16 = 0;
let buf: *mut u8 = ::libctru::gfxGetFramebuffer( let buf: *mut u8 =
screen.into(), ctru_sys::gfxGetFramebuffer(screen.into(), side.into(), &mut width, &mut height);
side.into(),
&mut width,
&mut height,
);
(buf, width, height) (buf, width, height)
} }
} }
} }
impl From<Screen> for ::libctru::gfxScreen_t { impl From<Screen> for ctru_sys::gfxScreen_t {
fn from(g: Screen) -> ::libctru::gfxScreen_t { fn from(g: Screen) -> ctru_sys::gfxScreen_t {
use self::Screen::*; use self::Screen::*;
match g { match g {
Top => ::libctru::GFX_TOP, Top => ctru_sys::GFX_TOP,
Bottom => ::libctru::GFX_BOTTOM, Bottom => ctru_sys::GFX_BOTTOM,
} }
} }
} }
impl From<Side> for ::libctru::gfx3dSide_t { impl From<Side> for ctru_sys::gfx3dSide_t {
fn from(s: Side) -> ::libctru::gfx3dSide_t { fn from(s: Side) -> ctru_sys::gfx3dSide_t {
use self::Side::*; use self::Side::*;
match s { match s {
Left => ::libctru::GFX_LEFT, Left => ctru_sys::GFX_LEFT,
Right => ::libctru::GFX_RIGHT, Right => ctru_sys::GFX_RIGHT,
} }
} }
} }
impl Default for Gfx { impl Default for Gfx {
fn default() -> Self { fn default() -> Self {
unsafe { ::libctru::gfxInitDefault() }; unsafe { ctru_sys::gfxInitDefault() };
Gfx(()) Gfx(())
} }
} }
impl Drop for Gfx { impl Drop for Gfx {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ::libctru::gfxExit() }; unsafe { ctru_sys::gfxExit() };
} }
} }

13
ctru-rs/src/lib.rs

@ -3,11 +3,10 @@
#[macro_use] #[macro_use]
extern crate bitflags; extern crate bitflags;
extern crate ctru_sys;
extern crate libc; extern crate libc;
extern crate widestring; extern crate widestring;
extern crate ctru_sys as libctru;
/// Call this somewhere to force Rust to link some required crates /// Call this somewhere to force Rust to link some required crates
/// This is also a setup for some crate integration only available at runtime /// This is also a setup for some crate integration only available at runtime
/// ///
@ -20,7 +19,7 @@ pub fn init() {
// Panic Hook setup // Panic Hook setup
let default_hook = std::panic::take_hook(); let default_hook = std::panic::take_hook();
let new_hook = Box::new( move |info: &PanicInfo| { let new_hook = Box::new(move |info: &PanicInfo| {
let _bt_console = console::Console::default(); let _bt_console = console::Console::default();
println!("\x1b[1;31m\n--------------------------------------------------"); println!("\x1b[1;31m\n--------------------------------------------------");
@ -47,8 +46,8 @@ pub mod services;
pub mod srv; pub mod srv;
pub mod thread; pub mod thread;
pub use error::{Error, Result}; pub use crate::error::{Error, Result};
pub use gfx::Gfx; pub use crate::gfx::Gfx;
pub use sdmc::Sdmc; pub use crate::sdmc::Sdmc;
pub use srv::Srv; pub use crate::srv::Srv;

6
ctru-rs/src/sdmc.rs

@ -1,9 +1,9 @@
pub struct Sdmc(()); pub struct Sdmc(());
impl Sdmc { impl Sdmc {
pub fn init() -> ::Result<Sdmc> { pub fn init() -> crate::Result<Sdmc> {
unsafe { unsafe {
let r = ::libctru::archiveMountSdmc(); let r = ctru_sys::archiveMountSdmc();
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -15,6 +15,6 @@ impl Sdmc {
impl Drop for Sdmc { impl Drop for Sdmc {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ::libctru::archiveUnmountAll() }; unsafe { ctru_sys::archiveUnmountAll() };
} }
} }

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

@ -1,9 +1,9 @@
pub struct Apt(()); pub struct Apt(());
impl Apt { impl Apt {
pub fn init() -> ::Result<Apt> { pub fn init() -> crate::Result<Apt> {
unsafe { unsafe {
let r = ::libctru::aptInit(); let r = ctru_sys::aptInit();
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -13,14 +13,12 @@ impl Apt {
} }
pub fn main_loop(&self) -> bool { pub fn main_loop(&self) -> bool {
unsafe { unsafe { ctru_sys::aptMainLoop() }
::libctru::aptMainLoop()
}
} }
pub fn set_app_cpu_time_limit(&self, percent: u32) -> ::Result<()> { pub fn set_app_cpu_time_limit(&self, percent: u32) -> crate::Result<()> {
unsafe { unsafe {
let r = ::libctru::APT_SetAppCpuTimeLimit(percent); let r = ctru_sys::APT_SetAppCpuTimeLimit(percent);
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -32,6 +30,6 @@ impl Apt {
impl Drop for Apt { impl Drop for Apt {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ::libctru::aptExit() }; unsafe { ctru_sys::aptExit() };
} }
} }

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

@ -272,7 +272,7 @@ pub struct ReadDir<'a> {
/// filesystem. Each entry can be inspected via methods to learn about the full /// filesystem. Each entry can be inspected via methods to learn about the full
/// path or possibly other metadata. /// path or possibly other metadata.
pub struct DirEntry<'a> { pub struct DirEntry<'a> {
entry: ::libctru::FS_DirectoryEntry, entry: ctru_sys::FS_DirectoryEntry,
root: Arc<PathBuf>, root: Arc<PathBuf>,
arch: &'a Archive, arch: &'a Archive,
} }
@ -298,9 +298,9 @@ impl Fs {
/// ctrulib services are reference counted, so this function may be called /// ctrulib services are reference counted, so this function may be called
/// as many times as desired and the service will not exit until all /// as many times as desired and the service will not exit until all
/// instances of Fs drop out of scope. /// instances of Fs drop out of scope.
pub fn init() -> ::Result<Fs> { pub fn init() -> crate::Result<Fs> {
unsafe { unsafe {
let r = ::libctru::fsInit(); let r = ctru_sys::fsInit();
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -310,12 +310,12 @@ impl Fs {
} }
/// Returns a handle to the SDMC (memory card) Archive. /// Returns a handle to the SDMC (memory card) Archive.
pub fn sdmc(&self) -> ::Result<Archive> { pub fn sdmc(&self) -> crate::Result<Archive> {
unsafe { unsafe {
let mut handle = 0; let mut handle = 0;
let id = ArchiveID::Sdmc; let id = ArchiveID::Sdmc;
let path = ::libctru::fsMakePath(PathType::Empty.into(), ptr::null() as _); let path = ctru_sys::fsMakePath(PathType::Empty.into(), ptr::null() as _);
let r = ::libctru::FSUSER_OpenArchive(&mut handle, id.into(), path); let r = ctru_sys::FSUSER_OpenArchive(&mut handle, id.into(), path);
if r < 0 { if r < 0 {
Err(::Error::from(r)) Err(::Error::from(r))
} else { } else {
@ -406,7 +406,7 @@ impl File {
/// This function will return an error if the file is not opened for writing. /// This function will return an error if the file is not opened for writing.
pub fn set_len(&mut self, size: u64) -> IoResult<()> { pub fn set_len(&mut self, size: u64) -> IoResult<()> {
unsafe { unsafe {
let r = ::libctru::FSFILE_SetSize(self.handle, size); let r = ctru_sys::FSFILE_SetSize(self.handle, size);
if r < 0 { if r < 0 {
Err(IoError::new( Err(IoError::new(
IoErrorKind::PermissionDenied, IoErrorKind::PermissionDenied,
@ -424,7 +424,7 @@ impl File {
// This is likely to change in the future. // This is likely to change in the future.
unsafe { unsafe {
let mut size = 0; let mut size = 0;
let r = ::libctru::FSFILE_GetSize(self.handle, &mut size); let r = ctru_sys::FSFILE_GetSize(self.handle, &mut size);
if r < 0 { if r < 0 {
Err(IoError::new( Err(IoError::new(
IoErrorKind::PermissionDenied, IoErrorKind::PermissionDenied,
@ -442,7 +442,7 @@ impl File {
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize> { fn read(&mut self, buf: &mut [u8]) -> IoResult<usize> {
unsafe { unsafe {
let mut n_read = 0; let mut n_read = 0;
let r = ::libctru::FSFILE_Read( let r = ctru_sys::FSFILE_Read(
self.handle, self.handle,
&mut n_read, &mut n_read,
self.offset, self.offset,
@ -465,7 +465,7 @@ impl File {
fn write(&mut self, buf: &[u8]) -> IoResult<usize> { fn write(&mut self, buf: &[u8]) -> IoResult<usize> {
unsafe { unsafe {
let mut n_written = 0; let mut n_written = 0;
let r = ::libctru::FSFILE_Write( let r = ctru_sys::FSFILE_Write(
self.handle, self.handle,
&mut n_written, &mut n_written,
self.offset, self.offset,
@ -603,8 +603,8 @@ impl OpenOptions {
unsafe { unsafe {
let mut file_handle = 0; let mut file_handle = 0;
let path = to_utf16(path); let path = to_utf16(path);
let fs_path = ::libctru::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); let fs_path = ctru_sys::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _);
let r = ::libctru::FSUSER_OpenFile( let r = ctru_sys::FSUSER_OpenFile(
&mut file_handle, &mut file_handle,
self.arch_handle, self.arch_handle,
fs_path, fs_path,
@ -662,7 +662,7 @@ impl<'a> Iterator for ReadDir<'a> {
}; };
let mut entries_read = 0; let mut entries_read = 0;
let entry_count = 1; let entry_count = 1;
let r = ::libctru::FSDIR_Read( let r = ctru_sys::FSDIR_Read(
self.handle.0, self.handle.0,
&mut entries_read, &mut entries_read,
entry_count, entry_count,
@ -716,8 +716,8 @@ impl<'a> DirEntry<'a> {
pub fn create_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> { pub fn create_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> {
unsafe { unsafe {
let path = to_utf16(path.as_ref()); let path = to_utf16(path.as_ref());
let fs_path = ::libctru::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); let fs_path = ctru_sys::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _);
let r = ::libctru::FSUSER_CreateDirectory( let r = ctru_sys::FSUSER_CreateDirectory(
arch.handle, arch.handle,
fs_path, fs_path,
FsAttribute::FS_ATTRIBUTE_DIRECTORY.bits(), FsAttribute::FS_ATTRIBUTE_DIRECTORY.bits(),
@ -778,8 +778,8 @@ pub fn metadata<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<Metadata> {
pub fn remove_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> { pub fn remove_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> {
unsafe { unsafe {
let path = to_utf16(path.as_ref()); let path = to_utf16(path.as_ref());
let fs_path = ::libctru::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); let fs_path = ctru_sys::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _);
let r = ::libctru::FSUSER_DeleteDirectory(arch.handle, fs_path); let r = ctru_sys::FSUSER_DeleteDirectory(arch.handle, fs_path);
if r < 0 { if r < 0 {
Err(IoError::new(IoErrorKind::Other, ::Error::from(r))) Err(IoError::new(IoErrorKind::Other, ::Error::from(r)))
} else { } else {
@ -796,8 +796,8 @@ pub fn remove_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> {
pub fn remove_dir_all<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> { pub fn remove_dir_all<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> {
unsafe { unsafe {
let path = to_utf16(path.as_ref()); let path = to_utf16(path.as_ref());
let fs_path = ::libctru::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); let fs_path = ctru_sys::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _);
let r = ::libctru::FSUSER_DeleteDirectoryRecursively(arch.handle, fs_path); let r = ctru_sys::FSUSER_DeleteDirectoryRecursively(arch.handle, fs_path);
if r < 0 { if r < 0 {
Err(IoError::new(IoErrorKind::Other, ::Error::from(r))) Err(IoError::new(IoErrorKind::Other, ::Error::from(r)))
} else { } else {
@ -822,8 +822,8 @@ pub fn read_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<ReadDir> {
let mut handle = 0; let mut handle = 0;
let root = Arc::new(path.as_ref().to_path_buf()); let root = Arc::new(path.as_ref().to_path_buf());
let path = to_utf16(path.as_ref()); let path = to_utf16(path.as_ref());
let fs_path = ::libctru::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); let fs_path = ctru_sys::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _);
let r = ::libctru::FSUSER_OpenDirectory(&mut handle, arch.handle, fs_path); let r = ctru_sys::FSUSER_OpenDirectory(&mut handle, arch.handle, fs_path);
if r < 0 { if r < 0 {
Err(IoError::new(IoErrorKind::Other, ::Error::from(r))) Err(IoError::new(IoErrorKind::Other, ::Error::from(r)))
} else { } else {
@ -848,8 +848,8 @@ pub fn read_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<ReadDir> {
pub fn remove_file<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> { pub fn remove_file<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> {
unsafe { unsafe {
let path = to_utf16(path.as_ref()); let path = to_utf16(path.as_ref());
let fs_path = ::libctru::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); let fs_path = ctru_sys::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _);
let r = ::libctru::FSUSER_DeleteFile(arch.handle, fs_path); let r = ctru_sys::FSUSER_DeleteFile(arch.handle, fs_path);
if r < 0 { if r < 0 {
Err(IoError::new(IoErrorKind::Other, ::Error::from(r))) Err(IoError::new(IoErrorKind::Other, ::Error::from(r)))
} else { } else {
@ -877,14 +877,14 @@ where
let from = to_utf16(from.as_ref()); let from = to_utf16(from.as_ref());
let to = to_utf16(to.as_ref()); let to = to_utf16(to.as_ref());
let fs_from = ::libctru::fsMakePath(PathType::UTF16.into(), from.as_ptr() as _); let fs_from = ctru_sys::fsMakePath(PathType::UTF16.into(), from.as_ptr() as _);
let fs_to = ::libctru::fsMakePath(PathType::UTF16.into(), to.as_ptr() as _); let fs_to = ctru_sys::fsMakePath(PathType::UTF16.into(), to.as_ptr() as _);
let r = ::libctru::FSUSER_RenameFile(arch.handle, fs_from, arch.handle, fs_to); let r = ctru_sys::FSUSER_RenameFile(arch.handle, fs_from, arch.handle, fs_to);
if r == 0 { if r == 0 {
return Ok(()); return Ok(());
} }
let r = ::libctru::FSUSER_RenameDirectory(arch.handle, fs_from, arch.handle, fs_to); let r = ctru_sys::FSUSER_RenameDirectory(arch.handle, fs_from, arch.handle, fs_to);
if r == 0 { if r == 0 {
return Ok(()); return Ok(());
} }
@ -998,7 +998,7 @@ impl Seek for File {
impl Drop for Fs { impl Drop for Fs {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
::libctru::fsExit(); ctru_sys::fsExit();
} }
} }
} }
@ -1006,7 +1006,7 @@ impl Drop for Fs {
impl Drop for Archive { impl Drop for Archive {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
::libctru::FSUSER_CloseArchive(self.handle); ctru_sys::FSUSER_CloseArchive(self.handle);
} }
} }
} }
@ -1014,7 +1014,7 @@ impl Drop for Archive {
impl Drop for File { impl Drop for File {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
::libctru::FSFILE_Close(self.handle); ctru_sys::FSFILE_Close(self.handle);
} }
} }
} }
@ -1022,50 +1022,50 @@ impl Drop for File {
impl Drop for Dir { impl Drop for Dir {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
::libctru::FSDIR_Close(self.0); ctru_sys::FSDIR_Close(self.0);
} }
} }
} }
impl From<PathType> for ::libctru::FS_PathType { impl From<PathType> for ctru_sys::FS_PathType {
fn from(p: PathType) -> Self { fn from(p: PathType) -> Self {
use self::PathType::*; use self::PathType::*;
match p { match p {
Invalid => ::libctru::PATH_INVALID, Invalid => ctru_sys::PATH_INVALID,
Empty => ::libctru::PATH_EMPTY, Empty => ctru_sys::PATH_EMPTY,
Binary => ::libctru::PATH_BINARY, Binary => ctru_sys::PATH_BINARY,
ASCII => ::libctru::PATH_ASCII, ASCII => ctru_sys::PATH_ASCII,
UTF16 => ::libctru::PATH_UTF16, UTF16 => ctru_sys::PATH_UTF16,
} }
} }
} }
impl From<ArchiveID> for ::libctru::FS_ArchiveID { impl From<ArchiveID> for ctru_sys::FS_ArchiveID {
fn from(a: ArchiveID) -> Self { fn from(a: ArchiveID) -> Self {
use self::ArchiveID::*; use self::ArchiveID::*;
match a { match a {
RomFS => ::libctru::ARCHIVE_ROMFS, RomFS => ctru_sys::ARCHIVE_ROMFS,
Savedata => ::libctru::ARCHIVE_SAVEDATA, Savedata => ctru_sys::ARCHIVE_SAVEDATA,
Extdata => ::libctru::ARCHIVE_EXTDATA, Extdata => ctru_sys::ARCHIVE_EXTDATA,
SharedExtdata => ::libctru::ARCHIVE_SHARED_EXTDATA, SharedExtdata => ctru_sys::ARCHIVE_SHARED_EXTDATA,
SystemSavedata => ::libctru::ARCHIVE_SYSTEM_SAVEDATA, SystemSavedata => ctru_sys::ARCHIVE_SYSTEM_SAVEDATA,
Sdmc => ::libctru::ARCHIVE_SDMC, Sdmc => ctru_sys::ARCHIVE_SDMC,
SdmcWriteOnly => ::libctru::ARCHIVE_SDMC_WRITE_ONLY, SdmcWriteOnly => ctru_sys::ARCHIVE_SDMC_WRITE_ONLY,
BossExtdata => ::libctru::ARCHIVE_BOSS_EXTDATA, BossExtdata => ctru_sys::ARCHIVE_BOSS_EXTDATA,
CardSpiFS => ::libctru::ARCHIVE_CARD_SPIFS, CardSpiFS => ctru_sys::ARCHIVE_CARD_SPIFS,
ExtDataAndBossExtdata => ::libctru::ARCHIVE_EXTDATA_AND_BOSS_EXTDATA, ExtDataAndBossExtdata => ctru_sys::ARCHIVE_EXTDATA_AND_BOSS_EXTDATA,
SystemSaveData2 => ::libctru::ARCHIVE_SYSTEM_SAVEDATA2, SystemSaveData2 => ctru_sys::ARCHIVE_SYSTEM_SAVEDATA2,
NandRW => ::libctru::ARCHIVE_NAND_RW, NandRW => ctru_sys::ARCHIVE_NAND_RW,
NandRO => ::libctru::ARCHIVE_NAND_RO, NandRO => ctru_sys::ARCHIVE_NAND_RO,
NandROWriteAccess => ::libctru::ARCHIVE_NAND_RO_WRITE_ACCESS, NandROWriteAccess => ctru_sys::ARCHIVE_NAND_RO_WRITE_ACCESS,
SaveDataAndContent => ::libctru::ARCHIVE_SAVEDATA_AND_CONTENT, SaveDataAndContent => ctru_sys::ARCHIVE_SAVEDATA_AND_CONTENT,
SaveDataAndContent2 => ::libctru::ARCHIVE_SAVEDATA_AND_CONTENT2, SaveDataAndContent2 => ctru_sys::ARCHIVE_SAVEDATA_AND_CONTENT2,
NandCtrFS => ::libctru::ARCHIVE_NAND_CTR_FS, NandCtrFS => ctru_sys::ARCHIVE_NAND_CTR_FS,
TwlPhoto => ::libctru::ARCHIVE_TWL_PHOTO, TwlPhoto => ctru_sys::ARCHIVE_TWL_PHOTO,
NandTwlFS => ::libctru::ARCHIVE_NAND_TWL_FS, NandTwlFS => ctru_sys::ARCHIVE_NAND_TWL_FS,
GameCardSavedata => ::libctru::ARCHIVE_GAMECARD_SAVEDATA, GameCardSavedata => ctru_sys::ARCHIVE_GAMECARD_SAVEDATA,
UserSavedata => ::libctru::ARCHIVE_USER_SAVEDATA, UserSavedata => ctru_sys::ARCHIVE_USER_SAVEDATA,
DemoSavedata => ::libctru::ARCHIVE_DEMO_SAVEDATA, DemoSavedata => ctru_sys::ARCHIVE_DEMO_SAVEDATA,
} }
} }
} }

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

@ -47,48 +47,48 @@ impl FramebufferFormat {
/// `discard_current` determines whether to discard the current event and wait for the next event /// `discard_current` determines whether to discard the current event and wait for the next event
pub fn wait_for_event(ev: Event, discard_current: bool) { pub fn wait_for_event(ev: Event, discard_current: bool) {
unsafe { unsafe {
::libctru::gspWaitForEvent(ev.into(), discard_current); ctru_sys::gspWaitForEvent(ev.into(), discard_current);
} }
} }
impl From<::libctru::GSPGPU_FramebufferFormat> for FramebufferFormat { impl From<ctru_sys::GSPGPU_FramebufferFormat> for FramebufferFormat {
fn from(g: ::libctru::GSPGPU_FramebufferFormat) -> Self { fn from(g: ctru_sys::GSPGPU_FramebufferFormat) -> Self {
use self::FramebufferFormat::*; use self::FramebufferFormat::*;
match g { match g {
::libctru::GSP_RGBA8_OES => Rgba8, ctru_sys::GSP_RGBA8_OES => Rgba8,
::libctru::GSP_BGR8_OES => Bgr8, ctru_sys::GSP_BGR8_OES => Bgr8,
::libctru::GSP_RGB565_OES => Rgb565, ctru_sys::GSP_RGB565_OES => Rgb565,
::libctru::GSP_RGB5_A1_OES => Rgb5A1, ctru_sys::GSP_RGB5_A1_OES => Rgb5A1,
::libctru::GSP_RGBA4_OES => Rgba4, ctru_sys::GSP_RGBA4_OES => Rgba4,
_ => unreachable!(), _ => unreachable!(),
} }
} }
} }
impl From<FramebufferFormat> for ::libctru::GSPGPU_FramebufferFormat { impl From<FramebufferFormat> for ctru_sys::GSPGPU_FramebufferFormat {
fn from(g: FramebufferFormat) -> Self { fn from(g: FramebufferFormat) -> Self {
use self::FramebufferFormat::*; use self::FramebufferFormat::*;
match g { match g {
Rgba8 => ::libctru::GSP_RGBA8_OES, Rgba8 => ctru_sys::GSP_RGBA8_OES,
Bgr8 => ::libctru::GSP_BGR8_OES, Bgr8 => ctru_sys::GSP_BGR8_OES,
Rgb565 => ::libctru::GSP_RGB565_OES, Rgb565 => ctru_sys::GSP_RGB565_OES,
Rgb5A1 => ::libctru::GSP_RGB5_A1_OES, Rgb5A1 => ctru_sys::GSP_RGB5_A1_OES,
Rgba4 => ::libctru::GSP_RGBA4_OES, Rgba4 => ctru_sys::GSP_RGBA4_OES,
} }
} }
} }
impl From<Event> for ::libctru::GSPGPU_Event { impl From<Event> for ctru_sys::GSPGPU_Event {
fn from(ev: Event) -> Self { fn from(ev: Event) -> Self {
use self::Event::*; use self::Event::*;
match ev { match ev {
Psc0 => ::libctru::GSPGPU_EVENT_PSC0, Psc0 => ctru_sys::GSPGPU_EVENT_PSC0,
Psc1 => ::libctru::GSPGPU_EVENT_PSC1, Psc1 => ctru_sys::GSPGPU_EVENT_PSC1,
VBlank0 => ::libctru::GSPGPU_EVENT_VBlank0, VBlank0 => ctru_sys::GSPGPU_EVENT_VBlank0,
VBlank1 => ::libctru::GSPGPU_EVENT_VBlank1, VBlank1 => ctru_sys::GSPGPU_EVENT_VBlank1,
PPF => ::libctru::GSPGPU_EVENT_PPF, PPF => ctru_sys::GSPGPU_EVENT_PPF,
P3D => ::libctru::GSPGPU_EVENT_P3D, P3D => ctru_sys::GSPGPU_EVENT_P3D,
DMA => ::libctru::GSPGPU_EVENT_DMA, DMA => ctru_sys::GSPGPU_EVENT_DMA,
} }
} }
} }

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

@ -47,10 +47,10 @@ bitflags! {
pub struct Hid(()); pub struct Hid(());
/// Represents user input to the touchscreen. /// Represents user input to the touchscreen.
pub struct TouchPosition(::libctru::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.
pub struct CirclePosition(::libctru::circlePosition); pub struct CirclePosition(ctru_sys::circlePosition);
/// Initializes the HID service. /// Initializes the HID service.
/// ///
@ -60,9 +60,9 @@ pub struct CirclePosition(::libctru::circlePosition);
/// Since this service requires no special or elevated permissions, errors are /// Since this service requires no special or elevated permissions, errors are
/// rare in practice. /// rare in practice.
impl Hid { impl Hid {
pub fn init() -> ::Result<Hid> { pub fn init() -> crate::Result<Hid> {
unsafe { unsafe {
let r = ::libctru::hidInit(); let r = ctru_sys::hidInit();
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -75,14 +75,14 @@ impl Hid {
/// frame. This function should be called on every frame when polling /// frame. This function should be called on every frame when polling
/// for user input. /// for user input.
pub fn scan_input(&self) { pub fn scan_input(&self) {
unsafe { ::libctru::hidScanInput() }; unsafe { ctru_sys::hidScanInput() };
} }
/// Returns a bitflag struct representing which buttons have just been pressed /// Returns a bitflag struct representing which buttons have just been pressed
/// on the current frame (and were not pressed on the previous frame). /// on the current frame (and were not pressed on the previous frame).
pub fn keys_down(&self) -> KeyPad { pub fn keys_down(&self) -> KeyPad {
unsafe { unsafe {
let keys = ::libctru::hidKeysDown(); let keys = ctru_sys::hidKeysDown();
KeyPad::from_bits_truncate(keys) KeyPad::from_bits_truncate(keys)
} }
} }
@ -91,7 +91,7 @@ impl Hid {
/// during the current frame. /// during the current frame.
pub fn keys_held(&self) -> KeyPad { pub fn keys_held(&self) -> KeyPad {
unsafe { unsafe {
let keys = ::libctru::hidKeysHeld(); let keys = ctru_sys::hidKeysHeld();
KeyPad::from_bits_truncate(keys) KeyPad::from_bits_truncate(keys)
} }
} }
@ -100,7 +100,7 @@ impl Hid {
/// the current frame. /// the current frame.
pub fn keys_up(&self) -> KeyPad { pub fn keys_up(&self) -> KeyPad {
unsafe { unsafe {
let keys = ::libctru::hidKeysUp(); let keys = ctru_sys::hidKeysUp();
KeyPad::from_bits_truncate(keys) KeyPad::from_bits_truncate(keys)
} }
} }
@ -109,13 +109,13 @@ impl Hid {
impl TouchPosition { impl TouchPosition {
/// Create a new TouchPosition instance. /// Create a new TouchPosition instance.
pub fn new() -> Self { pub fn new() -> Self {
TouchPosition(::libctru::touchPosition { px: 0, py: 0 }) TouchPosition(ctru_sys::touchPosition { px: 0, py: 0 })
} }
/// Returns the current touch position in pixels. /// Returns the current touch position in pixels.
pub fn get(&mut self) -> (u16, u16) { pub fn get(&mut self) -> (u16, u16) {
unsafe { unsafe {
::libctru::hidTouchRead(&mut self.0); ctru_sys::hidTouchRead(&mut self.0);
} }
(self.0.px, self.0.py) (self.0.px, self.0.py)
} }
@ -124,13 +124,13 @@ impl TouchPosition {
impl CirclePosition { impl CirclePosition {
/// Create a new CirclePosition instance. /// Create a new CirclePosition instance.
pub fn new() -> Self { pub fn new() -> Self {
CirclePosition(::libctru::circlePosition { dx: 0, dy: 0 }) CirclePosition(ctru_sys::circlePosition { dx: 0, dy: 0 })
} }
/// Returns the current circle pad position in (x, y) form. /// Returns the current circle pad position in (x, y) form.
pub fn get(&mut self) -> (i16, i16) { pub fn get(&mut self) -> (i16, i16) {
unsafe { unsafe {
::libctru::hidCircleRead(&mut self.0); ctru_sys::hidCircleRead(&mut self.0);
} }
(self.0.dx, self.0.dy) (self.0.dx, self.0.dy)
} }
@ -138,6 +138,6 @@ impl CirclePosition {
impl Drop for Hid { impl Drop for Hid {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ::libctru::hidExit() }; unsafe { ctru_sys::hidExit() };
} }
} }

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

@ -1,6 +1,6 @@
use ctru_sys::{socExit, socInit};
use libc::{free, memalign};
use std::net::Ipv4Addr; use std::net::Ipv4Addr;
use libctru::{socInit, socExit};
use libc::{memalign, free};
/// Soc service. Initializing this service will enable the use of network sockets and utilities /// Soc service. Initializing this service will enable the use of network sockets and utilities
/// such as those found in `std::net`. The service will be closed when this struct is is dropped. /// such as those found in `std::net`. The service will be closed when this struct is is dropped.
@ -14,7 +14,7 @@ impl Soc {
/// # Errors /// # Errors
/// ///
/// This function will return an error if the `Soc` service is already initialized /// This function will return an error if the `Soc` service is already initialized
pub fn init() -> ::Result<Soc> { pub fn init() -> crate::Result<Soc> {
Soc::init_with_buffer_size(0x100000) Soc::init_with_buffer_size(0x100000)
} }
@ -24,7 +24,7 @@ impl Soc {
/// # Errors /// # Errors
/// ///
/// This function will return an error if the `Soc` service is already initialized /// This function will return an error if the `Soc` service is already initialized
pub fn init_with_buffer_size(num_bytes: usize) -> ::Result<Soc> { pub fn init_with_buffer_size(num_bytes: usize) -> crate::Result<Soc> {
unsafe { unsafe {
let soc_mem = memalign(0x1000, num_bytes) as *mut u32; let soc_mem = memalign(0x1000, num_bytes) as *mut u32;
@ -33,7 +33,7 @@ impl Soc {
free(soc_mem as *mut _); free(soc_mem as *mut _);
Err(r.into()) Err(r.into())
} else { } else {
Ok(Soc { soc_mem, }) Ok(Soc { soc_mem })
} }
} }
} }

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

@ -4,9 +4,9 @@ pub struct SslC(());
impl SslC { impl SslC {
/// Initialize sslc /// Initialize sslc
pub fn init() -> ::Result<Self> { pub fn init() -> crate::Result<Self> {
unsafe { unsafe {
let r = ::libctru::sslcInit(0); let r = ctru_sys::sslcInit(0);
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -16,9 +16,9 @@ impl SslC {
} }
/// Fill `buf` with `buf.len()` random bytes /// Fill `buf` with `buf.len()` random bytes
pub fn generate_random_data(&self, buf: &mut [u8]) -> ::Result<()> { pub fn generate_random_data(&self, buf: &mut [u8]) -> crate::Result<()> {
unsafe { unsafe {
let r = ::libctru::sslcGenerateRandomData(buf.as_ptr() as _, buf.len() as u32); let r = ctru_sys::sslcGenerateRandomData(buf.as_ptr() as _, buf.len() as u32);
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -30,6 +30,6 @@ impl SslC {
impl Drop for SslC { impl Drop for SslC {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ::libctru::sslcExit() }; unsafe { ctru_sys::sslcExit() };
} }
} }

6
ctru-rs/src/srv.rs

@ -1,9 +1,9 @@
pub struct Srv(()); pub struct Srv(());
impl Srv { impl Srv {
pub fn init() -> ::Result<Srv> { pub fn init() -> crate::Result<Srv> {
unsafe { unsafe {
let r = ::libctru::srvInit(); let r = ctru_sys::srvInit();
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -15,6 +15,6 @@ impl Srv {
impl Drop for Srv { impl Drop for Srv {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ::libctru::srvExit() }; unsafe { ctru_sys::srvExit() };
} }
} }

4
ctru-rs/src/thread.rs

@ -896,7 +896,7 @@ mod imp {
use libc; use libc;
use libctru::{ use ctru_sys::{
svcGetProcessorID, svcGetThreadId, svcGetThreadPriority, svcSleepThread, threadCreate, svcGetProcessorID, svcGetThreadId, svcGetThreadPriority, svcSleepThread, threadCreate,
threadDetach, threadFree, threadJoin, Thread as ThreadHandle, threadDetach, threadFree, threadJoin, Thread as ThreadHandle,
}; };
@ -1009,8 +1009,8 @@ mod imp {
} }
mod thread_info { mod thread_info {
use crate::thread::Thread;
use std::cell::RefCell; use std::cell::RefCell;
use thread::Thread;
struct ThreadInfo { struct ThreadInfo {
thread: Thread, thread: Thread,

Loading…
Cancel
Save