Iterate through volume labels
This commit is contained in:
parent
31e5b10ce5
commit
f2bf073676
4
justfile
4
justfile
|
@ -1,2 +1,6 @@
|
|||
build:
|
||||
cargo build
|
||||
|
||||
rerun:
|
||||
probe-rs reset --chip RP2040
|
||||
probe-rs attach --chip RP2040 target/thumbv6m-none-eabi/debug/co2_sensing
|
||||
|
|
37
src/main.rs
37
src/main.rs
|
@ -13,9 +13,8 @@ use embassy_executor::Spawner;
|
|||
use embassy_rp::spi::Spi;
|
||||
use embassy_rp::{gpio, spi};
|
||||
use embedded_hal_bus::spi::ExclusiveDevice;
|
||||
use embedded_sdmmc::fat::Bpb;
|
||||
use embedded_sdmmc::sdcard::{DummyCsPin, SdCard};
|
||||
use embedded_sdmmc::{Block, BlockCount, BlockDevice, BlockIdx, FatVolume, VolumeIdx, VolumeType};
|
||||
use embedded_sdmmc::{Block, BlockDevice, BlockIdx, VolumeIdx};
|
||||
use gpio::{Level, Output};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
|
@ -61,8 +60,13 @@ async fn main(_spawner: Spawner) {
|
|||
let mut volume_mgr = embedded_sdmmc::VolumeManager::new(sdcard, DummyTimesource());
|
||||
{
|
||||
let device = volume_mgr.device();
|
||||
let info = read_volume_label(device, VolumeIdx(0)).unwrap();
|
||||
info!("Volume 0: name: {:?}", core::str::from_utf8(&info).unwrap());
|
||||
for (index, label) in valid_volumes(device).into_iter().flatten() {
|
||||
info!(
|
||||
"Volume {}: name: {:?}",
|
||||
index.0,
|
||||
core::str::from_utf8(&label).unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Try and access Volume 0 (i.e. the first partition).
|
||||
|
@ -102,6 +106,19 @@ async fn main(_spawner: Spawner) {
|
|||
info!("Program end")
|
||||
}
|
||||
|
||||
pub fn valid_volumes<D>(block_device: &mut D) -> [Option<(VolumeIdx, [u8; 11])>; 4]
|
||||
where
|
||||
D: BlockDevice,
|
||||
{
|
||||
let mut res = [None; 4];
|
||||
for i in 0..4 {
|
||||
let index_and_label = read_volume_label(block_device, VolumeIdx(i))
|
||||
.ok()
|
||||
.map(|label| (VolumeIdx(i), label));
|
||||
res[i] = index_and_label;
|
||||
}
|
||||
res
|
||||
}
|
||||
/// Read out the volume label a partition
|
||||
///
|
||||
/// I mostly pulled out some interiors of `embedded_sdmmc` and plugged
|
||||
|
@ -125,7 +142,6 @@ where
|
|||
const PARTITION_INFO_STATUS_INDEX: usize = 0;
|
||||
const PARTITION_INFO_TYPE_INDEX: usize = 4;
|
||||
const PARTITION_INFO_LBA_START_INDEX: usize = 8;
|
||||
const PARTITION_INFO_NUM_BLOCKS_INDEX: usize = 12;
|
||||
/// Marker for a FAT32 partition. Sometimes also use for FAT16 formatted
|
||||
/// partitions.
|
||||
const PARTITION_ID_FAT32_LBA: u8 = 0x0C;
|
||||
|
@ -138,7 +154,7 @@ where
|
|||
/// use.
|
||||
const PARTITION_ID_FAT32_CHS_LBA: u8 = 0x0B;
|
||||
|
||||
let (part_type, lba_start, num_blocks) = {
|
||||
let (part_type, lba_start) = {
|
||||
let mut blocks = [Block::new()];
|
||||
block_device
|
||||
.read(&mut blocks, BlockIdx(0), "read_mbr")
|
||||
|
@ -165,14 +181,7 @@ where
|
|||
let lba_start = LittleEndian::read_u32(
|
||||
&partition[PARTITION_INFO_LBA_START_INDEX..(PARTITION_INFO_LBA_START_INDEX + 4)],
|
||||
);
|
||||
let num_blocks = LittleEndian::read_u32(
|
||||
&partition[PARTITION_INFO_NUM_BLOCKS_INDEX..(PARTITION_INFO_NUM_BLOCKS_INDEX + 4)],
|
||||
);
|
||||
(
|
||||
partition[PARTITION_INFO_TYPE_INDEX],
|
||||
BlockIdx(lba_start),
|
||||
BlockCount(num_blocks),
|
||||
)
|
||||
(partition[PARTITION_INFO_TYPE_INDEX], BlockIdx(lba_start))
|
||||
};
|
||||
match part_type {
|
||||
PARTITION_ID_FAT32_CHS_LBA
|
||||
|
|
Loading…
Reference in a new issue