Skip to content

Commit 735d01f

Browse files
committed
Refactor StoreDevice to use spi::flash API
Replace legacy `spi_flash_*` calls in `storedevice.cpp` with the namespaced `spi::flash` and `spi::flash::cmd` interfaces for probe, metadata, read, erase, and write operations. Also updates the startup log line to explicitly label the detected device as SPI flash.
1 parent 7932323 commit 735d01f

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

lib-configstore/device/spi/storedevice.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@
3737
StoreDevice::StoreDevice() {
3838
CONFIGSTORE_DEBUG_ENTRY();
3939

40-
if (!spi_flash_probe()) {
40+
if (!spi::flash::Probe()) {
4141
puts("StoreDevice: No SPI flash chip.");
4242
} else {
43-
printf("StoreDevice: %s sector size %u total %u bytes [%u kB]\n", spi_flash_get_name(), static_cast<unsigned int>(spi_flash_get_sector_size()), static_cast<unsigned int>(spi_flash_get_size()),
44-
static_cast<unsigned int>(spi_flash_get_size() / 1024U));
43+
printf("StoreDevice: SPI flash %s sector size %u total %u bytes [%u kB]\n",
44+
spi::flash::Name(),
45+
static_cast<unsigned int>(spi::flash::SectorSize()),
46+
static_cast<unsigned int>(spi::flash::Size()),
47+
static_cast<unsigned int>(spi::flash::Size() / 1024U));
4548
detected_ = true;
4649
}
4750

@@ -54,17 +57,17 @@ StoreDevice::~StoreDevice() {
5457
}
5558

5659
uint32_t StoreDevice::GetSize() const {
57-
return spi_flash_get_size();
60+
return spi::flash::Size();
5861
}
5962

6063
uint32_t StoreDevice::GetSectorSize() const {
61-
return spi_flash_get_sector_size();
64+
return spi::flash::SectorSize();
6265
}
6366

6467
bool StoreDevice::Read(uint32_t offset, uint32_t length, uint8_t* buffer, storedevice::Result& result) {
6568
CONFIGSTORE_DEBUG_ENTRY();
6669

67-
result = spi_flash_cmd_read_fast(offset, length, buffer) ? storedevice::Result::kOk : storedevice::Result::kError;
70+
result = spi::flash::cmd::Read(offset, length, buffer) ? storedevice::Result::kOk : storedevice::Result::kError;
6871

6972
CONFIGSTORE_DEBUG_PRINTF("result=%d", static_cast<int>(result));
7073
CONFIGSTORE_DEBUG_EXIT();
@@ -74,7 +77,7 @@ bool StoreDevice::Read(uint32_t offset, uint32_t length, uint8_t* buffer, stored
7477
bool StoreDevice::Erase(uint32_t offset, uint32_t length, storedevice::Result& result) {
7578
CONFIGSTORE_DEBUG_ENTRY();
7679

77-
result = spi_flash_cmd_erase(offset, length) ? storedevice::Result::kOk : storedevice::Result::kError;
80+
result = spi::flash::cmd::Erase(offset, length) ? storedevice::Result::kOk : storedevice::Result::kError;
7881

7982
CONFIGSTORE_DEBUG_PRINTF("result=%d", static_cast<int>(result));
8083
CONFIGSTORE_DEBUG_EXIT();
@@ -84,7 +87,7 @@ bool StoreDevice::Erase(uint32_t offset, uint32_t length, storedevice::Result& r
8487
bool StoreDevice::Write(uint32_t offset, uint32_t length, const uint8_t* buffer, storedevice::Result& result) {
8588
CONFIGSTORE_DEBUG_ENTRY();
8689

87-
result = spi_flash_cmd_write_multi(offset, length, buffer) ? storedevice::Result::kOk : storedevice::Result::kError;
90+
result = spi::flash::cmd::Write(offset, length, buffer) ? storedevice::Result::kOk : storedevice::Result::kError;
8891

8992
CONFIGSTORE_DEBUG_PRINTF("result=%d", static_cast<int>(result));
9093
CONFIGSTORE_DEBUG_EXIT();

0 commit comments

Comments
 (0)