diff --git a/ctru-rs/examples/camera-image.rs b/ctru-rs/examples/camera-image.rs index 52728be..b277679 100644 --- a/ctru-rs/examples/camera-image.rs +++ b/ctru-rs/examples/camera-image.rs @@ -107,7 +107,8 @@ fn main() { } 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"); 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) .expect("Failed to activate camera"); - cam.clear_buffer(CamPort::PORT_BOTH) .expect("Failed to clear buffer"); cam.synchronize_vsync_timing(CamSelect::SELECT_OUT1, CamSelect::SELECT_OUT2) @@ -125,21 +125,18 @@ fn take_picture(cam: &mut Cam, buf: &mut [u8]) { cam.start_capture(CamPort::PORT_BOTH) .expect("Failed to start capture"); - let receive_event = cam.set_receiving( - buf, - CamPort::PORT_CAM1, - SCREEN_SIZE as u32, - buf_size as i16, - ) - .expect("Failed to set receiving"); + let receive_event = cam + .set_receiving(buf, CamPort::PORT_CAM1, SCREEN_SIZE as u32, buf_size as i16) + .expect("Failed to set receiving"); - let receive_event2 = cam.set_receiving( - &mut buf[SCREEN_SIZE..], - CamPort::PORT_CAM2, - SCREEN_SIZE as u32, - buf_size as i16, - ) - .expect("Failed to set receiving"); + let receive_event2 = cam + .set_receiving( + &mut buf[SCREEN_SIZE..], + CamPort::PORT_CAM2, + SCREEN_SIZE as u32, + buf_size as i16, + ) + .expect("Failed to set receiving"); unsafe { let mut r = ctru_sys::svcWaitSynchronization(receive_event, WAIT_TIMEOUT); @@ -172,14 +169,14 @@ fn take_picture(cam: &mut Cam, buf: &mut [u8]) { fn write_picture_to_frame_buffer_rgb_565( fb: RawFrameBuffer, - img: &mut [u8], + img: &[u8], x: u16, y: u16, width: u16, height: u16, ) { 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_y; for j in 0..height { diff --git a/ctru-rs/src/services/cam.rs b/ctru-rs/src/services/cam.rs index 180cc59..b2a757b 100644 --- a/ctru-rs/src/services/cam.rs +++ b/ctru-rs/src/services/cam.rs @@ -266,10 +266,7 @@ impl Cam { } } - pub fn get_buffer_error_interrupt_event( - &self, - port: CamPort, - ) -> crate::Result { + pub fn get_buffer_error_interrupt_event(&self, port: CamPort) -> crate::Result { unsafe { let mut event: Handle = 0; let r = ctru_sys::CAMU_GetBufferErrorInterruptEvent(&mut event, port.bits()); @@ -305,10 +302,7 @@ impl Cam { } } - pub fn is_finished_receiving( - &self, - port: CamPort, - ) -> crate::Result { + pub fn is_finished_receiving(&self, port: CamPort) -> crate::Result { unsafe { let mut finished_receiving = false; let r = ctru_sys::CAMU_IsFinishedReceiving(&mut finished_receiving, port.bits()); @@ -419,7 +413,13 @@ impl Cam { params: CamTrimmingParams, ) -> crate::Result<()> { 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 { Err(r.into()) } else { @@ -428,24 +428,27 @@ impl Cam { } } - pub fn get_trimming_params( - &self, - port: CamPort, - ) -> crate::Result { + pub fn get_trimming_params(&self, port: CamPort) -> crate::Result { unsafe { let mut x_start = 0; let mut y_start = 0; let mut x_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 { Err(r.into()) } else { - Ok(CamTrimmingParams{ + Ok(CamTrimmingParams { x_start, y_start, x_end, - y_end + y_end, }) } } @@ -561,12 +564,9 @@ impl Cam { } } - pub fn is_auto_exposure( - &self, - camera: CamSelect, - ) -> crate::Result { + pub fn is_auto_exposure(&self, camera: CamSelect) -> crate::Result { 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()); if r < 0 { Err(r.into()) @@ -587,10 +587,7 @@ impl Cam { } } - pub fn is_auto_white_balance( - &self, - camera: CamSelect, - ) -> crate::Result { + pub fn is_auto_white_balance(&self, camera: CamSelect) -> crate::Result { unsafe { let mut is_auto_white_balance = false; 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( - &self, - port: CamPort, - past: u32, - ) -> crate::Result { + pub fn get_latest_vsync_timing(&self, port: CamPort, past: u32) -> crate::Result { let mut timing = 0; unsafe { let r = ctru_sys::CAMU_GetLatestVsyncTiming(&mut timing, port.bits(), past); @@ -849,11 +842,7 @@ impl Cam { } } - pub fn read_register_i2c_exclusive( - &self, - camera: CamSelect, - addr: u16, - ) -> crate::Result { + pub fn read_register_i2c_exclusive(&self, camera: CamSelect, addr: u16) -> crate::Result { unsafe { let mut data = 0; 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 { let r = ctru_sys::CAMU_SetImageQualityCalibrationData(data.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 { let r = ctru_sys::CAMU_SetPackageParameterWithoutContext(param.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 { let r = ctru_sys::CAMU_SetPackageParameterWithContext(param.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 { let r = ctru_sys::CAMU_SetPackageParameterWithContextDetail(param.0); if r < 0 {