Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/v0.8.0 #137

Merged
merged 27 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ec01477
Merge pull request #118 from rust-embedded-community/main
thejpster Feb 9, 2024
f880b51
Upgrade to heapless ^0.8
bsodmike Feb 25, 2024
ba27644
Merge pull request #120 from bsodmike/upgrade_heapless_0.8
thejpster Feb 25, 2024
3cdb6cb
Add ability to flush written data
peterkrull Mar 25, 2024
55c77ce
Merge pull request #121 from peterkrull/flush-written-file
thejpster Mar 25, 2024
86c20e0
Do not panic on errors during drop, add optional manual closing to no…
peterkrull Mar 29, 2024
710bd34
Merge pull request #123 from peterkrull/always-closing
thejpster Mar 30, 2024
1e89779
split FatVolume.iterate_dir into 2 subfunctions
orsinium Apr 3, 2024
f26de60
FIx some docs
orsinium Apr 3, 2024
44b63de
Merge pull request #127 from orsinium-forks/fat-iterate-dir-refactor
thejpster Apr 4, 2024
83128a3
Add new test.
thejpster Jun 1, 2024
07d7bd2
Bug fix for #131
thejpster Jun 1, 2024
a3c895b
Fix read_file_backwards.
thejpster Jun 1, 2024
a04e5f0
Fix seek_from_end.
thejpster Jun 1, 2024
0de58d3
Move new test into read_file.
thejpster Jun 1, 2024
59e4c2f
Code cleanups.
thejpster Jun 1, 2024
7b5b876
Appease clippy.
thejpster Jun 1, 2024
6b1ef4c
Update README example
thejpster Jun 1, 2024
ee72ddc
Merge pull request #134 from rust-embedded-community/fix-warnings
eldruin Jun 6, 2024
92c8ca9
Merge branch 'develop' into fix-seeking
eldruin Jun 6, 2024
860e072
Merge pull request #133 from rust-embedded-community/fix-seeking
eldruin Jun 10, 2024
510d50e
Use SpiDevice to control the chip select.
thejpster Jul 6, 2024
44a5736
Merge pull request #136 from rust-embedded-community/use-spidevice-pr…
thejpster Jul 12, 2024
c828250
Minor clean-ups of docs.
jonathanpallant Jul 12, 2024
4e4e084
Merge pull request #138 from rust-embedded-community/clean-up-docs
thejpster Jul 12, 2024
b178599
Update CHANGELOG.
jonathanpallant Jul 12, 2024
a1cc455
Update version to 0.8.0
jonathanpallant Jul 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,39 @@ The format is based on [Keep a Changelog] and this project adheres to [Semantic

## [Unreleased]

* None
### Changed

- None

### Added

- None

### Removed

- None

## [Version 0.8.0] - 2024-07-12

### Changed

- Fixed a bug when seeking backwards through files.
- Updated to `heapless-0.8` and `embedded-hal-bus-0.2`.
- No longer panics if the close fails when a `Volume` is dropped - the failure is instead ignored.

### Added

- `File` now has a `flush()` method.
- `File` now has a `close()` method.

### Removed

- __Breaking Change__: Removed `CS` type-param on `SdCard` - now we use the `SpiDevice` chip-select (closing [#126])
- __Breaking Change__: Removed the 74 clock cycle 'init' sequence - now applications must do this

## [Version 0.7.0] - 2024-02-04

## Changed
### Changed

- __Breaking Change__: `Volume`, `Directory` and `File` are now smart! They hold references to the thing they were made from, and will clean themselves up when dropped. The trade-off is you can can't open multiple volumes, directories or files at the same time.
- __Breaking Change__: Renamed the old types to `RawVolume`, `RawDirectory` and `RawFile`
Expand All @@ -19,18 +47,19 @@ The format is based on [Keep a Changelog] and this project adheres to [Semantic
- You can now open directories multiple times without error
- Updated to [embedded-hal] 1.0

## Added
### Added

- `RawVolume`, `RawDirectory` and `RawFile` types (like the old `Volume`, `Directory` and `File` types)
- New method `make_dir_in_dir`
- Empty strings and `"."` convert to `ShortFileName::this_dir()`
- New API `change_dir` which changes a directory to point to some child directory (or the parent) without opening a new directory.
- Updated 'shell' example to support `mkdir`, `tree` and relative/absolute paths

## Removed
### Removed

* None
- None

[#126]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/issues/126
[#74]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/issues/74
[embedded-hal]: https://crates.io/crates/embedded-hal

Expand Down Expand Up @@ -126,7 +155,7 @@ The format is based on [Keep a Changelog] and this project adheres to [Semantic

- Reduce delay waiting for response. Big speed improvements.

## [Version 0.1.0] - 2018-12-23
## [Version 0.1.1] - 2018-12-23

### Changed

Expand All @@ -137,7 +166,8 @@ The format is based on [Keep a Changelog] and this project adheres to [Semantic

[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/
[Semantic Versioning]: http://semver.org/spec/v2.0.0.html
[Unreleased]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.7.0...develop
[Unreleased]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.8.0...develop
[Version 0.8.0]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.8.0...v0.7.0
[Version 0.7.0]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.7.0...v0.6.0
[Version 0.6.0]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.6.0...v0.5.0
[Version 0.5.0]: https://github.com/rust-embedded-community/embedded-sdmmc-rs/compare/v0.5.0...v0.4.0
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ license = "MIT OR Apache-2.0"
name = "embedded-sdmmc"
readme = "README.md"
repository = "https://github.com/rust-embedded-community/embedded-sdmmc-rs"
version = "0.7.0"
version = "0.8.0"

[dependencies]
byteorder = {version = "1", default-features = false}
defmt = {version = "0.3", optional = true}
embedded-hal = "1.0.0"
heapless = "0.7"
heapless = "^0.8"
log = {version = "0.4", default-features = false, optional = true}

[dev-dependencies]
chrono = "0.4"
embedded-hal-bus = "0.1.0"
embedded-hal-bus = "0.2.0"
env_logger = "0.10.0"
flate2 = "1.0"
hex-literal = "0.4.1"
Expand Down
3 changes: 2 additions & 1 deletion LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Copyright (c) 2018-2023 Jonathan 'theJPster' Pallant and the Rust Embedded Community developers
Copyright (c) 2018-2024 Jonathan 'theJPster' Pallant and the Rust Embedded Community developers
Copyright (c) 2011-2018 Bill Greiman

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
Expand Down
6 changes: 6 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright Notices

This is a copyright notices file, as described by the Apache-2.0 license.

Copyright (c) 2018-2024 Jonathan 'theJPster' Pallant and the Rust Embedded Community developers
Copyright (c) 2011-2018 Bill Greiman
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ You will need something that implements the `BlockDevice` trait, which can read

```rust
// Build an SD Card interface out of an SPI device, a chip-select pin and the delay object
let sdcard = embedded_sdmmc::SdCard::new(sdmmc_spi, sdmmc_cs, delay);
let sdcard = embedded_sdmmc::SdCard::new(sdmmc_spi, delay);
// Get the card size (this also triggers card initialisation because it's not been done yet)
println!("Card size is {} bytes", sdcard.num_bytes()?);
// Now let's look for volumes (also known as partitions) on our block device.
Expand All @@ -27,7 +27,7 @@ let mut root_dir = volume0.open_root_dir()?;
// Open a file called "MY_FILE.TXT" in the root directory
// This mutably borrows the directory.
let mut my_file = root_dir.open_file_in_dir("MY_FILE.TXT", embedded_sdmmc::Mode::ReadOnly)?;
// Print the contents of the file
// Print the contents of the file, assuming it's in ISO-8859-1 encoding
while !my_file.is_eof() {
let mut buffer = [0u8; 32];
let num_read = my_file.read(&mut buffer)?;
Expand Down Expand Up @@ -59,10 +59,12 @@ let mut cont: VolumeManager<_, _, 6, 12, 4> = VolumeManager::new_with_limits(blo
* Log over defmt or the common log interface (feature flags).

## No-std usage

This repository houses no examples for no-std usage, however you can check out the following examples:
- [Pi Pico](https://github.com/rp-rs/rp-hal-boards/blob/main/boards/rp-pico/examples/pico_spi_sd_card.rs)
- [STM32H7XX](https://github.com/stm32-rs/stm32h7xx-hal/blob/master/examples/sdmmc_fat.rs)
- [atsamd(pygamer)](https://github.com/atsamd-rs/atsamd/blob/master/boards/pygamer/examples/sd_card.rs)

* [Pi Pico](https://github.com/rp-rs/rp-hal-boards/blob/main/boards/rp-pico/examples/pico_spi_sd_card.rs)
* [STM32H7XX](https://github.com/stm32-rs/stm32h7xx-hal/blob/master/examples/sdmmc_fat.rs)
* [atsamd(pygamer)](https://github.com/atsamd-rs/atsamd/blob/master/boards/pygamer/examples/sd_card.rs)

## Todo List (PRs welcome!)

Expand All @@ -79,12 +81,14 @@ The changelog has moved to [CHANGELOG.md](/CHANGELOG.md)
Licensed under either of

- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
<http://www.apache.org/licenses/LICENSE-2.0>)

- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)

at your option.

Copyright notices are stored in the [NOTICE](./NOTICE) file.

## Contribution

Unless you explicitly state otherwise, any contribution intentionally
Expand Down
27 changes: 22 additions & 5 deletions examples/readme_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,27 @@
//! We add enough stuff to make it compile, but it won't run because our fake
//! SPI doesn't do any replies.

#![allow(dead_code)]

use core::cell::RefCell;

use embedded_sdmmc::sdcard::DummyCsPin;
pub struct DummyCsPin;

impl embedded_hal::digital::ErrorType for DummyCsPin {
type Error = core::convert::Infallible;
}

impl embedded_hal::digital::OutputPin for DummyCsPin {
#[inline(always)]
fn set_low(&mut self) -> Result<(), Self::Error> {
Ok(())
}

#[inline(always)]
fn set_high(&mut self) -> Result<(), Self::Error> {
Ok(())
}
}

struct FakeSpiBus();

Expand Down Expand Up @@ -97,13 +115,12 @@ fn main() -> Result<(), Error> {
// BEGIN Fake stuff that will be replaced with real peripherals
let spi_bus = RefCell::new(FakeSpiBus());
let delay = FakeDelayer();
let sdmmc_spi = embedded_hal_bus::spi::RefCellDevice::new(&spi_bus, DummyCsPin, delay);
let sdmmc_cs = FakeCs();
let sdmmc_spi = embedded_hal_bus::spi::RefCellDevice::new(&spi_bus, DummyCsPin, delay).unwrap();
let time_source = FakeTimesource();
// END Fake stuff that will be replaced with real peripherals

// Build an SD Card interface out of an SPI device, a chip-select pin and the delay object
let sdcard = embedded_sdmmc::SdCard::new(sdmmc_spi, sdmmc_cs, delay);
let sdcard = embedded_sdmmc::SdCard::new(sdmmc_spi, delay);
// Get the card size (this also triggers card initialisation because it's not been done yet)
println!("Card size is {} bytes", sdcard.num_bytes()?);
// Now let's look for volumes (also known as partitions) on our block device.
Expand All @@ -118,7 +135,7 @@ fn main() -> Result<(), Error> {
// Open a file called "MY_FILE.TXT" in the root directory
// This mutably borrows the directory.
let mut my_file = root_dir.open_file_in_dir("MY_FILE.TXT", embedded_sdmmc::Mode::ReadOnly)?;
// Print the contents of the file
// Print the contents of the file, assuming it's in ISO-8859-1 encoding
while !my_file.is_eof() {
let mut buffer = [0u8; 32];
let num_read = my_file.read(&mut buffer)?;
Expand Down
23 changes: 13 additions & 10 deletions src/blockdevice.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//! Block Device support
//! Traits and types for working with Block Devices.
//!
//! Generic code for handling block devices, such as types for identifying
//! a particular block on a block device by its index.

/// Represents a standard 512 byte block (also known as a sector). IBM PC
/// formatted 5.25" and 3.5" floppy disks, SD/MMC cards up to 1 GiB in size
/// and IDE/SATA Hard Drives up to about 2 TiB all have 512 byte blocks.
/// A standard 512 byte block (also known as a sector).
///
/// IBM PC formatted 5.25" and 3.5" floppy disks, IDE/SATA Hard Drives up to
/// about 2 TiB, and almost all SD/MMC cards have 512 byte blocks.
///
/// This library does not support devices with a block size other than 512
/// bytes.
Expand All @@ -15,15 +16,17 @@ pub struct Block {
pub contents: [u8; Block::LEN],
}

/// Represents the linear numeric address of a block (or sector). The first
/// block on a disk gets `BlockIdx(0)` (which usually contains the Master Boot
/// Record).
/// The linear numeric address of a block (or sector).
///
/// The first block on a disk gets `BlockIdx(0)` (which usually contains the
/// Master Boot Record).
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct BlockIdx(pub u32);

/// Represents the a number of blocks (or sectors). Add this to a `BlockIdx`
/// to get an actual address on disk.
/// The a number of blocks (or sectors).
///
/// Add this to a `BlockIdx` to get an actual address on disk.
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct BlockCount(pub u32);
Expand All @@ -34,7 +37,7 @@ pub struct BlockIter {
current: BlockIdx,
}

/// Represents a block device - a device which can read and write blocks (or
/// A block device - a device which can read and write blocks (or
/// sectors). Only supports devices which are <= 2 TiB in size.
pub trait BlockDevice {
/// The errors that the `BlockDevice` can return. Must be debug formattable.
Expand Down
7 changes: 4 additions & 3 deletions src/fat/bpb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use crate::{
};
use byteorder::{ByteOrder, LittleEndian};

/// Represents a Boot Parameter Block. This is the first sector of a FAT
/// formatted partition, and it describes various properties of the FAT
/// filesystem.
/// A Boot Parameter Block.
///
/// This is the first sector of a FAT formatted partition, and it describes
/// various properties of the FAT filesystem.
pub struct Bpb<'a> {
data: &'a [u8; 512],
pub(crate) fat_type: FatType,
Expand Down
7 changes: 4 additions & 3 deletions src/fat/ondiskdirentry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
use crate::{fat::FatType, Attributes, BlockIdx, ClusterId, DirEntry, ShortFileName, Timestamp};
use byteorder::{ByteOrder, LittleEndian};

/// Represents a 32-byte directory entry as stored on-disk in a directory file.
/// A 32-byte directory entry as stored on-disk in a directory file.
///
/// This is the same for FAT16 and FAT32 (except FAT16 doesn't use
/// first_cluster_hi).
pub struct OnDiskDirEntry<'a> {
data: &'a [u8],
}
Expand Down Expand Up @@ -38,8 +41,6 @@ impl<'a> core::fmt::Debug for OnDiskDirEntry<'a> {
}
}

/// Represents the 32 byte directory entry. This is the same for FAT16 and
/// FAT32 (except FAT16 doesn't use first_cluster_hi).
impl<'a> OnDiskDirEntry<'a> {
pub(crate) const LEN: usize = 32;
pub(crate) const LEN_U32: u32 = 32;
Expand Down
Loading