[ion/device] Prevent the user from leaving DFU during software download

We prevent the use of the Back key to leave DFU after a flash erase
operation. This way, we prevent the user from interrupting a software
download. After every software download, the calculator resets, which
unlocks the "exit on pressing back"
This commit is contained in:
Léa Saviot
2019-09-24 18:37:20 +02:00
parent 0f52335183
commit 78eea601c7
4 changed files with 13 additions and 2 deletions

View File

@@ -20,7 +20,7 @@ void Calculator::PollAndReset(bool exitWithKeyboard) {
Ion::Device::Keyboard::activateRow(exitKeyRow);
while (!(exitWithKeyboard && Ion::Device::Keyboard::columnIsActive(exitKeyColumn)) &&
while (!(exitWithKeyboard && !c.isErasingAndWriting() && Ion::Device::Keyboard::columnIsActive(exitKeyColumn)) &&
Ion::USB::isPlugged() &&
!c.isSoftDisconnected()) {
c.poll();

View File

@@ -115,6 +115,7 @@ public:
{
}
uint32_t addressPointer() const { return m_dfuInterface.addressPointer(); }
bool isErasingAndWriting() const { return m_dfuInterface.isErasingAndWriting(); }
protected:
virtual Descriptor * descriptor(uint8_t type, uint8_t index) override;
virtual void setActiveConfiguration(uint8_t configurationIndex) override {

View File

@@ -209,6 +209,7 @@ void DFUInterface::eraseMemoryIfNeeded() {
return;
}
willErase();
if (m_erasePage == Flash::TotalNumberOfSectors()) {
Flash::MassErase();
} else {

View File

@@ -27,12 +27,14 @@ public:
m_largeBuffer{0},
m_largeBufferLength(0),
m_writeAddress(0),
m_bInterfaceAlternateSetting(bInterfaceAlternateSetting)
m_bInterfaceAlternateSetting(bInterfaceAlternateSetting),
m_isErasingAndWriting(false)
{
}
uint32_t addressPointer() const { return m_addressPointer; }
void wholeDataReceivedCallback(SetupPacket * request, uint8_t * transferBuffer, uint16_t * transferBufferLength) override;
void wholeDataSentCallback(SetupPacket * request, uint8_t * transferBuffer, uint16_t * transferBufferLength) override;
bool isErasingAndWriting() const { return m_isErasingAndWriting; }
protected:
void setActiveInterfaceAlternative(uint8_t interfaceAlternativeIndex) override {
@@ -151,6 +153,12 @@ private:
bool dfuAbort(uint16_t * transferBufferLength);
// Leave DFU
void leaveDFUAndReset();
/* Erase and Write state. After starting the erase of flash memory, the user
* can no longer leave DFU mode by pressing the Back key of the keyboard. This
* way, we prevent the user from interrupting a software download. After every
* software download, the calculator resets, which unlocks the "exit on
* pressing back". */
void willErase() { m_isErasingAndWriting = true; }
Device * m_device;
Status m_status;
@@ -162,6 +170,7 @@ private:
uint16_t m_largeBufferLength;
uint32_t m_writeAddress;
uint8_t m_bInterfaceAlternateSetting;
bool m_isErasingAndWriting;
};
}