Skip to content

Commit

Permalink
More render reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
DDRBoxman committed Oct 15, 2023
1 parent b4a9b4f commit 6a3c5e6
Show file tree
Hide file tree
Showing 12 changed files with 481 additions and 363 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions cappy3ds/src/capture/katsukitty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ fn open_device<T: UsbContext>(

pub fn do_capture<T: UsbContext, F>(handle: &mut DeviceHandle<T>, data_callback: F)
where
F: Fn(&[i16], BytesMut, BytesMut),
F: FnMut(&[i16], BytesMut, BytesMut),
{
bulk_read(handle, data_callback);
}

extern "system" fn transfer_finished<T: UsbContext, F>(transfer_ptr: *mut usbffi::libusb_transfer)
where
F: Fn(&[i16], BytesMut, BytesMut),
F: FnMut(&[i16], BytesMut, BytesMut),
{
let transfer: &mut usbffi::libusb_transfer = unsafe { &mut *transfer_ptr };

Expand Down Expand Up @@ -162,8 +162,8 @@ where
let (_, short, _) = unsafe { sound_buffer.align_to::<i16>() };
(handler.data_callback)(
short,
parse::rgb565_to_rgb(&upper_buffer),
parse::rgb565_to_rgb(&lower_buffer),
parse::rgb565_to_rgba(&upper_buffer),
parse::rgb565_to_rgba(&lower_buffer),
);

handler.current_buffer += 1;
Expand Down Expand Up @@ -209,7 +209,7 @@ const TRANSFER_SIZE: usize = 0x4000;

impl<F> CaptureHandler<F>
where
F: Fn(&[i16], BytesMut, BytesMut),
F: FnMut(&[i16], BytesMut, BytesMut),
{
fn new(data_callback: F) -> Self {
let mut buffers = Vec::<BytesMut>::with_capacity(NUM_BUFFERS);
Expand All @@ -230,7 +230,7 @@ where

fn bulk_read<T: UsbContext, F>(handle: &mut DeviceHandle<T>, data_callback: F)
where
F: Fn(&[i16], BytesMut, BytesMut),
F: FnMut(&[i16], BytesMut, BytesMut),
{
println!("Starting Bulk Read");

Expand Down Expand Up @@ -289,10 +289,10 @@ where
}

loop {
let current_buffer = capture_handler.lock().unwrap().current_buffer;
if current_buffer >= NUM_BUFFERS - 10 {
//break;
}
//let current_buffer = capture_handler.lock().unwrap().current_buffer;
//if current_buffer >= NUM_BUFFERS - 10 {
//break;
//}
//let ten_millis = time::Duration::from_millis(1);
//thread::sleep(ten_millis);
}
Expand Down
25 changes: 25 additions & 0 deletions cappy3ds/src/capture/katsukitty/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,28 @@ pub fn rgb565_to_rgb(data: &BytesMut) -> BytesMut {

image_buffer
}

pub fn rgb565_to_rgba(data: &BytesMut) -> BytesMut {
let mut image_buffer = BytesMut::with_capacity(data.len() / 2 * 4);
image_buffer.resize(data.len() / 2 * 4, 0);

let mut j = 0;
for i in (0..data.len()).step_by(2) {
let high = (data[i + 1] as u16) << 8;
let c: u16 = data[i] as u16 + high;
let r = (((c & 0xF800) >> 11) << 3) as u8;
let g = (((c & 0x7E0) >> 5) << 2) as u8;
let b = ((c & 0x1F) << 3) as u8;

image_buffer[j] = r;
j += 1;
image_buffer[j] = g;
j += 1;
image_buffer[j] = b;
j += 1;
image_buffer[j] = 0;
j += 1;
}

image_buffer
}
22 changes: 22 additions & 0 deletions cappy3ds/src/capture/loopy_ds/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
USBDS_VID = 0x16D0,
USBDS_PID = 0x0647,

//device vendor requests:
CMDIN_STATUS = 0x31,
// Returns device status:
// struct {
// u32 framecount, //free running frame counter
// u8 lcd_on,
// u8 capture_in_progress,
// }
CMDIN_FRAMEINFO = 0x30,
// Returns record of last captured frame:
// struct {
// u8 bitmap[48], //bitmap of lines sent (1 bit per half-line)
// u32 frame, //frame number
// u8 valid, //0 if capture timed out (LCD is inactive)
// }
CMDOUT_CAPTURE_START = 0x30,
// capture new frame
CMDOUT_CAPTURE_STOP = 0x31,
// stop capture in progress and reset frame counter to 0
7 changes: 2 additions & 5 deletions cappy3ds/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ pub struct Cappy3ds<F> {

impl<F> Cappy3ds<F>
where
F: Fn(&[i16], BytesMut, BytesMut),
F: FnMut(&[i16], BytesMut, BytesMut),
{
pub fn new(data_callback: F) -> Self
where
F: Fn(&[i16], BytesMut, BytesMut),
{
pub fn new(data_callback: F) -> Self {
Self {
data_callback,
usb_context: None,
Expand Down
1 change: 1 addition & 0 deletions cappy3ds_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ cappy3ds = { path = "../cappy3ds" }
ringbuf = "0.3.3"
simple-error = "0.3.0"
bytes = "1.5.0"
glam = "0.24.2"

[lib]
name = "cappy3ds_render"
Expand Down
Binary file added cappy3ds_render/resources/test/lower_wow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6a3c5e6

Please sign in to comment.