Skip to content

Commit 4d54d8c

Browse files
authored
Merge pull request #5 from AaronPerl/master
Fixed Macro Overwriting
2 parents 2ce324f + 9422334 commit 4d54d8c

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

inc/astrokey.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#define ASTROKEY_GET_MACRO 0x02
1919

2020
// Switch configuration
21-
#define NUM_SWITCHES 2
21+
#define NUM_SWITCHES 5
2222
#define S0 P0_B0
2323
#define S1 P0_B1
2424
#define S2 P0_B2
@@ -41,12 +41,20 @@ typedef struct {
4141
uint8_t value;
4242
} Macro_TypeDef;
4343

44-
#define MACRO_MAX_SIZE 10
44+
// User data flash
45+
#define USER_PAGE_SIZE 64
46+
#define USER_START_ADDR 0xF800
47+
48+
// Number of pages per macro
49+
#define MACRO_PAGES 2
50+
// Number of bytes per macro
51+
#define MACRO_BYTES (MACRO_PAGES * USER_PAGE_SIZE)
52+
// Maximum number of actions in a macro
53+
#define MACRO_MAX_SIZE ((MACRO_BYTES) / sizeof(Macro_TypeDef))
54+
// Max number of keys simultaenously held by macro
4555
#define MACRO_MAX_KEYS 6
46-
#define MACRO_BYTES (MACRO_MAX_SIZE * sizeof(Macro_TypeDef))
4756

48-
#define BOOTLOADER_START_ADDR 0x1A00
49-
#define MACRO_FLASH_ADDR (BOOTLOADER_START_ADDR - (NUM_SWITCHES * MACRO_BYTES))
57+
#define MACRO_FLASH_ADDR USER_START_ADDR
5058

5159
void saveMacro(Macro_TypeDef* macroData, uint8_t saveIndex);
5260
void loadMacro(Macro_TypeDef* macroData, uint8_t loadIndex);

src/descriptors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ SI_SEGMENT_VARIABLE(deviceDesc[],
8989
64, // bMaxPacketSize
9090
USB_VENDOR_ID, // idVendor
9191
USB_PRODUCT_ID, // idProduct
92-
htole16(0x0001), // bcdDevice
92+
htole16(0x0002), // bcdDevice
9393
1, // iManufacturer
9494
2, // iProduct
9595
3, // iSerialNumber

src/main.c

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
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
7576
Macro_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.)
8079
uint8_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

153152
void 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

160161
void 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

Comments
 (0)