Browse Source

doc(alias) everywhere

pull/134/head
Andrea Ciliberti 1 year ago
parent
commit
d315ebd10c
  1. 9
      ctru-rs/src/applets/mii_selector.rs
  2. 11
      ctru-rs/src/applets/swkbd.rs
  3. 5
      ctru-rs/src/console.rs
  4. 3
      ctru-rs/src/linear.rs
  5. 1
      ctru-rs/src/mii.rs
  6. 46
      ctru-rs/src/services/cam.rs
  7. 10
      ctru-rs/src/services/cfgu.rs
  8. 18
      ctru-rs/src/services/fs.rs
  9. 17
      ctru-rs/src/services/gfx.rs
  10. 3
      ctru-rs/src/services/gspgpu.rs
  11. 8
      ctru-rs/src/services/hid.rs
  12. 27
      ctru-rs/src/services/ndsp/mod.rs
  13. 7
      ctru-rs/src/services/ps.rs
  14. 6
      ctru-rs/src/services/romfs.rs
  15. 5
      ctru-rs/src/services/soc.rs
  16. 2
      ctru-rs/src/services/sslc.rs

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

@ -46,6 +46,7 @@ bitflags! {
/// ///
/// let result = mii_selector.launch().unwrap(); /// let result = mii_selector.launch().unwrap();
/// ``` /// ```
#[doc(alias = "MiiSelectorConf")]
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct MiiSelector { pub struct MiiSelector {
config: Box<ctru_sys::MiiSelectorConf>, config: Box<ctru_sys::MiiSelectorConf>,
@ -70,6 +71,7 @@ pub enum LaunchError {
impl MiiSelector { impl MiiSelector {
/// Initializes a Mii Selector /// Initializes a Mii Selector
#[doc(alias = "miiSelectorInit")]
pub fn new() -> Self { pub fn new() -> Self {
let mut config = Box::<ctru_sys::MiiSelectorConf>::default(); let mut config = Box::<ctru_sys::MiiSelectorConf>::default();
unsafe { unsafe {
@ -81,6 +83,7 @@ impl MiiSelector {
/// Set the title of the Mii Selector. /// Set the title of the Mii Selector.
/// ///
/// This function would panic if the given ``&str`` contains NUL bytes. /// This function would panic if the given ``&str`` contains NUL bytes.
#[doc(alias = "miiSelectorSetTitle")]
pub fn set_title(&mut self, text: &str) { pub fn set_title(&mut self, text: &str) {
// This can only fail if the text contains NUL bytes in the string... which seems // This can only fail if the text contains NUL bytes in the string... which seems
// unlikely and is documented // unlikely and is documented
@ -91,11 +94,13 @@ impl MiiSelector {
} }
/// Set the options of the Mii Selector /// Set the options of the Mii Selector
#[doc(alias = "miiSelectorSetOptions")]
pub fn set_options(&mut self, options: Options) { pub fn set_options(&mut self, options: Options) {
unsafe { ctru_sys::miiSelectorSetOptions(self.config.as_mut(), options.bits) } unsafe { ctru_sys::miiSelectorSetOptions(self.config.as_mut(), options.bits) }
} }
/// Whitelist a guest Mii /// Whitelist a guest Mii
#[doc(alias = "miiSelectorWhitelistGuestMii")]
pub fn whitelist_guest_mii(&mut self, mii_index: Index) { pub fn whitelist_guest_mii(&mut self, mii_index: Index) {
let index = match mii_index { let index = match mii_index {
Index::Index(i) => i, Index::Index(i) => i,
@ -106,6 +111,7 @@ impl MiiSelector {
} }
/// Blacklist a guest Mii /// Blacklist a guest Mii
#[doc(alias = "miiSelectorBlacklistGuestMii")]
pub fn blacklist_guest_mii(&mut self, mii_index: Index) { pub fn blacklist_guest_mii(&mut self, mii_index: Index) {
let index = match mii_index { let index = match mii_index {
Index::Index(i) => i, Index::Index(i) => i,
@ -116,6 +122,7 @@ impl MiiSelector {
} }
/// Whitelist a user Mii /// Whitelist a user Mii
#[doc(alias = "miiSelectorWhitelistUserMii")]
pub fn whitelist_user_mii(&mut self, mii_index: Index) { pub fn whitelist_user_mii(&mut self, mii_index: Index) {
let index = match mii_index { let index = match mii_index {
Index::Index(i) => i, Index::Index(i) => i,
@ -126,6 +133,7 @@ impl MiiSelector {
} }
/// Blacklist a user Mii /// Blacklist a user Mii
#[doc(alias = "miiSelectorBlacklistUserMii")]
pub fn blacklist_user_mii(&mut self, mii_index: Index) { pub fn blacklist_user_mii(&mut self, mii_index: Index) {
let index = match mii_index { let index = match mii_index {
Index::Index(i) => i, Index::Index(i) => i,
@ -145,6 +153,7 @@ impl MiiSelector {
/// Launch the Mii Selector. /// Launch the Mii Selector.
/// Returns an error when the checksum of the Mii is invalid. /// Returns an error when the checksum of the Mii is invalid.
#[doc(alias = "miiSelectorLaunch")]
pub fn launch(&mut self) -> Result<SelectionResult, LaunchError> { pub fn launch(&mut self) -> Result<SelectionResult, LaunchError> {
let mut return_val = Box::<ctru_sys::MiiSelectorReturn>::default(); let mut return_val = Box::<ctru_sys::MiiSelectorReturn>::default();
unsafe { ctru_sys::miiSelectorLaunch(self.config.as_mut(), return_val.as_mut()) } unsafe { ctru_sys::miiSelectorLaunch(self.config.as_mut(), return_val.as_mut()) }

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

@ -7,6 +7,7 @@ use std::iter::once;
use std::str; use std::str;
/// An instance of the software keyboard. /// An instance of the software keyboard.
#[doc(alias = "SwkbdState")]
#[derive(Clone)] #[derive(Clone)]
pub struct Swkbd { pub struct Swkbd {
state: Box<SwkbdState>, state: Box<SwkbdState>,
@ -19,6 +20,7 @@ pub struct Swkbd {
/// Numpad is a number pad. /// Numpad is a number pad.
/// Western is a text keyboard without japanese symbols (only applies to JPN systems). For other /// Western is a text keyboard without japanese symbols (only applies to JPN systems). For other
/// systems it's the same as a Normal keyboard. /// systems it's the same as a Normal keyboard.
#[doc(alias = "SwkbdType")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum Kind { pub enum Kind {
@ -29,6 +31,7 @@ pub enum Kind {
} }
/// Represents which button the user pressed to close the software keyboard. /// Represents which button the user pressed to close the software keyboard.
#[doc(alias = "SwkbdButton")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum Button { pub enum Button {
@ -38,6 +41,7 @@ pub enum Button {
} }
/// Error type for the software keyboard. /// Error type for the software keyboard.
#[doc(alias = "SwkbdResult")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(i32)] #[repr(i32)]
pub enum Error { pub enum Error {
@ -52,6 +56,7 @@ pub enum Error {
} }
/// Restrictions on keyboard input /// Restrictions on keyboard input
#[doc(alias = "SwkbdValidInput")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum ValidInput { pub enum ValidInput {
@ -90,6 +95,7 @@ bitflags! {
impl Swkbd { impl Swkbd {
/// Initializes a software keyboard of the specified type and the chosen number of buttons /// Initializes a software keyboard of the specified type and the chosen number of buttons
/// (from 1-3). /// (from 1-3).
#[doc(alias = "swkbdInit")]
pub fn new(keyboard_type: Kind, num_buttons: i32) -> Self { pub fn new(keyboard_type: Kind, num_buttons: i32) -> Self {
unsafe { unsafe {
let mut state = Box::<SwkbdState>::default(); let mut state = Box::<SwkbdState>::default();
@ -101,6 +107,7 @@ impl Swkbd {
/// Gets input from this keyboard and appends it to the provided string. /// Gets input from this keyboard and appends it to the provided string.
/// ///
/// The text received from the keyboard will be truncated if it is longer than `max_bytes`. /// The text received from the keyboard will be truncated if it is longer than `max_bytes`.
#[doc(alias = "swkbdInputText")]
pub fn get_string(&mut self, max_bytes: usize) -> Result<(String, Button), Error> { pub fn get_string(&mut self, max_bytes: usize) -> Result<(String, Button), Error> {
// Unfortunately the libctru API doesn't really provide a way to get the exact length // Unfortunately the libctru API doesn't really provide a way to get the exact length
// of the string that it receieves from the software keyboard. Instead it expects you // of the string that it receieves from the software keyboard. Instead it expects you
@ -125,6 +132,7 @@ impl Swkbd {
/// ///
/// If the buffer is too small to contain the entire sequence received from the keyboard, /// If the buffer is too small to contain the entire sequence received from the keyboard,
/// the output will be truncated but should still be well-formed UTF-8. /// the output will be truncated but should still be well-formed UTF-8.
#[doc(alias = "swkbdInputText")]
pub fn write_exact(&mut self, buf: &mut [u8]) -> Result<Button, Error> { pub fn write_exact(&mut self, buf: &mut [u8]) -> Result<Button, Error> {
unsafe { unsafe {
match swkbdInputText(self.state.as_mut(), buf.as_mut_ptr(), buf.len()) { match swkbdInputText(self.state.as_mut(), buf.as_mut_ptr(), buf.len()) {
@ -138,6 +146,7 @@ impl Swkbd {
} }
/// Sets special features for this keyboard /// Sets special features for this keyboard
#[doc(alias = "swkbdSetFeatures")]
pub fn set_features(&mut self, features: Features) { pub fn set_features(&mut self, features: Features) {
unsafe { swkbdSetFeatures(self.state.as_mut(), features.bits) } unsafe { swkbdSetFeatures(self.state.as_mut(), features.bits) }
} }
@ -156,6 +165,7 @@ impl Swkbd {
/// Sets the hint text for this software keyboard (that is, the help text that is displayed /// Sets the hint text for this software keyboard (that is, the help text that is displayed
/// when the textbox is empty) /// when the textbox is empty)
#[doc(alias = "swkbdSetHintText")]
pub fn set_hint_text(&mut self, text: &str) { pub fn set_hint_text(&mut self, text: &str) {
unsafe { unsafe {
let nul_terminated: String = text.chars().chain(once('\0')).collect(); let nul_terminated: String = text.chars().chain(once('\0')).collect();
@ -169,6 +179,7 @@ impl Swkbd {
/// `text` configures the display text for the button /// `text` configures the display text for the button
/// `submit` configures whether pressing the button will accept the keyboard's input or /// `submit` configures whether pressing the button will accept the keyboard's input or
/// discard it. /// discard it.
#[doc(alias = "swkbdSetButton")]
pub fn configure_button(&mut self, button: Button, text: &str, submit: bool) { pub fn configure_button(&mut self, button: Button, text: &str, submit: bool) {
unsafe { unsafe {
let nul_terminated: String = text.chars().chain(once('\0')).collect(); let nul_terminated: String = text.chars().chain(once('\0')).collect();

5
ctru-rs/src/console.rs

@ -7,6 +7,7 @@ use crate::services::gfx::Screen;
static mut EMPTY_CONSOLE: PrintConsole = unsafe { const_zero::const_zero!(PrintConsole) }; static mut EMPTY_CONSOLE: PrintConsole = unsafe { const_zero::const_zero!(PrintConsole) };
#[doc(alias = "PrintConsole")]
pub struct Console<'screen> { pub struct Console<'screen> {
context: Box<PrintConsole>, context: Box<PrintConsole>,
_screen: RefMut<'screen, dyn Screen>, _screen: RefMut<'screen, dyn Screen>,
@ -20,6 +21,7 @@ impl<'screen> Console<'screen> {
/// # Notes /// # Notes
/// ///
/// [`Console`] automatically takes care of flushing and swapping buffers for its screen when printing. /// [`Console`] automatically takes care of flushing and swapping buffers for its screen when printing.
#[doc(alias = "consoleInit")]
pub fn new(screen: RefMut<'screen, dyn Screen>) -> Self { pub fn new(screen: RefMut<'screen, dyn Screen>) -> Self {
let mut context = Box::<PrintConsole>::default(); let mut context = Box::<PrintConsole>::default();
@ -45,6 +47,7 @@ impl<'screen> Console<'screen> {
} }
/// Select this console as the current target for stdout /// Select this console as the current target for stdout
#[doc(alias = "consoleSelect")]
pub fn select(&self) { pub fn select(&self) {
unsafe { unsafe {
consoleSelect(self.context.as_ref() as *const _ as *mut _); consoleSelect(self.context.as_ref() as *const _ as *mut _);
@ -52,6 +55,7 @@ impl<'screen> Console<'screen> {
} }
/// Clears all text from the console /// Clears all text from the console
#[doc(alias = "consoleClear")]
pub fn clear(&self) { pub fn clear(&self) {
unsafe { consoleClear() } unsafe { consoleClear() }
} }
@ -64,6 +68,7 @@ impl<'screen> Console<'screen> {
/// # Safety /// # Safety
/// This function is unsafe because it does not validate that the input will produce /// This function is unsafe because it does not validate that the input will produce
/// a console that actually fits on the screen /// a console that actually fits on the screen
#[doc(alias = "consoleSetWindow")]
pub unsafe fn set_window(&mut self, x: i32, y: i32, width: i32, height: i32) { pub unsafe fn set_window(&mut self, x: i32, y: i32, width: i32, height: i32) {
consoleSetWindow(self.context.as_mut(), x, y, width, height); consoleSetWindow(self.context.as_mut(), x, y, width, height);
} }

3
ctru-rs/src/linear.rs

@ -22,12 +22,14 @@ pub struct LinearAllocator;
impl LinearAllocator { impl LinearAllocator {
/// Returns the amount of free space left in the LINEAR sector /// Returns the amount of free space left in the LINEAR sector
#[doc(alias = "linearSpaceFree")]
pub fn free_space() -> u32 { pub fn free_space() -> u32 {
unsafe { ctru_sys::linearSpaceFree() } unsafe { ctru_sys::linearSpaceFree() }
} }
} }
unsafe impl Allocator for LinearAllocator { unsafe impl Allocator for LinearAllocator {
#[doc(alias = "linearAlloc", alias = "linearMemAlign")]
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> { fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
let pointer = unsafe { ctru_sys::linearMemAlign(layout.size(), layout.align()) }; let pointer = unsafe { ctru_sys::linearMemAlign(layout.size(), layout.align()) };
@ -36,6 +38,7 @@ unsafe impl Allocator for LinearAllocator {
.ok_or(AllocError) .ok_or(AllocError)
} }
#[doc(alias = "linearFree")]
unsafe fn deallocate(&self, ptr: NonNull<u8>, _layout: Layout) { unsafe fn deallocate(&self, ptr: NonNull<u8>, _layout: Layout) {
ctru_sys::linearFree(ptr.as_ptr().cast()); ctru_sys::linearFree(ptr.as_ptr().cast());
} }

1
ctru-rs/src/mii.rs

@ -177,6 +177,7 @@ pub struct MoleDetails {
/// <https://www.3dbrew.org/wiki/Mii#Mapped_Editor_.3C-.3E_Hex_values> /// <https://www.3dbrew.org/wiki/Mii#Mapped_Editor_.3C-.3E_Hex_values>
/// ///
/// This struct is returned by the [`MiiSelector`](crate::applets::mii_selector::MiiSelector) /// This struct is returned by the [`MiiSelector`](crate::applets::mii_selector::MiiSelector)
#[doc(alias = "MiiData")]
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct MiiData { pub struct MiiData {
pub options: MiiDataOptions, pub options: MiiDataOptions,

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

@ -21,6 +21,7 @@ pub struct Cam {
} }
/// Flag to pass to [`Camera::flip_image`] /// Flag to pass to [`Camera::flip_image`]
#[doc(alias = "CAMU_Flip")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum FlipMode { pub enum FlipMode {
@ -31,6 +32,7 @@ pub enum FlipMode {
} }
/// Flag to pass to [`Camera::set_view_size`] /// Flag to pass to [`Camera::set_view_size`]
#[doc(alias = "CAMU_Size")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum ViewSize { pub enum ViewSize {
@ -48,6 +50,7 @@ pub enum ViewSize {
} }
/// Flag to pass to [`Camera::set_frame_rate`] /// Flag to pass to [`Camera::set_frame_rate`]
#[doc(alias = "CAMU_FramRate")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum FrameRate { pub enum FrameRate {
@ -68,6 +71,7 @@ pub enum FrameRate {
/// Flag to pass to [`Camera::set_white_balance`] or /// Flag to pass to [`Camera::set_white_balance`] or
/// [`Camera::set_white_balance_without_base_up`] /// [`Camera::set_white_balance_without_base_up`]
#[doc(alias = "CAMU_WhiteBalance")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum WhiteBalance { pub enum WhiteBalance {
@ -86,6 +90,7 @@ pub enum WhiteBalance {
} }
/// Flag to pass to [`Camera::set_photo_mode`] /// Flag to pass to [`Camera::set_photo_mode`]
#[doc(alias = "CAMU_PhotoMode")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum PhotoMode { pub enum PhotoMode {
@ -97,6 +102,7 @@ pub enum PhotoMode {
} }
/// Flag to pass to [`Camera::set_effect`] /// Flag to pass to [`Camera::set_effect`]
#[doc(alias = "CAMU_Effect")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum Effect { pub enum Effect {
@ -109,6 +115,7 @@ pub enum Effect {
} }
/// Flag to pass to [`Camera::set_contrast`] /// Flag to pass to [`Camera::set_contrast`]
#[doc(alias = "CAMU_Contrast")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum Contrast { pub enum Contrast {
@ -121,6 +128,7 @@ pub enum Contrast {
} }
/// Flag to pass to [`Camera::set_lens_correction`] /// Flag to pass to [`Camera::set_lens_correction`]
#[doc(alias = "CAMU_LensCorrection")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum LensCorrection { pub enum LensCorrection {
@ -130,6 +138,7 @@ pub enum LensCorrection {
} }
/// Flag to pass to [`Camera::set_output_format`] /// Flag to pass to [`Camera::set_output_format`]
#[doc(alias = "CAMU_OutputFormat")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum OutputFormat { pub enum OutputFormat {
@ -138,6 +147,7 @@ pub enum OutputFormat {
} }
/// Flag to pass to [`Cam::play_shutter_sound`] /// Flag to pass to [`Cam::play_shutter_sound`]
#[doc(alias = "CAMU_ShutterSoundType")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum ShutterSound { pub enum ShutterSound {
@ -194,10 +204,12 @@ impl TrimmingParams {
} }
/// Represents data used by the camera to calibrate image quality /// Represents data used by the camera to calibrate image quality
#[doc(alias = "CAMU_ImageQualityCalibrationData")]
#[derive(Default, Clone, Copy, Debug)] #[derive(Default, Clone, Copy, Debug)]
pub struct ImageQualityCalibrationData(pub ctru_sys::CAMU_ImageQualityCalibrationData); pub struct ImageQualityCalibrationData(pub ctru_sys::CAMU_ImageQualityCalibrationData);
/// Represents data used by the camera to calibrate image quality when using both outward cameras /// Represents data used by the camera to calibrate image quality when using both outward cameras
#[doc(alias = "CAMU_StereoCameraCalibrationData")]
#[derive(Default, Clone, Copy, Debug)] #[derive(Default, Clone, Copy, Debug)]
pub struct StereoCameraCalibrationData(pub ctru_sys::CAMU_StereoCameraCalibrationData); pub struct StereoCameraCalibrationData(pub ctru_sys::CAMU_StereoCameraCalibrationData);
@ -240,6 +252,7 @@ pub struct BothOutwardCam;
impl BothOutwardCam { impl BothOutwardCam {
/// Sets whether to enable or disable synchronization /// Sets whether to enable or disable synchronization
/// of brightness for both left and right cameras /// of brightness for both left and right cameras
#[doc(alias = "CAMU_SetBrightnessSynchronization")]
pub fn set_brightness_synchronization( pub fn set_brightness_synchronization(
&mut self, &mut self,
brightness_synchronization: bool, brightness_synchronization: bool,
@ -274,6 +287,7 @@ pub trait Camera {
} }
/// Returns true if the camera is busy (receiving data) /// Returns true if the camera is busy (receiving data)
#[doc(alias = "CAMU_IsBusy")]
fn is_busy(&self) -> crate::Result<bool> { fn is_busy(&self) -> crate::Result<bool> {
unsafe { unsafe {
let mut is_busy = false; let mut is_busy = false;
@ -284,6 +298,7 @@ pub trait Camera {
/// Returns the maximum amount of transfer bytes based on the view size, trimming, and other /// Returns the maximum amount of transfer bytes based on the view size, trimming, and other
/// modifications set to the camera /// modifications set to the camera
#[doc(alias = "CAMU_GetTransferBytes")]
fn transfer_byte_count(&self) -> crate::Result<u32> { fn transfer_byte_count(&self) -> crate::Result<u32> {
unsafe { unsafe {
let mut transfer_bytes = 0; let mut transfer_bytes = 0;
@ -297,6 +312,7 @@ pub trait Camera {
/// Sets whether or not the camera should trim the image based on parameters set by /// Sets whether or not the camera should trim the image based on parameters set by
/// [`Camera::set_trimming_params`] /// [`Camera::set_trimming_params`]
#[doc(alias = "CAMU_SetTrimming")]
fn set_trimming(&mut self, enabled: bool) -> crate::Result<()> { fn set_trimming(&mut self, enabled: bool) -> crate::Result<()> {
unsafe { unsafe {
ResultCode(ctru_sys::CAMU_SetTrimming(self.port_as_raw(), enabled))?; ResultCode(ctru_sys::CAMU_SetTrimming(self.port_as_raw(), enabled))?;
@ -305,6 +321,7 @@ pub trait Camera {
} }
/// Returns whether or not trimming is currently enabled for the camera /// Returns whether or not trimming is currently enabled for the camera
#[doc(alias = "CAMU_IsTrimming")]
fn is_trimming_enabled(&self) -> crate::Result<bool> { fn is_trimming_enabled(&self) -> crate::Result<bool> {
unsafe { unsafe {
let mut trimming = false; let mut trimming = false;
@ -314,6 +331,7 @@ pub trait Camera {
} }
/// Sets trimming parameters based on coordinates specified inside a [`TrimmingParams`] /// Sets trimming parameters based on coordinates specified inside a [`TrimmingParams`]
#[doc(alias = "CAMU_SetTrimmingParams")]
fn set_trimming_params(&mut self, params: TrimmingParams) -> crate::Result<()> { fn set_trimming_params(&mut self, params: TrimmingParams) -> crate::Result<()> {
unsafe { unsafe {
ResultCode(ctru_sys::CAMU_SetTrimmingParams( ResultCode(ctru_sys::CAMU_SetTrimmingParams(
@ -328,6 +346,7 @@ pub trait Camera {
} }
/// Returns the [`TrimmingParams`] set /// Returns the [`TrimmingParams`] set
#[doc(alias = "CAMU_GetTrimmingParams")]
fn trimming_params(&self) -> crate::Result<TrimmingParams> { fn trimming_params(&self) -> crate::Result<TrimmingParams> {
unsafe { unsafe {
let mut x_start = 0; let mut x_start = 0;
@ -354,6 +373,7 @@ pub trait Camera {
/// Sets the trimming parameters revolving around the center of the image. /// Sets the trimming parameters revolving around the center of the image.
/// The new width will be `trim_width / 2` to the left and right of the center. /// 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. /// The new height will be `trim_height / 2` above and below the center.
#[doc(alias = "CAMU_SetTrimmingParamsCenter")]
fn set_trimming_params_center( fn set_trimming_params_center(
&mut self, &mut self,
trim_width: i16, trim_width: i16,
@ -374,6 +394,7 @@ pub trait Camera {
} }
/// Sets the exposure level of the camera /// Sets the exposure level of the camera
#[doc(alias = "CAMU_SetExposure")]
fn set_exposure(&mut self, exposure: i8) -> crate::Result<()> { fn set_exposure(&mut self, exposure: i8) -> crate::Result<()> {
unsafe { unsafe {
ResultCode(ctru_sys::CAMU_SetExposure(self.camera_as_raw(), exposure))?; ResultCode(ctru_sys::CAMU_SetExposure(self.camera_as_raw(), exposure))?;
@ -382,6 +403,7 @@ pub trait Camera {
} }
/// Sets the white balance mod of the camera based on the passed [`WhiteBalance`] argument /// Sets the white balance mod of the camera based on the passed [`WhiteBalance`] argument
#[doc(alias = "CAMU_SetWhiteBalance")]
fn set_white_balance(&mut self, white_balance: WhiteBalance) -> crate::Result<()> { fn set_white_balance(&mut self, white_balance: WhiteBalance) -> crate::Result<()> {
unsafe { unsafe {
ResultCode(ctru_sys::CAMU_SetWhiteBalance( ResultCode(ctru_sys::CAMU_SetWhiteBalance(
@ -394,6 +416,7 @@ pub trait Camera {
/// Sets the white balance mode of the camera based on the passed [`WhiteBalance`] argument /// Sets the white balance mode of the camera based on the passed [`WhiteBalance`] argument
// TODO: Explain base up // TODO: Explain base up
#[doc(alias = "CAMU_SetWhiteBalanceWithoutBaseUp")]
fn set_white_balance_without_base_up( fn set_white_balance_without_base_up(
&mut self, &mut self,
white_balance: WhiteBalance, white_balance: WhiteBalance,
@ -408,6 +431,7 @@ pub trait Camera {
} }
/// Sets the sharpness of the camera /// Sets the sharpness of the camera
#[doc(alias = "CAMU_SetSharpness")]
fn set_sharpness(&mut self, sharpness: i8) -> crate::Result<()> { fn set_sharpness(&mut self, sharpness: i8) -> crate::Result<()> {
unsafe { unsafe {
ResultCode(ctru_sys::CAMU_SetSharpness(self.camera_as_raw(), sharpness))?; ResultCode(ctru_sys::CAMU_SetSharpness(self.camera_as_raw(), sharpness))?;
@ -416,6 +440,7 @@ pub trait Camera {
} }
/// Sets whether auto exposure is enabled or disabled for the camera /// Sets whether auto exposure is enabled or disabled for the camera
#[doc(alias = "CAMU_SetAutoExposure")]
fn set_auto_exposure(&mut self, enabled: bool) -> crate::Result<()> { fn set_auto_exposure(&mut self, enabled: bool) -> crate::Result<()> {
unsafe { unsafe {
ResultCode(ctru_sys::CAMU_SetAutoExposure( ResultCode(ctru_sys::CAMU_SetAutoExposure(
@ -427,6 +452,7 @@ pub trait Camera {
} }
/// Returns true if auto exposure is enabled for the camera /// Returns true if auto exposure is enabled for the camera
#[doc(alias = "CAMU_IsAutoExposure")]
fn is_auto_exposure_enabled(&self) -> crate::Result<bool> { fn is_auto_exposure_enabled(&self) -> crate::Result<bool> {
unsafe { unsafe {
let mut enabled = false; let mut enabled = false;
@ -439,6 +465,7 @@ pub trait Camera {
} }
/// Sets whether auto white balance is enabled or disabled for the camera /// Sets whether auto white balance is enabled or disabled for the camera
#[doc(alias = "CAMU_SetAutoWhiteBalance")]
fn set_auto_white_balance(&mut self, enabled: bool) -> crate::Result<()> { fn set_auto_white_balance(&mut self, enabled: bool) -> crate::Result<()> {
unsafe { unsafe {
ResultCode(ctru_sys::CAMU_SetAutoWhiteBalance( ResultCode(ctru_sys::CAMU_SetAutoWhiteBalance(
@ -450,6 +477,7 @@ pub trait Camera {
} }
/// Returns true if auto white balance is enabled for the camera /// Returns true if auto white balance is enabled for the camera
#[doc(alias = "CAMU_IsAutoWhiteBalance")]
fn is_auto_white_balance_enabled(&self) -> crate::Result<bool> { fn is_auto_white_balance_enabled(&self) -> crate::Result<bool> {
unsafe { unsafe {
let mut enabled = false; let mut enabled = false;
@ -462,6 +490,7 @@ pub trait Camera {
} }
/// Sets the flip direction of the camera's image based on the passed [`FlipMode`] argument /// Sets the flip direction of the camera's image based on the passed [`FlipMode`] argument
#[doc(alias = "CAMU_FlipImage")]
fn flip_image(&mut self, flip: FlipMode) -> crate::Result<()> { fn flip_image(&mut self, flip: FlipMode) -> crate::Result<()> {
unsafe { unsafe {
ResultCode(ctru_sys::CAMU_FlipImage( ResultCode(ctru_sys::CAMU_FlipImage(
@ -485,6 +514,7 @@ pub trait Camera {
/// * `height` - height of the image /// * `height` - height of the image
/// * `crop_0` - The first crop point in which the image will be trimmed /// * `crop_0` - The first crop point in which the image will be trimmed
/// * `crop_0` - The second crop point in which the image will be trimmed /// * `crop_0` - The second crop point in which the image will be trimmed
#[doc(alias = "CAMU_SetDetailSize")]
fn set_detail_size( fn set_detail_size(
&mut self, &mut self,
width: i16, width: i16,
@ -508,6 +538,7 @@ pub trait Camera {
} }
/// Sets the view size of the camera based on the passed [`ViewSize`] argument. /// Sets the view size of the camera based on the passed [`ViewSize`] argument.
#[doc(alias = "CAMU_SetSize")]
fn set_view_size(&mut self, size: ViewSize) -> crate::Result<()> { fn set_view_size(&mut self, size: ViewSize) -> crate::Result<()> {
unsafe { unsafe {
ResultCode(ctru_sys::CAMU_SetSize( ResultCode(ctru_sys::CAMU_SetSize(
@ -520,6 +551,7 @@ pub trait Camera {
} }
/// Sets the frame rate of the camera based on the passed [`FrameRate`] argument. /// Sets the frame rate of the camera based on the passed [`FrameRate`] argument.
#[doc(alias = "CAMU_SetFrameRate")]
fn set_frame_rate(&mut self, frame_rate: FrameRate) -> crate::Result<()> { fn set_frame_rate(&mut self, frame_rate: FrameRate) -> crate::Result<()> {
unsafe { unsafe {
ResultCode(ctru_sys::CAMU_SetFrameRate( ResultCode(ctru_sys::CAMU_SetFrameRate(
@ -531,6 +563,7 @@ pub trait Camera {
} }
/// Sets the photo mode of the camera based on the passed [`PhotoMode`] argument. /// Sets the photo mode of the camera based on the passed [`PhotoMode`] argument.
#[doc(alias = "CAMU_SetPhotoMode")]
fn set_photo_mode(&mut self, photo_mode: PhotoMode) -> crate::Result<()> { fn set_photo_mode(&mut self, photo_mode: PhotoMode) -> crate::Result<()> {
unsafe { unsafe {
ResultCode(ctru_sys::CAMU_SetPhotoMode( ResultCode(ctru_sys::CAMU_SetPhotoMode(
@ -544,6 +577,7 @@ pub trait Camera {
/// Sets the effect of the camera based on the passed [`Effect`] argument. /// Sets the effect of the camera based on the passed [`Effect`] argument.
/// ///
/// Multiple effects can be set at once by combining the bitflags of [`Effect`] /// Multiple effects can be set at once by combining the bitflags of [`Effect`]
#[doc(alias = "CAMU_SetEffect")]
fn set_effect(&mut self, effect: Effect) -> crate::Result<()> { fn set_effect(&mut self, effect: Effect) -> crate::Result<()> {
unsafe { unsafe {
ResultCode(ctru_sys::CAMU_SetEffect( ResultCode(ctru_sys::CAMU_SetEffect(
@ -556,6 +590,7 @@ pub trait Camera {
} }
/// Sets the contrast of the camera based on the passed [`Contrast`] argument. /// Sets the contrast of the camera based on the passed [`Contrast`] argument.
#[doc(alias = "CAMU_SetContrast")]
fn set_contrast(&mut self, contrast: Contrast) -> crate::Result<()> { fn set_contrast(&mut self, contrast: Contrast) -> crate::Result<()> {
unsafe { unsafe {
ResultCode(ctru_sys::CAMU_SetContrast( ResultCode(ctru_sys::CAMU_SetContrast(
@ -567,6 +602,7 @@ pub trait Camera {
} }
/// Sets the lens correction of the camera based on the passed [`LensCorrection`] argument. /// Sets the lens correction of the camera based on the passed [`LensCorrection`] argument.
#[doc(alias = "CAMU_SetLensCorrection")]
fn set_lens_correction(&mut self, lens_correction: LensCorrection) -> crate::Result<()> { fn set_lens_correction(&mut self, lens_correction: LensCorrection) -> crate::Result<()> {
unsafe { unsafe {
ResultCode(ctru_sys::CAMU_SetLensCorrection( ResultCode(ctru_sys::CAMU_SetLensCorrection(
@ -578,6 +614,7 @@ pub trait Camera {
} }
/// Sets the output format of the camera based on the passed [`OutputFormat`] argument. /// Sets the output format of the camera based on the passed [`OutputFormat`] argument.
#[doc(alias = "CAMU_SetOutputFormat")]
fn set_output_format(&mut self, format: OutputFormat) -> crate::Result<()> { fn set_output_format(&mut self, format: OutputFormat) -> crate::Result<()> {
unsafe { unsafe {
ResultCode(ctru_sys::CAMU_SetOutputFormat( ResultCode(ctru_sys::CAMU_SetOutputFormat(
@ -597,6 +634,7 @@ pub trait Camera {
/// * `y` - Starting y coordinate of the window /// * `y` - Starting y coordinate of the window
/// * `width` - Width of the window /// * `width` - Width of the window
/// * `height` - Height of the window /// * `height` - Height of the window
#[doc(alias = "CAMU_SetAutoExposureWindow")]
fn set_auto_exposure_window( fn set_auto_exposure_window(
&mut self, &mut self,
x: i16, x: i16,
@ -624,6 +662,7 @@ pub trait Camera {
/// * `y` - Starting y coordinate of the window /// * `y` - Starting y coordinate of the window
/// * `width` - Width of the window /// * `width` - Width of the window
/// * `height` - Height of the window /// * `height` - Height of the window
#[doc(alias = "CAMU_SetAutoWhiteBalanceWindow")]
fn set_auto_white_balance_window( fn set_auto_white_balance_window(
&mut self, &mut self,
x: i16, x: i16,
@ -644,6 +683,7 @@ pub trait Camera {
} }
/// Sets whether the noise filter should be enabled or disabled for the camera /// Sets whether the noise filter should be enabled or disabled for the camera
#[doc(alias = "CAMU_SetNoiseFilter")]
fn set_noise_filter(&mut self, enabled: bool) -> crate::Result<()> { fn set_noise_filter(&mut self, enabled: bool) -> crate::Result<()> {
unsafe { unsafe {
ResultCode(ctru_sys::CAMU_SetNoiseFilter(self.camera_as_raw(), enabled))?; ResultCode(ctru_sys::CAMU_SetNoiseFilter(self.camera_as_raw(), enabled))?;
@ -653,6 +693,7 @@ pub trait Camera {
/// Sets the image quality calibration data for the camera based on the passed in /// Sets the image quality calibration data for the camera based on the passed in
/// [`ImageQualityCalibrationData`] argument /// [`ImageQualityCalibrationData`] argument
#[doc(alias = "CAMU_SetImageQualityCalibrationData")]
fn set_image_quality_calibration_data( fn set_image_quality_calibration_data(
&mut self, &mut self,
data: ImageQualityCalibrationData, data: ImageQualityCalibrationData,
@ -664,6 +705,7 @@ pub trait Camera {
} }
/// Returns the current [`ImageQualityCalibrationData`] for the camera /// Returns the current [`ImageQualityCalibrationData`] for the camera
#[doc(alias = "CAMU_GetImageQualityCalibrationData")]
fn image_quality_calibration_data(&self) -> crate::Result<ImageQualityCalibrationData> { fn image_quality_calibration_data(&self) -> crate::Result<ImageQualityCalibrationData> {
unsafe { unsafe {
let mut data = ImageQualityCalibrationData::default(); let mut data = ImageQualityCalibrationData::default();
@ -674,6 +716,7 @@ pub trait Camera {
/// Sets the camera as the current sleep camera /// Sets the camera as the current sleep camera
// TODO: Explain sleep camera // TODO: Explain sleep camera
#[doc(alias = "CAMU_SetSleepCamera")]
fn set_sleep_camera(&mut self) -> crate::Result<()> { fn set_sleep_camera(&mut self) -> crate::Result<()> {
unsafe { unsafe {
ResultCode(ctru_sys::CAMU_SetSleepCamera(self.camera_as_raw()))?; ResultCode(ctru_sys::CAMU_SetSleepCamera(self.camera_as_raw()))?;
@ -771,6 +814,7 @@ impl Cam {
/// This function will return an error if the service was unable to be initialized. /// This function will return an error if the service was unable to be initialized.
/// 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.
#[doc(alias = "camInit")]
pub fn new() -> crate::Result<Cam> { pub fn new() -> crate::Result<Cam> {
unsafe { unsafe {
ResultCode(ctru_sys::camInit())?; ResultCode(ctru_sys::camInit())?;
@ -784,6 +828,7 @@ impl Cam {
} }
/// Plays the specified sound based on the [`ShutterSound`] argument /// Plays the specified sound based on the [`ShutterSound`] argument
#[doc(alias = "CAMU_PlayShutterSound")]
pub fn play_shutter_sound(&self, sound: ShutterSound) -> crate::Result<()> { pub fn play_shutter_sound(&self, sound: ShutterSound) -> crate::Result<()> {
unsafe { unsafe {
ResultCode(ctru_sys::CAMU_PlayShutterSound(sound.into()))?; ResultCode(ctru_sys::CAMU_PlayShutterSound(sound.into()))?;
@ -793,6 +838,7 @@ impl Cam {
} }
impl Drop for Cam { impl Drop for Cam {
#[doc(alias = "camExit")]
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ctru_sys::camExit() }; unsafe { ctru_sys::camExit() };
} }

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

@ -4,6 +4,7 @@
use crate::error::ResultCode; use crate::error::ResultCode;
#[doc(alias = "CFG_Region")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum Region { pub enum Region {
@ -16,6 +17,7 @@ pub enum Region {
Taiwan = ctru_sys::CFG_REGION_TWN, Taiwan = ctru_sys::CFG_REGION_TWN,
} }
#[doc(alias = "CFG_Language")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum Language { pub enum Language {
@ -33,6 +35,7 @@ pub enum Language {
TraditionalChinese = ctru_sys::CFG_LANGUAGE_TW, TraditionalChinese = ctru_sys::CFG_LANGUAGE_TW,
} }
#[doc(alias = "CFG_SystemModel")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum SystemModel { pub enum SystemModel {
@ -61,12 +64,14 @@ impl Cfgu {
/// 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 Cfgu drop out of scope. /// instances of Cfgu drop out of scope.
#[doc(alias = "cfguInit")]
pub fn new() -> crate::Result<Cfgu> { pub fn new() -> crate::Result<Cfgu> {
ResultCode(unsafe { ctru_sys::cfguInit() })?; ResultCode(unsafe { ctru_sys::cfguInit() })?;
Ok(Cfgu(())) Ok(Cfgu(()))
} }
/// Gets system region from secure info /// Gets system region from secure info
#[doc(alias = "CFGU_SecureInfoGetRegion")]
pub fn region(&self) -> crate::Result<Region> { pub fn region(&self) -> crate::Result<Region> {
let mut region: u8 = 0; let mut region: u8 = 0;
@ -75,6 +80,7 @@ impl Cfgu {
} }
/// Gets system's model /// Gets system's model
#[doc(alias = "CFGU_GetSystemModel")]
pub fn model(&self) -> crate::Result<SystemModel> { pub fn model(&self) -> crate::Result<SystemModel> {
let mut model: u8 = 0; let mut model: u8 = 0;
@ -83,6 +89,7 @@ impl Cfgu {
} }
/// Gets system's language /// Gets system's language
#[doc(alias = "CFGU_GetSystemLanguage")]
pub fn language(&self) -> crate::Result<Language> { pub fn language(&self) -> crate::Result<Language> {
let mut language: u8 = 0; let mut language: u8 = 0;
@ -91,6 +98,7 @@ impl Cfgu {
} }
/// Checks if NFC is supported by the console /// Checks if NFC is supported by the console
#[doc(alias = "CFGU_IsNFCSupported")]
pub fn is_nfc_supported(&self) -> crate::Result<bool> { pub fn is_nfc_supported(&self) -> crate::Result<bool> {
let mut supported: bool = false; let mut supported: bool = false;
@ -99,6 +107,7 @@ impl Cfgu {
} }
/// Check if the console is from the 2DS family (2DS, New2DS, New2DSXL) /// Check if the console is from the 2DS family (2DS, New2DS, New2DSXL)
#[doc(alias = "CFGU_GetModelNintendo2DS")]
pub fn is_2ds_family(&self) -> crate::Result<bool> { pub fn is_2ds_family(&self) -> crate::Result<bool> {
let mut is_2ds_family: u8 = 0; let mut is_2ds_family: u8 = 0;
@ -108,6 +117,7 @@ impl Cfgu {
} }
impl Drop for Cfgu { impl Drop for Cfgu {
#[doc(alias = "cfguExit")]
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
ctru_sys::cfguExit(); ctru_sys::cfguExit();

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

@ -39,6 +39,7 @@ bitflags! {
} }
} }
#[doc(alias = "FS_MediaType")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum FsMediaType { pub enum FsMediaType {
@ -47,6 +48,7 @@ pub enum FsMediaType {
GameCard = ctru_sys::MEDIATYPE_GAME_CARD, GameCard = ctru_sys::MEDIATYPE_GAME_CARD,
} }
#[doc(alias = "FS_PathType")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum PathType { pub enum PathType {
@ -57,6 +59,7 @@ pub enum PathType {
UTF16 = ctru_sys::PATH_UTF16, UTF16 = ctru_sys::PATH_UTF16,
} }
#[doc(alias = "FS_ArchiveID")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum ArchiveID { pub enum ArchiveID {
@ -391,6 +394,7 @@ impl File {
/// # Errors /// # Errors
/// ///
/// 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.
#[doc(alias = "FSFILE_SetSize")]
pub fn set_len(&mut self, size: u64) -> IoResult<()> { pub fn set_len(&mut self, size: u64) -> IoResult<()> {
unsafe { unsafe {
let r = ctru_sys::FSFILE_SetSize(self.handle, size); let r = ctru_sys::FSFILE_SetSize(self.handle, size);
@ -426,6 +430,7 @@ impl File {
} }
} }
#[doc(alias = "FSFILE_Read")]
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;
@ -449,6 +454,7 @@ impl File {
unsafe { read_to_end_uninitialized(self, buf) } unsafe { read_to_end_uninitialized(self, buf) }
} }
#[doc(alias = "FSFILE_Write")]
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;
@ -576,6 +582,7 @@ impl OpenOptions {
/// to the `archive` method. /// to the `archive` method.
/// * Filesystem-level errors (full disk, etc). /// * Filesystem-level errors (full disk, etc).
/// * Invalid combinations of open options. /// * Invalid combinations of open options.
#[doc(alias = "FSUSER_OpenFile")]
pub fn open<P: AsRef<Path>>(&mut self, path: P) -> IoResult<File> { pub fn open<P: AsRef<Path>>(&mut self, path: P) -> IoResult<File> {
self._open(path.as_ref(), self.open_flags()) self._open(path.as_ref(), self.open_flags())
} }
@ -694,6 +701,7 @@ impl<'a> DirEntry<'a> {
/// but is not limited to just these cases: /// but is not limited to just these cases:
/// ///
/// * User lacks permissions to create directory at `path` /// * User lacks permissions to create directory at `path`
#[doc(alias = "FSUSER_CreateDirectory")]
pub fn create_dir<P: AsRef<Path>>(arch: &mut Archive, path: P) -> IoResult<()> { pub fn create_dir<P: AsRef<Path>>(arch: &mut Archive, path: P) -> IoResult<()> {
unsafe { unsafe {
let path = to_utf16(path.as_ref()); let path = to_utf16(path.as_ref());
@ -720,6 +728,7 @@ pub fn create_dir<P: AsRef<Path>>(arch: &mut Archive, path: P) -> IoResult<()> {
/// ///
/// * If any directory in the path specified by `path` does not already exist /// * If any directory in the path specified by `path` does not already exist
/// and it could not be created otherwise. /// and it could not be created otherwise.
#[doc(alias = "FSUSER_CreateDirectory")]
pub fn create_dir_all<P: AsRef<Path>>(arch: &mut Archive, path: P) -> IoResult<()> { pub fn create_dir_all<P: AsRef<Path>>(arch: &mut Archive, path: P) -> IoResult<()> {
let path = path.as_ref(); let path = path.as_ref();
let mut dir = PathBuf::new(); let mut dir = PathBuf::new();
@ -756,6 +765,7 @@ pub fn metadata<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<Metadata> {
/// ///
/// * The user lacks permissions to remove the directory at the provided path. /// * The user lacks permissions to remove the directory at the provided path.
/// * The directory isn't empty. /// * The directory isn't empty.
#[doc(alias = "FSUSER_DeleteDirectory")]
pub fn remove_dir<P: AsRef<Path>>(arch: &mut Archive, path: P) -> IoResult<()> { pub fn remove_dir<P: AsRef<Path>>(arch: &mut Archive, path: P) -> IoResult<()> {
unsafe { unsafe {
let path = to_utf16(path.as_ref()); let path = to_utf16(path.as_ref());
@ -774,6 +784,7 @@ pub fn remove_dir<P: AsRef<Path>>(arch: &mut Archive, path: P) -> IoResult<()> {
/// # Errors /// # Errors
/// ///
/// see `file::remove_file` and `fs::remove_dir` /// see `file::remove_file` and `fs::remove_dir`
#[doc(alias = "FSUSER_DeleteDirectoryRecursively")]
pub fn remove_dir_all<P: AsRef<Path>>(arch: &mut Archive, path: P) -> IoResult<()> { pub fn remove_dir_all<P: AsRef<Path>>(arch: &mut Archive, path: P) -> IoResult<()> {
unsafe { unsafe {
let path = to_utf16(path.as_ref()); let path = to_utf16(path.as_ref());
@ -798,6 +809,7 @@ pub fn remove_dir_all<P: AsRef<Path>>(arch: &mut Archive, path: P) -> IoResult<(
/// * The provided path doesn't exist. /// * The provided path doesn't exist.
/// * The process lacks permissions to view the contents. /// * The process lacks permissions to view the contents.
/// * The path points at a non-directory file. /// * The path points at a non-directory file.
#[doc(alias = "FSUSER_OpenDirectory")]
pub fn read_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<ReadDir> { pub fn read_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<ReadDir> {
unsafe { unsafe {
let mut handle = 0; let mut handle = 0;
@ -826,6 +838,7 @@ pub fn read_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<ReadDir> {
/// ///
/// * path points to a directory. /// * path points to a directory.
/// * The user lacks permissions to remove the file. /// * The user lacks permissions to remove the file.
#[doc(alias = "FSUSER_DeleteFile")]
pub fn remove_file<P: AsRef<Path>>(arch: &mut Archive, path: P) -> IoResult<()> { pub fn remove_file<P: AsRef<Path>>(arch: &mut Archive, path: P) -> IoResult<()> {
unsafe { unsafe {
let path = to_utf16(path.as_ref()); let path = to_utf16(path.as_ref());
@ -849,6 +862,7 @@ pub fn remove_file<P: AsRef<Path>>(arch: &mut Archive, path: P) -> IoResult<()>
/// ///
/// * from does not exist. /// * from does not exist.
/// * The user lacks permissions to view contents. /// * The user lacks permissions to view contents.
#[doc(alias = "FSUSER_RenameFile", alias = "FSUSER_RenameDirectory")]
pub fn rename<P, Q>(arch: &mut Archive, from: P, to: Q) -> IoResult<()> pub fn rename<P, Q>(arch: &mut Archive, from: P, to: Q) -> IoResult<()>
where where
P: AsRef<Path>, P: AsRef<Path>,
@ -972,6 +986,7 @@ impl Seek for File {
} }
impl Drop for Fs { impl Drop for Fs {
#[doc(alias = "fsExit")]
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
ctru_sys::fsExit(); ctru_sys::fsExit();
@ -980,6 +995,7 @@ impl Drop for Fs {
} }
impl Drop for Archive { impl Drop for Archive {
#[doc(alias = "FSUSER_CloseArchive")]
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
let _ = ctru_sys::FSUSER_CloseArchive(self.handle); let _ = ctru_sys::FSUSER_CloseArchive(self.handle);
@ -988,6 +1004,7 @@ impl Drop for Archive {
} }
impl Drop for File { impl Drop for File {
#[doc(alias = "FSFILE_Close")]
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
let _ = ctru_sys::FSFILE_Close(self.handle); let _ = ctru_sys::FSFILE_Close(self.handle);
@ -996,6 +1013,7 @@ impl Drop for File {
} }
impl Drop for Dir { impl Drop for Dir {
#[doc(alias = "FSDIR_Close")]
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
let _ = ctru_sys::FSDIR_Close(self.0); let _ = ctru_sys::FSDIR_Close(self.0);

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

@ -23,6 +23,7 @@ mod private {
/// This trait is implemented by the screen structs for working with frame buffers and /// This trait is implemented by the screen structs for working with frame buffers and
/// drawing to the screens. Graphics-related code can be made generic over this /// drawing to the screens. Graphics-related code can be made generic over this
/// trait to work with any of the given screens. /// trait to work with any of the given screens.
#[doc(alias = "gfxScreen_t")]
pub trait Screen: private::Sealed { pub trait Screen: private::Sealed {
/// Returns the `libctru` value for the Screen kind. /// Returns the `libctru` value for the Screen kind.
fn as_raw(&self) -> ctru_sys::gfxScreen_t; fn as_raw(&self) -> ctru_sys::gfxScreen_t;
@ -34,6 +35,7 @@ pub trait Screen: private::Sealed {
/// ///
/// Note that the pointer of the framebuffer returned by this function can /// Note that the pointer of the framebuffer returned by this function can
/// change after each call to this function if double buffering is enabled. /// change after each call to this function if double buffering is enabled.
#[doc(alias = "gfxGetFramebuffer")]
fn raw_framebuffer(&mut self) -> RawFrameBuffer { fn raw_framebuffer(&mut self) -> RawFrameBuffer {
let mut width: u16 = 0; let mut width: u16 = 0;
let mut height: u16 = 0; let mut height: u16 = 0;
@ -52,11 +54,13 @@ pub trait Screen: private::Sealed {
/// ///
/// [`Swap::swap_buffers`] must be called after this function for the configuration /// [`Swap::swap_buffers`] must be called after this function for the configuration
/// change to take effect. /// change to take effect.
#[doc(alias = "gfxSetDoubleBuffering")]
fn set_double_buffering(&mut self, enabled: bool) { fn set_double_buffering(&mut self, enabled: bool) {
unsafe { ctru_sys::gfxSetDoubleBuffering(self.as_raw(), enabled) } unsafe { ctru_sys::gfxSetDoubleBuffering(self.as_raw(), enabled) }
} }
/// Gets the framebuffer format. /// Gets the framebuffer format.
#[doc(alias = "gfxGetScreenFormat")]
fn framebuffer_format(&self) -> FramebufferFormat { fn framebuffer_format(&self) -> FramebufferFormat {
unsafe { ctru_sys::gfxGetScreenFormat(self.as_raw()) }.into() unsafe { ctru_sys::gfxGetScreenFormat(self.as_raw()) }.into()
} }
@ -65,6 +69,7 @@ pub trait Screen: private::Sealed {
/// ///
/// [`Swap::swap_buffers`] must be called after this method for the configuration /// [`Swap::swap_buffers`] must be called after this method for the configuration
/// change to take effect. /// change to take effect.
#[doc(alias = "gfxSetScreenFormat")]
fn set_framebuffer_format(&mut self, fmt: FramebufferFormat) { fn set_framebuffer_format(&mut self, fmt: FramebufferFormat) {
unsafe { ctru_sys::gfxSetScreenFormat(self.as_raw(), fmt.into()) } unsafe { ctru_sys::gfxSetScreenFormat(self.as_raw(), fmt.into()) }
} }
@ -94,6 +99,7 @@ pub trait Swap: private::Sealed {
/// [`Screen::set_framebuffer_format`], [`Screen::set_double_buffering`]). /// [`Screen::set_framebuffer_format`], [`Screen::set_double_buffering`]).
/// ///
/// This should be called once per frame at most. /// This should be called once per frame at most.
#[doc(alias = "gfxScreenSwapBuffers")]
fn swap_buffers(&mut self); fn swap_buffers(&mut self);
} }
@ -126,6 +132,7 @@ impl Swap for BottomScreen {
pub trait Flush: private::Sealed { pub trait Flush: private::Sealed {
/// Flushes the video buffer(s) for this screen. Note that you must still call /// Flushes the video buffer(s) for this screen. Note that you must still call
/// [`Swap::swap_buffers`] after this method for the buffer contents to be displayed. /// [`Swap::swap_buffers`] after this method for the buffer contents to be displayed.
#[doc(alias = "gfxFlushBuffers")]
fn flush_buffers(&mut self); fn flush_buffers(&mut self);
} }
@ -184,11 +191,12 @@ pub struct RawFrameBuffer<'screen> {
screen: PhantomData<&'screen mut dyn Screen>, screen: PhantomData<&'screen mut dyn Screen>,
} }
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)]
/// Side of top screen framebuffer /// Side of top screen framebuffer
/// ///
/// The top screen of the 3DS can have two separate sets of framebuffers to support its 3D functionality /// The top screen of the 3DS can have two separate sets of framebuffers to support its 3D functionality
#[doc(alias = "gfx3dSide_t")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)]
pub enum Side { pub enum Side {
/// The left framebuffer. This framebuffer is also the one used when 3D is disabled /// The left framebuffer. This framebuffer is also the one used when 3D is disabled
Left = ctru_sys::GFX_LEFT, Left = ctru_sys::GFX_LEFT,
@ -215,6 +223,7 @@ impl Gfx {
/// ``` /// ```
/// Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false) /// Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false)
/// ``` /// ```
#[doc(alias = "gfxInit")]
pub fn new() -> Result<Self> { pub fn new() -> Result<Self> {
Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false) Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false)
} }
@ -223,6 +232,7 @@ impl Gfx {
/// screens /// screens
/// ///
/// Use `Gfx::new()` instead of this function to initialize the module with default parameters /// Use `Gfx::new()` instead of this function to initialize the module with default parameters
#[doc(alias = "gfxInit")]
pub fn with_formats( pub fn with_formats(
top_fb_fmt: FramebufferFormat, top_fb_fmt: FramebufferFormat,
bottom_fb_fmt: FramebufferFormat, bottom_fb_fmt: FramebufferFormat,
@ -269,6 +279,7 @@ impl TopScreen3D<'_> {
} }
impl<'screen> From<&'screen RefCell<TopScreen>> for TopScreen3D<'screen> { impl<'screen> From<&'screen RefCell<TopScreen>> for TopScreen3D<'screen> {
#[doc(alias = "gfxSet3D")]
fn from(top_screen: &'screen RefCell<TopScreen>) -> Self { fn from(top_screen: &'screen RefCell<TopScreen>) -> Self {
unsafe { unsafe {
ctru_sys::gfxSet3D(true); ctru_sys::gfxSet3D(true);
@ -298,6 +309,7 @@ impl TopScreen {
/// ///
/// [`Swap::swap_buffers`] must be called after this method for the configuration /// [`Swap::swap_buffers`] must be called after this method for the configuration
/// to take effect. /// to take effect.
#[doc(alias = "gfxSetWide")]
pub fn set_wide_mode(&mut self, enable: bool) { pub fn set_wide_mode(&mut self, enable: bool) {
unsafe { unsafe {
ctru_sys::gfxSetWide(enable); ctru_sys::gfxSetWide(enable);
@ -305,6 +317,7 @@ impl TopScreen {
} }
/// Returns whether or not wide mode is enabled on the top screen. /// Returns whether or not wide mode is enabled on the top screen.
#[doc(alias = "gfxIsWide")]
pub fn is_wide(&self) -> bool { pub fn is_wide(&self) -> bool {
unsafe { ctru_sys::gfxIsWide() } unsafe { ctru_sys::gfxIsWide() }
} }

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

@ -1,5 +1,6 @@
//! GSPGPU service //! GSPGPU service
#[doc(alias = "GSPGPU_Event")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum Event { pub enum Event {
@ -12,6 +13,7 @@ pub enum Event {
DMA = ctru_sys::GSPGPU_EVENT_DMA, DMA = ctru_sys::GSPGPU_EVENT_DMA,
} }
#[doc(alias = "GSPGPU_FramebufferFormat")]
/// Framebuffer formats supported by the 3DS /// Framebuffer formats supported by the 3DS
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
@ -45,6 +47,7 @@ impl FramebufferFormat {
/// Waits for a GSPGPU event to occur. /// Waits for a GSPGPU event to occur.
/// ///
/// `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
#[doc(alias = "gspWaitForEvent")]
pub fn wait_for_event(ev: Event, discard_current: bool) { pub fn wait_for_event(ev: Event, discard_current: bool) {
unsafe { unsafe {
ctru_sys::gspWaitForEvent(ev.into(), discard_current); ctru_sys::gspWaitForEvent(ev.into(), discard_current);

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

@ -54,6 +54,7 @@ pub struct Hid(());
/// 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 {
#[doc(alias = "hidInit")]
pub fn new() -> crate::Result<Hid> { pub fn new() -> crate::Result<Hid> {
unsafe { unsafe {
ResultCode(ctru_sys::hidInit())?; ResultCode(ctru_sys::hidInit())?;
@ -64,12 +65,14 @@ impl Hid {
/// Scans the HID service for all user input occurring on the current /// Scans the HID service for all user input occurring on the current
/// 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.
#[doc(alias = "hidScanInput")]
pub fn scan_input(&mut self) { pub fn scan_input(&mut self) {
unsafe { ctru_sys::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).
#[doc(alias = "hidKeysDown")]
pub fn keys_down(&self) -> KeyPad { pub fn keys_down(&self) -> KeyPad {
unsafe { unsafe {
let keys = ctru_sys::hidKeysDown(); let keys = ctru_sys::hidKeysDown();
@ -79,6 +82,7 @@ impl Hid {
/// Returns a bitflag struct representing which buttons have been held down /// Returns a bitflag struct representing which buttons have been held down
/// during the current frame. /// during the current frame.
#[doc(alias = "hidKeysHeld")]
pub fn keys_held(&self) -> KeyPad { pub fn keys_held(&self) -> KeyPad {
unsafe { unsafe {
let keys = ctru_sys::hidKeysHeld(); let keys = ctru_sys::hidKeysHeld();
@ -88,6 +92,7 @@ impl Hid {
/// Returns a bitflag struct representing which buttons have just been released on /// Returns a bitflag struct representing which buttons have just been released on
/// the current frame. /// the current frame.
#[doc(alias = "hidKeysUp")]
pub fn keys_up(&self) -> KeyPad { pub fn keys_up(&self) -> KeyPad {
unsafe { unsafe {
let keys = ctru_sys::hidKeysUp(); let keys = ctru_sys::hidKeysUp();
@ -100,6 +105,7 @@ impl Hid {
/// # Notes /// # Notes
/// ///
/// (0, 0) represents the top left corner of the screen. /// (0, 0) represents the top left corner of the screen.
#[doc(alias = "hidTouchRead")]
pub fn touch_position(&mut self) -> (u16, u16) { pub fn touch_position(&mut self) -> (u16, u16) {
let mut res = ctru_sys::touchPosition { px: 0, py: 0 }; let mut res = ctru_sys::touchPosition { px: 0, py: 0 };
@ -114,6 +120,7 @@ impl Hid {
/// # Notes /// # Notes
/// ///
/// (0, 0) represents the center of the circle pad. /// (0, 0) represents the center of the circle pad.
#[doc(alias = "hidCircleRead")]
pub fn circlepad_position(&mut self) -> (i16, i16) { pub fn circlepad_position(&mut self) -> (i16, i16) {
let mut res = ctru_sys::circlePosition { dx: 0, dy: 0 }; let mut res = ctru_sys::circlePosition { dx: 0, dy: 0 };
@ -125,6 +132,7 @@ impl Hid {
} }
impl Drop for Hid { impl Drop for Hid {
#[doc(alias = "hidExit")]
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ctru_sys::hidExit() }; unsafe { ctru_sys::hidExit() };
} }

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

@ -14,6 +14,7 @@ use std::sync::Mutex;
const NUMBER_OF_CHANNELS: u8 = 24; const NUMBER_OF_CHANNELS: u8 = 24;
#[doc(alias = "ndspOutputMode")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum OutputMode { pub enum OutputMode {
@ -37,6 +38,7 @@ pub struct AudioMix {
raw: [f32; 12], raw: [f32; 12],
} }
#[doc(alias = "ndspInterpType")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum InterpolationType { pub enum InterpolationType {
@ -80,6 +82,7 @@ impl Ndsp {
/// ///
/// This function will return an error if an instance of the `Ndsp` struct already exists /// This function will return an error if an instance of the `Ndsp` struct already exists
/// or if there are any issues during initialization. /// or if there are any issues during initialization.
#[doc(alias = "ndspInit")]
pub fn new() -> crate::Result<Self> { pub fn new() -> crate::Result<Self> {
let _service_handler = ServiceReference::new( let _service_handler = ServiceReference::new(
&NDSP_ACTIVE, &NDSP_ACTIVE,
@ -121,6 +124,7 @@ impl Ndsp {
} }
/// Set the audio output mode. Defaults to `OutputMode::Stereo`. /// Set the audio output mode. Defaults to `OutputMode::Stereo`.
#[doc(alias = "ndspSetOutputMode")]
pub fn set_output_mode(&mut self, mode: OutputMode) { pub fn set_output_mode(&mut self, mode: OutputMode) {
unsafe { ctru_sys::ndspSetOutputMode(mode.into()) }; unsafe { ctru_sys::ndspSetOutputMode(mode.into()) };
} }
@ -128,21 +132,25 @@ impl Ndsp {
impl Channel<'_> { impl Channel<'_> {
/// Reset the channel /// Reset the channel
#[doc(alias = "ndspChnReset")]
pub fn reset(&mut self) { pub fn reset(&mut self) {
unsafe { ctru_sys::ndspChnReset(self.id.into()) }; unsafe { ctru_sys::ndspChnReset(self.id.into()) };
} }
/// Initialize the channel's parameters /// Initialize the channel's parameters
#[doc(alias = "ndspChnInitParams")]
pub fn init_parameters(&self) { pub fn init_parameters(&self) {
unsafe { ctru_sys::ndspChnInitParams(self.id.into()) }; unsafe { ctru_sys::ndspChnInitParams(self.id.into()) };
} }
/// Returns whether the channel is playing any audio. /// Returns whether the channel is playing any audio.
#[doc(alias = "ndspChnIsPlaying")]
pub fn is_playing(&self) -> bool { pub fn is_playing(&self) -> bool {
unsafe { ctru_sys::ndspChnIsPlaying(self.id.into()) } unsafe { ctru_sys::ndspChnIsPlaying(self.id.into()) }
} }
/// Returns whether the channel's playback is currently paused. /// Returns whether the channel's playback is currently paused.
#[doc(alias = "ndspChnIsPaused")]
pub fn is_paused(&self) -> bool { pub fn is_paused(&self) -> bool {
unsafe { ctru_sys::ndspChnIsPaused(self.id.into()) } unsafe { ctru_sys::ndspChnIsPaused(self.id.into()) }
} }
@ -155,37 +163,44 @@ impl Channel<'_> {
/// Returns the index of the currently played sample. /// Returns the index of the currently played sample.
/// ///
/// Because of how fast this value changes, it should only be used as a rough estimate of the current progress. /// Because of how fast this value changes, it should only be used as a rough estimate of the current progress.
#[doc(alias = "ndspChnGetSamplePos")]
pub fn sample_position(&self) -> usize { pub fn sample_position(&self) -> usize {
(unsafe { ctru_sys::ndspChnGetSamplePos(self.id.into()) }) as usize (unsafe { ctru_sys::ndspChnGetSamplePos(self.id.into()) }) as usize
} }
/// Returns the channel's current wave sequence's id. /// Returns the channel's current wave sequence's id.
#[doc(alias = "ndspChnGetWaveBufSeq")]
pub fn wave_sequence_id(&self) -> u16 { pub fn wave_sequence_id(&self) -> u16 {
unsafe { ctru_sys::ndspChnGetWaveBufSeq(self.id.into()) } unsafe { ctru_sys::ndspChnGetWaveBufSeq(self.id.into()) }
} }
/// Pause or un-pause the channel's playback. /// Pause or un-pause the channel's playback.
#[doc(alias = "ndspChnSetPaused")]
pub fn set_paused(&mut self, state: bool) { pub fn set_paused(&mut self, state: bool) {
unsafe { ctru_sys::ndspChnSetPaused(self.id.into(), state) }; unsafe { ctru_sys::ndspChnSetPaused(self.id.into(), state) };
} }
/// Set the channel's output format. /// Set the channel's output format.
/// Change this setting based on the used sample's format. /// Change this setting based on the used sample's format.
#[doc(alias = "ndspChnSetFormat")]
pub fn set_format(&mut self, format: AudioFormat) { pub fn set_format(&mut self, format: AudioFormat) {
unsafe { ctru_sys::ndspChnSetFormat(self.id.into(), format.into()) }; unsafe { ctru_sys::ndspChnSetFormat(self.id.into(), format.into()) };
} }
/// Set the channel's interpolation mode. /// Set the channel's interpolation mode.
#[doc(alias = "ndspChnSetInterp")]
pub fn set_interpolation(&mut self, interp_type: InterpolationType) { pub fn set_interpolation(&mut self, interp_type: InterpolationType) {
unsafe { ctru_sys::ndspChnSetInterp(self.id.into(), interp_type.into()) }; unsafe { ctru_sys::ndspChnSetInterp(self.id.into(), interp_type.into()) };
} }
/// Set the channel's volume mix. /// Set the channel's volume mix.
#[doc(alias = "ndspChnSetMix")]
pub fn set_mix(&mut 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()) } unsafe { ctru_sys::ndspChnSetMix(self.id.into(), mix.as_raw().as_ptr().cast_mut()) }
} }
/// Set the channel's rate of sampling. /// Set the channel's rate of sampling.
#[doc(alias = "ndspChnSetRate")]
pub fn set_sample_rate(&mut self, rate: f32) { pub fn set_sample_rate(&mut self, rate: f32) {
unsafe { ctru_sys::ndspChnSetRate(self.id.into(), rate) }; unsafe { ctru_sys::ndspChnSetRate(self.id.into(), rate) };
} }
@ -195,6 +210,7 @@ impl Channel<'_> {
// We suggest using other wave formats when developing homebrew applications. // We suggest using other wave formats when developing homebrew applications.
/// Clear the wave buffer queue and stop playback. /// Clear the wave buffer queue and stop playback.
#[doc(alias = "ndspChnWaveBufClear")]
pub fn clear_queue(&mut self) { pub fn clear_queue(&mut self) {
unsafe { ctru_sys::ndspChnWaveBufClear(self.id.into()) }; unsafe { ctru_sys::ndspChnWaveBufClear(self.id.into()) };
} }
@ -206,6 +222,7 @@ impl Channel<'_> {
/// ///
/// `libctru` expects the user to manually keep the info data (in this case [`Wave`]) alive during playback. /// `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. /// To ensure safety, checks within [`Wave`] will clear the whole channel queue if any queued [`Wave`] is dropped prematurely.
#[doc(alias = "ndspChnWaveBufAdd")]
pub fn queue_wave(&mut self, wave: &mut Wave) -> std::result::Result<(), NdspError> { pub fn queue_wave(&mut self, wave: &mut Wave) -> std::result::Result<(), NdspError> {
match wave.status() { match wave.status() {
WaveStatus::Playing | WaveStatus::Queued => return Err(NdspError::WaveBusy(self.id)), WaveStatus::Playing | WaveStatus::Queued => return Err(NdspError::WaveBusy(self.id)),
@ -225,6 +242,7 @@ impl Channel<'_> {
/// Refer to [`libctru`](https://libctru.devkitpro.org/channel_8h.html#a1da3b363c2edfd318c92276b527daae6) for more info. /// Refer to [`libctru`](https://libctru.devkitpro.org/channel_8h.html#a1da3b363c2edfd318c92276b527daae6) for more info.
impl Channel<'_> { impl Channel<'_> {
/// Enables/disables monopole filters. /// Enables/disables monopole filters.
#[doc(alias = "ndspChnIirMonoSetEnable")]
pub fn iir_mono_set_enabled(&mut self, enable: bool) { pub fn iir_mono_set_enabled(&mut self, enable: bool) {
unsafe { ctru_sys::ndspChnIirMonoSetEnable(self.id.into(), enable) }; unsafe { ctru_sys::ndspChnIirMonoSetEnable(self.id.into(), enable) };
} }
@ -234,6 +252,7 @@ impl Channel<'_> {
/// # Notes /// # Notes
/// ///
/// This is a lower quality filter than the Biquad alternative. /// This is a lower quality filter than the Biquad alternative.
#[doc(alias = "ndspChnIirMonoSetParamsHighPassFilter")]
pub fn iir_mono_set_params_high_pass_filter(&mut 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) }; unsafe { ctru_sys::ndspChnIirMonoSetParamsHighPassFilter(self.id.into(), cut_off_freq) };
} }
@ -243,16 +262,19 @@ impl Channel<'_> {
/// # Notes /// # Notes
/// ///
/// This is a lower quality filter than the Biquad alternative. /// This is a lower quality filter than the Biquad alternative.
#[doc(alias = "ndspChnIirMonoSetParamsLowPassFilter")]
pub fn iir_mono_set_params_low_pass_filter(&mut 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) }; unsafe { ctru_sys::ndspChnIirMonoSetParamsLowPassFilter(self.id.into(), cut_off_freq) };
} }
/// Enables/disables biquad filters. /// Enables/disables biquad filters.
#[doc(alias = "ndspChnIirBiquadSetEnable")]
pub fn iir_biquad_set_enabled(&mut self, enable: bool) { pub fn iir_biquad_set_enabled(&mut self, enable: bool) {
unsafe { ctru_sys::ndspChnIirBiquadSetEnable(self.id.into(), enable) }; unsafe { ctru_sys::ndspChnIirBiquadSetEnable(self.id.into(), enable) };
} }
/// Sets the biquad to be a high pass filter. /// Sets the biquad to be a high pass filter.
#[doc(alias = "ndspChnIirBiquadSetParamsHighPassFilter")]
pub fn iir_biquad_set_params_high_pass_filter(&mut 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 { unsafe {
ctru_sys::ndspChnIirBiquadSetParamsHighPassFilter(self.id.into(), cut_off_freq, quality) ctru_sys::ndspChnIirBiquadSetParamsHighPassFilter(self.id.into(), cut_off_freq, quality)
@ -260,6 +282,7 @@ impl Channel<'_> {
} }
/// Sets the biquad to be a low pass filter. /// Sets the biquad to be a low pass filter.
#[doc(alias = "ndspChnIirBiquadSetParamsLowPassFilter")]
pub fn iir_biquad_set_params_low_pass_filter(&mut 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 { unsafe {
ctru_sys::ndspChnIirBiquadSetParamsLowPassFilter(self.id.into(), cut_off_freq, quality) ctru_sys::ndspChnIirBiquadSetParamsLowPassFilter(self.id.into(), cut_off_freq, quality)
@ -267,6 +290,7 @@ impl Channel<'_> {
} }
/// Sets the biquad to be a notch filter. /// Sets the biquad to be a notch filter.
#[doc(alias = "ndspChnIirBiquadSetParamsNotchFilter")]
pub fn iir_biquad_set_params_notch_filter(&mut self, notch_freq: f32, quality: f32) { pub fn iir_biquad_set_params_notch_filter(&mut self, notch_freq: f32, quality: f32) {
unsafe { unsafe {
ctru_sys::ndspChnIirBiquadSetParamsNotchFilter(self.id.into(), notch_freq, quality) ctru_sys::ndspChnIirBiquadSetParamsNotchFilter(self.id.into(), notch_freq, quality)
@ -274,6 +298,7 @@ impl Channel<'_> {
} }
/// Sets the biquad to be a band pass filter. /// Sets the biquad to be a band pass filter.
#[doc(alias = "ndspChnIirBiquadSetParamsBandPassFilter")]
pub fn iir_biquad_set_params_band_pass_filter(&mut self, mid_freq: f32, quality: f32) { pub fn iir_biquad_set_params_band_pass_filter(&mut self, mid_freq: f32, quality: f32) {
unsafe { unsafe {
ctru_sys::ndspChnIirBiquadSetParamsBandPassFilter(self.id.into(), mid_freq, quality) ctru_sys::ndspChnIirBiquadSetParamsBandPassFilter(self.id.into(), mid_freq, quality)
@ -281,6 +306,7 @@ impl Channel<'_> {
} }
/// Sets the biquad to be a peaking equalizer. /// Sets the biquad to be a peaking equalizer.
#[doc(alias = "ndspChnIirBiquadSetParamsPeakingEqualizer")]
pub fn iir_biquad_set_params_peaking_equalizer( pub fn iir_biquad_set_params_peaking_equalizer(
&mut self, &mut self,
central_freq: f32, central_freq: f32,
@ -448,6 +474,7 @@ impl fmt::Display for NdspError {
impl error::Error for NdspError {} impl error::Error for NdspError {}
impl Drop for Ndsp { impl Drop for Ndsp {
#[doc(alias = "ndspExit")]
fn drop(&mut self) { fn drop(&mut self) {
for i in 0..NUMBER_OF_CHANNELS { for i in 0..NUMBER_OF_CHANNELS {
self.channel(i).unwrap().reset(); self.channel(i).unwrap().reset();

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

@ -6,6 +6,7 @@
use crate::error::ResultCode; use crate::error::ResultCode;
use crate::Result; use crate::Result;
#[doc(alias = "PS_AESAlgorithm")]
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum AESAlgorithm { pub enum AESAlgorithm {
@ -17,6 +18,7 @@ pub enum AESAlgorithm {
CcmDec = ctru_sys::PS_ALGORITHM_CCM_DEC, CcmDec = ctru_sys::PS_ALGORITHM_CCM_DEC,
} }
#[doc(alias = "PS_AESKeyType")]
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum AESKeyType { pub enum AESKeyType {
@ -35,6 +37,7 @@ pub enum AESKeyType {
pub struct Ps(()); pub struct Ps(());
impl Ps { impl Ps {
#[doc(alias = "psInit")]
pub fn new() -> Result<Self> { pub fn new() -> Result<Self> {
unsafe { unsafe {
ResultCode(ctru_sys::psInit())?; ResultCode(ctru_sys::psInit())?;
@ -42,6 +45,7 @@ impl Ps {
} }
} }
#[doc(alias = "PS_GetLocalFriendCodeSeed")]
pub fn local_friend_code_seed(&self) -> crate::Result<u64> { pub fn local_friend_code_seed(&self) -> crate::Result<u64> {
let mut seed: u64 = 0; let mut seed: u64 = 0;
@ -49,6 +53,7 @@ impl Ps {
Ok(seed) Ok(seed)
} }
#[doc(alias = "PS_GetDeviceId")]
pub fn device_id(&self) -> crate::Result<u32> { pub fn device_id(&self) -> crate::Result<u32> {
let mut id: u32 = 0; let mut id: u32 = 0;
@ -56,6 +61,7 @@ impl Ps {
Ok(id) Ok(id)
} }
#[doc(alias = "PS_GenerateRandomBytes")]
pub fn generate_random_bytes(&self, out: &mut [u8]) -> crate::Result<()> { pub fn generate_random_bytes(&self, out: &mut [u8]) -> crate::Result<()> {
ResultCode(unsafe { ResultCode(unsafe {
ctru_sys::PS_GenerateRandomBytes(out.as_mut_ptr().cast(), out.len()) ctru_sys::PS_GenerateRandomBytes(out.as_mut_ptr().cast(), out.len())
@ -65,6 +71,7 @@ impl Ps {
} }
impl Drop for Ps { impl Drop for Ps {
#[doc(alias = "psExit")]
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
ctru_sys::psExit(); ctru_sys::psExit();

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

@ -25,6 +25,7 @@ pub struct RomFS {
static ROMFS_ACTIVE: Mutex<usize> = Mutex::new(0); static ROMFS_ACTIVE: Mutex<usize> = Mutex::new(0);
impl RomFS { impl RomFS {
#[doc(alias = "romfsMountSelf")]
pub fn new() -> crate::Result<Self> { pub fn new() -> crate::Result<Self> {
let _service_handler = ServiceReference::new( let _service_handler = ServiceReference::new(
&ROMFS_ACTIVE, &ROMFS_ACTIVE,
@ -44,6 +45,11 @@ impl RomFS {
} }
} }
impl Drop for RomFS {
#[doc(alias = "romfsUnmount")]
fn drop(&mut self) {}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

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

@ -25,6 +25,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
#[doc(alias = "socInit")]
pub fn new() -> crate::Result<Self> { pub fn new() -> crate::Result<Self> {
Self::init_with_buffer_size(0x100000) Self::init_with_buffer_size(0x100000)
} }
@ -35,6 +36,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
#[doc(alias = "socInit")]
pub fn init_with_buffer_size(num_bytes: usize) -> crate::Result<Self> { pub fn init_with_buffer_size(num_bytes: usize) -> crate::Result<Self> {
let _service_handler = ServiceReference::new( let _service_handler = ServiceReference::new(
&SOC_ACTIVE, &SOC_ACTIVE,
@ -61,6 +63,7 @@ impl Soc {
} }
/// IP Address of the Nintendo 3DS system. /// IP Address of the Nintendo 3DS system.
#[doc(alias = "gethostid")]
pub fn host_address(&self) -> Ipv4Addr { pub fn host_address(&self) -> Ipv4Addr {
let raw_id = unsafe { libc::gethostid() }; let raw_id = unsafe { libc::gethostid() };
Ipv4Addr::from(raw_id.to_ne_bytes()) Ipv4Addr::from(raw_id.to_ne_bytes())
@ -73,6 +76,7 @@ impl Soc {
/// ///
/// Returns an error if a connection cannot be established to the server, or /// Returns an error if a connection cannot be established to the server, or
/// output was already previously redirected. /// output was already previously redirected.
#[doc(alias = "link3dsConnectToHost")]
pub fn redirect_to_3dslink(&mut self, stdout: bool, stderr: bool) -> crate::Result<()> { pub fn redirect_to_3dslink(&mut self, stdout: bool, stderr: bool) -> crate::Result<()> {
if self.sock_3dslink >= 0 { if self.sock_3dslink >= 0 {
return Err(Error::OutputAlreadyRedirected); return Err(Error::OutputAlreadyRedirected);
@ -92,6 +96,7 @@ impl Soc {
} }
impl Drop for Soc { impl Drop for Soc {
#[doc(alias = "socExit")]
fn drop(&mut self) { fn drop(&mut self) {
if self.sock_3dslink >= 0 { if self.sock_3dslink >= 0 {
unsafe { unsafe {

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

@ -8,6 +8,7 @@ pub struct SslC(());
impl SslC { impl SslC {
/// Initialize the service /// Initialize the service
#[doc(alias = "sslcInit")]
pub fn new() -> crate::Result<Self> { pub fn new() -> crate::Result<Self> {
unsafe { unsafe {
ResultCode(ctru_sys::sslcInit(0))?; ResultCode(ctru_sys::sslcInit(0))?;
@ -17,6 +18,7 @@ impl SslC {
} }
impl Drop for SslC { impl Drop for SslC {
#[doc(alias = "sslcExit")]
fn drop(&mut self) { fn drop(&mut self) {
unsafe { ctru_sys::sslcExit() }; unsafe { ctru_sys::sslcExit() };
} }

Loading…
Cancel
Save