ProgMem.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * ProgMem.h
8  *
9  ****/
10 #pragma once
11 
12 #include "CustomDevice.h"
13 
14 namespace Storage
15 {
19 class ProgMem : public CustomDevice
20 {
21 public:
22  String getName() const override
23  {
24  return F("ProgMem");
25  }
26 
27  size_t getBlockSize() const override
28  {
29  return sizeof(uint32_t);
30  }
31 
32  size_t getSize() const override
33  {
34  return 0x80000000;
35  }
36 
37  Type getType() const override
38  {
39  return Type::flash;
40  }
41 
42  bool read(uint32_t address, void* dst, size_t size) override;
43 
44  bool write(uint32_t address, const void* src, size_t size) override
45  {
46  return false;
47  }
48 
49  bool erase_range(uint32_t address, size_t size) override
50  {
51  return false;
52  }
53 
55 
65  Partition createPartition(const String& name, const void* flashPtr, size_t size, Partition::Type type,
66  uint8_t subtype);
67 
68  template <typename T> Partition createPartition(const String& name, const void* flashPtr, size_t size, T subType)
69  {
70  return createPartition(name, flashPtr, size, Partition::Type(T::partitionType), uint8_t(subType));
71  }
72 
76  Partition createPartition(const String& name, const FSTR::ObjectBase& fstr, Partition::Type type, uint8_t subtype)
77  {
78  return createPartition(name, fstr.data(), fstr.size(), type, subtype);
79  }
80 
81  template <typename T> Partition createPartition(const String& name, const FSTR::ObjectBase& fstr, T subType)
82  {
83  return createPartition(name, fstr, Partition::Type(T::partitionType), uint8_t(subType));
84  }
85 };
86 
87 extern ProgMem progMem;
88 
89 } // namespace Storage
Used when defining data structures.
Definition: ObjectBase.hpp:32
const uint8_t * data() const
Get a pointer to the flash data.
Partition createPartition(const String &name, const void *flashPtr, size_t size, Partition::Type type, uint8_t subtype)
Create partition for PROGMEM data access.
size_t getSize() const override
Obtain addressable size of this device.
Definition: ProgMem.h:32
The String class.
Definition: WString.h:136
Partition createPartition(const String &name, const FSTR::ObjectBase &fstr, Partition::Type type, uint8_t subtype)
Create partition for FlashString data access.
Definition: ProgMem.h:76
Class to support dynamic partitions.
Definition: CustomDevice.h:16
Type
Storage type.
Definition: Components/Storage/src/include/Storage/Device.h:41
#define F(string_literal)
Wrap a string literal stored in flash and access it using a String object.
Definition: WString.h:113
Partition createPartition(const String &name, const FSTR::ObjectBase &fstr, T subType)
Definition: ProgMem.h:81
size_t getBlockSize() const override
Obtain smallest allocation unit for erase operations.
Definition: ProgMem.h:27
Partition createPartition(const String &name, const void *flashPtr, size_t size, T subType)
Definition: ProgMem.h:68
bool read(uint32_t address, void *dst, size_t size) override
Read data from the storage device.
bool write(uint32_t address, const void *src, size_t size) override
Write data to the storage device.
Definition: ProgMem.h:44
Partition createPartition(const Partition::Info &info)
ProgMem progMem
String getName() const override
Obtain unique device name.
Definition: ProgMem.h:22
Storage device to access PROGMEM using flash API.
Definition: ProgMem.h:19
Type getType() const override
Obtain device type.
Definition: ProgMem.h:37
Type
Definition: Partition.h:81
bool erase_range(uint32_t address, size_t size) override
Erase a region of storage in preparation for writing.
Definition: ProgMem.h:49
Represents a flash partition.
Definition: Partition.h:78
Definition: FileDevice.h:23
size_t size() const
Get the object data size in bytes.
Definition: ObjectBase.hpp:44