Skip to content

Commit 46477f7

Browse files
committed
add async support using bisync crate
This moves the existing API into a `blocking` module and duplicates the API into a new `asynchronous` module, using `async fn` where applicable. Fixes #50
1 parent 5a5b4a9 commit 46477f7

36 files changed

+866
-784
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog] and this project adheres to [Semantic
88

99
### Changed
1010

11+
- __Breaking Change__: Existing API moved into `blocking` module. Adjust your imports from `embedded_sdmmc` to `embedded_sdmmc::blocking` to keep old code building.
1112
- __Breaking Change__: `VolumeManager` now uses interior-mutability (with a `RefCell`) and so most methods are now `&self`. This also makes it easier to open multiple `File`, `Directory` or `Volume` objects at once.
1213
- __Breaking Change__: The `VolumeManager`, `File`, `Directory` and `Volume` no longer implement `Send` or `Sync.
1314
- `VolumeManager` uses an interior block cache of 512 bytes, increasing its size by about 520 bytes but hugely reducing stack space required at run-time.
@@ -17,6 +18,7 @@ The format is based on [Keep a Changelog] and this project adheres to [Semantic
1718

1819
### Added
1920

21+
- Async API in `asynchronous` module
2022
- `File` now implements the `embedded-io` `Read`, `Write` and `Seek` traits.
2123
- New `iterate_dir_lfn` method on `VolumeManager` and `Directory` - provides decoded Long File Names as `Option<&str>`
2224

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ version = "0.8.0"
1414
rust-version = "1.76"
1515

1616
[dependencies]
17+
bisync = "0.2.3"
1718
byteorder = {version = "1", default-features = false}
1819
defmt = {version = "0.3", optional = true}
1920
embedded-hal = "1.0.0"
21+
embedded-hal-async = "1.0.0"
2022
embedded-io = "0.6.1"
23+
embedded-io-async = "0.6.1"
2124
heapless = "^0.8"
2225
log = {version = "0.4", default-features = false, optional = true}
2326

examples/append_file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ use linux::*;
1919

2020
const FILE_TO_APPEND: &str = "README.TXT";
2121

22-
use embedded_sdmmc::{Error, Mode, VolumeIdx};
22+
use embedded_sdmmc::blocking::{Error, Mode, VolumeIdx};
2323

24-
type VolumeManager = embedded_sdmmc::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;
24+
type VolumeManager = embedded_sdmmc::blocking::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;
2525

2626
fn main() -> Result<(), Error<std::io::Error>> {
2727
env_logger::init();

examples/big_dir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
mod linux;
2222
use linux::*;
2323

24-
use embedded_sdmmc::{Error, Mode, VolumeIdx};
24+
use embedded_sdmmc::blocking::{Error, Mode, VolumeIdx};
2525

26-
type VolumeManager = embedded_sdmmc::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;
26+
type VolumeManager = embedded_sdmmc::blocking::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;
2727

2828
fn main() -> Result<(), Error<std::io::Error>> {
2929
env_logger::init();

examples/create_file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ use linux::*;
1919

2020
const FILE_TO_CREATE: &str = "CREATE.TXT";
2121

22-
use embedded_sdmmc::{Error, Mode, VolumeIdx};
22+
use embedded_sdmmc::blocking::{Error, Mode, VolumeIdx};
2323

24-
type VolumeManager = embedded_sdmmc::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;
24+
type VolumeManager = embedded_sdmmc::blocking::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;
2525

2626
fn main() -> Result<(), Error<std::io::Error>> {
2727
env_logger::init();

examples/delete_file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ use linux::*;
2222

2323
const FILE_TO_DELETE: &str = "README.TXT";
2424

25-
use embedded_sdmmc::{Error, VolumeIdx};
25+
use embedded_sdmmc::blocking::{Error, VolumeIdx};
2626

27-
type VolumeManager = embedded_sdmmc::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;
27+
type VolumeManager = embedded_sdmmc::blocking::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;
2828

2929
fn main() -> Result<(), Error<std::io::Error>> {
3030
env_logger::init();

examples/linux/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Helpers for using embedded-sdmmc on Linux
22
33
use chrono::Timelike;
4-
use embedded_sdmmc::{Block, BlockCount, BlockDevice, BlockIdx, TimeSource, Timestamp};
4+
use embedded_sdmmc::blocking::{Block, BlockCount, BlockDevice, BlockIdx, TimeSource, Timestamp};
55
use std::cell::RefCell;
66
use std::fs::{File, OpenOptions};
77
use std::io::prelude::*;

examples/list_dir.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
mod linux;
3535
use linux::*;
3636

37-
use embedded_sdmmc::{ShortFileName, VolumeIdx};
37+
use embedded_sdmmc::blocking::{ShortFileName, VolumeIdx};
3838

39-
type Error = embedded_sdmmc::Error<std::io::Error>;
39+
type Error = embedded_sdmmc::blocking::Error<std::io::Error>;
4040

41-
type Directory<'a> = embedded_sdmmc::Directory<'a, LinuxBlockDevice, Clock, 8, 4, 4>;
42-
type VolumeManager = embedded_sdmmc::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;
41+
type Directory<'a> = embedded_sdmmc::blocking::Directory<'a, LinuxBlockDevice, Clock, 8, 4, 4>;
42+
type VolumeManager = embedded_sdmmc::blocking::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;
4343

4444
fn main() -> Result<(), Error> {
4545
env_logger::init();

examples/read_file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ use linux::*;
3636

3737
const FILE_TO_READ: &str = "README.TXT";
3838

39-
use embedded_sdmmc::{Error, Mode, VolumeIdx};
39+
use embedded_sdmmc::blocking::{Error, Mode, VolumeIdx};
4040

41-
type VolumeManager = embedded_sdmmc::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;
41+
type VolumeManager = embedded_sdmmc::blocking::VolumeManager<LinuxBlockDevice, Clock, 8, 4, 4>;
4242

4343
fn main() -> Result<(), Error<std::io::Error>> {
4444
env_logger::init();

examples/readme_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
use core::cell::RefCell;
99

10-
use embedded_sdmmc::{Error, SdCardError, TimeSource, Timestamp};
10+
use embedded_sdmmc::blocking::{Error, SdCardError, TimeSource, Timestamp};
1111

1212
pub struct DummyCsPin;
1313

@@ -121,7 +121,7 @@ fn main() -> Result<(), MyError> {
121121
let time_source = FakeTimesource();
122122
// END Fake stuff that will be replaced with real peripherals
123123

124-
use embedded_sdmmc::{Mode, SdCard, VolumeIdx, VolumeManager};
124+
use embedded_sdmmc::blocking::{Mode, SdCard, VolumeIdx, VolumeManager};
125125
// Build an SD Card interface out of an SPI device, a chip-select pin and the delay object
126126
let sdcard = SdCard::new(sdmmc_spi, delay);
127127
// Get the card size (this also triggers card initialisation because it's not been done yet)

0 commit comments

Comments
 (0)