ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
ram_disk.cpp
Go to the documentation of this file.
1#include "ram_disk.h"
2
3#include <cstring>
4
6#include "esphome/core/log.h"
7
9
10ESPHOME_LOG_TAG(TAG, "ram_disk");
11
13
15 const size_t size = static_cast<size_t>(this->geometry_.block_size) * this->block_count_;
16 RAMAllocator<uint8_t> allocator;
17 this->data_ = allocator.allocate(size);
18 if (this->data_ == nullptr) {
19 this->mark_failed(LOG_STR("Not enough memory"));
20 return;
21 }
22 memset(this->data_, 0, size);
24 this->media_changed_();
25}
26
28 ESP_LOGCONFIG(TAG, "RAM disk:");
29 this->dump_geometry_(TAG);
30}
31
33 memcpy(buf, this->data_ + static_cast<size_t>(block) * this->geometry_.block_size + offset, len);
35}
36
38 memcpy(this->data_ + static_cast<size_t>(block) * this->geometry_.block_size + offset, buf, len);
40}
41
42} // namespace esphome::ram_disk
void mark_failed()
Mark this component as failed.
An STL allocator that uses SPI or internal RAM.
Definition helpers.h:2670
T * allocate(size_t n)
Definition helpers.h:2697
void dump_config() override
Definition ram_disk.cpp:27
void setup() override
Definition ram_disk.cpp:14
storage::StorageError device_program(uint32_t block, uint32_t offset, const void *buf, uint32_t len) override
Definition ram_disk.cpp:37
storage::StorageError device_read(uint32_t block, uint32_t offset, void *buf, uint32_t len) override
Definition ram_disk.cpp:32
void dump_geometry_(const char *tag) const
ESPHOME_LOG_TAG(TAG, "ram_disk")
const void size_t len
Definition hal.h:68
uint16_t size
Definition helpers.cpp:44
static void uint32_t