mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-09-29 21:30:39 +00:00
Add defmt
to esp-storage
(#4127)
* Add defmt to esp-storage * changelog * Fix technically-incorrect feature comment * Add some docs for pub API * Move demft in the optional deps * reviews * reviews
This commit is contained in:
parent
099b70fef9
commit
555922b887
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Added
|
||||
|
||||
- `defmt` feature and `FlashStorage`, `FlashStorageError` now implements `Defmt` (#4127)
|
||||
|
||||
### Changed
|
||||
|
||||
|
@ -24,6 +24,7 @@ procmacros = { version = "0.19.0", package = "esp-hal-procmacros", path =
|
||||
# Optional dependencies
|
||||
esp-sync = { version = "0.0.0", path = "../esp-sync", optional = true }
|
||||
esp-rom-sys = { version = "0.1.1", path = "../esp-rom-sys", optional = true }
|
||||
defmt = { version = "1.0.1", optional = true }
|
||||
|
||||
# Unstable dependencies that are not (strictly) part of the public API
|
||||
document-features = "0.2.11"
|
||||
@ -37,6 +38,9 @@ critical-section = []
|
||||
## Bytewise read emulation
|
||||
bytewise-read = []
|
||||
|
||||
## Implement `defmt::Format` on certain types.
|
||||
defmt = ["dep:defmt"]
|
||||
|
||||
#! ### Chip selection
|
||||
#! One of the following features must be enabled to select the target chip:
|
||||
|
||||
|
@ -2,18 +2,27 @@ use core::mem::MaybeUninit;
|
||||
|
||||
use crate::chip_specific;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
/// Flash storage error.
|
||||
pub enum FlashStorageError {
|
||||
/// I/O error.
|
||||
IoError,
|
||||
/// I/O operation timed out.
|
||||
IoTimeout,
|
||||
/// Flash could not be unlocked for writing.
|
||||
CantUnlock,
|
||||
/// Address or length not aligned to required boundary.
|
||||
NotAligned,
|
||||
/// Address or length out of bounds.
|
||||
OutOfBounds,
|
||||
/// Other error with the given error code.
|
||||
Other(i32),
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
/// Check return code from flash operations.
|
||||
pub fn check_rc(rc: i32) -> Result<(), FlashStorageError> {
|
||||
match rc {
|
||||
0 => Ok(()),
|
||||
@ -24,6 +33,8 @@ pub fn check_rc(rc: i32) -> Result<(), FlashStorageError> {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
/// Flash storage abstraction.
|
||||
pub struct FlashStorage {
|
||||
pub(crate) capacity: usize,
|
||||
unlocked: bool,
|
||||
@ -36,9 +47,12 @@ impl Default for FlashStorage {
|
||||
}
|
||||
|
||||
impl FlashStorage {
|
||||
/// Flash word size in bytes.
|
||||
pub const WORD_SIZE: u32 = 4;
|
||||
/// Flash sector size in bytes.
|
||||
pub const SECTOR_SIZE: u32 = 4096;
|
||||
|
||||
/// Create a new flash storage instance.
|
||||
pub fn new() -> FlashStorage {
|
||||
let mut storage = FlashStorage {
|
||||
capacity: 0,
|
||||
|
@ -332,6 +332,9 @@ impl Package {
|
||||
Package::EspPreempt => {
|
||||
cases.push(vec!["esp-alloc".to_owned(), "esp-hal/unstable".to_owned()])
|
||||
}
|
||||
Package::EspStorage => {
|
||||
cases.push(vec!["defmt".to_owned()]);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user