aboutsummaryrefslogtreecommitdiffstats
path: root/src/Components/Ble/DfuService.h
diff options
context:
space:
mode:
authorJF <jf@codingfield.com>2020-06-01 18:32:46 +0200
committerJF <jf@codingfield.com>2020-06-01 18:32:46 +0200
commitde822cc3a2f07033e881331ac8914b26023bb003 (patch)
tree23f043a10afe9f934264f043a8b5559495648a47 /src/Components/Ble/DfuService.h
parentf6aa41c214eef418b55cf0f063c5a296b1e57b63 (diff)
Encapsulate DFU Image buffering and writing into spi flash in DfuImage.
Add some const in SPI driver.
Diffstat (limited to 'src/Components/Ble/DfuService.h')
-rw-r--r--src/Components/Ble/DfuService.h37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/Components/Ble/DfuService.h b/src/Components/Ble/DfuService.h
index b0eccdf5..d7ba460c 100644
--- a/src/Components/Ble/DfuService.h
+++ b/src/Components/Ble/DfuService.h
@@ -20,7 +20,6 @@ namespace Pinetime {
DfuService(Pinetime::System::SystemTask &systemTask, Pinetime::Controllers::Ble &bleController,
Pinetime::Drivers::SpiNorFlash &spiNorFlash);
void Init();
- bool Validate();
int OnServiceData(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt *context);
void OnTimeout();
void Reset();
@@ -40,11 +39,38 @@ namespace Pinetime {
void OnNotificationTimer();
void Reset();
};
+ class DfuImage {
+ public:
+ DfuImage(Pinetime::Drivers::SpiNorFlash& spiNorFlash) : spiNorFlash{spiNorFlash} {}
+ void Init(size_t chunkSize, size_t totalSize, uint16_t expectedCrc);
+ void Erase();
+ void Append(uint8_t* data, size_t size);
+ bool Validate();
+ bool IsComplete();
+
+ private:
+ Pinetime::Drivers::SpiNorFlash& spiNorFlash;
+ static constexpr size_t bufferSize = 200;
+ bool ready = false;
+ size_t chunkSize = 0;
+ size_t totalSize = 0;
+ size_t maxSize = 475136;
+ size_t bufferWriteIndex = 0;
+ size_t totalWriteIndex = 0;
+ static constexpr size_t writeOffset = 0x40000;
+ uint8_t tempBuffer[bufferSize];
+ uint16_t expectedCrc = 0;
+
+ void WriteMagicNumber();
+ uint16_t ComputeCrc(uint8_t const *p_data, uint32_t size, uint16_t const *p_crc);
+
+ };
private:
Pinetime::System::SystemTask &systemTask;
Pinetime::Controllers::Ble &bleController;
- Pinetime::Drivers::SpiNorFlash &spiNorFlash;
+ DfuImage dfuImage;
+ NotificationManager notificationManager;
static constexpr uint16_t dfuServiceId{0x1530};
static constexpr uint16_t packetCharacteristicId{0x1532};
@@ -119,22 +145,17 @@ namespace Pinetime {
uint8_t nbPacketsToNotify = 0;
uint32_t nbPacketReceived = 0;
uint32_t bytesReceived = 0;
- uint32_t writeOffset = 0x40000;
uint32_t softdeviceSize = 0;
uint32_t bootloaderSize = 0;
uint32_t applicationSize = 0;
- static constexpr uint32_t maxImageSize = 475136;
uint16_t expectedCrc = 0;
int SendDfuRevision(os_mbuf *om) const;
int WritePacketHandler(uint16_t connectionHandle, os_mbuf *om);
int ControlPointHandler(uint16_t connectionHandle, os_mbuf *om);
- uint8_t tempBuffer[200];
- uint16_t ComputeCrc(uint8_t const *p_data, uint32_t size, uint16_t const *p_crc);
- void WriteMagicNumber();
+
TimerHandle_t timeoutTimer;
- NotificationManager notificationManager;
};
}
} \ No newline at end of file