5050#include "idle.h"
5151#include "InitDevice.h"
5252#include "astrokey.h"
53+ #include "EFM8UB1_FlashPrimitives.h"
5354#include "EFM8UB1_FlashUtils.h"
5455
5556#include <stdint.h>
@@ -73,8 +74,6 @@ Macro_TypeDef SI_SEG_XDATA tmpMacro[MACRO_MAX_SIZE];
7374
7475// The data of the current macro
7576Macro_TypeDef SI_SEG_XDATA macro [MACRO_MAX_SIZE ];
76- // Number of actions in current macro
77- uint8_t macroNumActions = 0 ;
7877
7978// Index of current macro running (i.e. 0 for 1st key, etc.)
8079uint8_t macroIndex = NO_MACRO ;
@@ -144,37 +143,25 @@ void stepMacro()
144143 keyReportSent = false;
145144
146145 actionIndex ++ ;
147- if (actionIndex == macroNumActions )
146+ if (actionType == 0x00 || actionIndex == MACRO_MAX_SIZE )
148147 {
149148 macroIndex = NO_MACRO ;
150149 }
151150}
152151
153152void saveMacro (Macro_TypeDef * macroData , uint8_t saveIndex )
154153{
154+ uint8_t i ;
155155 FLADDR flashAddr = MACRO_FLASH_ADDR + (saveIndex * MACRO_BYTES );
156- //FLASH_Clear(flashAddr, MACRO_BYTES);
156+ for (i = 0 ; i < MACRO_PAGES ; i ++ )
157+ FLASH_PageErase (flashAddr + (USER_PAGE_SIZE * i ));
157158 FLASH_Write (flashAddr , (uint8_t * ) macroData , MACRO_BYTES );
158159}
159160
160161void loadMacro (Macro_TypeDef * macroData , uint8_t loadIndex )
161162{
162- uint8_t i ;
163-
164-
165163 FLADDR flashAddr = MACRO_FLASH_ADDR + (loadIndex * MACRO_BYTES );
166164 FLASH_Read ((uint8_t * )macroData , flashAddr , MACRO_BYTES );
167-
168- macroNumActions = MACRO_MAX_SIZE ;
169-
170- for (i = 0 ; i < MACRO_MAX_SIZE ; i ++ )
171- {
172- if (macroData [i ].actionType == 0 )
173- {
174- macroNumActions = i ;
175- break ;
176- }
177- }
178165}
179166
180167// Starts running a macro
0 commit comments