Skip to content

Commit 9422334

Browse files
author
Aaron Perl
committed
Changed macro running code to not need to know macro number of actions (to save code size), fixed flash clearing to clear all pages of flash for a macro
1 parent 10372f7 commit 9422334

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

src/main.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ Macro_TypeDef SI_SEG_XDATA tmpMacro[MACRO_MAX_SIZE];
7474

7575
// The data of the current macro
7676
Macro_TypeDef SI_SEG_XDATA macro[MACRO_MAX_SIZE];
77-
// Number of actions in current macro
78-
uint8_t macroNumActions = 0;
7977

8078
// Index of current macro running (i.e. 0 for 1st key, etc.)
8179
uint8_t macroIndex = NO_MACRO;
@@ -145,37 +143,25 @@ void stepMacro()
145143
keyReportSent = false;
146144

147145
actionIndex++;
148-
if (actionIndex == macroNumActions)
146+
if (actionType == 0x00 || actionIndex == MACRO_MAX_SIZE)
149147
{
150148
macroIndex = NO_MACRO;
151149
}
152150
}
153151

154152
void saveMacro(Macro_TypeDef* macroData, uint8_t saveIndex)
155153
{
154+
uint8_t i;
156155
FLADDR flashAddr = MACRO_FLASH_ADDR + (saveIndex * MACRO_BYTES);
157-
FLASH_PageErase(MACRO_FLASH_ADDR + (saveIndex * MACRO_BYTES));
156+
for (i = 0; i < MACRO_PAGES; i++)
157+
FLASH_PageErase(flashAddr + (USER_PAGE_SIZE * i));
158158
FLASH_Write(flashAddr, (uint8_t*) macroData, MACRO_BYTES);
159159
}
160160

161161
void loadMacro(Macro_TypeDef* macroData, uint8_t loadIndex)
162162
{
163-
uint8_t i;
164-
165-
166163
FLADDR flashAddr = MACRO_FLASH_ADDR + (loadIndex * MACRO_BYTES);
167164
FLASH_Read((uint8_t *)macroData, flashAddr, MACRO_BYTES);
168-
169-
macroNumActions = MACRO_MAX_SIZE;
170-
171-
for (i = 0; i < MACRO_MAX_SIZE; i++)
172-
{
173-
if (macroData[i].actionType == 0)
174-
{
175-
macroNumActions = i;
176-
break;
177-
}
178-
}
179165
}
180166

181167
// Starts running a macro

0 commit comments

Comments
 (0)