Browse Source

More modules starndardised

pull/107/head
Andrea Ciliberti 2 years ago
parent
commit
43b83b5356
  1. 10
      ctru-rs/examples/audio-filters.rs
  2. 10
      ctru-rs/examples/buttons.rs
  3. 4
      ctru-rs/examples/camera-image.rs
  4. 12
      ctru-rs/examples/file-explorer.rs
  5. 4
      ctru-rs/examples/gfx-3d-mode.rs
  6. 4
      ctru-rs/examples/gfx-wide-mode.rs
  7. 2
      ctru-rs/examples/graphics-bitmap.rs
  8. 2
      ctru-rs/examples/hashmaps.rs
  9. 2
      ctru-rs/examples/hello-both-screens.rs
  10. 2
      ctru-rs/examples/hello-world.rs
  11. 2
      ctru-rs/examples/linear-memory.rs
  12. 2
      ctru-rs/examples/mii-selector.rs
  13. 2
      ctru-rs/examples/network-sockets.rs
  14. 2
      ctru-rs/examples/output-3dslink.rs
  15. 2
      ctru-rs/examples/romfs.rs
  16. 4
      ctru-rs/examples/software-keyboard.rs
  17. 2
      ctru-rs/examples/system-configuration.rs
  18. 2
      ctru-rs/examples/time-rtc.rs
  19. 8
      ctru-rs/examples/title-info.rs
  20. 6
      ctru-rs/src/lib.rs
  21. 58
      ctru-rs/src/services/fs.rs
  22. 56
      ctru-rs/src/services/hid.rs
  23. 32
      ctru-rs/src/services/ps.rs
  24. 8
      ctru-rs/src/services/soc.rs
  25. 4
      ctru-rs/src/services/sslc.rs
  26. 2
      ctru-rs/src/test_runner.rs

10
ctru-rs/examples/audio-filters.rs

@ -102,23 +102,23 @@ fn main() { @@ -102,23 +102,23 @@ fn main() {
hid.scan_input();
let keys_down = hid.keys_down();
if keys_down.contains(KeyPad::KEY_START) {
if keys_down.contains(KeyPad::START) {
break;
} // break in order to return to hbmenu
if keys_down.intersects(KeyPad::KEY_DOWN) {
if keys_down.intersects(KeyPad::DOWN) {
note = note.saturating_sub(1);
} else if keys_down.intersects(KeyPad::KEY_UP) {
} else if keys_down.intersects(KeyPad::UP) {
note = std::cmp::min(note + 1, NOTEFREQ.len() - 1);
}
let mut update_params = false;
if keys_down.intersects(KeyPad::KEY_LEFT) {
if keys_down.intersects(KeyPad::LEFT) {
filter -= 1;
filter = filter.rem_euclid(filter_names.len() as _);
update_params = true;
} else if keys_down.intersects(KeyPad::KEY_RIGHT) {
} else if keys_down.intersects(KeyPad::RIGHT) {
filter += 1;
filter = filter.rem_euclid(filter_names.len() as _);

10
ctru-rs/examples/buttons.rs

@ -42,19 +42,19 @@ fn main() { @@ -42,19 +42,19 @@ fn main() {
// You can also use the .bits() method to do direct comparisons on
// the underlying bits
if keys.contains(KeyPad::KEY_A) {
if keys.contains(KeyPad::A) {
println!("You held A!");
}
if keys.bits() & KeyPad::KEY_B.bits() != 0 {
if keys.bits() & KeyPad::B.bits() != 0 {
println!("You held B!");
}
if keys.contains(KeyPad::KEY_X | KeyPad::KEY_Y) {
if keys.contains(KeyPad::X | KeyPad::Y) {
println!("You held X and Y!");
}
if keys.intersects(KeyPad::KEY_L | KeyPad::KEY_R | KeyPad::KEY_ZL | KeyPad::KEY_ZR) {
if keys.intersects(KeyPad::L | KeyPad::R | KeyPad::ZL | KeyPad::ZR) {
println!("You held a shoulder button!");
}
if keys.intersects(KeyPad::KEY_START) {
if keys.intersects(KeyPad::START) {
println!("See ya!");
break;
}

4
ctru-rs/examples/camera-image.rs

@ -65,11 +65,11 @@ fn main() { @@ -65,11 +65,11 @@ fn main() {
hid.scan_input();
keys_down = hid.keys_down();
if keys_down.contains(KeyPad::KEY_START) {
if keys_down.contains(KeyPad::START) {
break;
}
if keys_down.contains(KeyPad::KEY_R) {
if keys_down.contains(KeyPad::R) {
println!("Capturing new image");
let camera = &mut cam.outer_right_cam;

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

@ -56,15 +56,15 @@ impl<'a> FileExplorer<'a> { @@ -56,15 +56,15 @@ impl<'a> FileExplorer<'a> {
self.hid.scan_input();
let input = self.hid.keys_down();
if input.contains(KeyPad::KEY_START) {
if input.contains(KeyPad::START) {
break;
} else if input.contains(KeyPad::KEY_B) && self.path.components().count() > 1 {
} else if input.contains(KeyPad::B) && self.path.components().count() > 1 {
self.path.pop();
self.console.clear();
self.print_menu();
} else if input.contains(KeyPad::KEY_A) {
} else if input.contains(KeyPad::A) {
self.get_input_and_run(Self::set_next_path);
} else if input.contains(KeyPad::KEY_X) {
} else if input.contains(KeyPad::X) {
self.get_input_and_run(Self::set_exact_path);
}
@ -147,11 +147,11 @@ impl<'a> FileExplorer<'a> { @@ -147,11 +147,11 @@ impl<'a> FileExplorer<'a> {
self.hid.scan_input();
let input = self.hid.keys_down();
if input.contains(KeyPad::KEY_A) {
if input.contains(KeyPad::A) {
break;
}
if input.contains(KeyPad::KEY_START) {
if input.contains(KeyPad::START) {
self.running = false;
return;
}

4
ctru-rs/examples/gfx-3d-mode.rs

@ -31,7 +31,7 @@ fn main() { @@ -31,7 +31,7 @@ fn main() {
//Scan all the inputs. This should be done once for each frame
hid.scan_input();
if hid.keys_down().contains(KeyPad::KEY_START) {
if hid.keys_down().contains(KeyPad::START) {
break;
}
@ -44,7 +44,7 @@ fn main() { @@ -44,7 +44,7 @@ fn main() {
right_buf.ptr.copy_from(ZERO.as_ptr(), ZERO.len());
}
if hid.keys_down().contains(KeyPad::KEY_A) {
if hid.keys_down().contains(KeyPad::A) {
// flip which buffer we're writing to
current_side = match current_side {
Side::Left => Side::Right,

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

@ -13,11 +13,11 @@ fn main() { @@ -13,11 +13,11 @@ fn main() {
while apt.main_loop() {
hid.scan_input();
if hid.keys_down().contains(KeyPad::KEY_START) {
if hid.keys_down().contains(KeyPad::START) {
break;
}
if hid.keys_down().contains(KeyPad::KEY_A) {
if hid.keys_down().contains(KeyPad::A) {
drop(console);
let wide_mode = gfx.top_screen.borrow().get_wide_mode();

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

@ -43,7 +43,7 @@ fn main() { @@ -43,7 +43,7 @@ fn main() {
//Scan all the inputs. This should be done once for each frame
hid.scan_input();
if hid.keys_down().contains(KeyPad::KEY_START) {
if hid.keys_down().contains(KeyPad::START) {
break;
}

2
ctru-rs/examples/hashmaps.rs

@ -26,7 +26,7 @@ fn main() { @@ -26,7 +26,7 @@ fn main() {
gfx.wait_for_vblank();
hid.scan_input();
if hid.keys_down().contains(KeyPad::KEY_START) {
if hid.keys_down().contains(KeyPad::START) {
break;
}
}

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

@ -32,7 +32,7 @@ fn main() { @@ -32,7 +32,7 @@ fn main() {
gfx.wait_for_vblank();
hid.scan_input();
if hid.keys_down().contains(KeyPad::KEY_START) {
if hid.keys_down().contains(KeyPad::START) {
break;
}
}

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

@ -26,7 +26,7 @@ fn main() { @@ -26,7 +26,7 @@ fn main() {
//Scan all the inputs. This should be done once for each frame
hid.scan_input();
if hid.keys_down().contains(KeyPad::KEY_START) {
if hid.keys_down().contains(KeyPad::START) {
break;
}
// Flush and swap framebuffers

2
ctru-rs/examples/linear-memory.rs

@ -34,7 +34,7 @@ fn main() { @@ -34,7 +34,7 @@ fn main() {
//Scan all the inputs. This should be done once for each frame
hid.scan_input();
if hid.keys_down().contains(KeyPad::KEY_START) {
if hid.keys_down().contains(KeyPad::START) {
break;
}
// Flush and swap framebuffers

2
ctru-rs/examples/mii-selector.rs

@ -30,7 +30,7 @@ fn main() { @@ -30,7 +30,7 @@ fn main() {
//Scan all the inputs. This should be done once for each frame
hid.scan_input();
if hid.keys_down().contains(KeyPad::KEY_START) {
if hid.keys_down().contains(KeyPad::START) {
break;
}
// Flush and swap framebuffers

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

@ -61,7 +61,7 @@ fn main() { @@ -61,7 +61,7 @@ fn main() {
}
hid.scan_input();
if hid.keys_down().contains(KeyPad::KEY_START) {
if hid.keys_down().contains(KeyPad::START) {
break;
};
}

2
ctru-rs/examples/output-3dslink.rs

@ -30,7 +30,7 @@ fn main() { @@ -30,7 +30,7 @@ fn main() {
//Scan all the inputs. This should be done once for each frame
hid.scan_input();
if hid.keys_down().contains(KeyPad::KEY_START) {
if hid.keys_down().contains(KeyPad::START) {
break;
}
// Flush and swap framebuffers

2
ctru-rs/examples/romfs.rs

@ -33,7 +33,7 @@ fn main() { @@ -33,7 +33,7 @@ fn main() {
//Scan all the inputs. This should be done once for each frame
hid.scan_input();
if hid.keys_down().contains(KeyPad::KEY_START) {
if hid.keys_down().contains(KeyPad::START) {
break;
}
// Flush and swap framebuffers

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

@ -18,7 +18,7 @@ fn main() { @@ -18,7 +18,7 @@ fn main() {
hid.scan_input();
if hid.keys_down().contains(KeyPad::KEY_A) {
if hid.keys_down().contains(KeyPad::A) {
// Prepares a software keyboard with two buttons: One to cancel input and one
// to accept it. You can also use `Swkbd::init()` to launch the keyboard in different
// configurations.
@ -37,7 +37,7 @@ fn main() { @@ -37,7 +37,7 @@ fn main() {
}
}
if hid.keys_down().contains(KeyPad::KEY_START) {
if hid.keys_down().contains(KeyPad::START) {
break;
}
}

2
ctru-rs/examples/system-configuration.rs

@ -19,7 +19,7 @@ fn main() { @@ -19,7 +19,7 @@ fn main() {
//Scan all the inputs. This should be done once for each frame
hid.scan_input();
if hid.keys_down().contains(KeyPad::KEY_START) {
if hid.keys_down().contains(KeyPad::START) {
break;
}
// Flush and swap framebuffers

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

@ -16,7 +16,7 @@ fn main() { @@ -16,7 +16,7 @@ fn main() {
// Scan all the inputs. This should be done once for each frame
hid.scan_input();
if hid.keys_down().contains(KeyPad::KEY_START) {
if hid.keys_down().contains(KeyPad::START) {
break;
}

8
ctru-rs/examples/title-info.rs

@ -35,10 +35,10 @@ fn main() { @@ -35,10 +35,10 @@ fn main() {
//Scan all the inputs. This should be done once for each frame
hid.scan_input();
if hid.keys_down().contains(KeyPad::KEY_START) {
if hid.keys_down().contains(KeyPad::START) {
break;
}
if hid.keys_down().contains(KeyPad::KEY_SELECT) {
if hid.keys_down().contains(KeyPad::SELECT) {
refresh = true;
offset = 0;
use_nand = !use_nand;
@ -46,12 +46,12 @@ fn main() { @@ -46,12 +46,12 @@ fn main() {
let cur_list = if use_nand { &nand_list } else { &sd_list };
if hid.keys_down().intersects(KeyPad::KEY_DOWN) {
if hid.keys_down().intersects(KeyPad::DOWN) {
if offset + 1 < cur_list.len() {
offset = offset + 1;
refresh = true;
}
} else if hid.keys_down().intersects(KeyPad::KEY_UP) {
} else if hid.keys_down().intersects(KeyPad::UP) {
if offset > 0 {
offset = offset - 1;
refresh = true;

6
ctru-rs/src/lib.rs

@ -15,10 +15,10 @@ extern crate pthread_3ds; @@ -15,10 +15,10 @@ extern crate pthread_3ds;
#[cfg(feature = "big-stack")]
static __stacksize__: usize = 2 * 1024 * 1024; // 2MB
/// Activate ´ctru-rs´' 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].
/// 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] the program will just exit.
///
/// # Notes
///
@ -48,7 +48,7 @@ fn panic_hook_setup() { @@ -48,7 +48,7 @@ fn panic_hook_setup() {
Ok(hid) => loop {
hid.scan_input();
let keys = hid.keys_down();
if keys.contains(KeyPad::KEY_SELECT) {
if keys.contains(KeyPad::SELECT) {
break;
}
},

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

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
//! Filesystem service
//!
//! This module contains basic methods to manipulate the contents of the 3DS's filesystem.
//! Only the SD card is currently supported.
//! Only the SD card is currently supported. You should prefer using `std::fs`.
use bitflags::bitflags;
use std::ffi::OsString;
@ -52,38 +52,40 @@ pub enum FsMediaType { @@ -52,38 +52,40 @@ pub enum FsMediaType {
}
#[derive(Copy, Clone, Debug)]
#[repr(u32)]
pub enum PathType {
Invalid,
Empty,
Binary,
ASCII,
UTF16,
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,
}
#[derive(Copy, Clone, Debug)]
#[repr(u32)]
pub enum ArchiveID {
RomFS,
Savedata,
Extdata,
SharedExtdata,
SystemSavedata,
Sdmc,
SdmcWriteOnly,
BossExtdata,
CardSpiFS,
ExtDataAndBossExtdata,
SystemSaveData2,
NandRW,
NandRO,
NandROWriteAccess,
SaveDataAndContent,
SaveDataAndContent2,
NandCtrFS,
TwlPhoto,
NandTwlFS,
GameCardSavedata,
UserSavedata,
DemoSavedata,
RomFS = ctru_sys::ARCHIVE_ROMFS,
Savedata = ctru_sys::ARCHIVE_ROMFS,
Extdata = ctru_sys::ARCHIVE_ROMFS,
SharedExtdata = ctru_sys::ARCHIVE_ROMFS,
SystemSavedata = ctru_sys::ARCHIVE_ROMFS,
Sdmc = ctru_sys::ARCHIVE_ROMFS,
SdmcWriteOnly = ctru_sys::ARCHIVE_ROMFS,
BossExtdata = ctru_sys::ARCHIVE_ROMFS,
CardSpiFS = ctru_sys::ARCHIVE_ROMFS,
ExtDataAndBossExtdata = ctru_sys::ARCHIVE_ROMFS,
SystemSaveData2 = ctru_sys::ARCHIVE_ROMFS,
NandRW = ctru_sys::ARCHIVE_ROMFS,
NandRO = ctru_sys::ARCHIVE_ROMFS,
NandROWriteAccess = ctru_sys::ARCHIVE_ROMFS,
SaveDataAndContent = ctru_sys::ARCHIVE_ROMFS,
SaveDataAndContent2 = ctru_sys::ARCHIVE_ROMFS,
NandCtrFS = ctru_sys::ARCHIVE_ROMFS,
TwlPhoto = ctru_sys::ARCHIVE_ROMFS,
NandTwlFS = ctru_sys::ARCHIVE_ROMFS,
GameCardSavedata = ctru_sys::ARCHIVE_ROMFS,
UserSavedata = ctru_sys::ARCHIVE_ROMFS,
DemoSavedata = ctru_sys::ARCHIVE_ROMFS,
}
/// Represents the filesystem service. No file IO can be performed

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

@ -10,34 +10,34 @@ bitflags::bitflags! { @@ -10,34 +10,34 @@ bitflags::bitflags! {
/// inputs on the 3DS
#[derive(Default)]
pub struct KeyPad: u32 {
const KEY_A = 1u32 << 0;
const KEY_B = 1u32 << 1;
const KEY_SELECT = 1u32 << 2;
const KEY_START = 1u32 << 3;
const KEY_DRIGHT = 1u32 << 4;
const KEY_DLEFT = 1u32 << 5;
const KEY_DUP = 1u32 << 6;
const KEY_DDOWN = 1u32 << 7;
const KEY_R = 1u32 << 8;
const KEY_L = 1u32 << 9;
const KEY_X = 1u32 << 10;
const KEY_Y = 1u32 << 11;
const KEY_ZL = 1u32 << 14;
const KEY_ZR = 1u32 << 15;
const KEY_TOUCH = 1u32 << 20;
const KEY_CSTICK_RIGHT = 1u32 << 24;
const KEY_CSTICK_LEFT = 1u32 << 25;
const KEY_CSTICK_UP = 1u32 << 26;
const KEY_CSTICK_DOWN = 1u32 << 27;
const KEY_CPAD_RIGHT = 1u32 << 28;
const KEY_CPAD_LEFT = 1u32 << 29;
const KEY_CPAD_UP = 1u32 << 30;
const KEY_CPAD_DOWN = 1u32 << 31;
// convenience catch-all for the dpad and cpad
const KEY_UP = KeyPad::KEY_DUP.bits | KeyPad::KEY_CPAD_UP.bits;
const KEY_DOWN = KeyPad::KEY_DDOWN.bits | KeyPad::KEY_CPAD_DOWN.bits;
const KEY_LEFT = KeyPad::KEY_DLEFT.bits | KeyPad::KEY_CPAD_LEFT.bits;
const KEY_RIGHT = KeyPad::KEY_DRIGHT.bits | KeyPad::KEY_CPAD_RIGHT.bits;
const A = ctru_sys::KEY_A;
const B = ctru_sys::KEY_B;
const SELECT = ctru_sys::KEY_SELECT;
const START = ctru_sys::KEY_START;
const DRIGHT = ctru_sys::KEY_DRIGHT;
const DLEFT = ctru_sys::KEY_DLEFT;
const DUP = ctru_sys::KEY_DUP;
const DDOWN = ctru_sys::KEY_DDOWN;
const R = ctru_sys::KEY_R;
const L = ctru_sys::KEY_L;
const X = ctru_sys::KEY_X;
const Y = ctru_sys::KEY_Y;
const ZL = ctru_sys::KEY_ZL;
const ZR = ctru_sys::KEY_ZR;
const TOUCH = ctru_sys::KEY_TOUCH;
const CSTICK_RIGHT = ctru_sys::KEY_CSTICK_RIGHT;
const CSTICK_LEFT = ctru_sys::KEY_CSTICK_LEFT;
const CSTICK_UP = ctru_sys::KEY_CSTICK_UP;
const CSTICK_DOWN = ctru_sys::KEY_CSTICK_DOWN;
const CPAD_RIGHT = ctru_sys::KEY_CPAD_RIGHT;
const CPAD_LEFT = ctru_sys::KEY_CPAD_LEFT;
const CPAD_UP = ctru_sys::KEY_CPAD_UP;
const CPAD_DOWN = ctru_sys::KEY_CPAD_DOWN;
// Convenience catch-all for the dpad and cpad
const UP = KeyPad::DUP.bits() | KeyPad::CPAD_UP.bits();
const DOWN = KeyPad::DDOWN.bits() | KeyPad::CPAD_DOWN.bits();
const LEFT = KeyPad::DLEFT.bits() | KeyPad::CPAD_LEFT.bits();
const RIGHT = KeyPad::DRIGHT.bits() | KeyPad::CPAD_RIGHT.bits();
}
}

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

@ -8,26 +8,26 @@ use crate::Result; @@ -8,26 +8,26 @@ use crate::Result;
#[repr(u32)]
pub enum AESAlgorithm {
CbcEnc,
CbcDec,
CtrEnc,
CtrDec,
CcmEnc,
CcmDec,
CbcEnc = ctru_sys::PS_ALGORITHM_CBC_ENC,
CbcDec = ctru_sys::PS_ALGORITHM_CBC_DEC,
CtrEnc = ctru_sys::PS_ALGORITHM_CTR_ENC,
CtrDec = ctru_sys::PS_ALGORITHM_CTR_DEC,
CcmEnc = ctru_sys::PS_ALGORITHM_CCM_ENC,
CcmDec = ctru_sys::PS_ALGORITHM_CCM_DEC,
}
#[repr(u32)]
pub enum AESKeyType {
Keyslot0D,
Keyslot2D,
Keyslot31,
Keyslot38,
Keyslot32,
Keyslot39Dlp,
Keyslot2E,
KeyslotInvalid,
Keyslot36,
Keyslot39Nfc,
Keyslot0D = ctru_sys::PS_KEYSLOT_0D,
Keyslot2D = ctru_sys::PS_KEYSLOT_2D,
Keyslot2E = ctru_sys::PS_KEYSLOT_2E,
Keyslot31 = ctru_sys::PS_KEYSLOT_31,
Keyslot32 = ctru_sys::PS_KEYSLOT_32,
Keyslot36 = ctru_sys::PS_KEYSLOT_36,
Keyslot38 = ctru_sys::PS_KEYSLOT_38,
Keyslot39Dlp = ctru_sys::PS_KEYSLOT_39_DLP,
Keyslot39Nfc = ctru_sys::PS_KEYSLOT_39_NFC,
KeyslotInvalid = ctru_sys::PS_KEYSLOT_INVALID,
}
pub struct Ps(());

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

@ -1,3 +1,5 @@ @@ -1,3 +1,5 @@
//! Network Socket
use libc::memalign;
use std::net::Ipv4Addr;
use std::sync::Mutex;
@ -6,8 +8,10 @@ use crate::error::ResultCode; @@ -6,8 +8,10 @@ use crate::error::ResultCode;
use crate::services::ServiceReference;
use crate::Error;
/// Soc service. Initializing this service will enable the use of network sockets and utilities
/// such as those found in `std::net`. The service will be closed when this struct is is dropped.
/// Network socket service
///
/// Initializing this service will enable the use of network sockets and utilities
/// such as those found in `std::net`. The service will close once this struct gets dropped.
pub struct Soc {
_service_handler: ServiceReference,
sock_3dslink: libc::c_int,

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

@ -1,3 +1,5 @@ @@ -1,3 +1,5 @@
//! SSLC (TLS) service
// TODO: Implement remaining functions
use crate::error::ResultCode;
@ -5,7 +7,7 @@ use crate::error::ResultCode; @@ -5,7 +7,7 @@ use crate::error::ResultCode;
pub struct SslC(());
impl SslC {
/// Initialize sslc
/// Initialize the service
pub fn init() -> crate::Result<Self> {
unsafe {
ResultCode(ctru_sys::sslcInit(0))?;

2
ctru-rs/src/test_runner.rs

@ -44,7 +44,7 @@ pub(crate) fn run(tests: &[&TestDescAndFn]) { @@ -44,7 +44,7 @@ pub(crate) fn run(tests: &[&TestDescAndFn]) {
gfx.wait_for_vblank();
hid.scan_input();
if hid.keys_down().contains(KeyPad::KEY_START) {
if hid.keys_down().contains(KeyPad::START) {
break;
}
}

Loading…
Cancel
Save