Skip to content

Commit d7f6bdf

Browse files
Make all SelfProgram methods static
This removes the need for keeping an instance around.
1 parent 1a0011d commit d7f6bdf

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

SelfProgram.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ void startApplication();
2424

2525
class SelfProgram {
2626
public:
27-
void readFlash(uint16_t address, uint8_t *data, uint8_t len);
27+
static void readFlash(uint16_t address, uint8_t *data, uint8_t len);
2828

29-
uint8_t readByte(uint16_t address);
29+
static uint8_t readByte(uint16_t address);
3030

31-
uint8_t writePage(uint16_t address, uint8_t *data, uint8_t len);
31+
static uint8_t writePage(uint16_t address, uint8_t *data, uint8_t len);
3232

33-
void writeTrampoline(uint16_t instruction);
33+
static void writeTrampoline(uint16_t instruction);
3434

35-
uint16_t offsetRelativeJump(uint16_t instruction, int16_t offset);
35+
static uint16_t offsetRelativeJump(uint16_t instruction, int16_t offset);
3636

3737
static uint16_t trampolineStart;
3838

bootloader.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ struct Commands {
4646
static const uint8_t READ_FLASH = 0x08;
4747
};
4848

49-
SelfProgram selfProgram;
5049
volatile bool bootloaderExit = false;
5150

5251
static uint8_t writeBuffer[SPM_ERASESIZE];
@@ -55,7 +54,7 @@ static uint16_t nextWriteAddress = 0;
5554
static bool equalToFlash(uint16_t address, uint8_t len) {
5655
uint8_t offset = 0;
5756
while (len > 0) {
58-
if (writeBuffer[offset] != selfProgram.readByte(address + offset))
57+
if (writeBuffer[offset] != SelfProgram::readByte(address + offset))
5958
return false;
6059
--len;
6160
++offset;
@@ -72,7 +71,7 @@ static uint8_t commitToFlash(uint16_t address, uint8_t len) {
7271
uint8_t offset = 0;
7372
while (len > 0) {
7473
uint8_t pageLen = len < SPM_PAGESIZE ? len : SPM_PAGESIZE;
75-
uint8_t err = selfProgram.writePage(address + offset, &writeBuffer[offset], pageLen);
74+
uint8_t err = SelfProgram::writePage(address + offset, &writeBuffer[offset], pageLen);
7675
if (err)
7776
return err;
7877
len -= pageLen;
@@ -174,7 +173,7 @@ cmd_result processCommand(uint8_t cmd, uint8_t *datain, uint8_t len, uint8_t *da
174173
dataout[2] = INFO_BL_VERSION;
175174
// Available flash size is up to startApplication.
176175
// Convert from words to bytes.
177-
uint16_t size = selfProgram.applicationSize;
176+
uint16_t size = SelfProgram::applicationSize;
178177
dataout[3] = size >> 8;
179178
dataout[4] = size;
180179
return cmd_ok(5);
@@ -237,7 +236,7 @@ cmd_result processCommand(uint8_t cmd, uint8_t *datain, uint8_t len, uint8_t *da
237236
if (len > maxLen)
238237
return cmd_result(Status::INVALID_ARGUMENTS);
239238

240-
selfProgram.readFlash(address, dataout, len);
239+
SelfProgram::readFlash(address, dataout, len);
241240
return cmd_ok(len);
242241
}
243242

0 commit comments

Comments
 (0)