Browse Source

Cargo fmt

pull/65/head
Steve Cook 2 years ago
parent
commit
2405754d1b
  1. 19
      ctru-rs/examples/camera-image.rs
  2. 75
      ctru-rs/src/services/cam.rs

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

@ -107,7 +107,8 @@ fn main() {
} }
fn take_picture(cam: &mut Cam, buf: &mut [u8]) { fn take_picture(cam: &mut Cam, buf: &mut [u8]) {
let buf_size = cam.get_max_bytes(WIDTH as i16, HEIGHT as i16) let buf_size = cam
.get_max_bytes(WIDTH as i16, HEIGHT as i16)
.expect("Failed to get max bytes"); .expect("Failed to get max bytes");
cam.set_transfer_bytes(CamPort::PORT_BOTH, buf_size, WIDTH as i16, HEIGHT as i16) cam.set_transfer_bytes(CamPort::PORT_BOTH, buf_size, WIDTH as i16, HEIGHT as i16)
@ -116,7 +117,6 @@ fn take_picture(cam: &mut Cam, buf: &mut [u8]) {
cam.activate(CamSelect::SELECT_OUT1_OUT2) cam.activate(CamSelect::SELECT_OUT1_OUT2)
.expect("Failed to activate camera"); .expect("Failed to activate camera");
cam.clear_buffer(CamPort::PORT_BOTH) cam.clear_buffer(CamPort::PORT_BOTH)
.expect("Failed to clear buffer"); .expect("Failed to clear buffer");
cam.synchronize_vsync_timing(CamSelect::SELECT_OUT1, CamSelect::SELECT_OUT2) cam.synchronize_vsync_timing(CamSelect::SELECT_OUT1, CamSelect::SELECT_OUT2)
@ -125,15 +125,12 @@ fn take_picture(cam: &mut Cam, buf: &mut [u8]) {
cam.start_capture(CamPort::PORT_BOTH) cam.start_capture(CamPort::PORT_BOTH)
.expect("Failed to start capture"); .expect("Failed to start capture");
let receive_event = cam.set_receiving( let receive_event = cam
buf, .set_receiving(buf, CamPort::PORT_CAM1, SCREEN_SIZE as u32, buf_size as i16)
CamPort::PORT_CAM1,
SCREEN_SIZE as u32,
buf_size as i16,
)
.expect("Failed to set receiving"); .expect("Failed to set receiving");
let receive_event2 = cam.set_receiving( let receive_event2 = cam
.set_receiving(
&mut buf[SCREEN_SIZE..], &mut buf[SCREEN_SIZE..],
CamPort::PORT_CAM2, CamPort::PORT_CAM2,
SCREEN_SIZE as u32, SCREEN_SIZE as u32,
@ -172,14 +169,14 @@ fn take_picture(cam: &mut Cam, buf: &mut [u8]) {
fn write_picture_to_frame_buffer_rgb_565( fn write_picture_to_frame_buffer_rgb_565(
fb: RawFrameBuffer, fb: RawFrameBuffer,
img: &mut [u8], img: &[u8],
x: u16, x: u16,
y: u16, y: u16,
width: u16, width: u16,
height: u16, height: u16,
) { ) {
let fb_8 = fb.ptr; let fb_8 = fb.ptr;
let img_16 = img.as_mut_ptr() as *mut u16; let img_16 = img.as_ptr() as *const u16;
let mut draw_x; let mut draw_x;
let mut draw_y; let mut draw_y;
for j in 0..height { for j in 0..height {

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

@ -266,10 +266,7 @@ impl Cam {
} }
} }
pub fn get_buffer_error_interrupt_event( pub fn get_buffer_error_interrupt_event(&self, port: CamPort) -> crate::Result<u32> {
&self,
port: CamPort,
) -> crate::Result<u32> {
unsafe { unsafe {
let mut event: Handle = 0; let mut event: Handle = 0;
let r = ctru_sys::CAMU_GetBufferErrorInterruptEvent(&mut event, port.bits()); let r = ctru_sys::CAMU_GetBufferErrorInterruptEvent(&mut event, port.bits());
@ -305,10 +302,7 @@ impl Cam {
} }
} }
pub fn is_finished_receiving( pub fn is_finished_receiving(&self, port: CamPort) -> crate::Result<bool> {
&self,
port: CamPort,
) -> crate::Result<bool> {
unsafe { unsafe {
let mut finished_receiving = false; let mut finished_receiving = false;
let r = ctru_sys::CAMU_IsFinishedReceiving(&mut finished_receiving, port.bits()); let r = ctru_sys::CAMU_IsFinishedReceiving(&mut finished_receiving, port.bits());
@ -419,7 +413,13 @@ impl Cam {
params: CamTrimmingParams, params: CamTrimmingParams,
) -> crate::Result<()> { ) -> crate::Result<()> {
unsafe { unsafe {
let r = ctru_sys::CAMU_SetTrimmingParams(port.bits(), params.x_start, params.y_start, params.x_end, params.y_end); let r = ctru_sys::CAMU_SetTrimmingParams(
port.bits(),
params.x_start,
params.y_start,
params.x_end,
params.y_end,
);
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -428,16 +428,19 @@ impl Cam {
} }
} }
pub fn get_trimming_params( pub fn get_trimming_params(&self, port: CamPort) -> crate::Result<CamTrimmingParams> {
&self,
port: CamPort,
) -> crate::Result<CamTrimmingParams> {
unsafe { unsafe {
let mut x_start = 0; let mut x_start = 0;
let mut y_start = 0; let mut y_start = 0;
let mut x_end = 0; let mut x_end = 0;
let mut y_end = 0; let mut y_end = 0;
let r = ctru_sys::CAMU_GetTrimmingParams(&mut x_start, &mut y_start, &mut x_end, &mut y_end, port.bits()); let r = ctru_sys::CAMU_GetTrimmingParams(
&mut x_start,
&mut y_start,
&mut x_end,
&mut y_end,
port.bits(),
);
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -445,7 +448,7 @@ impl Cam {
x_start, x_start,
y_start, y_start,
x_end, x_end,
y_end y_end,
}) })
} }
} }
@ -561,10 +564,7 @@ impl Cam {
} }
} }
pub fn is_auto_exposure( pub fn is_auto_exposure(&self, camera: CamSelect) -> crate::Result<bool> {
&self,
camera: CamSelect,
) -> crate::Result<bool> {
unsafe { unsafe {
let mut is_auto_exposure = false; let mut is_auto_exposure = false;
let r = ctru_sys::CAMU_IsAutoExposure(&mut is_auto_exposure, camera.bits()); let r = ctru_sys::CAMU_IsAutoExposure(&mut is_auto_exposure, camera.bits());
@ -587,10 +587,7 @@ impl Cam {
} }
} }
pub fn is_auto_white_balance( pub fn is_auto_white_balance(&self, camera: CamSelect) -> crate::Result<bool> {
&self,
camera: CamSelect,
) -> crate::Result<bool> {
unsafe { unsafe {
let mut is_auto_white_balance = false; let mut is_auto_white_balance = false;
let r = ctru_sys::CAMU_IsAutoWhiteBalance(&mut is_auto_white_balance, camera.bits()); let r = ctru_sys::CAMU_IsAutoWhiteBalance(&mut is_auto_white_balance, camera.bits());
@ -806,11 +803,7 @@ impl Cam {
} }
} }
pub fn get_latest_vsync_timing( pub fn get_latest_vsync_timing(&self, port: CamPort, past: u32) -> crate::Result<i64> {
&self,
port: CamPort,
past: u32,
) -> crate::Result<i64> {
let mut timing = 0; let mut timing = 0;
unsafe { unsafe {
let r = ctru_sys::CAMU_GetLatestVsyncTiming(&mut timing, port.bits(), past); let r = ctru_sys::CAMU_GetLatestVsyncTiming(&mut timing, port.bits(), past);
@ -849,11 +842,7 @@ impl Cam {
} }
} }
pub fn read_register_i2c_exclusive( pub fn read_register_i2c_exclusive(&self, camera: CamSelect, addr: u16) -> crate::Result<u16> {
&self,
camera: CamSelect,
addr: u16,
) -> crate::Result<u16> {
unsafe { unsafe {
let mut data = 0; let mut data = 0;
let r = ctru_sys::CAMU_ReadRegisterI2cExclusive(&mut data, camera.bits(), addr); let r = ctru_sys::CAMU_ReadRegisterI2cExclusive(&mut data, camera.bits(), addr);
@ -881,7 +870,10 @@ impl Cam {
} }
} }
pub fn set_image_quality_calibration_data(&self, data: ImageQualityCalibrationData) -> crate::Result<()> { pub fn set_image_quality_calibration_data(
&self,
data: ImageQualityCalibrationData,
) -> crate::Result<()> {
unsafe { unsafe {
let r = ctru_sys::CAMU_SetImageQualityCalibrationData(data.0); let r = ctru_sys::CAMU_SetImageQualityCalibrationData(data.0);
if r < 0 { if r < 0 {
@ -904,7 +896,10 @@ impl Cam {
} }
} }
pub fn set_package_parameter_without_context(&self, param: PackageParameterCameraSelect) -> crate::Result<()> { pub fn set_package_parameter_without_context(
&self,
param: PackageParameterCameraSelect,
) -> crate::Result<()> {
unsafe { unsafe {
let r = ctru_sys::CAMU_SetPackageParameterWithoutContext(param.0); let r = ctru_sys::CAMU_SetPackageParameterWithoutContext(param.0);
if r < 0 { if r < 0 {
@ -915,7 +910,10 @@ impl Cam {
} }
} }
pub fn set_package_parameter_with_context(&self, param: PackageParameterContext) -> crate::Result<()> { pub fn set_package_parameter_with_context(
&self,
param: PackageParameterContext,
) -> crate::Result<()> {
unsafe { unsafe {
let r = ctru_sys::CAMU_SetPackageParameterWithContext(param.0); let r = ctru_sys::CAMU_SetPackageParameterWithContext(param.0);
if r < 0 { if r < 0 {
@ -926,7 +924,10 @@ impl Cam {
} }
} }
pub fn set_package_parameter_with_context_detail(&self, param: PackageParameterContextDetail) -> crate::Result<()> { pub fn set_package_parameter_with_context_detail(
&self,
param: PackageParameterContextDetail,
) -> crate::Result<()> {
unsafe { unsafe {
let r = ctru_sys::CAMU_SetPackageParameterWithContextDetail(param.0); let r = ctru_sys::CAMU_SetPackageParameterWithContextDetail(param.0);
if r < 0 { if r < 0 {

Loading…
Cancel
Save