diff --git a/tag_fw/drawing.c b/tag_fw/drawing.c index a0a33d9e..1e0d577a 100644 --- a/tag_fw/drawing.c +++ b/tag_fw/drawing.c @@ -215,7 +215,9 @@ static void drawPrvDecodeImageOnce(void) { uint16_t __xdata bitpoolOut = 0; #endif // get a row + epdDeselect(); eepromRead(mathPrvMul16x16(er, mDrawInfo.stride) + mDrawInfo.dataAddr, rowBuf, mDrawInfo.stride); + epdSelect(); // convert to our format c = mDrawInfo.effectiveW; do { @@ -329,16 +331,13 @@ void ByteDecode(uint8_t byte) { prev |= (mColorMap[mPassNo][byte >> 4] << 1) | mColorMap[mPassNo][byte & 0x0f]; if (++step == 4) { step = 0; - epdSelect(); epdSend(prev); - epdDeselect(); } } void drawImageAtAddress(uint32_t addr, uint8_t lut) { struct EepromImageHeader* __xdata eih = (struct EepromImageHeader*)mClutMap; eepromRead(addr, mClutMap, sizeof(struct EepromImageHeader)); - switch (eih->dataType) { case DATATYPE_IMG_RAW_1BPP: pr("Doing raw 1bpp\n"); @@ -392,7 +391,7 @@ void drawImageAtAddress(uint32_t addr, uint8_t lut) { break; case DATATYPE_IMG_BMP:; uint32_t __xdata clutAddr; - pr("sending to EPD - "); + pr("sending BMP to EPD - "); clutAddr = drawPrvParseHeader(addr); if (!clutAddr) return; diff --git a/tag_fw/fw154.bin b/tag_fw/fw154.bin index 54c79608..e06ead87 100644 Binary files a/tag_fw/fw154.bin and b/tag_fw/fw154.bin differ diff --git a/tag_fw/fw29.bin b/tag_fw/fw29.bin index b84198e2..044f56e2 100644 Binary files a/tag_fw/fw29.bin and b/tag_fw/fw29.bin differ diff --git a/tag_fw/fw42.bin b/tag_fw/fw42.bin index 0d14fcb2..2152652d 100644 Binary files a/tag_fw/fw42.bin and b/tag_fw/fw42.bin differ diff --git a/tag_fw/powermgt.c b/tag_fw/powermgt.c index b0a0b6ba..7c8ac12e 100644 --- a/tag_fw/powermgt.c +++ b/tag_fw/powermgt.c @@ -111,7 +111,7 @@ static void configEEPROM(const bool setup) { powerDown(INIT_RADIO); powerUp(INIT_EPD); showNoEEPROM(); - powerDown(INIT_EEPROM | INIT_EPD | INIT_GPIO); + powerDown(INIT_EEPROM | INIT_EPD); doSleep(-1); wdtDeviceReset(); } diff --git a/tag_fw/syncedproto.c b/tag_fw/syncedproto.c index 09af79e2..b9ac524d 100644 --- a/tag_fw/syncedproto.c +++ b/tag_fw/syncedproto.c @@ -373,7 +373,7 @@ static void sendXferCompletePacket() { static void sendXferComplete() { radioRxEnable(true, true); - for (uint8_t c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 16; c++) { sendXferCompletePacket(); uint32_t __xdata start = timerGet(); while ((timerGet() - start) < (TIMER_TICKS_PER_MS * 6UL)) { @@ -617,8 +617,21 @@ static bool downloadImageDataToEEPROM(const struct AvailDataInfo *__xdata avail) nextImgSlot++; if (nextImgSlot >= imgSlots) nextImgSlot = 0; curImgSlot = nextImgSlot; + pr("Saving to image slot %d\n", curImgSlot); drawWithLut = avail->dataTypeArgument; - eepromErase(getAddressForSlot(curImgSlot), EEPROM_IMG_EACH / EEPROM_ERZ_SECTOR_SZ); + powerUp(INIT_EEPROM); + uint8_t __xdata attempt = 5; + while (attempt--) { + if (eepromErase(getAddressForSlot(curImgSlot), EEPROM_IMG_EACH / EEPROM_ERZ_SECTOR_SZ)) goto eraseSuccess; + } + eepromFail: + powerDown(INIT_RADIO); + powerUp(INIT_EPD); + showNoEEPROM(); + powerDown(INIT_EEPROM | INIT_EPD); + doSleep(-1); + wdtDeviceReset(); + eraseSuccess: pr("new download, writing to slot %d\n", curImgSlot); // start, or restart the transfer. Copy data from the AvailDataInfo struct, and the struct intself. This forces a new transfer @@ -643,6 +656,7 @@ static bool downloadImageDataToEEPROM(const struct AvailDataInfo *__xdata avail) // succesfully downloaded datablock, save to eeprom powerUp(INIT_EEPROM); saveImgBlockData(curImgSlot, curBlock.blockId); + powerDown(INIT_EEPROM); curBlock.blockId++; curDataInfo.dataSize -= dataRequestSize; } else { @@ -650,6 +664,7 @@ static bool downloadImageDataToEEPROM(const struct AvailDataInfo *__xdata avail) return false; } } + // no more data, download complete // borrow the blockXferBuffer temporarily struct EepromImageHeader __xdata *eih = (struct EepromImageHeader __xdata *)blockXferBuffer; @@ -658,12 +673,11 @@ static bool downloadImageDataToEEPROM(const struct AvailDataInfo *__xdata avail) eih->id = ++curHighSlotId; eih->size = imageSize; eih->dataType = curDataInfo.dataType; - eepromWrite(getAddressForSlot(curImgSlot), eih, sizeof(struct EepromImageHeader)); - powerUp(INIT_RADIO); - sendXferComplete(); - powerDown(INIT_RADIO); - // no more data, download complete + powerUp(INIT_EEPROM); + eepromWrite(getAddressForSlot(curImgSlot), eih, sizeof(struct EepromImageHeader)); + powerDown(INIT_EEPROM); + return true; } @@ -707,14 +721,24 @@ bool processAvailDataInfo(const struct AvailDataInfo *__xdata avail) { return true; } else { // not found in cache, prepare to download + pr("downloading to imgslot\n"); drawWithLut = avail->dataTypeArgument; powerUp(INIT_EEPROM); - downloadImageDataToEEPROM(avail); - wdt60s(); - powerUp(INIT_EPD); - drawImageFromEeprom(curImgSlot); - powerDown(INIT_EPD | INIT_EEPROM); - return true; + if (downloadImageDataToEEPROM(avail)) { + pr("download complete!\n"); + powerUp(INIT_RADIO); + sendXferComplete(); + powerDown(INIT_RADIO); + + wdt60s(); + powerUp(INIT_EPD | INIT_EEPROM); + drawImageFromEeprom(curImgSlot); + powerDown(INIT_EPD | INIT_EEPROM); + return true; + } else { + powerDown(INIT_EEPROM); + return false; + } } break; case DATATYPE_FW_UPDATE: