Browse Source

Add Soc service

pull/10/head
Fenrir 7 years ago committed by FenrirWolf
parent
commit
745dd51df0
  1. 3
      ctru-rs/Cargo.toml
  2. 1
      ctru-rs/src/lib.rs
  3. 1
      ctru-rs/src/services/mod.rs
  4. 33
      ctru-rs/src/services/soc.rs

3
ctru-rs/Cargo.toml

@ -13,6 +13,9 @@ name = "ctru"
path = "../ctru-sys" path = "../ctru-sys"
version = "0.4" version = "0.4"
[dependencies.libc]
version = "0.2"
[dependencies.bitflags] [dependencies.bitflags]
version = "1.0.0" version = "1.0.0"

1
ctru-rs/src/lib.rs

@ -3,6 +3,7 @@
#[macro_use] #[macro_use]
extern crate bitflags; extern crate bitflags;
extern crate libc;
extern crate widestring; extern crate widestring;
extern crate ctru_sys as libctru; extern crate ctru_sys as libctru;

1
ctru-rs/src/services/mod.rs

@ -2,6 +2,7 @@ pub mod apt;
pub mod fs; pub mod fs;
pub mod hid; pub mod hid;
pub mod gspgpu; pub mod gspgpu;
pub mod soc;
pub mod sslc; pub mod sslc;
pub use self::hid::Hid; pub use self::hid::Hid;

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

@ -0,0 +1,33 @@
use libctru::{socInit, socExit};
use libc::{memalign, free};
pub struct Soc {
soc_mem: *mut u32,
}
impl Soc {
pub fn init() -> ::Result<Soc> {
const SOC_MEM_SIZE: usize = 0x100000;
unsafe {
let soc_mem = memalign(0x1000, SOC_MEM_SIZE) as *mut u32;
let r = socInit(soc_mem, SOC_MEM_SIZE as u32);
if r < 0 {
Err(r.into())
} else {
Ok(Soc { soc_mem, })
}
}
}
}
impl Drop for Soc {
fn drop(&mut self) {
unsafe {
socExit();
free(self.soc_mem as *mut _);
}
}
}
Loading…
Cancel
Save