@@ -494,7 +494,7 @@ uint32_t EspClass::getSketchSize() {
494
494
495
495
image_header_t image_header;
496
496
uint32_t pos = APP_START_OFFSET;
497
- if (spi_flash_read (pos, (uint32_t *) &image_header, sizeof (image_header))) {
497
+ if (spi_flash_read (pos, (uint32_t *) &image_header, sizeof (image_header)) != SPI_FLASH_RESULT_OK ) {
498
498
return 0 ;
499
499
}
500
500
pos += sizeof (image_header);
@@ -506,7 +506,7 @@ uint32_t EspClass::getSketchSize() {
506
506
++section_index)
507
507
{
508
508
section_header_t section_header = {0 , 0 };
509
- if (spi_flash_read (pos, (uint32_t *) §ion_header, sizeof (section_header))) {
509
+ if (spi_flash_read (pos, (uint32_t *) §ion_header, sizeof (section_header)) != SPI_FLASH_RESULT_OK ) {
510
510
return 0 ;
511
511
}
512
512
pos += sizeof (section_header);
@@ -579,24 +579,25 @@ bool EspClass::flashEraseSector(uint32_t sector) {
579
579
#if PUYA_SUPPORT
580
580
static int spi_flash_write_puya (uint32_t offset, uint32_t *data, size_t size) {
581
581
if (data == nullptr ) {
582
- return 1 ; // SPI_FLASH_RESULT_ERR
582
+ return SPI_FLASH_RESULT_ERR;
583
583
}
584
584
// PUYA flash chips need to read existing data, update in memory and write modified data again.
585
585
static uint32_t *flash_write_puya_buf = nullptr ;
586
- int rc = 0 ;
587
- uint32_t * ptr = data;
588
586
589
587
if (flash_write_puya_buf == nullptr ) {
590
588
flash_write_puya_buf = (uint32_t *) malloc (PUYA_BUFFER_SIZE);
591
589
// No need to ever free this, since the flash chip will never change at runtime.
592
590
if (flash_write_puya_buf == nullptr ) {
593
591
// Memory could not be allocated.
594
- return 1 ; // SPI_FLASH_RESULT_ERR
592
+ return SPI_FLASH_RESULT_ERR;
595
593
}
596
594
}
595
+
596
+ SpiFlashOpResult rc = SPI_FLASH_RESULT_OK;
597
+ uint32_t * ptr = data;
597
598
size_t bytesLeft = size;
598
599
uint32_t pos = offset;
599
- while (bytesLeft > 0 && rc == 0 ) {
600
+ while (bytesLeft > 0 && rc == SPI_FLASH_RESULT_OK ) {
600
601
size_t bytesNow = bytesLeft;
601
602
if (bytesNow > PUYA_BUFFER_SIZE) {
602
603
bytesNow = PUYA_BUFFER_SIZE;
@@ -605,8 +606,8 @@ static int spi_flash_write_puya(uint32_t offset, uint32_t *data, size_t size) {
605
606
bytesLeft = 0 ;
606
607
}
607
608
rc = spi_flash_read (pos, flash_write_puya_buf, bytesNow);
608
- if (rc != 0 ) {
609
- return rc;
609
+ if (rc != SPI_FLASH_RESULT_OK ) {
610
+ return ( int ) rc;
610
611
}
611
612
for (size_t i = 0 ; i < bytesNow / 4 ; ++i) {
612
613
flash_write_puya_buf[i] &= *ptr;
@@ -615,12 +616,12 @@ static int spi_flash_write_puya(uint32_t offset, uint32_t *data, size_t size) {
615
616
rc = spi_flash_write (pos, flash_write_puya_buf, bytesNow);
616
617
pos += bytesNow;
617
618
}
618
- return rc;
619
+ return ( int ) rc;
619
620
}
620
621
#endif
621
622
622
623
bool EspClass::flashWrite (uint32_t offset, uint32_t *data, size_t size) {
623
- int rc = 0 ;
624
+ SpiFlashOpResult rc = SPI_FLASH_RESULT_OK ;
624
625
#if PUYA_SUPPORT
625
626
if (getFlashChipVendorId () == SPI_FLASH_VENDOR_PUYA) {
626
627
rc = spi_flash_write_puya (offset, data, size);
@@ -630,12 +631,12 @@ bool EspClass::flashWrite(uint32_t offset, uint32_t *data, size_t size) {
630
631
{
631
632
rc = spi_flash_write (offset, data, size);
632
633
}
633
- return rc == 0 ;
634
+ return rc == SPI_FLASH_RESULT_OK ;
634
635
}
635
636
636
637
bool EspClass::flashRead (uint32_t offset, uint32_t *data, size_t size) {
637
- int rc = spi_flash_read (offset, (uint32_t *) data, size);
638
- return rc == 0 ;
638
+ auto rc = spi_flash_read (offset, (uint32_t *) data, size);
639
+ return rc == SPI_FLASH_RESULT_OK ;
639
640
}
640
641
641
642
String EspClass::getSketchMD5 ()
0 commit comments