1 #if !defined(UNIT_TEST)
3 #include "EspFlashStream.h"
5 EspFlashStream::EspFlashStream()
10 void EspFlashStream::fillBuffer()
12 // Could also use spi_flash_read() here, but the return values differ between ESP (SPI_FLASH_RESULT_OK) and ESP32 (ESP_OK)
13 if (ESP
.flashRead(_flashBase
+ _flashOffset
, (uint32_t *)_buffer
, sizeof(_buffer
)))
19 // _bufferPos > sizeof() indicates error
20 _bufferPos
= sizeof(_buffer
) + 1;
24 void EspFlashStream::setBaseAddress(size_t base
)
27 _flashOffset
= 0 - sizeof(_buffer
); // underflow intentionally so offset+pos = 0
28 _bufferPos
= sizeof(_buffer
);
31 void EspFlashStream::setPosition(size_t offset
)
33 // align(4), rounding down
34 _flashOffset
= (offset
>> 2) << 2;
35 // capture the new bufferPos before fill advances it
36 uint8_t newBufferPos
= offset
- _flashOffset
;
39 _bufferPos
= newBufferPos
;
42 int EspFlashStream::read()
49 int EspFlashStream::peek()
51 if (_bufferPos
== sizeof(_buffer
))
53 _flashOffset
+= sizeof(_buffer
);
56 return _buffer
[_bufferPos
];