Reformatted all the files according to clang-format style
This commit is contained in:
@@ -6,17 +6,16 @@
|
||||
|
||||
using namespace Pinetime::Drivers;
|
||||
|
||||
SpiNorFlash::SpiNorFlash(Spi& spi) : spi{spi} {
|
||||
|
||||
SpiNorFlash::SpiNorFlash(Spi& spi) : spi {spi} {
|
||||
}
|
||||
|
||||
void SpiNorFlash::Init() {
|
||||
device_id = ReadIdentificaion();
|
||||
NRF_LOG_INFO("[SpiNorFlash] Manufacturer : %d, Memory type : %d, memory density : %d", device_id.manufacturer, device_id.type, device_id.density);
|
||||
NRF_LOG_INFO(
|
||||
"[SpiNorFlash] Manufacturer : %d, Memory type : %d, memory density : %d", device_id.manufacturer, device_id.type, device_id.density);
|
||||
}
|
||||
|
||||
void SpiNorFlash::Uninit() {
|
||||
|
||||
}
|
||||
|
||||
void SpiNorFlash::Sleep() {
|
||||
@@ -30,12 +29,11 @@ void SpiNorFlash::Wakeup() {
|
||||
static constexpr uint8_t cmdSize = 4;
|
||||
uint8_t cmd[cmdSize] = {static_cast<uint8_t>(Commands::ReleaseFromDeepPowerDown), 0x01, 0x02, 0x03};
|
||||
uint8_t id = 0;
|
||||
spi.Read(reinterpret_cast<uint8_t *>(&cmd), cmdSize, &id, 1);
|
||||
auto devId = device_id = ReadIdentificaion();
|
||||
if(devId.type != device_id.type) {
|
||||
spi.Read(reinterpret_cast<uint8_t*>(&cmd), cmdSize, &id, 1);
|
||||
auto devId = device_id = ReadIdentificaion();
|
||||
if (devId.type != device_id.type) {
|
||||
NRF_LOG_INFO("[SpiNorFlash] ID on Wakeup: Failed");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
NRF_LOG_INFO("[SpiNorFlash] ID on Wakeup: %d", id);
|
||||
}
|
||||
NRF_LOG_INFO("[SpiNorFlash] Wakeup")
|
||||
@@ -44,7 +42,7 @@ void SpiNorFlash::Wakeup() {
|
||||
SpiNorFlash::Identification SpiNorFlash::ReadIdentificaion() {
|
||||
auto cmd = static_cast<uint8_t>(Commands::ReadIdentification);
|
||||
Identification identification;
|
||||
spi.Read(&cmd, 1, reinterpret_cast<uint8_t *>(&identification), sizeof(Identification));
|
||||
spi.Read(&cmd, 1, reinterpret_cast<uint8_t*>(&identification), sizeof(Identification));
|
||||
return identification;
|
||||
}
|
||||
|
||||
@@ -70,11 +68,10 @@ uint8_t SpiNorFlash::ReadConfigurationRegister() {
|
||||
return status;
|
||||
}
|
||||
|
||||
void SpiNorFlash::Read(uint32_t address, uint8_t *buffer, size_t size) {
|
||||
void SpiNorFlash::Read(uint32_t address, uint8_t* buffer, size_t size) {
|
||||
static constexpr uint8_t cmdSize = 4;
|
||||
uint8_t cmd[cmdSize] = { static_cast<uint8_t>(Commands::Read), (uint8_t)(address >> 16U), (uint8_t)(address >> 8U),
|
||||
(uint8_t)address };
|
||||
spi.Read(reinterpret_cast<uint8_t *>(&cmd), cmdSize, buffer, size);
|
||||
uint8_t cmd[cmdSize] = {static_cast<uint8_t>(Commands::Read), (uint8_t) (address >> 16U), (uint8_t) (address >> 8U), (uint8_t) address};
|
||||
spi.Read(reinterpret_cast<uint8_t*>(&cmd), cmdSize, buffer, size);
|
||||
}
|
||||
|
||||
void SpiNorFlash::WriteEnable() {
|
||||
@@ -84,15 +81,19 @@ void SpiNorFlash::WriteEnable() {
|
||||
|
||||
void SpiNorFlash::SectorErase(uint32_t sectorAddress) {
|
||||
static constexpr uint8_t cmdSize = 4;
|
||||
uint8_t cmd[cmdSize] = { static_cast<uint8_t>(Commands::SectorErase), (uint8_t)(sectorAddress >> 16U), (uint8_t)(sectorAddress >> 8U),
|
||||
(uint8_t)sectorAddress };
|
||||
uint8_t cmd[cmdSize] = {static_cast<uint8_t>(Commands::SectorErase),
|
||||
(uint8_t) (sectorAddress >> 16U),
|
||||
(uint8_t) (sectorAddress >> 8U),
|
||||
(uint8_t) sectorAddress};
|
||||
|
||||
WriteEnable();
|
||||
while(!WriteEnabled()) vTaskDelay(1);
|
||||
while (!WriteEnabled())
|
||||
vTaskDelay(1);
|
||||
|
||||
spi.Read(reinterpret_cast<uint8_t *>(&cmd), cmdSize, nullptr, 0);
|
||||
spi.Read(reinterpret_cast<uint8_t*>(&cmd), cmdSize, nullptr, 0);
|
||||
|
||||
while(WriteInProgress()) vTaskDelay(1);
|
||||
while (WriteInProgress())
|
||||
vTaskDelay(1);
|
||||
}
|
||||
|
||||
uint8_t SpiNorFlash::ReadSecurityRegister() {
|
||||
@@ -110,29 +111,29 @@ bool SpiNorFlash::EraseFailed() {
|
||||
return (ReadSecurityRegister() & 0x40u) == 0x40u;
|
||||
}
|
||||
|
||||
void SpiNorFlash::Write(uint32_t address, const uint8_t *buffer, size_t size) {
|
||||
void SpiNorFlash::Write(uint32_t address, const uint8_t* buffer, size_t size) {
|
||||
static constexpr uint8_t cmdSize = 4;
|
||||
|
||||
size_t len = size;
|
||||
uint32_t addr = address;
|
||||
const uint8_t* b = buffer;
|
||||
while(len > 0) {
|
||||
while (len > 0) {
|
||||
uint32_t pageLimit = (addr & ~(pageSize - 1u)) + pageSize;
|
||||
uint32_t toWrite = pageLimit - addr > len ? len : pageLimit - addr;
|
||||
uint32_t toWrite = pageLimit - addr > len ? len : pageLimit - addr;
|
||||
|
||||
uint8_t cmd[cmdSize] = { static_cast<uint8_t>(Commands::PageProgram), (uint8_t)(addr >> 16U), (uint8_t)(addr >> 8U),
|
||||
(uint8_t)addr };
|
||||
uint8_t cmd[cmdSize] = {static_cast<uint8_t>(Commands::PageProgram), (uint8_t) (addr >> 16U), (uint8_t) (addr >> 8U), (uint8_t) addr};
|
||||
|
||||
WriteEnable();
|
||||
while(!WriteEnabled()) vTaskDelay(1);
|
||||
while (!WriteEnabled())
|
||||
vTaskDelay(1);
|
||||
|
||||
spi.WriteCmdAndBuffer(cmd, cmdSize, b, toWrite);
|
||||
|
||||
while(WriteInProgress()) vTaskDelay(1);
|
||||
while (WriteInProgress())
|
||||
vTaskDelay(1);
|
||||
|
||||
addr += toWrite;
|
||||
b += toWrite;
|
||||
len -= toWrite;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user