Code Monkey home page Code Monkey logo

embedded-sdmmc-rs's Introduction

Embedded SD/MMC crates.io Documentation

This crate is intended to allow you to read/write files on a FAT formatted SD card on your Rust Embedded device, as easily as using the SdFat Arduino library. It is written in pure-Rust, is #![no_std] and does not use alloc or collections to keep the memory footprint low. In the first instance it is designed for readability and simplicity over performance.

Using the crate

You will need something that implements the BlockDevice trait, which can read and write the 512-byte blocks (or sectors) from your card. If you were to implement this over USB Mass Storage, there's no reason this crate couldn't work with a USB Thumb Drive, but we only supply a BlockDevice suitable for reading SD and SDHC cards over SPI.

let mut cont = embedded_sdmmc::Controller::new(embedded_sdmmc::SdMmcSpi::new(sdmmc_spi, sdmmc_cs), time_source);
write!(uart, "Init SD card...").unwrap();
match cont.device().init() {
    Ok(_) => {
        write!(uart, "OK!\nCard size...").unwrap();
        match cont.device().card_size_bytes() {
            Ok(size) => writeln!(uart, "{}", size).unwrap(),
            Err(e) => writeln!(uart, "Err: {:?}", e).unwrap(),
        }
        write!(uart, "Volume 0...").unwrap();
        match cont.get_volume(embedded_sdmmc::VolumeIdx(0)) {
            Ok(v) => writeln!(uart, "{:?}", v).unwrap(),
            Err(e) => writeln!(uart, "Err: {:?}", e).unwrap(),
        }
    }
    Err(e) => writeln!(uart, "{:?}!", e).unwrap(),
}

Supported features

  • Open files in all supported methods from an open directory
  • Read data from open files
  • Write data to open files
  • Close files
  • Iterate root directory
  • Iterate sub-directories

Todo List (PRs welcome!)

  • Create new dirs
  • Delete files
  • Delete (empty) directories
  • Handle MS-DOS /path/foo/bar.txt style paths.

Changelog

Unreleased changes (will be 0.3.1)

  • Code tidy-ups and more documentation.

Version 0.3.0

  • Updated to v2 embedded-hal traits.
  • Added open support for all modes.
  • Added write support for files.
  • Added Info_Sector tracking for FAT32.
  • Change directory iteration to look in all the directory's clusters.
  • Added write_test and create_test.
  • De-duplicated FAT16 and FAT32 code (rust-embedded-community#10)

Version 0.2.1

  • Added readme=README.md to Cargo.toml

Version 0.2.0

  • Reduce delay waiting for response. Big speed improvements.

Version 0.1.0

  • Can read blocks from an SD Card using an embedded_hal::SPI device and a embedded_hal::OutputPin for Chip Select.
  • Can read partition tables and open a FAT32 or FAT16 formatted partition.
  • Can open and iterate the root directory of a FAT16 formatted partition.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.