Skip to content

Commit 5f21c61

Browse files
authored
ESP has no data members, is used as singleton object, and can be called before C++ runtime setup during boot: make all member functions static. (#8006)
1 parent bdd341c commit 5f21c61

File tree

2 files changed

+64
-64
lines changed

2 files changed

+64
-64
lines changed

cores/esp8266/Esp.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ bool EspClass::eraseConfig(void) {
525525
return true;
526526
}
527527

528-
uint8_t *EspClass::random(uint8_t *resultArray, const size_t outputSizeBytes) const
528+
uint8_t *EspClass::random(uint8_t *resultArray, const size_t outputSizeBytes)
529529
{
530530
/**
531531
* The ESP32 Technical Reference Manual v4.1 chapter 24 has the following to say about random number generation (no information found for ESP8266):
@@ -575,7 +575,7 @@ uint8_t *EspClass::random(uint8_t *resultArray, const size_t outputSizeBytes) co
575575
return resultArray;
576576
}
577577

578-
uint32_t EspClass::random() const
578+
uint32_t EspClass::random()
579579
{
580580
union { uint32_t b32; uint8_t b8[4]; } result;
581581
random(result.b8, 4);

cores/esp8266/Esp.h

+62-62
Original file line numberDiff line numberDiff line change
@@ -87,75 +87,75 @@ typedef enum {
8787
class EspClass {
8888
public:
8989
// TODO: figure out how to set WDT timeout
90-
void wdtEnable(uint32_t timeout_ms = 0);
90+
static void wdtEnable(uint32_t timeout_ms = 0);
9191
// note: setting the timeout value is not implemented at the moment
92-
void wdtEnable(WDTO_t timeout_ms = WDTO_0MS);
92+
static void wdtEnable(WDTO_t timeout_ms = WDTO_0MS);
9393

94-
void wdtDisable();
95-
void wdtFeed();
94+
static void wdtDisable();
95+
static void wdtFeed();
9696

97-
void deepSleep(uint64_t time_us, RFMode mode = RF_DEFAULT);
98-
void deepSleepInstant(uint64_t time_us, RFMode mode = RF_DEFAULT);
99-
uint64_t deepSleepMax();
97+
static void deepSleep(uint64_t time_us, RFMode mode = RF_DEFAULT);
98+
static void deepSleepInstant(uint64_t time_us, RFMode mode = RF_DEFAULT);
99+
static uint64_t deepSleepMax();
100100

101-
bool rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size);
102-
bool rtcUserMemoryWrite(uint32_t offset, uint32_t *data, size_t size);
101+
static bool rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size);
102+
static bool rtcUserMemoryWrite(uint32_t offset, uint32_t *data, size_t size);
103103

104-
void reset();
105-
void restart();
104+
static void reset();
105+
static void restart();
106106
/**
107107
* @brief When calling this method the ESP8266 reboots into the UART download mode without
108108
* the need of any external wiring. This is the same mode which can also be entered by
109109
* pulling GPIO0=low, GPIO2=high, GPIO15=low and resetting the ESP8266.
110110
*/
111-
[[noreturn]] void rebootIntoUartDownloadMode();
111+
[[noreturn]] static void rebootIntoUartDownloadMode();
112112

113-
uint16_t getVcc();
114-
uint32_t getChipId();
113+
static uint16_t getVcc();
114+
static uint32_t getChipId();
115115

116-
uint32_t getFreeHeap();
117-
uint16_t getMaxFreeBlockSize();
118-
uint8_t getHeapFragmentation(); // in %
119-
void getHeapStats(uint32_t* free = nullptr, uint16_t* max = nullptr, uint8_t* frag = nullptr);
116+
static uint32_t getFreeHeap();
117+
static uint16_t getMaxFreeBlockSize();
118+
static uint8_t getHeapFragmentation(); // in %
119+
static void getHeapStats(uint32_t* free = nullptr, uint16_t* max = nullptr, uint8_t* frag = nullptr);
120120

121-
uint32_t getFreeContStack();
122-
void resetFreeContStack();
121+
static uint32_t getFreeContStack();
122+
static void resetFreeContStack();
123123

124-
const char * getSdkVersion();
125-
String getCoreVersion();
126-
String getFullVersion();
124+
static const char * getSdkVersion();
125+
static String getCoreVersion();
126+
static String getFullVersion();
127127

128-
uint8_t getBootVersion();
129-
uint8_t getBootMode();
128+
static uint8_t getBootVersion();
129+
static uint8_t getBootMode();
130130

131131
#if defined(F_CPU) || defined(CORE_MOCK)
132132
constexpr
133133
#endif
134-
inline uint8_t getCpuFreqMHz() const __attribute__((always_inline))
134+
static inline uint8_t getCpuFreqMHz() __attribute__((always_inline))
135135
{
136136
return esp_get_cpu_freq_mhz();
137137
}
138138

139-
uint32_t getFlashChipId();
140-
uint8_t getFlashChipVendorId();
139+
static uint32_t getFlashChipId();
140+
static uint8_t getFlashChipVendorId();
141141

142142
//gets the actual chip size based on the flash id
143-
uint32_t getFlashChipRealSize();
143+
static uint32_t getFlashChipRealSize();
144144
//gets the size of the flash as set by the compiler
145-
uint32_t getFlashChipSize();
146-
uint32_t getFlashChipSpeed();
147-
FlashMode_t getFlashChipMode();
148-
uint32_t getFlashChipSizeByChipId();
145+
static uint32_t getFlashChipSize();
146+
static uint32_t getFlashChipSpeed();
147+
static FlashMode_t getFlashChipMode();
148+
static uint32_t getFlashChipSizeByChipId();
149149

150-
uint32_t magicFlashChipSize(uint8_t byte);
151-
uint32_t magicFlashChipSpeed(uint8_t byte);
152-
FlashMode_t magicFlashChipMode(uint8_t byte);
150+
static uint32_t magicFlashChipSize(uint8_t byte);
151+
static uint32_t magicFlashChipSpeed(uint8_t byte);
152+
static FlashMode_t magicFlashChipMode(uint8_t byte);
153153

154-
bool checkFlashConfig(bool needsEquals = false);
154+
static bool checkFlashConfig(bool needsEquals = false);
155155

156-
bool checkFlashCRC();
156+
static bool checkFlashCRC();
157157

158-
bool flashEraseSector(uint32_t sector);
158+
static bool flashEraseSector(uint32_t sector);
159159
/**
160160
* @brief Write @a size bytes from @a data to flash at @a address
161161
* This overload requires @a data and @a size to be always 4 byte aligned and
@@ -168,7 +168,7 @@ class EspClass {
168168
* @retval true success
169169
* @retval false failure to write to flash or incorrect alignment of params
170170
*/
171-
bool flashWrite(uint32_t address, const uint32_t *data, size_t size);
171+
static bool flashWrite(uint32_t address, const uint32_t *data, size_t size);
172172
/**
173173
* @brief Write @a size bytes from @a data to flash at @a address
174174
* This overload handles all misalignment cases
@@ -177,7 +177,7 @@ class EspClass {
177177
* @param size amount of data, passing not multiple of 4 will cause additional reads and writes
178178
* @return bool result of operation
179179
*/
180-
bool flashWrite(uint32_t address, const uint8_t *data, size_t size);
180+
static bool flashWrite(uint32_t address, const uint8_t *data, size_t size);
181181
/**
182182
* @brief Read @a size bytes to @a data to flash at @a address
183183
* This overload requires @a data and @a size to be 4 byte aligned
@@ -188,7 +188,7 @@ class EspClass {
188188
* @retval true success
189189
* @retval false failure to read from flash or incorrect alignment of params
190190
*/
191-
bool flashRead(uint32_t address, uint32_t *data, size_t size);
191+
static bool flashRead(uint32_t address, uint32_t *data, size_t size);
192192
/**
193193
* @brief Read @a size bytes to @a data to flash at @a address
194194
* This overload handles all misalignment cases
@@ -197,59 +197,59 @@ class EspClass {
197197
* @param size amount of data, passing not multiple of 4 will cause additional read
198198
* @return bool result of operation
199199
*/
200-
bool flashRead(uint32_t address, uint8_t *data, size_t size);
200+
static bool flashRead(uint32_t address, uint8_t *data, size_t size);
201201

202-
uint32_t getSketchSize();
203-
String getSketchMD5();
204-
uint32_t getFreeSketchSpace();
205-
bool updateSketch(Stream& in, uint32_t size, bool restartOnFail = false, bool restartOnSuccess = true);
202+
static uint32_t getSketchSize();
203+
static String getSketchMD5();
204+
static uint32_t getFreeSketchSpace();
205+
static bool updateSketch(Stream& in, uint32_t size, bool restartOnFail = false, bool restartOnSuccess = true);
206206

207-
String getResetReason();
208-
String getResetInfo();
209-
struct rst_info * getResetInfoPtr();
207+
static String getResetReason();
208+
static String getResetInfo();
209+
static struct rst_info * getResetInfoPtr();
210210

211-
bool eraseConfig();
211+
static bool eraseConfig();
212212

213-
uint8_t *random(uint8_t *resultArray, const size_t outputSizeBytes) const;
214-
uint32_t random() const;
213+
static uint8_t *random(uint8_t *resultArray, const size_t outputSizeBytes);
214+
static uint32_t random();
215215

216216
#if !defined(CORE_MOCK)
217-
inline uint32_t getCycleCount() __attribute__((always_inline))
217+
static inline uint32_t getCycleCount() __attribute__((always_inline))
218218
{
219219
return esp_get_cycle_count();
220220
}
221221
#else
222-
uint32_t getCycleCount();
222+
static uint32_t getCycleCount();
223223
#endif // !defined(CORE_MOCK)
224224
/**
225225
* @brief Push current Heap selection and set Heap selection to DRAM.
226226
*
227227
* @param none
228228
* @return none
229229
*/
230-
void setDramHeap();
230+
static void setDramHeap();
231231
/**
232232
* @brief Push current Heap selection and set Heap selection to IRAM.
233233
*
234234
* @param none
235235
* @return none
236236
*/
237-
void setIramHeap();
237+
static void setIramHeap();
238238
/**
239239
* @brief Push current Heap selection and set Heap selection to External. (Experimental)
240240
*
241241
* @param none
242242
* @return none
243243
*/
244-
void setExternalHeap();
244+
static void setExternalHeap();
245245
/**
246246
* @brief Restores Heap selection back to value present when
247247
* setDramHeap, setIramHeap, or setExternalHeap was called.
248248
*
249249
* @param none
250250
* @return none
251251
*/
252-
void resetHeap();
252+
static void resetHeap();
253253
private:
254254
/**
255255
* @brief Replaces @a byteCount bytes of a 4 byte block on flash
@@ -261,7 +261,7 @@ class EspClass {
261261
* @retval true success
262262
* @retval false failed to read/write or invalid args
263263
*/
264-
bool flashReplaceBlock(uint32_t address, const uint8_t *value, uint32_t byteCount);
264+
static bool flashReplaceBlock(uint32_t address, const uint8_t *value, uint32_t byteCount);
265265
/**
266266
* @brief Write up to @a size bytes from @a data to flash at @a address
267267
* This function takes case of unaligned memory acces by copying @a data to a temporary buffer,
@@ -272,7 +272,7 @@ class EspClass {
272272
* @param size amount of data
273273
* @return size_t amount of data written, 0 on failure
274274
*/
275-
size_t flashWriteUnalignedMemory(uint32_t address, const uint8_t *data, size_t size);
275+
static size_t flashWriteUnalignedMemory(uint32_t address, const uint8_t *data, size_t size);
276276
/**
277277
* @brief Splits up to 4 bytes into 4 byte blocks and writes them to flash
278278
* We need this since spi_flash_write cannot handle writing over a page boundary with unaligned offset
@@ -283,7 +283,7 @@ class EspClass {
283283
* @param size amount of data, must be < 4
284284
* @return bool result of operation
285285
*/
286-
bool flashWritePageBreak(uint32_t address, const uint8_t *data, size_t size);
286+
static bool flashWritePageBreak(uint32_t address, const uint8_t *data, size_t size);
287287
};
288288

289289
extern EspClass ESP;

0 commit comments

Comments
 (0)