Browse Source

Fix enum conversion

pull/107/head
Andrea Ciliberti 2 years ago
parent
commit
55ed7cc5f8
  1. 27
      ctru-rs/src/applets/swkbd.rs
  2. 40
      ctru-rs/src/lib.rs
  3. 8
      ctru-rs/src/services/am.rs
  4. 33
      ctru-rs/src/services/cam.rs
  5. 10
      ctru-rs/src/services/cfgu.rs
  6. 45
      ctru-rs/src/services/fs.rs
  7. 9
      ctru-rs/src/services/gfx.rs
  8. 31
      ctru-rs/src/services/gspgpu.rs
  9. 10
      ctru-rs/src/services/ndsp/mod.rs
  10. 3
      ctru-rs/src/services/ps.rs

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

@ -213,26 +213,7 @@ impl Default for Swkbd { @@ -213,26 +213,7 @@ impl Default for Swkbd {
}
}
impl From<Kind> for u32 {
fn from(value: Kind) -> Self {
value as u32
}
}
impl From<Button> for u32 {
fn from(value: Button) -> Self {
value as u32
}
}
impl From<Error> for u32 {
fn from(value: Error) -> Self {
value as u32
}
}
impl From<ValidInput> for i32 {
fn from(value: ValidInput) -> Self {
value as i32
}
}
from_type_to_u32!(Kind);
from_type_to_u32!(Button);
from_type_to_u32!(Error);
from_type_to_i32!(ValidInput);

40
ctru-rs/src/lib.rs

@ -15,6 +15,46 @@ extern crate pthread_3ds; @@ -15,6 +15,46 @@ extern crate pthread_3ds;
#[cfg(feature = "big-stack")]
static __stacksize__: usize = 2 * 1024 * 1024; // 2MB
macro_rules! from_type_to_u8 {
($from_type:ty) => {
impl From<$from_type> for u8 {
fn from(v: $from_type) -> Self {
v as u8
}
}
};
}
macro_rules! from_type_to_u16 {
($from_type:ty) => {
impl From<$from_type> for u16 {
fn from(v: $from_type) -> Self {
v as u16
}
}
};
}
macro_rules! from_type_to_u32 {
($from_type:ty) => {
impl From<$from_type> for u32 {
fn from(v: $from_type) -> Self {
v as u32
}
}
};
}
macro_rules! from_type_to_i32 {
($from_type:ty) => {
impl From<$from_type> for i32 {
fn from(v: $from_type) -> Self {
v as i32
}
}
};
}
/// Activate the default panic handler.
///
/// With this implementation, the main thread will stop and try to print debug info to an available [console::Console].

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

@ -34,7 +34,7 @@ impl<'a> Title<'a> { @@ -34,7 +34,7 @@ impl<'a> Title<'a> {
unsafe {
ResultCode(ctru_sys::AM_GetTitleProductCode(
self.mediatype as u32,
self.mediatype.into(),
self.id,
buf.as_mut_ptr(),
))?;
@ -47,7 +47,7 @@ impl<'a> Title<'a> { @@ -47,7 +47,7 @@ impl<'a> Title<'a> {
unsafe {
ResultCode(ctru_sys::AM_GetTitleInfo(
self.mediatype as u32,
self.mediatype.into(),
1,
&mut self.id.clone(),
info.as_mut_ptr() as _,
@ -71,7 +71,7 @@ impl Am { @@ -71,7 +71,7 @@ impl Am {
pub fn get_title_count(&self, mediatype: FsMediaType) -> crate::Result<u32> {
unsafe {
let mut count = 0;
ResultCode(ctru_sys::AM_GetTitleCount(mediatype as u32, &mut count))?;
ResultCode(ctru_sys::AM_GetTitleCount(mediatype.into(), &mut count))?;
Ok(count)
}
}
@ -83,7 +83,7 @@ impl Am { @@ -83,7 +83,7 @@ impl Am {
unsafe {
ResultCode(ctru_sys::AM_GetTitleList(
&mut read_amount,
mediatype as u32,
mediatype.into(),
count,
buf.as_mut_ptr(),
))?;

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

@ -382,7 +382,7 @@ pub trait Camera { @@ -382,7 +382,7 @@ pub trait Camera {
unsafe {
ResultCode(ctru_sys::CAMU_SetWhiteBalance(
self.camera_as_raw(),
white_balance as u32,
white_balance.into(),
))?;
Ok(())
}
@ -397,7 +397,7 @@ pub trait Camera { @@ -397,7 +397,7 @@ pub trait Camera {
unsafe {
ResultCode(ctru_sys::CAMU_SetWhiteBalanceWithoutBaseUp(
self.camera_as_raw(),
white_balance as u32,
white_balance.into(),
))?;
Ok(())
}
@ -462,7 +462,7 @@ pub trait Camera { @@ -462,7 +462,7 @@ pub trait Camera {
unsafe {
ResultCode(ctru_sys::CAMU_FlipImage(
self.camera_as_raw(),
flip as u32,
flip.into(),
ctru_sys::CONTEXT_A,
))?;
Ok(())
@ -508,7 +508,7 @@ pub trait Camera { @@ -508,7 +508,7 @@ pub trait Camera {
unsafe {
ResultCode(ctru_sys::CAMU_SetSize(
self.camera_as_raw(),
size as u32,
size.into(),
ctru_sys::CONTEXT_A,
))?;
Ok(())
@ -520,7 +520,7 @@ pub trait Camera { @@ -520,7 +520,7 @@ pub trait Camera {
unsafe {
ResultCode(ctru_sys::CAMU_SetFrameRate(
self.camera_as_raw(),
frame_rate as u32,
frame_rate.into(),
))?;
Ok(())
}
@ -531,7 +531,7 @@ pub trait Camera { @@ -531,7 +531,7 @@ pub trait Camera {
unsafe {
ResultCode(ctru_sys::CAMU_SetPhotoMode(
self.camera_as_raw(),
photo_mode as u32,
photo_mode.into(),
))?;
Ok(())
}
@ -544,7 +544,7 @@ pub trait Camera { @@ -544,7 +544,7 @@ pub trait Camera {
unsafe {
ResultCode(ctru_sys::CAMU_SetEffect(
self.camera_as_raw(),
effect as u32,
effect.into(),
ctru_sys::CONTEXT_A,
))?;
Ok(())
@ -556,7 +556,7 @@ pub trait Camera { @@ -556,7 +556,7 @@ pub trait Camera {
unsafe {
ResultCode(ctru_sys::CAMU_SetContrast(
self.camera_as_raw(),
contrast as u32,
contrast.into(),
))?;
Ok(())
}
@ -567,7 +567,7 @@ pub trait Camera { @@ -567,7 +567,7 @@ pub trait Camera {
unsafe {
ResultCode(ctru_sys::CAMU_SetLensCorrection(
self.camera_as_raw(),
lens_correction as u32,
lens_correction.into(),
))?;
Ok(())
}
@ -578,7 +578,7 @@ pub trait Camera { @@ -578,7 +578,7 @@ pub trait Camera {
unsafe {
ResultCode(ctru_sys::CAMU_SetOutputFormat(
self.camera_as_raw(),
format as u32,
format.into(),
ctru_sys::CONTEXT_A,
))?;
Ok(())
@ -782,7 +782,7 @@ impl Cam { @@ -782,7 +782,7 @@ impl Cam {
/// Plays the specified sound based on the [ShutterSound] argument
pub fn play_shutter_sound(&self, sound: ShutterSound) -> crate::Result<()> {
unsafe {
ResultCode(ctru_sys::CAMU_PlayShutterSound(sound as u32))?;
ResultCode(ctru_sys::CAMU_PlayShutterSound(sound.into()))?;
Ok(())
}
}
@ -793,3 +793,14 @@ impl Drop for Cam { @@ -793,3 +793,14 @@ impl Drop for Cam {
unsafe { ctru_sys::camExit() };
}
}
from_type_to_u32!(FlipMode);
from_type_to_u32!(ViewSize);
from_type_to_u32!(FrameRate);
from_type_to_u32!(WhiteBalance);
from_type_to_u32!(PhotoMode);
from_type_to_u32!(Effect);
from_type_to_u32!(Contrast);
from_type_to_u32!(LensCorrection);
from_type_to_u32!(OutputFormat);
from_type_to_u32!(ShutterSound);

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

@ -115,16 +115,6 @@ impl Drop for Cfgu { @@ -115,16 +115,6 @@ impl Drop for Cfgu {
}
}
macro_rules! from_type_to_u8 {
($from_type:ty) => {
impl From<$from_type> for u8 {
fn from(v: $from_type) -> Self {
v as u8
}
}
};
}
from_type_to_u8!(Region);
from_type_to_u8!(Language);
from_type_to_u8!(SystemModel);

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

@ -1018,45 +1018,6 @@ impl Drop for Dir { @@ -1018,45 +1018,6 @@ impl Drop for Dir {
}
}
impl From<PathType> for ctru_sys::FS_PathType {
fn from(p: PathType) -> Self {
use self::PathType::*;
match p {
Invalid => ctru_sys::PATH_INVALID,
Empty => ctru_sys::PATH_EMPTY,
Binary => ctru_sys::PATH_BINARY,
ASCII => ctru_sys::PATH_ASCII,
UTF16 => ctru_sys::PATH_UTF16,
}
}
}
impl From<ArchiveID> for ctru_sys::FS_ArchiveID {
fn from(a: ArchiveID) -> Self {
use self::ArchiveID::*;
match a {
RomFS => ctru_sys::ARCHIVE_ROMFS,
Savedata => ctru_sys::ARCHIVE_SAVEDATA,
Extdata => ctru_sys::ARCHIVE_EXTDATA,
SharedExtdata => ctru_sys::ARCHIVE_SHARED_EXTDATA,
SystemSavedata => ctru_sys::ARCHIVE_SYSTEM_SAVEDATA,
Sdmc => ctru_sys::ARCHIVE_SDMC,
SdmcWriteOnly => ctru_sys::ARCHIVE_SDMC_WRITE_ONLY,
BossExtdata => ctru_sys::ARCHIVE_BOSS_EXTDATA,
CardSpiFS => ctru_sys::ARCHIVE_CARD_SPIFS,
ExtDataAndBossExtdata => ctru_sys::ARCHIVE_EXTDATA_AND_BOSS_EXTDATA,
SystemSaveData2 => ctru_sys::ARCHIVE_SYSTEM_SAVEDATA2,
NandRW => ctru_sys::ARCHIVE_NAND_RW,
NandRO => ctru_sys::ARCHIVE_NAND_RO,
NandROWriteAccess => ctru_sys::ARCHIVE_NAND_RO_WRITE_ACCESS,
SaveDataAndContent => ctru_sys::ARCHIVE_SAVEDATA_AND_CONTENT,
SaveDataAndContent2 => ctru_sys::ARCHIVE_SAVEDATA_AND_CONTENT2,
NandCtrFS => ctru_sys::ARCHIVE_NAND_CTR_FS,
TwlPhoto => ctru_sys::ARCHIVE_TWL_PHOTO,
NandTwlFS => ctru_sys::ARCHIVE_NAND_TWL_FS,
GameCardSavedata => ctru_sys::ARCHIVE_GAMECARD_SAVEDATA,
UserSavedata => ctru_sys::ARCHIVE_USER_SAVEDATA,
DemoSavedata => ctru_sys::ARCHIVE_DEMO_SAVEDATA,
}
}
}
from_type_to_u32!(FsMediaType);
from_type_to_u32!(PathType);
from_type_to_u32!(ArchiveID);

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

@ -283,14 +283,7 @@ impl Screen for BottomScreen { @@ -283,14 +283,7 @@ impl Screen for BottomScreen {
}
}
impl From<Side> for ctru_sys::gfx3dSide_t {
fn from(s: Side) -> ctru_sys::gfx3dSide_t {
match s {
Side::Left => ctru_sys::GFX_LEFT,
Side::Right => ctru_sys::GFX_RIGHT,
}
}
}
from_type_to_u32!(Side);
#[cfg(test)]
mod tests {

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

@ -1,7 +1,5 @@ @@ -1,7 +1,5 @@
//! GSPGPU service
use std::convert::From;
#[derive(Copy, Clone, Debug)]
#[repr(u32)]
pub enum Event {
@ -67,30 +65,5 @@ impl From<ctru_sys::GSPGPU_FramebufferFormat> for FramebufferFormat { @@ -67,30 +65,5 @@ impl From<ctru_sys::GSPGPU_FramebufferFormat> for FramebufferFormat {
}
}
impl From<FramebufferFormat> for ctru_sys::GSPGPU_FramebufferFormat {
fn from(g: FramebufferFormat) -> Self {
use self::FramebufferFormat::*;
match g {
Rgba8 => ctru_sys::GSP_RGBA8_OES,
Bgr8 => ctru_sys::GSP_BGR8_OES,
Rgb565 => ctru_sys::GSP_RGB565_OES,
Rgb5A1 => ctru_sys::GSP_RGB5_A1_OES,
Rgba4 => ctru_sys::GSP_RGBA4_OES,
}
}
}
impl From<Event> for ctru_sys::GSPGPU_Event {
fn from(ev: Event) -> Self {
use self::Event::*;
match ev {
Psc0 => ctru_sys::GSPGPU_EVENT_PSC0,
Psc1 => ctru_sys::GSPGPU_EVENT_PSC1,
VBlank0 => ctru_sys::GSPGPU_EVENT_VBlank0,
VBlank1 => ctru_sys::GSPGPU_EVENT_VBlank1,
PPF => ctru_sys::GSPGPU_EVENT_PPF,
P3D => ctru_sys::GSPGPU_EVENT_P3D,
DMA => ctru_sys::GSPGPU_EVENT_DMA,
}
}
}
from_type_to_u32!(FramebufferFormat);
from_type_to_u32!(Event);

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

@ -115,7 +115,7 @@ impl Ndsp { @@ -115,7 +115,7 @@ impl Ndsp {
/// Set the audio output mode. Defaults to `OutputMode::Stereo`.
pub fn set_output_mode(&mut self, mode: OutputMode) {
unsafe { ctru_sys::ndspSetOutputMode(mode as u32) };
unsafe { ctru_sys::ndspSetOutputMode(mode.into()) };
}
}
@ -163,12 +163,12 @@ impl Channel<'_> { @@ -163,12 +163,12 @@ impl Channel<'_> {
/// Set the channel's output format.
/// Change this setting based on the used sample's format.
pub fn set_format(&self, format: AudioFormat) {
unsafe { ctru_sys::ndspChnSetFormat(self.id.into(), format as u16) };
unsafe { ctru_sys::ndspChnSetFormat(self.id.into(), format.into()) };
}
/// Set the channel's interpolation mode.
pub fn set_interpolation(&self, interp_type: InterpolationType) {
unsafe { ctru_sys::ndspChnSetInterp(self.id.into(), interp_type as u32) };
unsafe { ctru_sys::ndspChnSetInterp(self.id.into(), interp_type.into()) };
}
/// Set the channel's volume mix.
@ -340,3 +340,7 @@ impl Drop for Ndsp { @@ -340,3 +340,7 @@ impl Drop for Ndsp {
}
}
}
from_type_to_u32!(InterpolationType);
from_type_to_u32!(OutputMode);
from_type_to_u16!(AudioFormat);

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

@ -70,6 +70,9 @@ impl Drop for Ps { @@ -70,6 +70,9 @@ impl Drop for Ps {
}
}
from_type_to_u32!(AESAlgorithm);
from_type_to_u32!(AESKeyType);
#[cfg(test)]
mod tests {
use std::collections::HashMap;

Loading…
Cancel
Save