mirror of
https://github.com/LegitCamper/picocalc-os-rs.git
synced 2025-12-27 15:55:25 +00:00
can mount and transfer files!
This commit is contained in:
@@ -10,6 +10,8 @@ use scsi_types::*;
|
|||||||
|
|
||||||
use crate::storage::SdCard;
|
use crate::storage::SdCard;
|
||||||
|
|
||||||
|
const BULK_ENDPOINT_PACKET_SIZE: usize = 64;
|
||||||
|
|
||||||
pub struct MassStorageClass<'d, D: Driver<'d>> {
|
pub struct MassStorageClass<'d, D: Driver<'d>> {
|
||||||
sdcard: SdCard,
|
sdcard: SdCard,
|
||||||
bulk_out: D::EndpointOut,
|
bulk_out: D::EndpointOut,
|
||||||
@@ -23,8 +25,8 @@ impl<'d, D: Driver<'d>> MassStorageClass<'d, D> {
|
|||||||
let mut interface = function.interface();
|
let mut interface = function.interface();
|
||||||
let mut alt = interface.alt_setting(0x08, SUBCLASS_SCSI, 0x50, None);
|
let mut alt = interface.alt_setting(0x08, SUBCLASS_SCSI, 0x50, None);
|
||||||
|
|
||||||
let bulk_out = alt.endpoint_bulk_out(64);
|
let bulk_out = alt.endpoint_bulk_out(BULK_ENDPOINT_PACKET_SIZE as u16);
|
||||||
let bulk_in = alt.endpoint_bulk_in(64);
|
let bulk_in = alt.endpoint_bulk_in(BULK_ENDPOINT_PACKET_SIZE as u16);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
bulk_out,
|
bulk_out,
|
||||||
@@ -53,7 +55,7 @@ impl<'d, D: Driver<'d>> MassStorageClass<'d, D> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_command(&mut self, cbw: &[u8]) -> Result<(), ()> {
|
async fn handle_command(&mut self, cbw: &[u8]) -> Result<(), ()> {
|
||||||
let mut response: Vec<u8, 64> = Vec::new();
|
let mut response: Vec<u8, BULK_ENDPOINT_PACKET_SIZE> = Vec::new();
|
||||||
let mut block = [Block::new(); 1];
|
let mut block = [Block::new(); 1];
|
||||||
|
|
||||||
match parse_cb(cbw) {
|
match parse_cb(cbw) {
|
||||||
@@ -211,22 +213,22 @@ impl<'d, D: Driver<'d>> MassStorageClass<'d, D> {
|
|||||||
ScsiCommand::Read { lba, len } => {
|
ScsiCommand::Read { lba, len } => {
|
||||||
for i in 0..len {
|
for i in 0..len {
|
||||||
let block_idx = BlockIdx(lba as u32 + i as u32);
|
let block_idx = BlockIdx(lba as u32 + i as u32);
|
||||||
defmt::info!("Reading LBA {} (block idx: {:?})", lba, block_idx);
|
|
||||||
self.sdcard.read_blocks(&mut block, block_idx);
|
self.sdcard.read_blocks(&mut block, block_idx);
|
||||||
self.bulk_in
|
for chunk in block[0].contents.chunks(BULK_ENDPOINT_PACKET_SIZE.into()) {
|
||||||
.write(&block[0].contents)
|
self.bulk_in.write(chunk).await.map_err(|_| ())?;
|
||||||
.await
|
}
|
||||||
.map_err(|_| ())?;
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
ScsiCommand::Write { lba, len } => {
|
ScsiCommand::Write { lba, len } => {
|
||||||
for i in 0..len {
|
for i in 0..len {
|
||||||
let block_idx = BlockIdx(lba as u32 + i as u32);
|
let block_idx = BlockIdx(lba as u32 + i as u32);
|
||||||
self.bulk_out
|
for chunk in block[0]
|
||||||
.read(&mut block[0].contents)
|
.contents
|
||||||
.await
|
.chunks_mut(BULK_ENDPOINT_PACKET_SIZE.into())
|
||||||
.map_err(|_| ())?;
|
{
|
||||||
|
slf.bulk_out.read(chunk).await.map_err(|_| ())?;
|
||||||
|
}
|
||||||
self.sdcard.write_blocks(&mut block, block_idx);
|
self.sdcard.write_blocks(&mut block, block_idx);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user