Skip to content

Commit 9c020d1

Browse files
committed
Migrate SPI flash API to C++ namespace
Replace C-style `spi_flash_*` function calls with C++ namespace equivalents (`spi::flash::` and `spi::flash::cmd::`) in StoreDevice and scenes SPI implementations.
1 parent 3601d2d commit 9c020d1

2 files changed

Lines changed: 18 additions & 15 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();

lib-dmxnode/src/scenes/spi/scenes.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ static bool CheckHaveFlash() {
3939
DMXNODE_DEBUG_PRINTF("s_hasFlash=%d", s_has_flash);
4040

4141
if (!s_has_flash) {
42-
if (!spi_flash_probe()) {
42+
if (!spi::flash::Probe()) {
4343
DMXNODE_DEBUG_EXIT();
4444
return false;
4545
}
4646

47-
const auto kEraseSize = spi_flash_get_sector_size();
47+
const auto kEraseSize = spi::flash::SectorSize();
4848
assert(kEraseSize <= dmxnode::scenes::kBytesNeeded);
4949
const auto kPages = 1 + (dmxnode::scenes::kBytesNeeded / kEraseSize);
5050

5151
DMXNODE_DEBUG_PRINTF("Bytes needed=%u, nEraseSize=%u, nPages=%u", dmxnode::scenes::kBytesNeeded, kEraseSize, kPages);
5252

53-
assert(((kPages + 1) * kEraseSize) <= spi_flash_get_size());
53+
assert(((kPages + 1) * kEraseSize) <= spi::flash::get_size());
5454

55-
s_offset_base = spi_flash_get_size() - ((kPages + 1) * kEraseSize);
55+
s_offset_base = spi::flash::Size() - ((kPages + 1) * kEraseSize);
5656

5757
DMXNODE_DEBUG_PRINTF("nOffsetBase=%p", s_offset_base);
5858
}
@@ -70,7 +70,7 @@ void WriteStart() {
7070
return;
7171
}
7272

73-
s_has_flash = spi_flash_cmd_erase(s_offset_base, spi_flash_get_sector_size());
73+
s_has_flash = spi::flash::cmd::Erase(s_offset_base, spi::flash::SectorSize());
7474

7575
DMXNODE_DEBUG_PRINTF("s_hasFlash=%d", s_has_flash);
7676
DMXNODE_DEBUG_EXIT();
@@ -90,7 +90,7 @@ void Write(uint32_t port_index, const uint8_t* data) {
9090

9191
DMXNODE_DEBUG_PRINTF("s_offset_base=%p, kOffset=%p", s_offset_base, kOffset);
9292

93-
spi_flash_cmd_write_multi(kOffset, dmxnode::kUniverseSize, data);
93+
spi::flash::cmd::Write(kOffset, dmxnode::kUniverseSize, data);
9494

9595
DMXNODE_DEBUG_EXIT();
9696
}
@@ -131,7 +131,7 @@ void Read(uint32_t port_index, uint8_t* data) {
131131

132132
DMXNODE_DEBUG_PRINTF("s_offset_base=%p, kOffset=%u", reinterpret_cast<void*>(s_offset_base), static_cast<unsigned>(kOffset));
133133

134-
spi_flash_cmd_read_fast(kOffset, dmxnode::kUniverseSize, data);
134+
spi::flash::cmd::Read(kOffset, dmxnode::kUniverseSize, data);
135135

136136
DMXNODE_DEBUG_EXIT();
137137
}

0 commit comments

Comments
 (0)