Skip to content

Commit f3fb15a

Browse files
authored
Merge branch 'develop' into fix/multiblock-writes
2 parents 3743f1a + ea53bc9 commit f3fb15a

File tree

7 files changed

+210
-83
lines changed

7 files changed

+210
-83
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ version = "0.5.0"
1414
byteorder = {version = "1", default-features = false}
1515
defmt = {version = "0.3", optional = true}
1616
embedded-hal = "0.2.3"
17+
heapless = "0.7"
1718
log = {version = "0.4", default-features = false, optional = true}
1819

1920
[dev-dependencies]

src/filesystem/directory.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use core::convert::TryFrom;
22

33
use crate::blockdevice::BlockIdx;
44
use crate::fat::{FatType, OnDiskDirEntry};
5-
use crate::filesystem::{Attributes, Cluster, ShortFileName, Timestamp};
5+
use crate::filesystem::{Attributes, Cluster, SearchId, ShortFileName, Timestamp};
66

77
/// Represents a directory entry, which tells you about
88
/// other files and directories.
@@ -33,8 +33,8 @@ pub struct DirEntry {
3333
pub struct Directory {
3434
/// The starting point of the directory listing.
3535
pub(crate) cluster: Cluster,
36-
/// Dir Entry of this directory, None for the root directory
37-
pub(crate) entry: Option<DirEntry>,
36+
/// Search ID for this directory.
37+
pub(crate) search_id: SearchId,
3838
}
3939

4040
impl DirEntry {

src/filesystem/files.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::filesystem::{Cluster, DirEntry};
1+
use crate::filesystem::{Cluster, DirEntry, SearchId};
22

33
/// Represents an open file on disk.
44
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
@@ -16,6 +16,8 @@ pub struct File {
1616
pub(crate) mode: Mode,
1717
/// DirEntry of this file
1818
pub(crate) entry: DirEntry,
19+
/// Search ID for this file
20+
pub(crate) search_id: SearchId,
1921
}
2022

2123
/// Errors related to file operations

src/filesystem/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ mod cluster;
1111
mod directory;
1212
mod filename;
1313
mod files;
14+
mod search_id;
1415
mod timestamp;
1516

1617
pub use self::attributes::Attributes;
1718
pub use self::cluster::Cluster;
1819
pub use self::directory::{DirEntry, Directory};
1920
pub use self::filename::{FilenameError, ShortFileName};
2021
pub use self::files::{File, FileError, Mode};
22+
pub use self::search_id::{IdGenerator, SearchId};
2123
pub use self::timestamp::{TimeSource, Timestamp};

src/filesystem/search_id.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use core::num::Wrapping;
2+
3+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
4+
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
5+
/// Unique ID used to search for files and directories in the open File/Directory lists
6+
pub struct SearchId(pub(crate) u32);
7+
8+
/// ID generator intented to be used in a static context.
9+
///
10+
/// This object will always return a different ID.
11+
pub struct IdGenerator {
12+
next_id: Wrapping<u32>,
13+
}
14+
15+
impl IdGenerator {
16+
/// Create a new [`IdGenerator`].
17+
pub const fn new() -> Self {
18+
Self {
19+
next_id: Wrapping(0),
20+
}
21+
}
22+
23+
/// Generate a new, unique [`SearchId`].
24+
pub fn get(&mut self) -> SearchId {
25+
let id = self.next_id;
26+
self.next_id += 1;
27+
SearchId(id.0)
28+
}
29+
}

src/sdcard/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ where
408408
// Assert CS
409409
s.cs_low()?;
410410
// Enter SPI mode.
411-
let mut delay = Delay::new_command();
411+
let mut delay = Delay::new(s.options.acquire_retries);
412412
for attempts in 1.. {
413413
trace!("Enter SPI mode, attempt: {}..", attempts);
414414
match s.card_command(CMD0, 0) {
@@ -593,11 +593,18 @@ pub struct AcquireOpts {
593593
/// On by default because without it you might get silent data corruption on
594594
/// your card.
595595
pub use_crc: bool,
596+
597+
/// Sets the number of times we will retry to acquire the card before giving up and returning
598+
/// `Err(Error::CardNotFound)`. By default, card acquisition will be retried 50 times.
599+
pub acquire_retries: u32,
596600
}
597601

598602
impl Default for AcquireOpts {
599603
fn default() -> Self {
600-
AcquireOpts { use_crc: true }
604+
AcquireOpts {
605+
use_crc: true,
606+
acquire_retries: 50,
607+
}
601608
}
602609
}
603610

0 commit comments

Comments
 (0)