Browse Source

Fixed wrong type quotations

pull/134/head
Andrea Ciliberti 2 years ago
parent
commit
243863cfb9
  1. 2
      ctru-rs/src/console.rs
  2. 7
      ctru-rs/src/lib.rs
  3. 2
      ctru-rs/src/linear.rs
  4. 2
      ctru-rs/src/mii.rs
  5. 60
      ctru-rs/src/services/cam.rs
  6. 38
      ctru-rs/src/services/fs.rs
  7. 15
      ctru-rs/src/services/gfx.rs
  8. 26
      ctru-rs/src/services/ndsp/mod.rs
  9. 10
      ctru-rs/src/services/ndsp/wave.rs

2
ctru-rs/src/console.rs

@ -19,7 +19,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.
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();

7
ctru-rs/src/lib.rs

@ -1,3 +1,6 @@
//! Safe Rust wrapper around `libctru`.
//!
//! This library behaves as the main tool to access system-specific features and feature fixes.
#![crate_type = "rlib"] #![crate_type = "rlib"]
#![crate_name = "ctru"] #![crate_name = "ctru"]
#![feature(test)] #![feature(test)]
@ -27,8 +30,8 @@ macro_rules! from_impl {
/// Activate the default panic handler. /// Activate the default panic handler.
/// ///
/// With this implementation, the main thread will stop and try to print debug info to an available [console::Console]. /// With this implementation, the main thread will stop and try to print debug info to an available [`Console`](console::Console).
/// In case it fails to find an active [console::Console] the program will just exit. /// In case it fails to find an active [`Console`](console::Console) the program will just exit.
/// ///
/// # Notes /// # Notes
/// ///

2
ctru-rs/src/linear.rs

@ -15,7 +15,7 @@ use std::ptr::NonNull;
// Sadly the linear memory allocator included in `libctru` doesn't implement `linearRealloc` at the time of these additions, // Sadly the linear memory allocator included in `libctru` doesn't implement `linearRealloc` at the time of these additions,
// but the default fallback of the `std` will take care of that for us. // but the default fallback of the `std` will take care of that for us.
/// [`std::alloc::Allocator`] struct for LINEAR memory /// [`Allocator`](std::alloc::Allocator) struct for LINEAR memory
/// To use this struct the main crate must activate the `allocator_api` unstable feature. /// To use this struct the main crate must activate the `allocator_api` unstable feature.
#[derive(Copy, Clone, Default, Debug)] #[derive(Copy, Clone, Default, Debug)]
pub struct LinearAllocator; pub struct LinearAllocator;

2
ctru-rs/src/mii.rs

@ -176,7 +176,7 @@ pub struct MoleDetails {
/// Some values are not ordered _like_ the Mii Editor UI. The mapped values can be seen here: /// Some values are not ordered _like_ the Mii Editor UI. The mapped values can be seen here:
/// <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)
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct MiiData { pub struct MiiData {
pub options: MiiDataOptions, pub options: MiiDataOptions,

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

@ -20,7 +20,7 @@ pub struct Cam {
pub both_outer_cams: BothOutwardCam, pub both_outer_cams: BothOutwardCam,
} }
/// Flag to pass to [Camera::flip_image] /// Flag to pass to [`Camera::flip_image`]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum FlipMode { pub enum FlipMode {
@ -30,7 +30,7 @@ pub enum FlipMode {
Reverse = ctru_sys::FLIP_REVERSE, Reverse = ctru_sys::FLIP_REVERSE,
} }
/// Flag to pass to [Camera::set_view_size] /// Flag to pass to [`Camera::set_view_size`]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum ViewSize { pub enum ViewSize {
@ -47,7 +47,7 @@ pub enum ViewSize {
DSX4 = ctru_sys::SIZE_DS_LCDx4, DSX4 = ctru_sys::SIZE_DS_LCDx4,
} }
/// Flag to pass to [Camera::set_frame_rate] /// Flag to pass to [`Camera::set_frame_rate`]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum FrameRate { pub enum FrameRate {
@ -66,8 +66,8 @@ pub enum FrameRate {
Fps30To10 = ctru_sys::FRAME_RATE_30_TO_10, Fps30To10 = ctru_sys::FRAME_RATE_30_TO_10,
} }
/// 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`]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum WhiteBalance { pub enum WhiteBalance {
@ -85,7 +85,7 @@ pub enum WhiteBalance {
Temp7000K = ctru_sys::WHITE_BALANCE_7000K, Temp7000K = ctru_sys::WHITE_BALANCE_7000K,
} }
/// Flag to pass to [Camera::set_photo_mode] /// Flag to pass to [`Camera::set_photo_mode`]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum PhotoMode { pub enum PhotoMode {
@ -96,7 +96,7 @@ pub enum PhotoMode {
Letter = ctru_sys::PHOTO_MODE_LETTER, Letter = ctru_sys::PHOTO_MODE_LETTER,
} }
/// Flag to pass to [Camera::set_effect] /// Flag to pass to [`Camera::set_effect`]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum Effect { pub enum Effect {
@ -108,7 +108,7 @@ pub enum Effect {
Sepia01 = ctru_sys::EFFECT_SEPIA01, Sepia01 = ctru_sys::EFFECT_SEPIA01,
} }
/// Flag to pass to [Camera::set_contrast] /// Flag to pass to [`Camera::set_contrast`]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum Contrast { pub enum Contrast {
@ -120,7 +120,7 @@ pub enum Contrast {
High = ctru_sys::CONTRAST_HIGH, High = ctru_sys::CONTRAST_HIGH,
} }
/// Flag to pass to [Camera::set_lens_correction] /// Flag to pass to [`Camera::set_lens_correction`]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum LensCorrection { pub enum LensCorrection {
@ -129,7 +129,7 @@ pub enum LensCorrection {
Bright = ctru_sys::LENS_CORRECTION_BRIGHT, Bright = ctru_sys::LENS_CORRECTION_BRIGHT,
} }
/// Flag to pass to [Camera::set_output_format] /// Flag to pass to [`Camera::set_output_format`]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum OutputFormat { pub enum OutputFormat {
@ -137,7 +137,7 @@ pub enum OutputFormat {
Rgb565 = ctru_sys::OUTPUT_RGB_565, Rgb565 = ctru_sys::OUTPUT_RGB_565,
} }
/// Flag to pass to [Cam::play_shutter_sound] /// Flag to pass to [`Cam::play_shutter_sound`]
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)] #[repr(u32)]
pub enum ShutterSound { pub enum ShutterSound {
@ -168,7 +168,7 @@ impl TryFrom<OutputFormat> for FramebufferFormat {
} }
} }
/// Struct containing coordinates passed to [Camera::set_trimming_params]. /// Struct containing coordinates passed to [`Camera::set_trimming_params`].
#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct TrimmingParams { pub struct TrimmingParams {
x_start: i16, x_start: i16,
@ -178,7 +178,7 @@ pub struct TrimmingParams {
} }
impl TrimmingParams { impl TrimmingParams {
/// Creates a new [CamTrimmingParams] and guarantees the start coordinates are less than or /// Creates a new [`TrimmingParams`] and guarantees the start coordinates are less than or
/// equal to the end coordinates. /// equal to the end coordinates.
/// ///
/// `x_start <= x_end && y_start <= y_end` /// `x_start <= x_end && y_start <= y_end`
@ -296,7 +296,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`]
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))?;
@ -313,7 +313,7 @@ pub trait Camera {
} }
} }
/// Sets trimming parameters based on coordinates specified inside a [TrimmingParams] /// Sets trimming parameters based on coordinates specified inside a [`TrimmingParams`]
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(
@ -327,7 +327,7 @@ pub trait Camera {
} }
} }
/// Returns the [TrimmingParams] set /// Returns the [`TrimmingParams`] set
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;
@ -381,7 +381,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
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(
@ -392,7 +392,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
fn set_white_balance_without_base_up( fn set_white_balance_without_base_up(
&mut self, &mut self,
@ -461,7 +461,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
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(
@ -507,7 +507,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.
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(
@ -519,7 +519,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.
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(
@ -530,7 +530,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.
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(
@ -541,9 +541,9 @@ 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 [CamEffect] /// Multiple effects can be set at once by combining the bitflags of [`Effect`]
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(
@ -555,7 +555,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.
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(
@ -566,7 +566,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.
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(
@ -577,7 +577,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.
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(
@ -652,7 +652,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
fn set_image_quality_calibration_data( fn set_image_quality_calibration_data(
&mut self, &mut self,
data: ImageQualityCalibrationData, data: ImageQualityCalibrationData,
@ -663,7 +663,7 @@ pub trait Camera {
} }
} }
/// Returns the current [ImageQualityCalibrationData] for the camera /// Returns the current [`ImageQualityCalibrationData`] for the camera
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();
@ -783,7 +783,7 @@ impl Cam {
} }
} }
/// Plays the specified sound based on the [ShutterSound] argument /// Plays the specified sound based on the [`ShutterSound`] argument
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()))?;

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

@ -183,36 +183,26 @@ pub struct File {
/// Metadata information about a file. /// Metadata information about a file.
/// ///
/// This structure is returned from the [`metadata`] function and /// This structure is returned from the [`File::metadata`] function and
/// represents known metadata about a file. /// represents known metadata about a file.
///
/// [`metadata`]: fn.metadata.html
pub struct Metadata { pub struct Metadata {
attributes: u32, attributes: u32,
size: u64, size: u64,
} }
/// Options and flags which can be used to configure how a [`File`] is opened. /// Options and flags which can be used to configure how a [`File`] is opened.
/// This builder exposes the ability to configure how a `File` is opened /// This builder exposes the ability to configure how a [`File`] is opened
/// and what operations are permitted on the open file. The [`File::open`] /// and what operations are permitted on the open file. The [`File::open`]
/// and [`File::create`] methods are aliases for commonly used options /// and [`File::create`] methods are aliases for commonly used options
/// using this builder. /// using this builder.
/// ///
/// [`File`]: struct.File.html /// Generally speaking, when using [`OpenOptions`], you'll first call [`OpenOptions::new`],
/// [`File::open`]: struct.File.html#method.open /// then chain calls to methods to set each option, then call [`OpenOptions::open`],
/// [`File::create`]: struct.File.html#method.create
///
/// Generally speaking, when using `OpenOptions`, you'll first call [`new()`],
/// then chain calls to methods to set each option, then call [`open()`],
/// passing the path of the file you're trying to open. /// passing the path of the file you're trying to open.
/// ///
/// It is required to also pass a reference to the [`Archive`] that the /// It is required to also pass a reference to the [`Archive`] that the
/// file lives in. /// file lives in.
/// ///
/// [`new()`]: struct.OpenOptions.html#method.new
/// [`open()`]: struct.OpenOptions.html#method.open
/// [`Archive`]: struct.Archive.html
///
/// # Examples /// # Examples
/// ///
/// Opening a file to read: /// Opening a file to read:
@ -257,14 +247,11 @@ pub struct OpenOptions {
/// Iterator over the entries in a directory. /// Iterator over the entries in a directory.
/// ///
/// This iterator is returned from the [`read_dir`] function of this module and /// This iterator is returned from the [`File::read_dir`] function of this module and
/// will yield instances of `Result<DirEntry, i32>`. Through a [`DirEntry`] /// will yield instances of `Result<DirEntry, i32>`. Through a [`DirEntry`]
/// information like the entry's path and possibly other metadata can be /// information like the entry's path and possibly other metadata can be
/// learned. /// learned.
/// ///
/// [`read_dir`]: fn.read_dir.html
/// [`DirEntry`]: struct.DirEntry.html
///
/// # Errors /// # Errors
/// ///
/// This Result will return Err if there's some sort of intermittent IO error /// This Result will return Err if there's some sort of intermittent IO error
@ -277,8 +264,6 @@ pub struct ReadDir<'a> {
/// Entries returned by the [`ReadDir`] iterator. /// Entries returned by the [`ReadDir`] iterator.
/// ///
/// [`ReadDir`]: struct.ReadDir.html
///
/// An instance of `DirEntry` represents an entry inside of a directory on the /// An instance of `DirEntry` represents an entry inside of a directory on the
/// 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.
@ -338,8 +323,6 @@ impl Fs {
impl Archive { impl Archive {
/// Retrieves an Archive's [`ArchiveID`] /// Retrieves an Archive's [`ArchiveID`]
///
/// [`ArchiveID`]: enum.ArchiveID.html
pub fn id(&self) -> ArchiveID { pub fn id(&self) -> ArchiveID {
self.id self.id
} }
@ -355,8 +338,6 @@ impl File {
/// This function will return an error if `path` does not already exit. /// This function will return an error if `path` does not already exit.
/// Other errors may also be returned accoridng to [`OpenOptions::open`] /// Other errors may also be returned accoridng to [`OpenOptions::open`]
/// ///
/// [`OpenOptions::open`]: struct.OpenOptions.html#method.open
///
/// # Examples /// # Examples
/// ///
/// ```no_run /// ```no_run
@ -382,9 +363,7 @@ impl File {
/// # Errors /// # Errors
/// ///
/// This function will return an error if `path` does not already exit. /// This function will return an error if `path` does not already exit.
/// Other errors may also be returned accoridng to [`OpenOptions::create`] /// Other errors may also be returned accoridng to [`OpenOptions::create`].
///
/// [`OpenOptions::create`]: struct.OpenOptions.html#method.create
/// ///
/// # Examples /// # Examples
/// ///
@ -597,8 +576,6 @@ 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.
///
/// [`Archive`]: struct.Archive.html
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())
} }
@ -901,7 +878,6 @@ fn to_utf16(path: &Path) -> WideCString {
WideCString::from_str(path).unwrap() WideCString::from_str(path).unwrap()
} }
// Adapted from sys/windows/fs.rs in libstd
fn truncate_utf16_at_nul(v: &[u16]) -> &[u16] { fn truncate_utf16_at_nul(v: &[u16]) -> &[u16] {
match v.iter().position(|c| *c == 0) { match v.iter().position(|c| *c == 0) {
// don't include the 0 // don't include the 0
@ -910,8 +886,6 @@ fn truncate_utf16_at_nul(v: &[u16]) -> &[u16] {
} }
} }
// Copied from sys/common/io.rs in libstd
// Provides read_to_end functionality over an uninitialized buffer. // Provides read_to_end functionality over an uninitialized buffer.
// This function is unsafe because it calls the underlying // This function is unsafe because it calls the underlying
// read function with a slice into uninitialized memory. The default // read function with a slice into uninitialized memory. The default

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

@ -90,14 +90,10 @@ pub trait Swap: private::Sealed {
/// Swaps the video buffers. /// Swaps the video buffers.
/// ///
/// If double buffering is disabled, "swapping" the buffers has the side effect /// If double buffering is disabled, "swapping" the buffers has the side effect
/// of committing any configuration changes to the buffers (e.g. [`set_wide_mode`], /// of committing any configuration changes to the buffers (e.g. [`TopScreen::set_wide_mode`],
/// [`set_framebuffer_format`], [`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.
///
/// [`set_wide_mode`]: TopScreen::set_wide_mode
/// [`set_framebuffer_format`]: Screen::set_framebuffer_format
/// [`set_double_buffering`]: Screen::set_double_buffering
fn swap_buffers(&mut self); fn swap_buffers(&mut self);
} }
@ -213,9 +209,12 @@ pub struct Gfx {
static GFX_ACTIVE: Mutex<usize> = Mutex::new(0); static GFX_ACTIVE: Mutex<usize> = Mutex::new(0);
impl Gfx { impl Gfx {
/// Creates a new [Gfx] instance with default init values /// Creates a new [`Gfx`] instance with default init values
/// It's the same as calling: /// It's the same as calling:
/// `Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false)` ///
/// ```
/// Gfx::with_formats(FramebufferFormat::Bgr8, FramebufferFormat::Bgr8, false)
/// ```
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)
} }

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

@ -204,8 +204,8 @@ impl Channel<'_> {
/// ///
/// # Warning /// # Warning
/// ///
/// `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.
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)),
@ -222,7 +222,7 @@ impl Channel<'_> {
/// Functions to handle audio filtering. /// Functions to handle audio filtering.
/// ///
/// 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.
pub fn iir_mono_set_enabled(&mut self, enable: bool) { pub fn iir_mono_set_enabled(&mut self, enable: bool) {
@ -314,7 +314,7 @@ impl AudioFormat {
} }
impl AudioMix { impl AudioMix {
/// Creates a new [AudioMix] with all volumes set to 0. /// Creates a new [`AudioMix`] with all volumes set to 0.
pub fn zeroed() -> Self { pub fn zeroed() -> Self {
Self { raw: [0.; 12] } Self { raw: [0.; 12] }
} }
@ -365,8 +365,8 @@ impl AudioMix {
/// ///
/// # Notes /// # Notes
/// ///
/// [Channel] will normalize the mix values to be within 0 and 1. /// [`Channel`] will normalize the mix values to be within 0 and 1.
/// However, an [AudioMix] instance with larger/smaller values is valid. /// However, an [`AudioMix`] instance with larger/smaller values is valid.
pub fn set_front(&mut self, left: f32, right: f32) { pub fn set_front(&mut self, left: f32, right: f32) {
self.raw[0] = left; self.raw[0] = left;
self.raw[1] = right; self.raw[1] = right;
@ -376,8 +376,8 @@ impl AudioMix {
/// ///
/// # Notes /// # Notes
/// ///
/// [Channel] will normalize the mix values to be within 0 and 1. /// [`Channel`] will normalize the mix values to be within 0 and 1.
/// However, an [AudioMix] instance with larger/smaller values is valid. /// However, an [`AudioMix`] instance with larger/smaller values is valid.
pub fn set_back(&mut self, left: f32, right: f32) { pub fn set_back(&mut self, left: f32, right: f32) {
self.raw[2] = left; self.raw[2] = left;
self.raw[3] = right; self.raw[3] = right;
@ -387,8 +387,8 @@ impl AudioMix {
/// ///
/// # Notes /// # Notes
/// ///
/// [Channel] will normalize the mix values to be within 0 and 1. /// [`Channel`] will normalize the mix values to be within 0 and 1.
/// However, an [AudioMix] instance with larger/smaller values is valid. /// However, an [`AudioMix`] instance with larger/smaller values is valid.
pub fn set_aux_front(&mut self, left: f32, right: f32, id: usize) { pub fn set_aux_front(&mut self, left: f32, right: f32, id: usize) {
if id > 1 { if id > 1 {
panic!("invalid auxiliary output device index") panic!("invalid auxiliary output device index")
@ -404,8 +404,8 @@ impl AudioMix {
/// ///
/// # Notes /// # Notes
/// ///
/// [Channel] will normalize the mix values to be within 0 and 1. /// [`Channel`] will normalize the mix values to be within 0 and 1.
/// However, an [AudioMix] instance with larger/smaller values is valid. /// However, an [`AudioMix`] instance with larger/smaller values is valid.
pub fn set_aux_back(&mut self, left: f32, right: f32, id: usize) { pub fn set_aux_back(&mut self, left: f32, right: f32, id: usize) {
if id > 1 { if id > 1 {
panic!("invalid auxiliary output device index") panic!("invalid auxiliary output device index")
@ -418,7 +418,7 @@ impl AudioMix {
} }
} }
/// Returns an [AudioMix] object with "front left" and "front right" volumes set to 100%, and all other volumes set to 0%. /// Returns an [`AudioMix`] object with "front left" and "front right" volumes set to 100%, and all other volumes set to 0%.
impl Default for AudioMix { impl Default for AudioMix {
fn default() -> Self { fn default() -> Self {
let mut mix = AudioMix::zeroed(); let mut mix = AudioMix::zeroed();

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

@ -1,7 +1,7 @@
use super::{AudioFormat, NdspError}; use super::{AudioFormat, NdspError};
use crate::linear::LinearAllocator; use crate::linear::LinearAllocator;
/// Informational struct holding the raw audio data and playback info. This corresponds to [ctru_sys::ndspWaveBuf]. /// Informational struct holding the raw audio data and playback info. This corresponds to [`ctru_sys::ndspWaveBuf`].
pub struct Wave { pub struct Wave {
/// Data block of the audio wave (and its format information). /// Data block of the audio wave (and its format information).
buffer: Box<[u8], LinearAllocator>, buffer: Box<[u8], LinearAllocator>,
@ -13,7 +13,7 @@ pub struct Wave {
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u8)] #[repr(u8)]
/// Enum representing the playback status of a [Wave]. /// Enum representing the playback status of a [`Wave`].
pub enum WaveStatus { pub enum WaveStatus {
Free = ctru_sys::NDSP_WBUF_FREE as u8, Free = ctru_sys::NDSP_WBUF_FREE as u8,
Queued = ctru_sys::NDSP_WBUF_QUEUED as u8, Queued = ctru_sys::NDSP_WBUF_QUEUED as u8,
@ -69,7 +69,7 @@ impl Wave {
/// ///
/// # Errors /// # Errors
/// ///
/// This function will return an error if the [Wave] is currently busy, /// This function will return an error if the [`Wave`] is currently busy,
/// with the id to the channel in which it's queued. /// with the id to the channel in which it's queued.
pub fn get_buffer_mut(&mut self) -> Result<&mut [u8], NdspError> { pub fn get_buffer_mut(&mut self) -> Result<&mut [u8], NdspError> {
match self.status() { match self.status() {
@ -89,7 +89,7 @@ impl Wave {
/// ///
/// # Notes /// # Notes
/// ///
/// This value varies depending on [Self::set_sample_count]. /// This value varies depending on [`Wave::set_sample_count`].
pub fn sample_count(&self) -> usize { pub fn sample_count(&self) -> usize {
self.raw_data.nsamples as usize self.raw_data.nsamples as usize
} }
@ -117,7 +117,7 @@ impl Wave {
/// # Errors /// # Errors
/// ///
/// This function will return an error if the sample size exceeds the buffer's capacity /// This function will return an error if the sample size exceeds the buffer's capacity
/// or if the [Wave] is currently queued. /// or if the [`Wave`] is currently queued.
pub fn set_sample_count(&mut self, sample_count: usize) -> Result<(), NdspError> { pub fn set_sample_count(&mut self, sample_count: usize) -> Result<(), NdspError> {
match self.status() { match self.status() {
WaveStatus::Playing | WaveStatus::Queued => { WaveStatus::Playing | WaveStatus::Queued => {

Loading…
Cancel
Save