Skip to content

Commit c106a20

Browse files
committed
ESP class is singleton without data members, define all member functions static.
1 parent 93c524c commit c106a20

File tree

2 files changed

+71
-71
lines changed

2 files changed

+71
-71
lines changed

cores/esp8266/Esp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ bool EspClass::eraseConfig(void) {
687687
return true;
688688
}
689689

690-
uint8_t *EspClass::random(uint8_t *resultArray, const size_t outputSizeBytes) const
690+
uint8_t *EspClass::random(uint8_t *resultArray, const size_t outputSizeBytes)
691691
{
692692
/**
693693
* The ESP32 Technical Reference Manual v4.1 chapter 24 has the following to say about random number generation (no information found for ESP8266):
@@ -737,7 +737,7 @@ uint8_t *EspClass::random(uint8_t *resultArray, const size_t outputSizeBytes) co
737737
return resultArray;
738738
}
739739

740-
uint32_t EspClass::random() const
740+
uint32_t EspClass::random()
741741
{
742742
union { uint32_t b32; uint8_t b8[4]; } result;
743743
random(result.b8, 4);

cores/esp8266/Esp.h

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -84,94 +84,94 @@ typedef enum {
8484
class EspClass {
8585
public:
8686
// TODO: figure out how to set WDT timeout
87-
void wdtEnable(uint32_t timeout_ms = 0);
87+
static void wdtEnable(uint32_t timeout_ms = 0);
8888
// note: setting the timeout value is not implemented at the moment
89-
void wdtEnable(WDTO_t timeout_ms = WDTO_0MS);
89+
static void wdtEnable(WDTO_t timeout_ms = WDTO_0MS);
9090

91-
void wdtDisable();
92-
void wdtFeed();
91+
static void wdtDisable();
92+
static void wdtFeed();
9393

94-
void deepSleep(uint64_t time_us);
95-
void deepSleepInstant(uint64_t time_us);
96-
uint64_t deepSleepMax();
94+
static void deepSleep(uint64_t time_us);
95+
static void deepSleepInstant(uint64_t time_us);
96+
static uint64_t deepSleepMax();
9797

98-
bool forcedModemSleep(uint32_t duration_us = 0, void (*wakeupCb)() = nullptr);
98+
static bool forcedModemSleep(uint32_t duration_us = 0, void (*wakeupCb)() = nullptr);
9999
/// The prior sleep type is restored, but only as automatic.
100100
/// If any forced sleep mode was effective before forcedModemSleep,
101101
/// it would have to be restored explicitly.
102-
void forcedModemSleepOff();
102+
static void forcedModemSleepOff();
103103

104-
bool forcedLightSleepBegin(uint32_t duration_us = 0, void (*wakeupCb)() = nullptr);
104+
static bool forcedLightSleepBegin(uint32_t duration_us = 0, void (*wakeupCb)() = nullptr);
105105
/// The prior sleep type is restored, but only as automatic.
106106
/// If any forced sleep mode was effective before forcedLightSleepBegin,
107107
/// it would have to be restored explicitly.
108-
void forcedLightSleepEnd(bool cancel = false);
108+
static void forcedLightSleepEnd(bool cancel = false);
109109

110-
void autoModemSleep();
111-
void autoLightSleep();
110+
static void autoModemSleep();
111+
static void autoLightSleep();
112112
/// The prior sleep type is restored, but only as automatic.
113113
/// If any forced sleep mode was effective before auto{Modem,Light}Sleep,
114114
/// it would have to be restored explicitly.
115-
void autoSleepOff();
115+
static void autoSleepOff();
116116

117-
bool rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size);
118-
bool rtcUserMemoryWrite(uint32_t offset, uint32_t *data, size_t size);
117+
static bool rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size);
118+
static bool rtcUserMemoryWrite(uint32_t offset, uint32_t *data, size_t size);
119119

120-
void reset();
121-
void restart();
120+
static void reset();
121+
static void restart();
122122
/**
123123
* @brief When calling this method the ESP8266 reboots into the UART download mode without
124124
* the need of any external wiring. This is the same mode which can also be entered by
125125
* pulling GPIO0=low, GPIO2=high, GPIO15=low and resetting the ESP8266.
126126
*/
127-
[[noreturn]] void rebootIntoUartDownloadMode();
127+
[[noreturn]] static void rebootIntoUartDownloadMode();
128128

129-
uint16_t getVcc();
130-
uint32_t getChipId();
129+
static uint16_t getVcc();
130+
static uint32_t getChipId();
131131

132-
uint32_t getFreeHeap();
133-
uint16_t getMaxFreeBlockSize();
134-
uint8_t getHeapFragmentation(); // in %
135-
void getHeapStats(uint32_t* free = nullptr, uint16_t* max = nullptr, uint8_t* frag = nullptr);
132+
static uint32_t getFreeHeap();
133+
static uint16_t getMaxFreeBlockSize();
134+
static uint8_t getHeapFragmentation(); // in %
135+
static void getHeapStats(uint32_t* free = nullptr, uint16_t* max = nullptr, uint8_t* frag = nullptr);
136136

137-
uint32_t getFreeContStack();
138-
void resetFreeContStack();
137+
static uint32_t getFreeContStack();
138+
static void resetFreeContStack();
139139

140-
const char * getSdkVersion();
141-
String getCoreVersion();
142-
String getFullVersion();
140+
static const char * getSdkVersion();
141+
static String getCoreVersion();
142+
static String getFullVersion();
143143

144-
uint8_t getBootVersion();
145-
uint8_t getBootMode();
144+
static uint8_t getBootVersion();
145+
static uint8_t getBootMode();
146146

147147
#if defined(F_CPU) || defined(CORE_MOCK)
148148
constexpr
149149
#endif
150-
inline uint8_t getCpuFreqMHz() const __attribute__((always_inline))
150+
static inline uint8_t getCpuFreqMHz() __attribute__((always_inline))
151151
{
152152
return esp_get_cpu_freq_mhz();
153153
}
154154

155-
uint32_t getFlashChipId();
156-
uint8_t getFlashChipVendorId();
155+
static uint32_t getFlashChipId();
156+
static uint8_t getFlashChipVendorId();
157157

158158
//gets the actual chip size based on the flash id
159-
uint32_t getFlashChipRealSize();
159+
static uint32_t getFlashChipRealSize();
160160
//gets the size of the flash as set by the compiler
161-
uint32_t getFlashChipSize();
162-
uint32_t getFlashChipSpeed();
163-
FlashMode_t getFlashChipMode();
164-
uint32_t getFlashChipSizeByChipId();
161+
static uint32_t getFlashChipSize();
162+
static uint32_t getFlashChipSpeed();
163+
static FlashMode_t getFlashChipMode();
164+
static uint32_t getFlashChipSizeByChipId();
165165

166-
uint32_t magicFlashChipSize(uint8_t byte);
167-
uint32_t magicFlashChipSpeed(uint8_t byte);
168-
FlashMode_t magicFlashChipMode(uint8_t byte);
166+
static uint32_t magicFlashChipSize(uint8_t byte);
167+
static uint32_t magicFlashChipSpeed(uint8_t byte);
168+
static FlashMode_t magicFlashChipMode(uint8_t byte);
169169

170-
bool checkFlashConfig(bool needsEquals = false);
170+
static bool checkFlashConfig(bool needsEquals = false);
171171

172-
bool checkFlashCRC();
172+
static bool checkFlashCRC();
173173

174-
bool flashEraseSector(uint32_t sector);
174+
static bool flashEraseSector(uint32_t sector);
175175
/**
176176
* @brief Write @a size bytes from @a data to flash at @a address
177177
* This overload requires @a data and @a size to be always 4 byte aligned and
@@ -184,7 +184,7 @@ class EspClass {
184184
* @retval true success
185185
* @retval false failure to write to flash or incorrect alignment of params
186186
*/
187-
bool flashWrite(uint32_t address, const uint32_t *data, size_t size);
187+
static bool flashWrite(uint32_t address, const uint32_t *data, size_t size);
188188
/**
189189
* @brief Write @a size bytes from @a data to flash at @a address
190190
* This overload handles all misalignment cases
@@ -193,7 +193,7 @@ class EspClass {
193193
* @param size amount of data, passing not multiple of 4 will cause additional reads and writes
194194
* @return bool result of operation
195195
*/
196-
bool flashWrite(uint32_t address, const uint8_t *data, size_t size);
196+
static bool flashWrite(uint32_t address, const uint8_t *data, size_t size);
197197
/**
198198
* @brief Read @a size bytes to @a data to flash at @a address
199199
* This overload requires @a data and @a size to be 4 byte aligned
@@ -204,7 +204,7 @@ class EspClass {
204204
* @retval true success
205205
* @retval false failure to read from flash or incorrect alignment of params
206206
*/
207-
bool flashRead(uint32_t address, uint32_t *data, size_t size);
207+
static bool flashRead(uint32_t address, uint32_t *data, size_t size);
208208
/**
209209
* @brief Read @a size bytes to @a data to flash at @a address
210210
* This overload handles all misalignment cases
@@ -213,59 +213,59 @@ class EspClass {
213213
* @param size amount of data, passing not multiple of 4 will cause additional read
214214
* @return bool result of operation
215215
*/
216-
bool flashRead(uint32_t address, uint8_t *data, size_t size);
216+
static bool flashRead(uint32_t address, uint8_t *data, size_t size);
217217

218-
uint32_t getSketchSize();
219-
String getSketchMD5();
220-
uint32_t getFreeSketchSpace();
221-
bool updateSketch(Stream& in, uint32_t size, bool restartOnFail = false, bool restartOnSuccess = true);
218+
static uint32_t getSketchSize();
219+
static String getSketchMD5();
220+
static uint32_t getFreeSketchSpace();
221+
static bool updateSketch(Stream& in, uint32_t size, bool restartOnFail = false, bool restartOnSuccess = true);
222222

223-
String getResetReason();
224-
String getResetInfo();
225-
struct rst_info * getResetInfoPtr();
223+
static String getResetReason();
224+
static String getResetInfo();
225+
static struct rst_info * getResetInfoPtr();
226226

227-
bool eraseConfig();
227+
static bool eraseConfig();
228228

229-
uint8_t *random(uint8_t *resultArray, const size_t outputSizeBytes) const;
230-
uint32_t random() const;
229+
static uint8_t *random(uint8_t *resultArray, const size_t outputSizeBytes);
230+
static uint32_t random();
231231

232232
#if !defined(CORE_MOCK)
233-
inline uint32_t getCycleCount() __attribute__((always_inline))
233+
static inline uint32_t getCycleCount() __attribute__((always_inline))
234234
{
235235
return esp_get_cycle_count();
236236
}
237237
#else
238-
uint32_t getCycleCount();
238+
static uint32_t getCycleCount();
239239
#endif // !defined(CORE_MOCK)
240240
/**
241241
* @brief Push current Heap selection and set Heap selection to DRAM.
242242
*
243243
* @param none
244244
* @return none
245245
*/
246-
void setDramHeap();
246+
static void setDramHeap();
247247
/**
248248
* @brief Push current Heap selection and set Heap selection to IRAM.
249249
*
250250
* @param none
251251
* @return none
252252
*/
253-
void setIramHeap();
253+
static void setIramHeap();
254254
/**
255255
* @brief Push current Heap selection and set Heap selection to External. (Experimental)
256256
*
257257
* @param none
258258
* @return none
259259
*/
260-
void setExternalHeap();
260+
static void setExternalHeap();
261261
/**
262262
* @brief Restores Heap selection back to value present when
263263
* setDramHeap, setIramHeap, or setExternalHeap was called.
264264
*
265265
* @param none
266266
* @return none
267267
*/
268-
void resetHeap();
268+
static void resetHeap();
269269
private:
270270
/**
271271
* @brief Replaces @a byteCount bytes of a 4 byte block on flash
@@ -277,7 +277,7 @@ class EspClass {
277277
* @retval true success
278278
* @retval false failed to read/write or invalid args
279279
*/
280-
bool flashReplaceBlock(uint32_t address, const uint8_t *value, uint32_t byteCount);
280+
static bool flashReplaceBlock(uint32_t address, const uint8_t *value, uint32_t byteCount);
281281
/**
282282
* @brief Write up to @a size bytes from @a data to flash at @a address
283283
* This function takes case of unaligned memory acces by copying @a data to a temporary buffer,
@@ -288,7 +288,7 @@ class EspClass {
288288
* @param size amount of data
289289
* @return size_t amount of data written, 0 on failure
290290
*/
291-
size_t flashWriteUnalignedMemory(uint32_t address, const uint8_t *data, size_t size);
291+
static size_t flashWriteUnalignedMemory(uint32_t address, const uint8_t *data, size_t size);
292292
/**
293293
* @brief Splits up to 4 bytes into 4 byte blocks and writes them to flash
294294
* We need this since spi_flash_write cannot handle writing over a page boundary with unaligned offset
@@ -299,7 +299,7 @@ class EspClass {
299299
* @param size amount of data, must be < 4
300300
* @return bool result of operation
301301
*/
302-
bool flashWritePageBreak(uint32_t address, const uint8_t *data, size_t size);
302+
static bool flashWritePageBreak(uint32_t address, const uint8_t *data, size_t size);
303303
};
304304

305305
extern EspClass ESP;

0 commit comments

Comments
 (0)