ESP32  1.0.4
EspClass クラス

#include <Esp.h>

公開メンバ関数

 EspClass ()
 
 ~EspClass ()
 
void restart ()
 
uint32_t getHeapSize ()
 
uint32_t getFreeHeap ()
 
uint32_t getMinFreeHeap ()
 
uint32_t getMaxAllocHeap ()
 
uint32_t getPsramSize ()
 
uint32_t getFreePsram ()
 
uint32_t getMinFreePsram ()
 
uint32_t getMaxAllocPsram ()
 
uint8_t getChipRevision ()
 
uint32_t getCpuFreqMHz ()
 
uint32_t getCycleCount () __attribute__((always_inline))
 
const char * getSdkVersion ()
 
void deepSleep (uint32_t time_us)
 
uint32_t getFlashChipSize ()
 
uint32_t getFlashChipSpeed ()
 
FlashMode_t getFlashChipMode ()
 
uint32_t magicFlashChipSize (uint8_t byte)
 
uint32_t magicFlashChipSpeed (uint8_t byte)
 
FlashMode_t magicFlashChipMode (uint8_t byte)
 
uint32_t getSketchSize ()
 
String getSketchMD5 ()
 
uint32_t getFreeSketchSpace ()
 
bool flashEraseSector (uint32_t sector)
 
bool flashWrite (uint32_t offset, uint32_t *data, size_t size)
 
bool flashRead (uint32_t offset, uint32_t *data, size_t size)
 
uint64_t getEfuseMac ()
 

詳解

Esp.h58 行目に定義があります。

構築子と解体子

◆ EspClass()

EspClass::EspClass ( )
inline

Esp.h61 行目に定義があります。

61 {}

◆ ~EspClass()

EspClass::~EspClass ( )
inline

Esp.h62 行目に定義があります。

62 {}

関数詳解

◆ deepSleep()

void EspClass::deepSleep ( uint32_t  time_us)

Esp.cpp90 行目に定義があります。

91 {
92  esp_deep_sleep(time_us);
93 }
void esp_deep_sleep(uint64_t time_in_us) __attribute__((noreturn))
Enter deep-sleep mode

◆ flashEraseSector()

bool EspClass::flashEraseSector ( uint32_t  sector)

Esp.cpp296 行目に定義があります。

297 {
298  return spi_flash_erase_sector(sector) == ESP_OK;
299 }
#define ESP_OK
Definition: esp_err.h:27
esp_err_t spi_flash_erase_sector(size_t sector)
Erase the Flash sector.

◆ flashRead()

bool EspClass::flashRead ( uint32_t  offset,
uint32_t data,
size_t  size 
)

Esp.cpp307 行目に定義があります。

308 {
309  return spi_flash_read(offset, (uint32_t*) data, size) == ESP_OK;
310 }
#define ESP_OK
Definition: esp_err.h:27
uint64_t offset
Definition: read_at.hpp:367
__uint32_t uint32_t
Definition: stdint.h:45
macro cache_index_all size
Definition: cacheasm.h:158
esp_err_t spi_flash_read(size_t src_addr, void *dest, size_t size)
Read data from Flash.

◆ flashWrite()

bool EspClass::flashWrite ( uint32_t  offset,
uint32_t data,
size_t  size 
)

Esp.cpp302 行目に定義があります。

303 {
304  return spi_flash_write(offset, (uint32_t*) data, size) == ESP_OK;
305 }
esp_err_t spi_flash_write(size_t dest_addr, const void *src, size_t size)
Write data to Flash.
#define ESP_OK
Definition: esp_err.h:27
uint64_t offset
Definition: read_at.hpp:367
__uint32_t uint32_t
Definition: stdint.h:45
macro cache_index_all size
Definition: cacheasm.h:158

◆ getChipRevision()

uint8_t EspClass::getChipRevision ( void  )

Esp.cpp214 行目に定義があります。

215 {
216  esp_chip_info_t chip_info;
217  esp_chip_info(&chip_info);
218  return chip_info.revision;
219 }
The structure represents information about the chip
Definition: esp_system.h:319
void esp_chip_info(esp_chip_info_t *out_info)
Fill an esp_chip_info_t structure with information about the chip
uint8_t revision
chip revision number
Definition: esp_system.h:323

◆ getCpuFreqMHz()

uint32_t EspClass::getCpuFreqMHz ( )
inline

Esp.h78 行目に定義があります。

78 { return getCpuFrequencyMhz(); }
uint32_t getCpuFrequencyMhz()

◆ getCycleCount()

uint32_t IRAM_ATTR EspClass::getCycleCount ( )
inline

Esp.h104 行目に定義があります。

105 {
106  uint32_t ccount;
107  __asm__ __volatile__("esync; rsr %0,ccount":"=a" (ccount));
108  return ccount;
109 }
__uint32_t uint32_t
Definition: stdint.h:45

◆ getEfuseMac()

uint64_t EspClass::getEfuseMac ( void  )

Esp.cpp313 行目に定義があります。

314 {
315  uint64_t _chipmacid = 0LL;
316  esp_efuse_mac_get_default((uint8_t*) (&_chipmacid));
317  return _chipmacid;
318 }
__uint64_t uint64_t
Definition: stdint.h:57
__uint8_t uint8_t
Definition: stdint.h:21
esp_err_t esp_efuse_mac_get_default(uint8_t *mac)
Return base MAC address which is factory-programmed by Espressif in BLK0 of EFUSE.

◆ getFlashChipMode()

FlashMode_t EspClass::getFlashChipMode ( void  )

Esp.cpp244 行目に定義があります。

245 {
246  esp_image_header_t fhdr;
247  if(flashRead(0x1000, (uint32_t*)&fhdr, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) {
248  return FM_UNKNOWN;
249  }
250  return magicFlashChipMode(fhdr.spi_mode);
251 }
__uint32_t uint32_t
Definition: stdint.h:45
bool flashRead(uint32_t offset, uint32_t *data, size_t size)
Definition: Esp.cpp:307
Definition: Esp.h:50
FlashMode_t magicFlashChipMode(uint8_t byte)
Definition: Esp.cpp:287
#define ESP_IMAGE_HEADER_MAGIC

◆ getFlashChipSize()

uint32_t EspClass::getFlashChipSize ( void  )

Esp.cpp226 行目に定義があります。

227 {
228  esp_image_header_t fhdr;
229  if(flashRead(0x1000, (uint32_t*)&fhdr, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) {
230  return 0;
231  }
232  return magicFlashChipSize(fhdr.spi_size);
233 }
__uint32_t uint32_t
Definition: stdint.h:45
bool flashRead(uint32_t offset, uint32_t *data, size_t size)
Definition: Esp.cpp:307
#define ESP_IMAGE_HEADER_MAGIC
uint32_t magicFlashChipSize(uint8_t byte)
Definition: Esp.cpp:253

◆ getFlashChipSpeed()

uint32_t EspClass::getFlashChipSpeed ( void  )

Esp.cpp235 行目に定義があります。

236 {
237  esp_image_header_t fhdr;
238  if(flashRead(0x1000, (uint32_t*)&fhdr, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) {
239  return 0;
240  }
241  return magicFlashChipSpeed(fhdr.spi_speed);
242 }
uint32_t magicFlashChipSpeed(uint8_t byte)
Definition: Esp.cpp:271
__uint32_t uint32_t
Definition: stdint.h:45
bool flashRead(uint32_t offset, uint32_t *data, size_t size)
Definition: Esp.cpp:307
#define ESP_IMAGE_HEADER_MAGIC

◆ getFreeHeap()

uint32_t EspClass::getFreeHeap ( void  )

Esp.cpp107 行目に定義があります。

108 {
110 }
size_t heap_caps_get_free_size(uint32_t caps)
Get the total free size of all the regions that have the given capabilities
#define MALLOC_CAP_INTERNAL
Memory must be internal; specifically it should not disappear when flash/spiram cache is switched off
Definition: esp_heap_caps.h:38

◆ getFreePsram()

uint32_t EspClass::getFreePsram ( void  )

Esp.cpp129 行目に定義があります。

130 {
132 }
size_t heap_caps_get_free_size(uint32_t caps)
Get the total free size of all the regions that have the given capabilities
#define MALLOC_CAP_SPIRAM
Memory must be in SPI RAM
Definition: esp_heap_caps.h:37

◆ getFreeSketchSpace()

uint32_t EspClass::getFreeSketchSpace ( )

Esp.cpp205 行目に定義があります。

205  {
207  if(!_partition){
208  return 0;
209  }
210 
211  return _partition->size;
212 }
#define NULL
Definition: def.h:70
const esp_partition_t * esp_ota_get_next_update_partition(const esp_partition_t *start_from)
Return the next OTA app partition which should be written with a new firmware.
partition information structure
Definition: esp_partition.h:99

◆ getHeapSize()

uint32_t EspClass::getHeapSize ( void  )

Esp.cpp100 行目に定義があります。

101 {
104  return info.total_free_bytes + info.total_allocated_bytes;
105 }
Structure to access heap metadata via multi_heap_get_info
Definition: multi_heap.h:150
void heap_caps_get_info(multi_heap_info_t *info, uint32_t caps)
Get heap info for all regions with the given capabilities.
#define info(...)
Definition: debug.h:64
#define MALLOC_CAP_INTERNAL
Memory must be internal; specifically it should not disappear when flash/spiram cache is switched off
Definition: esp_heap_caps.h:38

◆ getMaxAllocHeap()

uint32_t EspClass::getMaxAllocHeap ( void  )

Esp.cpp117 行目に定義があります。

118 {
120 }
size_t heap_caps_get_largest_free_block(uint32_t caps)
Get the largest free block of memory able to be allocated with the given capabilities.
#define MALLOC_CAP_INTERNAL
Memory must be internal; specifically it should not disappear when flash/spiram cache is switched off
Definition: esp_heap_caps.h:38

◆ getMaxAllocPsram()

uint32_t EspClass::getMaxAllocPsram ( void  )

Esp.cpp139 行目に定義があります。

140 {
142 }
#define MALLOC_CAP_SPIRAM
Memory must be in SPI RAM
Definition: esp_heap_caps.h:37
size_t heap_caps_get_largest_free_block(uint32_t caps)
Get the largest free block of memory able to be allocated with the given capabilities.

◆ getMinFreeHeap()

uint32_t EspClass::getMinFreeHeap ( void  )

Esp.cpp112 行目に定義があります。

113 {
115 }
size_t heap_caps_get_minimum_free_size(uint32_t caps)
Get the total minimum free memory of all regions with the given capabilities
#define MALLOC_CAP_INTERNAL
Memory must be internal; specifically it should not disappear when flash/spiram cache is switched off
Definition: esp_heap_caps.h:38

◆ getMinFreePsram()

uint32_t EspClass::getMinFreePsram ( void  )

Esp.cpp134 行目に定義があります。

135 {
137 }
#define MALLOC_CAP_SPIRAM
Memory must be in SPI RAM
Definition: esp_heap_caps.h:37
size_t heap_caps_get_minimum_free_size(uint32_t caps)
Get the total minimum free memory of all regions with the given capabilities

◆ getPsramSize()

uint32_t EspClass::getPsramSize ( void  )

Esp.cpp122 行目に定義があります。

123 {
126  return info.total_free_bytes + info.total_allocated_bytes;
127 }
#define MALLOC_CAP_SPIRAM
Memory must be in SPI RAM
Definition: esp_heap_caps.h:37
Structure to access heap metadata via multi_heap_get_info
Definition: multi_heap.h:150
void heap_caps_get_info(multi_heap_info_t *info, uint32_t caps)
Get heap info for all regions with the given capabilities.
#define info(...)
Definition: debug.h:64

◆ getSdkVersion()

const char * EspClass::getSdkVersion ( void  )

Esp.cpp221 行目に定義があります。

222 {
223  return esp_get_idf_version();
224 }
const char * esp_get_idf_version(void)

◆ getSketchMD5()

String EspClass::getSketchMD5 ( )

Esp.cpp165 行目に定義があります。

166 {
167  static String result;
168  if (result.length()) {
169  return result;
170  }
171  uint32_t lengthLeft = getSketchSize();
172 
174  if (!running) {
175  log_e("Partition could not be found");
176 
177  return String();
178  }
179  const size_t bufSize = SPI_FLASH_SEC_SIZE;
180  std::unique_ptr<uint8_t[]> buf(new uint8_t[bufSize]);
181  uint32_t offset = 0;
182  if(!buf.get()) {
183  log_e("Not enough memory to allocate buffer");
184 
185  return String();
186  }
187  MD5Builder md5;
188  md5.begin();
189  while( lengthLeft > 0) {
190  size_t readBytes = (lengthLeft < bufSize) ? lengthLeft : bufSize;
191  if (!ESP.flashRead(running->address + offset, reinterpret_cast<uint32_t*>(buf.get()), (readBytes + 3) & ~3)) {
192  log_e("Could not read buffer from flash");
193 
194  return String();
195  }
196  md5.add(buf.get(), readBytes);
197  lengthLeft -= readBytes;
198  offset += readBytes;
199  }
200  md5.calculate();
201  result = md5.toString();
202  return result;
203 }
partition information structure
Definition: esp_partition.h:99
uint64_t offset
Definition: read_at.hpp:367
__uint32_t uint32_t
Definition: stdint.h:45
bool flashRead(uint32_t offset, uint32_t *data, size_t size)
Definition: Esp.cpp:307
#define SPI_FLASH_SEC_SIZE
Definition: esp_spi_flash.h:32
EspClass ESP
Definition: Esp.cpp:88
#define log_e(format,...)
const esp_partition_t * esp_ota_get_running_partition(void)
Get partition info of currently running app
#define md5
Definition: compat-1.3.h:2003
__uint8_t uint8_t
Definition: stdint.h:21
uint32_t getSketchSize()
Definition: Esp.cpp:161

◆ getSketchSize()

uint32_t EspClass::getSketchSize ( )

Esp.cpp161 行目に定義があります。

161  {
162  return sketchSize(SKETCH_SIZE_TOTAL);
163 }

◆ magicFlashChipMode()

FlashMode_t EspClass::magicFlashChipMode ( uint8_t  byte)

Esp.cpp287 行目に定義があります。

288 {
289  FlashMode_t mode = (FlashMode_t) byte;
290  if(mode > FM_SLOW_READ) {
291  mode = FM_UNKNOWN;
292  }
293  return mode;
294 }
FlashMode_t
Definition: Esp.h:43
Definition: Esp.h:50

◆ magicFlashChipSize()

uint32_t EspClass::magicFlashChipSize ( uint8_t  byte)

Esp.cpp253 行目に定義があります。

254 {
255  switch(byte & 0x0F) {
256  case 0x0: // 8 MBit (1MB)
257  return (1_MB);
258  case 0x1: // 16 MBit (2MB)
259  return (2_MB);
260  case 0x2: // 32 MBit (4MB)
261  return (4_MB);
262  case 0x3: // 64 MBit (8MB)
263  return (8_MB);
264  case 0x4: // 128 MBit (16MB)
265  return (16_MB);
266  default: // fail?
267  return 0;
268  }
269 }

◆ magicFlashChipSpeed()

uint32_t EspClass::magicFlashChipSpeed ( uint8_t  byte)

Esp.cpp271 行目に定義があります。

272 {
273  switch(byte & 0x0F) {
274  case 0x0: // 40 MHz
275  return (40_MHz);
276  case 0x1: // 26 MHz
277  return (26_MHz);
278  case 0x2: // 20 MHz
279  return (20_MHz);
280  case 0xf: // 80 MHz
281  return (80_MHz);
282  default: // fail?
283  return 0;
284  }
285 }

◆ restart()

void EspClass::restart ( void  )

Esp.cpp95 行目に定義があります。

96 {
97  esp_restart();
98 }
void esp_restart(void) __attribute__((noreturn))
Restart PRO and APP CPUs.

このクラス詳解は次のファイルから抽出されました: