code cleanup, settings in eeprom, serial eeprom loader

This commit is contained in:
jjwbruijn
2023-12-04 22:01:21 +01:00
parent a941cad902
commit 14e4d17b31
17 changed files with 241 additions and 197 deletions

View File

@@ -9,6 +9,7 @@
#define ESP32_C6 0xC6
#define SOLUM_M2_BWR_16 0x20
#define SOLUM_M2_BW_29L 0x21
#define SOLUM_M2_BWR_29 0x23
#define SOLUM_M2_BWR_42 0x24
#define SOLUM_M2_BWR_75 0x26
@@ -30,6 +31,10 @@
#define SOLUM_M3_BWR_116 0x37
#define SOLUM_M3_BWY_116 0x3F
#define HS_NEBULAR_BWY_35 0x60
#define HS_NEBULAR_BWR_35 0x61
#define HS_NEBULAR_BW_35 0x62
#define CAPABILITY_SUPPORTS_COMPRESSION 0x02
#define CAPABILITY_SUPPORTS_CUSTOM_LUTS 0x04
#define CAPABILITY_ALT_LUT_SIZE 0x08
@@ -64,6 +69,7 @@
#define CMD_ENTER_SLIDESHOW_SLOW 0x08
#define CMD_ENTER_SLIDESHOW_GLACIAL 0x09
#define CMD_ENTER_NORMAL_MODE 0x0F
#define CMD_ENTER_WAIT_RFWAKE 0x20
#define WAKEUP_REASON_TIMED 0
#define WAKEUP_REASON_GPIO 2
@@ -102,4 +108,5 @@
#define TAG_CUSTOM_SLIDESHOW_FAST 0x06
#define TAG_CUSTOM_SLIDESHOW_MEDIUM 0x07
#define TAG_CUSTOM_SLIDESHOW_SLOW 0x08
#define TAG_CUSTOM_SLIDESHOW_GLACIAL 0x09
#define TAG_CUSTOM_SLIDESHOW_GLACIAL 0x09
#define TAG_CUSTOM_MODE_WAIT_RFWAKE 0x20

View File

@@ -24,8 +24,8 @@
extern void dump(uint8_t* __xdata a, uint16_t __xdata l); // remove me when done
extern uint8_t __xdata blockXferBuffer[];
__xdata uint8_t i2cbuffer[18];
extern uint8_t __xdata blockbuffer[];
bool supportsNFCWake() {
P1PULL |= (1 << 3);
@@ -57,7 +57,7 @@ void loadRawNTag(uint16_t blocksize) {
i2ctrans.deviceAddr = (uint8_t)0x55 << 1;
i2ctrans.bytes = i2cbuffer;
i2cbuffer[0] = c + 1;
memcpy(i2cbuffer + 1, sizeof(struct blockData) + blockXferBuffer + (c * 16), 16);
memcpy(i2cbuffer + 1, sizeof(struct blockData) + blockbuffer + (c * 16), 16);
uint8_t res = i2cTransact(&i2ctrans, 1);
timerDelay(133300);
}
@@ -67,9 +67,9 @@ void loadURLtoNTag() {
// https://learn.adafruit.com/adafruit-pn532-rfid-nfc/ndef << very helpful
uint8_t __xdata i2cbuffer[18];
__xdata uint8_t* tempbuffer = blockXferBuffer + 2048;
__xdata uint8_t* tempbuffer = blockbuffer + 2048;
strncpy(tempbuffer + 7, blockXferBuffer + sizeof(struct blockData), 245);
strncpy(tempbuffer + 7, blockbuffer + sizeof(struct blockData), 245);
uint8_t __xdata len = strlen(tempbuffer + 7);
struct I2cTransaction __xdata i2ctrans;

View File

@@ -21,6 +21,8 @@
#include "userinterface.h"
#include "wdt.h"
#include "uart.h"
#include "../oepl-definitions.h"
#include "../oepl-proto.h"
@@ -31,16 +33,81 @@ static const uint64_t __code __at(0x008b) mVersionRom = 0x1000011300000000ull;
#define TAG_MODE_CHANSEARCH 0
#define TAG_MODE_ASSOCIATED 1
#define DELAY_SLIDESHOW_FAST 30
#define DELAY_SLIDESHOW_MEDIUM 60
#define DELAY_SLIDESHOW_SLOW 300
#define DELAY_SLIDESHOW_GLACIAL 1800
uint8_t currentTagMode = TAG_MODE_CHANSEARCH;
uint8_t __xdata slideShowCurrentImg = 0;
uint8_t __xdata slideShowRefreshCount = 1;
extern uint8_t *__idata blockp;
extern uint8_t blockbuffer[];
#ifdef ENABLE_EEPROM_LOADER
extern bool __idata serialBypassActive;
bool __xdata serialActive = false;
void processSerial(uint8_t lastchar) {
static uint8_t __xdata cmdbuffer[4];
// shift characters in
for (uint8_t c = 0; c < 3; c++) {
cmdbuffer[c] = cmdbuffer[c + 1];
}
cmdbuffer[3] = lastchar;
if (strncmp(cmdbuffer + 1, ">D>", 3) == 0) {
wdt120s();
blockp = blockbuffer;
serialBypassActive = true;
pr("ACK>\n");
while (serialBypassActive)
;
if (validateBlockData()) {
pr("ACK>\n");
} else {
pr("NOK>\n");
}
}
if (strncmp(cmdbuffer + 1, "<D<", 3) == 0) {
wdt120s();
pr("ACK>");
for (uint16_t c = 0; c < 4100; c++) {
uartTx(blockbuffer[c]);
timerDelay(TIMER_TICKS_PER_MS / 400); // 30 okay // 50 kinda okay // 80 ook okay?
}
pr("blaat");
}
if (strncmp(cmdbuffer, "STE", 3) == 0) { // store block to offset
if (!eepromErase(4096UL * cmdbuffer[3], 4096 / EEPROM_ERZ_SECTOR_SZ)) {
pr("NOK>\n");
return;
}
if (eepromWrite(4096UL * cmdbuffer[3], blockbuffer + 4, 4096))
pr("ACK>\n");
else
pr("NOK>\n");
}
if (strncmp(cmdbuffer, "LDE", 3) == 0) { // load block from offset
eepromRead(4096UL * cmdbuffer[3], blockbuffer + 4, 4096);
uint16_t *header = blockbuffer;
*header = 4096;
uint16_t *sum = blockbuffer + 2;
*sum = 0;
for (uint16_t c = 4; c < 4100; c++) {
*sum += blockbuffer[c];
}
pr("ACK>\n");
}
}
void serialTerminal() {
serialActive = true;
while (serialActive) {
while (uartBytesAvail()) {
processSerial(uartRx());
}
}
}
#endif
void displayLoop() {
powerUp(INIT_BASE | INIT_UART);
@@ -165,11 +232,18 @@ void detectButtonOrJig() {
break;
case DETECT_P1_0_JIG:
wdt120s();
// show the screensaver, full LUT (minimal text to prevent image burn-in)
#ifdef ENABLE_EEPROM_LOADER
// run the eeprom loader interface
powerUp(INIT_EPD | INIT_EEPROM);
serialActive = true;
serialTerminal();
#else
// show splashscreen
powerUp(INIT_EPD);
afterFlashScreenSaver();
while (1)
;
#endif
break;
case DETECT_P1_0_NOTHING:
break;
@@ -403,7 +477,7 @@ void TagSlideShow() {
// same image, so don't update the screen; this only happens when there's exactly one slideshow image
powerDown(INIT_EEPROM);
}
tagSettings.enableRFWake = true;
switch (tagSettings.customMode) {
case TAG_CUSTOM_SLIDESHOW_FAST:
doSleep(1000UL * SLIDESHOW_INTERVAL_FAST);
@@ -422,14 +496,36 @@ void TagSlideShow() {
}
}
void TagShowWaitRFWake() {
pr("waiting for RF wake to start slideshow, now showing image\n");
currentChannel = 11; // suppress the no-rf image thing
displayCustomImage(CUSTOM_IMAGE_SLIDESHOW);
// powerDown(INIT_EEPROM | INIT_EPD);
tagSettings.enableRFWake = 1;
while (1) {
doSleep(-1);
if (wakeUpReason == WAKEUP_REASON_RF || wakeUpReason == WAKEUP_REASON_BUTTON1) {
break;
}
}
tagSettings.enableRFWake = 0;
tagSettings.customMode = TAG_CUSTOM_SLIDESHOW_SLOW;
powerUp(INIT_EEPROM);
writeSettings();
powerDown(INIT_EEPROM);
wdtDeviceReset();
}
void executeCommand(uint8_t cmd) {
switch (cmd) {
case CMD_DO_REBOOT:
wdtDeviceReset();
break;
case CMD_DO_RESET_SETTINGS:
powerUp(INIT_EEPROM);
loadDefaultSettings();
writeSettings();
powerDown(INIT_EEPROM);
break;
case CMD_DO_SCAN:
currentChannel = channelSelect(4);
@@ -453,9 +549,9 @@ void executeCommand(uint8_t cmd) {
powerDown(INIT_EEPROM);
return;
}
powerDown(INIT_EEPROM);
tagSettings.customMode = TAG_CUSTOM_SLIDESHOW_FAST;
writeSettings();
powerDown(INIT_EEPROM);
wdtDeviceReset();
break;
case CMD_ENTER_SLIDESHOW_MEDIUM:
@@ -464,9 +560,9 @@ void executeCommand(uint8_t cmd) {
powerDown(INIT_EEPROM);
return;
}
powerDown(INIT_EEPROM);
tagSettings.customMode = TAG_CUSTOM_SLIDESHOW_MEDIUM;
writeSettings();
powerDown(INIT_EEPROM);
wdtDeviceReset();
break;
case CMD_ENTER_SLIDESHOW_SLOW:
@@ -475,10 +571,9 @@ void executeCommand(uint8_t cmd) {
powerDown(INIT_EEPROM);
return;
}
powerDown(INIT_EEPROM);
tagSettings.customMode = TAG_CUSTOM_SLIDESHOW_SLOW;
writeSettings();
powerDown(INIT_EEPROM);
wdtDeviceReset();
break;
case CMD_ENTER_SLIDESHOW_GLACIAL:
@@ -487,14 +582,23 @@ void executeCommand(uint8_t cmd) {
powerDown(INIT_EEPROM);
return;
}
powerDown(INIT_EEPROM);
tagSettings.customMode = TAG_CUSTOM_SLIDESHOW_GLACIAL;
writeSettings();
powerDown(INIT_EEPROM);
wdtDeviceReset();
break;
case CMD_ENTER_NORMAL_MODE:
tagSettings.customMode = TAG_CUSTOM_MODE_NONE;
powerUp(INIT_EEPROM);
writeSettings();
powerDown(INIT_EEPROM);
wdtDeviceReset();
break;
case CMD_ENTER_WAIT_RFWAKE:
tagSettings.customMode = TAG_CUSTOM_MODE_WAIT_RFWAKE;
powerUp(INIT_EEPROM);
writeSettings();
powerDown(INIT_EEPROM);
wdtDeviceReset();
break;
}
@@ -516,13 +620,20 @@ void main() {
pr("%02X%02X", mSelfMac[4], mSelfMac[5]);
pr("%02X%02X\n", mSelfMac[6], mSelfMac[7]);
powerUp(INIT_EEPROM);
// load settings from infopage
loadSettings();
// get the highest slot number, number of slots
initializeProto();
powerDown(INIT_EEPROM);
// detect button or jig
detectButtonOrJig();
switch (tagSettings.customMode) {
case TAG_CUSTOM_MODE_WAIT_RFWAKE:
TagShowWaitRFWake();
break;
case TAG_CUSTOM_SLIDESHOW_FAST:
case TAG_CUSTOM_SLIDESHOW_MEDIUM:
case TAG_CUSTOM_SLIDESHOW_SLOW:
@@ -544,7 +655,7 @@ void main() {
}
} else {
// Normal boot/startup
pr("Normal boot\n");
// validate the mac address; this will display a warning on the screen if the mac address is invalid
validateMacAddress();
@@ -556,9 +667,6 @@ void main() {
// Get a voltage reading on the tag, loading down the battery with the radio
doVoltageReading();
// detect button or jig
detectButtonOrJig();
// show the splashscreen
currentChannel = 11;
showSplashScreen();
@@ -574,7 +682,9 @@ void main() {
tagSettings.fastBootCapabilities = capabilities;
// now that we've collected all possible capabilities, save it to settings
powerUp(INIT_EEPROM);
writeSettings();
powerDown(INIT_EEPROM);
// scan for channels
wdt30s();
@@ -613,4 +723,4 @@ void main() {
break;
}
}
}
}

View File

@@ -119,12 +119,13 @@ static void configSPI(const bool setup) {
static void configUART(const bool setup) {
if (uartActive == setup) return;
if (setup) {
P0FUNC |= (1 << 6);
P0FUNC |= (1 << 6)|(1<<7);
P0DIR &= ~(1 << 6);
P0DIR |= (1<<7);
uartInit();
} else {
P0DIR |= (1 << 6);
P0FUNC &= ~(1 << 6);
P0FUNC &= ~((1 << 6)|(1<<7));
CLKEN &= ~(0x20);
}
uartActive = setup;
@@ -268,7 +269,7 @@ void doSleep(const uint32_t __xdata t) {
// set up pins for spi(0.0,0.1,0.2), UART (0.6)
// setup 1.1(eeprom_nCS), 1.2(eink_BS1), 1.7(eink_nCS)
// setup 2.0(eink_nRST), 2.1(eink_BUSY), 2.2(eink_D/nC)
UartTxWait();
P0FUNC = 0;
P1FUNC = 0;
P2FUNC = 0;

View File

@@ -1,7 +1,7 @@
#define __packed
#include "settings.h"
#include <flash.h>
//#include <flash.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@@ -13,14 +13,13 @@
#include "powermgt.h"
#include "printf.h"
#include "syncedproto.h"
#include "eeprom.h"
#include "../oepl-definitions.h"
#include "../oepl-proto.h"
struct tagsettings __xdata tagSettings = {0};
extern uint8_t __xdata blockXferBuffer[];
uint8_t* __xdata infopageTempBuffer = 1024 + blockXferBuffer;
#define INFOPAGE_SETTINGS_OFFSET 0x50
extern uint8_t __xdata blockbuffer[];
uint8_t* __xdata settingsTempBuffer = 1024 + blockbuffer;
void loadDefaultSettings() {
tagSettings.settingsVer = SETTINGS_STRUCT_VERSION;
@@ -41,7 +40,6 @@ void loadSettingsFromBuffer(uint8_t* p) {
pr("SETTINGS: received settings from AP\n");
switch (*p) {
case SETTINGS_STRUCT_VERSION: // the current tag struct
pr("SETTINGS: received matching version\n");
memcpy((void*)tagSettings, (void*)p, sizeof(struct tagsettings));
break;
default:
@@ -53,9 +51,9 @@ void loadSettingsFromBuffer(uint8_t* p) {
}
static bool compareSettings() {
// check if the settings match the settings in the infopage
flashRead(FLASH_INFOPAGE_ADDR + INFOPAGE_SETTINGS_OFFSET, (void*)infopageTempBuffer, sizeof(struct tagsettings));
if (memcmp((void*)infopageTempBuffer, (void*)tagSettings, sizeof(struct tagsettings)) == 0) {
// check if the settings match the settings in the eeprom
eepromRead(EEPROM_SETTINGS_AREA_START, (void*)settingsTempBuffer, sizeof(struct tagsettings));
if (memcmp((void*)settingsTempBuffer, (void*)tagSettings, sizeof(struct tagsettings)) == 0) {
// same
return true;
}
@@ -68,8 +66,8 @@ static void upgradeSettings() {
}
void loadSettings() {
flashRead((FLASH_INFOPAGE_ADDR + INFOPAGE_SETTINGS_OFFSET), (void*)infopageTempBuffer, sizeof(struct tagsettings));
xMemCopy((void*)tagSettings, (void*)infopageTempBuffer, sizeof(struct tagsettings));
eepromRead(EEPROM_SETTINGS_AREA_START, (void*)settingsTempBuffer, sizeof(struct tagsettings));
xMemCopy((void*)tagSettings, (void*)settingsTempBuffer, sizeof(struct tagsettings));
if (tagSettings.settingsVer == 0xFF) {
// settings not set. load the defaults
loadDefaultSettings();
@@ -81,7 +79,7 @@ void loadSettings() {
pr("SETTINGS: Upgraded from previous version\n");
} else {
// settings are valid
pr("SETTINGS: Loaded from infopage\n");
pr("SETTINGS: Loaded from EEPROM\n");
}
}
}
@@ -91,9 +89,7 @@ void writeSettings() {
pr("SETTINGS: Settings matched current settings\n");
return;
}
flashRead(FLASH_INFOPAGE_ADDR, (void*)infopageTempBuffer, 1024);
xMemCopy((void*)(infopageTempBuffer + INFOPAGE_SETTINGS_OFFSET), (void*)tagSettings, sizeof(tagSettings));
flashErase(FLASH_INFOPAGE_ADDR + 1);
flashWrite(FLASH_INFOPAGE_ADDR, (void*)infopageTempBuffer, 1024, false);
pr("SETTINGS: Updated settings in infopage\n");
eepromErase(EEPROM_SETTINGS_AREA_START, 1);
eepromWrite(EEPROM_SETTINGS_AREA_START, (void*)tagSettings, sizeof(tagSettings));
pr("SETTINGS: Updated settings in EEPROM\n");
}

View File

@@ -3,11 +3,12 @@
#include <stdint.h>
#define FW_VERSION 22 // version number (max 2.5.5 :) )
#define FW_VERSION_SUFFIX "-RFW" // suffix, like -RC1 or whatever.
#define FW_VERSION 23 // version number (max 2.5.5 :) )
#define FW_VERSION_SUFFIX "-HWI" // suffix, like -RC1 or whatever.
// #define DEBUGBLOCKS // uncomment to enable extra debug information on the block transfers
// #define PRINT_LUT // uncomment if you want the tag to print the LUT for the current temperature bracket
#define ENABLE_GPIO_WAKE // uncomment to enable GPIO wake
// #define ENABLE_EEPROM_LOADER // uncomment if you want to load eeprom images via the serial interface
#define ENABLE_GPIO_WAKE // uncomment to enable GPIO wake
// #define ENABLE_RETURN_DATA // enables the tag to send blocks of data back. Enabling this costs about 4 IRAM bytes
#define SETTINGS_STRUCT_VERSION 0x01
@@ -42,4 +43,4 @@ void loadDefaultSettings();
void writeSettings();
void loadSettings();
void loadSettingsFromBuffer(uint8_t* p);
#endif
#endif

View File

@@ -27,7 +27,7 @@
#include "wdt.h"
// download-stuff
uint8_t __xdata blockXferBuffer[BLOCK_XFER_BUFFER_SIZE] = {0};
uint8_t __xdata blockbuffer[BLOCK_XFER_BUFFER_SIZE] = {0};
static struct blockRequest __xdata curBlock = {0}; // used by the block-requester, contains the next request that we'll send
static uint8_t __xdata curDispDataVer[8] = {0};
static struct AvailDataInfo __xdata xferDataInfo = {0}; // holds the AvailDataInfo during the transfer
@@ -39,6 +39,8 @@ uint8_t __xdata curImgSlot = 0xFF; // currently shown image
static uint32_t __xdata curHighSlotId = 0; // current highest ID, will be incremented before getting written to a new slot
static uint8_t __xdata nextImgSlot = 0; // next slot in sequence for writing
static uint8_t __xdata imgSlots = 0;
static uint32_t __xdata eeSize = 0;
#define OTA_UPDATE_SIZE 0x10000
// stuff we need to keep track of related to the network/AP
uint8_t __xdata APmac[8] = {0};
@@ -103,7 +105,7 @@ void dump(const uint8_t *__xdata a, const uint16_t __xdata l) {
}
pr("\n");
}
static bool checkCRC(const void *p, const uint8_t len) {
bool checkCRC(const void *p, const uint8_t len) {
uint8_t total = 0;
for (uint8_t c = 1; c < len; c++) {
total += ((uint8_t *)p)[c];
@@ -307,14 +309,14 @@ static bool processBlockPart(const struct blockPart *bp) {
// pr("got a packet for block %02X\n", bp->blockId);
return false;
}
if (start >= (sizeof(blockXferBuffer) - 1)) return false;
if (start >= (sizeof(blockbuffer) - 1)) return false;
if (bp->blockPart > BLOCK_MAX_PARTS) return false;
if ((start + size) > sizeof(blockXferBuffer)) {
size = sizeof(blockXferBuffer) - start;
if ((start + size) > sizeof(blockbuffer)) {
size = sizeof(blockbuffer) - start;
}
if (checkCRC(bp, sizeof(struct blockPart) + BLOCK_PART_DATA_SIZE)) {
// copy block data to buffer
xMemCopy((void *)(blockXferBuffer + start), (const void *)bp->data, size);
xMemCopy((void *)(blockbuffer + start), (const void *)bp->data, size);
// we don't need this block anymore, set bit to 0 so we don't request it again
curBlock.requestedParts[bp->blockPart / 8] &= ~(1 << (bp->blockPart % 8));
return true;
@@ -445,8 +447,8 @@ static void sendXferComplete() {
pr("XFC NACK!\n");
return;
}
static bool validateBlockData() {
struct blockData *bd = (struct blockData *)blockXferBuffer;
bool validateBlockData() {
struct blockData *bd = (struct blockData *)blockbuffer;
// pr("expected len = %04X, checksum=%04X\n", bd->size, bd->checksum);
uint16_t t = 0;
for (uint16_t c = 0; c < bd->size; c++) {
@@ -460,7 +462,7 @@ static uint32_t getAddressForSlot(const uint8_t s) {
return EEPROM_IMG_START + (EEPROM_IMG_EACH * s);
}
static void getNumSlots() {
uint32_t eeSize = eepromGetSize();
eeSize = eepromGetSize();
uint16_t nSlots = mathPrvDiv32x16(eeSize - EEPROM_IMG_START, EEPROM_IMG_EACH >> 8) >> 8;
if (eeSize < EEPROM_IMG_START || !nSlots) {
pr("eeprom is too small\n");
@@ -471,11 +473,13 @@ static void getNumSlots() {
imgSlots = 254;
} else
imgSlots = nSlots;
pr("PROTO: %d image slots total\n", imgSlots);
}
static uint8_t findSlotVer(const uint8_t *ver) {
// return 0xFF; // remove me! This forces the tag to re-download each and every upload without checking if it's already in the eeprom somewhere
for (uint8_t c = 0; c < imgSlots; c++) {
struct EepromImageHeader __xdata *eih = (struct EepromImageHeader __xdata *)blockXferBuffer;
struct EepromImageHeader __xdata *eih = (struct EepromImageHeader __xdata *)blockbuffer;
eepromRead(getAddressForSlot(c), eih, sizeof(struct EepromImageHeader));
if (xMemEqual4(&eih->validMarker, &markerValid)) {
if (xMemEqual(&eih->version, (void *)ver, 8)) {
@@ -490,7 +494,7 @@ static uint8_t findSlotVer(const uint8_t *ver) {
uint8_t __xdata findSlotDataTypeArg(uint8_t arg) __reentrant {
arg &= (0xF8); // unmatch with the 'preload' bit and LUT bits
for (uint8_t c = 0; c < imgSlots; c++) {
struct EepromImageHeader __xdata *eih = (struct EepromImageHeader __xdata *)blockXferBuffer;
struct EepromImageHeader __xdata *eih = (struct EepromImageHeader __xdata *)blockbuffer;
eepromRead(getAddressForSlot(c), eih, sizeof(struct EepromImageHeader));
if (xMemEqual4(&eih->validMarker, &markerValid)) {
if ((eih->argument & 0xF8) == arg) {
@@ -501,12 +505,12 @@ uint8_t __xdata findSlotDataTypeArg(uint8_t arg) __reentrant {
return 0xFF;
}
uint8_t getEepromImageDataArgument(const uint8_t slot) {
struct EepromImageHeader __xdata *eih = (struct EepromImageHeader __xdata *)blockXferBuffer;
struct EepromImageHeader __xdata *eih = (struct EepromImageHeader __xdata *)blockbuffer;
eepromRead(getAddressForSlot(slot), eih, sizeof(struct EepromImageHeader));
return eih->argument;
}
uint8_t __xdata findNextSlideshowImage(uint8_t start) __reentrant {
struct EepromImageHeader __xdata *eih = (struct EepromImageHeader __xdata *)blockXferBuffer;
struct EepromImageHeader __xdata *eih = (struct EepromImageHeader __xdata *)blockbuffer;
uint8_t c = start;
while (1) {
c++;
@@ -522,20 +526,20 @@ uint8_t __xdata findNextSlideshowImage(uint8_t start) __reentrant {
}
static void eraseUpdateBlock() {
eepromErase(EEPROM_UPDATA_AREA_START, EEPROM_UPDATE_AREA_LEN / EEPROM_ERZ_SECTOR_SZ);
eepromErase(eeSize - OTA_UPDATE_SIZE, OTA_UPDATE_SIZE / EEPROM_ERZ_SECTOR_SZ);
}
static void eraseImageBlock(const uint8_t c) {
eepromErase(getAddressForSlot(c), EEPROM_IMG_EACH / EEPROM_ERZ_SECTOR_SZ);
}
static void saveUpdateBlockData(uint8_t blockId) {
if (!eepromWrite(EEPROM_UPDATA_AREA_START + (blockId * BLOCK_DATA_SIZE), blockXferBuffer + sizeof(struct blockData), BLOCK_DATA_SIZE))
if (!eepromWrite(eeSize - OTA_UPDATE_SIZE + (blockId * BLOCK_DATA_SIZE), blockbuffer + sizeof(struct blockData), BLOCK_DATA_SIZE))
pr("EEPROM write failed\n");
}
static void saveImgBlockData(const uint8_t imgSlot, const uint8_t blockId) {
uint16_t length = EEPROM_IMG_EACH - (sizeof(struct EepromImageHeader) + (blockId * BLOCK_DATA_SIZE));
if (length > 4096) length = 4096;
if (!eepromWrite(getAddressForSlot(imgSlot) + sizeof(struct EepromImageHeader) + (blockId * BLOCK_DATA_SIZE), blockXferBuffer + sizeof(struct blockData), length))
if (!eepromWrite(getAddressForSlot(imgSlot) + sizeof(struct EepromImageHeader) + (blockId * BLOCK_DATA_SIZE), blockbuffer + sizeof(struct blockData), length))
pr("EEPROM write failed\n");
}
void eraseImageBlocks() {
@@ -549,7 +553,7 @@ void drawImageFromEeprom(const uint8_t imgSlot, uint8_t lut) {
static uint32_t getHighSlotId() {
uint32_t temp = 0;
for (uint8_t __xdata c = 0; c < imgSlots; c++) {
struct EepromImageHeader __xdata *eih = (struct EepromImageHeader __xdata *)blockXferBuffer;
struct EepromImageHeader __xdata *eih = (struct EepromImageHeader __xdata *)blockbuffer;
eepromRead(getAddressForSlot(c), eih, sizeof(struct EepromImageHeader));
if (xMemEqual4(&eih->validMarker, &markerValid)) {
if (temp < eih->id) {
@@ -713,8 +717,15 @@ static bool downloadImageDataToEEPROM(const struct AvailDataInfo *__xdata avail)
} else {
// new transfer
powerUp(INIT_EEPROM);
// go to the next image slot
uint8_t startingSlot = nextImgSlot;
// if we encounter a special image type, start looking from slot 0, to prevent the image being overwritten when we do an OTA update
if (avail->dataTypeArgument & 0xFC != 0x00) {
startingSlot = 0;
}
while (1) {
nextImgSlot++;
if (nextImgSlot >= imgSlots) nextImgSlot = 0;
@@ -723,7 +734,7 @@ static bool downloadImageDataToEEPROM(const struct AvailDataInfo *__xdata avail)
pr("No slots available. Too many images in the slideshow?\n");
return true;
}
struct EepromImageHeader __xdata *eih = (struct EepromImageHeader __xdata *)blockXferBuffer;
struct EepromImageHeader __xdata *eih = (struct EepromImageHeader __xdata *)blockbuffer;
eepromRead(getAddressForSlot(nextImgSlot), eih, sizeof(struct EepromImageHeader));
// check if the marker is indeed valid
if (xMemEqual4(&eih->validMarker, &markerValid)) {
@@ -787,8 +798,8 @@ static bool downloadImageDataToEEPROM(const struct AvailDataInfo *__xdata avail)
}
// no more data, download complete
// borrow the blockXferBuffer temporarily
struct EepromImageHeader __xdata *eih = (struct EepromImageHeader __xdata *)blockXferBuffer;
// borrow the blockbuffer temporarily
struct EepromImageHeader __xdata *eih = (struct EepromImageHeader __xdata *)blockbuffer;
xMemCopy8(&eih->version, &xferDataInfo.dataVer);
eih->validMarker = EEPROM_IMG_VALID;
eih->id = ++curHighSlotId;
@@ -936,7 +947,7 @@ bool processAvailDataInfo(struct AvailDataInfo *__xdata avail) {
powerUp(INIT_EEPROM);
wdt60s();
eepromReadStart(EEPROM_UPDATA_AREA_START);
eepromReadStart(eeSize - OTA_UPDATE_SIZE);
selfUpdate();
} else {
return false;
@@ -1006,7 +1017,9 @@ bool processAvailDataInfo(struct AvailDataInfo *__xdata avail) {
wdt10s();
if (getDataBlock(avail->dataSize)) {
xferDataInfo.dataSize = 0; // mark as transfer not pending
loadSettingsFromBuffer(sizeof(struct blockData) + blockXferBuffer);
powerUp(INIT_EEPROM);
loadSettingsFromBuffer(sizeof(struct blockData) + blockbuffer);
powerDown(INIT_EEPROM);
powerUp(INIT_RADIO);
sendXferComplete();
powerDown(INIT_RADIO);
@@ -1049,7 +1062,7 @@ bool processAvailDataInfo(struct AvailDataInfo *__xdata avail) {
wdt10s();
if (getDataBlock(avail->dataSize)) {
xferDataInfo.dataSize = 0; // mark as transfer not pending
memcpy(customLUT, sizeof(struct blockData) + blockXferBuffer, 6 + (dispLutSize * 10));
memcpy(customLUT, sizeof(struct blockData) + blockbuffer, 6 + (dispLutSize * 10));
powerUp(INIT_RADIO);
sendXferComplete();
powerDown(INIT_RADIO);
@@ -1063,8 +1076,6 @@ bool processAvailDataInfo(struct AvailDataInfo *__xdata avail) {
}
void initializeProto() {
powerUp(INIT_EEPROM);
getNumSlots();
curHighSlotId = getHighSlotId();
powerDown(INIT_EEPROM);
}

View File

@@ -18,15 +18,19 @@ extern uint8_t __xdata curImgSlot;
extern bool sendTagReturnData(uint8_t __xdata *data, uint8_t len, uint8_t type);
#endif
void dump(const uint8_t *__xdata a, const uint16_t __xdata l);
extern void dump(const uint8_t *__xdata a, const uint16_t __xdata l);
extern bool checkCRC(const void *p, const uint8_t len);
extern bool validateBlockData();
extern uint8_t __xdata findSlotDataTypeArg(uint8_t arg) __reentrant;
uint8_t __xdata findNextSlideshowImage(uint8_t start) __reentrant;
uint8_t getEepromImageDataArgument(const uint8_t slot);
extern uint8_t __xdata findNextSlideshowImage(uint8_t start) __reentrant;
extern uint8_t getEepromImageDataArgument(const uint8_t slot);
extern struct AvailDataInfo *__xdata getAvailDataInfo();
extern struct AvailDataInfo *__xdata getShortAvailDataInfo();
extern void drawImageFromEeprom(const uint8_t imgSlot, uint8_t lut);
void eraseImageBlocks();
extern void eraseImageBlocks();
extern bool processAvailDataInfo(struct AvailDataInfo *__xdata avail);
extern void initializeProto();
extern uint8_t detectAP(const uint8_t channel);

View File

@@ -18,35 +18,6 @@ __bit boardGetOwnMac(uint8_t __xdata *mac);
//some sanity checks
#include "eeprom.h"
#if !EEPROM_SETTINGS_AREA_START
#error "settings cannot be at address 0"
#endif
#if (EEPROM_SETTINGS_AREA_LEN % EEPROM_ERZ_SECTOR_SZ) != 0
#error "settings area must be an integer number of eeprom blocks"
#endif
#if (EEPROM_SETTINGS_AREA_START % EEPROM_ERZ_SECTOR_SZ) != 0
#error "settings must begin at an integer number of eeprom blocks"
#endif
#if (EEPROM_IMG_EACH % EEPROM_ERZ_SECTOR_SZ) != 0
#error "each image must be an integer number of eeprom blocks"
#endif
#if (EEPROM_IMG_START % EEPROM_ERZ_SECTOR_SZ) != 0
#error "images must begin at an integer number of eeprom blocks"
#endif
#if (EEPROM_UPDATE_AREA_LEN % EEPROM_ERZ_SECTOR_SZ) != 0
#error "update must be an integer number of eeprom blocks"
#endif
#if (EEPROM_UPDATA_AREA_START % EEPROM_ERZ_SECTOR_SZ) != 0
#error "images must begin at an integer number of eeprom blocks"
#endif
#endif
#endif

View File

@@ -819,26 +819,4 @@ void epdPrintEnd() {
}
}
commandEnd();
}
extern uint8_t __xdata blockXferBuffer[];
void readRam() {
setWindowY(296, 0);
setWindowX(0, 8);
setPosXY(0, 296);
shortCommand1(CMD_DATA_ENTRY_MODE, 1); // was 3
shortCommand1(0x41, 0x00);
commandReadBegin(0x27);
epdReadByte();
for (uint16_t c = 0; c < 293; c++) {
blockXferBuffer[c] = epdReadByte() | 0x10;
}
commandReadEnd();
commandBegin(CMD_WRITE_FB_BW);
for (uint16_t c = 0; c < 296; c++) {
epdSend(blockXferBuffer[c]);
}
commandEnd();
}
}

View File

@@ -786,6 +786,4 @@ void epdPrintEnd() {
commandEnd();
shortCommand(CMD_PARTIAL_OUT);
epdDrawDirection(true);
}
extern uint8_t __xdata blockXferBuffer[];
}

View File

@@ -13,11 +13,9 @@
#define eepromPrvDeselect() do { __asm__("nop\nnop\nnop\n"); P1_1 = 1; __asm__("nop\nnop\nnop\n"); } while(0)
//eeprom map
#define EEPROM_SETTINGS_AREA_START (0x01000UL)
#define EEPROM_SETTINGS_AREA_LEN (0x03000UL)
#define EEPROM_UPDATA_AREA_START (0x04000UL)
#define EEPROM_UPDATE_AREA_LEN (0x10000UL)
#define EEPROM_IMG_START (0x14000UL)
#define EEPROM_SETTINGS_AREA_START (0x00000UL)
#define EEPROM_SETTINGS_AREA_LEN (0x01000UL)
#define EEPROM_IMG_START (0x01000UL)
#define EEPROM_IMG_EACH (0x02000UL)
//till end of eeprom really. do not put anything after - it will be erased at pairing time!!!
#define EEPROM_PROGRESS_BYTES (128)

View File

@@ -13,12 +13,10 @@
#define eepromPrvDeselect() do { __asm__("nop\nnop\nnop\n"); P1_1 = 1; __asm__("nop\nnop\nnop\n"); } while(0)
//eeprom map
#define EEPROM_SETTINGS_AREA_START (0x01000UL)
#define EEPROM_SETTINGS_AREA_LEN (0x03000UL)
#define EEPROM_UPDATA_AREA_START (0x04000UL)
#define EEPROM_UPDATE_AREA_LEN (0x10000UL)
#define EEPROM_IMG_START (0x14000UL)
#define EEPROM_IMG_EACH (0x04000UL)
#define EEPROM_SETTINGS_AREA_START (0x00000UL)
#define EEPROM_SETTINGS_AREA_LEN (0x01000UL)
#define EEPROM_IMG_START (0x01000UL)
#define EEPROM_IMG_EACH (0x03000UL)
//till end of eeprom really. do not put anything after - it will be erased at pairing time!!!
#define EEPROM_PROGRESS_BYTES (128)

View File

@@ -13,14 +13,10 @@
#define eepromPrvDeselect() do { __asm__("nop\nnop\nnop\n"); P1_1 = 1; __asm__("nop\nnop\nnop\n"); } while(0)
//eeprom map
#define EEPROM_SETTINGS_AREA_START (0x01000UL)
#define EEPROM_SETTINGS_AREA_LEN (0x03000UL)
#define EEPROM_UPDATA_AREA_START (0x04000UL)
#define EEPROM_UPDATE_AREA_LEN (0x10000UL)
#define EEPROM_IMG_START (0x14000UL)
#define EEPROM_IMG_EACH (0x04000UL)
//till end of eeprom really. do not put anything after - it will be erased at pairing time!!!
#define EEPROM_PROGRESS_BYTES (128)
#define EEPROM_SETTINGS_AREA_START (0x00000UL)
#define EEPROM_SETTINGS_AREA_LEN (0x01000UL)
#define EEPROM_IMG_START (0x01000UL)
#define EEPROM_IMG_EACH (0x03000UL)
#define HAS_EEPROM 1
#define HAS_SCREEN 1

View File

@@ -11,11 +11,9 @@
#define eepromPrvDeselect() do { __asm__("nop\nnop\nnop\n"); P1_1 = 1; __asm__("nop\nnop\nnop\n"); } while(0)
//eeprom map
#define EEPROM_SETTINGS_AREA_START (0x01000UL)
#define EEPROM_SETTINGS_AREA_LEN (0x03000UL)
#define EEPROM_UPDATA_AREA_START (0x04000UL)
#define EEPROM_UPDATE_AREA_LEN (0x10000UL)
#define EEPROM_IMG_START (0x14000UL)
#define EEPROM_SETTINGS_AREA_START (0x00000UL)
#define EEPROM_SETTINGS_AREA_LEN (0x01000UL)
#define EEPROM_IMG_START (0x01000UL)
#define EEPROM_IMG_EACH (0x08000UL)
//till end of eeprom really. do not put anything after - it will be erased at pairing time!!!
#define EEPROM_PROGRESS_BYTES (128)

View File

@@ -2,47 +2,42 @@
#include "cpu.h"
#ifdef AP_FW
#include "stdbool.h"
#include "string.h"
#endif
// #include "string.h"
void uartInit(void) {
// clock it up
CLKEN |= 0x20;
// configure baud rate
UARTBRGH = 0x00;
#ifdef AP_FW
// UARTBRGL = 69; // nice. 230400 baud
//UARTBRGL = 70; // 79 == 200k
IEN_UART0 = 1;
UARTBRGL = 0x8A; // config for 115200
#else
UARTBRGL = 0x8A; // config for 115200
#endif
UARTSTA = 0x12; // also set the "empty" bit else we wait forever for it to go up
}
#ifndef AP_FW
void uartTx(uint8_t val) {
while (!(UARTSTA & (1 << 1)))
;
UARTSTA &= ~(1 << 1);
UARTBUF = val;
// UARTBRGL = 69; // nice. 230400 baud
// UARTBRGL = 70; // 79 == 200k
// UARTSTA = 0x12; // also set the "empty" bit else we wait forever for it to go up
UARTBRGL = 0x8A; // config for 115200
UARTSTA = 0x10; // clear the register, don't trigger the interrupt just yet
IEN_UART0 = 1;
}
#else
extern uint8_t __xdata blockbuffer[];
volatile uint8_t txtail = 0;
volatile uint8_t txhead = 0;
volatile uint8_t __xdata txtail = 0;
volatile uint8_t __xdata txhead = 0;
uint8_t __xdata txbuf[256] = {0};
volatile uint8_t __idata rxtail = 0;
volatile uint8_t __idata rxhead = 0;
uint8_t __xdata rxbuf[256] = {0};
void UartTxWait() {
while (txhead != txtail) {
}
}
void uartTx(uint8_t val) {
while(txhead+1 == txtail){
}
__critical {
txbuf[txhead] = val;
if (txhead == txtail) {
@@ -67,20 +62,8 @@ uint8_t uartBytesAvail() {
}
uint8_t* __idata blockp;
uint8_t __idata cmd[3];
volatile bool __idata serialBypassActive = false;
void checkcommand(uint8_t rx) {
for (uint8_t c = 0; c < 2; c++) {
cmd[c] = cmd[c + 1];
}
cmd[2] = rx;
if (strncmp(cmd, ">D>", 3) == 0) {
blockp = blockbuffer;
serialBypassActive = true;
}
}
void UART_IRQ1(void) __interrupt(0) {
if (UARTSTA & 1) { // RXC
UARTSTA &= 0xfe;
@@ -93,7 +76,6 @@ void UART_IRQ1(void) __interrupt(0) {
} else {
rxbuf[rxhead] = UARTBUF;
rxhead++;
// checkcommand(UARTBUF);
}
}
if (UARTSTA & 2) { // TXC
@@ -104,4 +86,3 @@ void UART_IRQ1(void) __interrupt(0) {
}
}
}
#endif

View File

@@ -3,17 +3,12 @@
#include <stdint.h>
//pre-configured for 115200 8n1
//RX can be done but i do not need it
#pragma callee_saves uartInit
void uartInit(void);
#pragma callee_saves uartTx
void uartTx(uint8_t val);
#ifdef AP_FW
void UART_IRQ1(void) __interrupt (0);
#pragma callee_saves uartBytesAvail
@@ -21,7 +16,8 @@ uint8_t uartBytesAvail(void);
#pragma callee_saves uartRX
uint8_t uartRx();
#endif
void UartTxWait();
#endif