|
ESPHome 2026.12.0-dev
|
A device addressed in fixed size blocks, such as a flash chip, an SD card or a RAM buffer. More...
#include <block_device.h>
Public Member Functions | |
| StorageError | read (uint32_t block, uint32_t offset, void *buf, uint32_t len) |
| StorageError | program (uint32_t block, uint32_t offset, const void *buf, uint32_t len) |
| StorageError | erase (uint32_t block, uint32_t count) |
| StorageError | sync () |
| Return once all earlier writes are stored on the media. | |
| StorageError | trim (uint32_t block, uint32_t count) |
| Tell the device that the blocks no longer hold data it needs to keep. | |
| const BlockGeometry & | get_geometry () const |
| bool | has_media () const |
| uint64_t | get_capacity () const |
| uint8_t | get_media_generation () const |
| Changes each time media is inserted or removed, so a user can tell that its cached state is stale. | |
| DeviceMutex & | mutex () |
Protected Member Functions | |
| virtual StorageError | device_read (uint32_t block, uint32_t offset, void *buf, uint32_t len)=0 |
| virtual StorageError | device_program (uint32_t block, uint32_t offset, const void *buf, uint32_t len)=0 |
| virtual StorageError | device_erase (uint32_t block, uint32_t count) |
| virtual StorageError | device_sync () |
| virtual StorageError | device_trim (uint32_t block, uint32_t count) |
| void | media_changed_ () |
| void | dump_geometry_ (const char *tag) const |
| StorageError | check_access_ (uint32_t block, uint32_t offset, uint32_t len, uint16_t align, bool write) const |
| StorageError | check_range_ (uint32_t block, uint32_t count) const |
Protected Attributes | |
| BlockGeometry | geometry_ {} |
| DeviceMutex | mutex_ |
| uint8_t | media_generation_ {0} |
A device addressed in fixed size blocks, such as a flash chip, an SD card or a RAM buffer.
Callers use the public methods, which check the address range, alignment and read-only state once, so a driver only implements the transfer. An access may span several blocks.
With USE_STORAGE_LOCK (a filesystem used from other tasks) each transfer holds mutex(). A driver that touches the device from its own loop() or timers must hold it too. The getters do not lock: a caller on another task that needs the geometry to stay as it is holds mutex() while it uses it.
Definition at line 61 of file block_device.h.
|
protected |
Definition at line 20 of file block_device.cpp.
|
protected |
Definition at line 34 of file block_device.cpp.
|
inlineprotectedvirtual |
Definition at line 83 of file block_device.h.
|
protectedpure virtual |
Implemented in esphome::ram_disk::RamDisk.
|
protectedpure virtual |
Implemented in esphome::ram_disk::RamDisk.
|
inlineprotectedvirtual |
Definition at line 84 of file block_device.h.
|
inlineprotectedvirtual |
Definition at line 85 of file block_device.h.
|
protected |
Definition at line 93 of file block_device.cpp.
| StorageError esphome::storage::BlockDevice::erase | ( | uint32_t | block, |
| uint32_t | count ) |
Definition at line 69 of file block_device.cpp.
|
inline |
Definition at line 73 of file block_device.h.
|
inline |
Definition at line 71 of file block_device.h.
|
inline |
Changes each time media is inserted or removed, so a user can tell that its cached state is stale.
Definition at line 77 of file block_device.h.
|
inline |
Definition at line 72 of file block_device.h.
|
inlineprotected |
Definition at line 87 of file block_device.h.
|
inline |
Definition at line 78 of file block_device.h.
| StorageError esphome::storage::BlockDevice::program | ( | uint32_t | block, |
| uint32_t | offset, | ||
| const void * | buf, | ||
| uint32_t | len ) |
Definition at line 58 of file block_device.cpp.
| StorageError esphome::storage::BlockDevice::read | ( | uint32_t | block, |
| uint32_t | offset, | ||
| void * | buf, | ||
| uint32_t | len ) |
Definition at line 44 of file block_device.cpp.
| StorageError esphome::storage::BlockDevice::sync | ( | ) |
Return once all earlier writes are stored on the media.
Definition at line 78 of file block_device.cpp.
| StorageError esphome::storage::BlockDevice::trim | ( | uint32_t | block, |
| uint32_t | count ) |
Tell the device that the blocks no longer hold data it needs to keep.
Definition at line 85 of file block_device.cpp.
|
protected |
Definition at line 93 of file block_device.h.
|
protected |
Definition at line 95 of file block_device.h.
|
protected |
Definition at line 94 of file block_device.h.