Skip to content

Commit

Permalink
M2 2.2 - RFW for added RF Wake
Browse files Browse the repository at this point in the history
  • Loading branch information
jjwbruijn committed Sep 28, 2023
1 parent aa48457 commit 125922f
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 71 deletions.
5 changes: 4 additions & 1 deletion oepl-definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@
#define WAKEUP_REASON_NFC 3
#define WAKEUP_REASON_BUTTON1 4
#define WAKEUP_REASON_BUTTON2 5
#define WAKEUP_REASON_RF 0x0F
#define WAKEUP_REASON_FIRSTBOOT 0xFC
#define WAKEUP_REASON_NETWORK_SCAN 0xFD
#define WAKEUP_REASON_WDT_RESET 0xFE


#define EPD_LUT_DEFAULT 0
#define EPD_LUT_NO_REPEATS 1
#define EPD_LUT_FAST_NO_REDS 2
Expand All @@ -90,7 +92,8 @@
#define CUSTOM_IMAGE_SLIDESHOW 0x0F // image is part of a slideshow
#define CUSTOM_IMAGE_BUTTON1 0x10
#define CUSTOM_IMAGE_BUTTON2 0x11
// UNUSED: 0x12 to 0x1C
// UNUSED: 0x12 to 0x1B
#define CUSTOM_IMAGE_RF_WAKE 0x1C
#define CUSTOM_IMAGE_GPIO 0x1D
#define CUSTOM_IMAGE_NFC_WAKE 0x1E

Expand Down
16 changes: 11 additions & 5 deletions zbs243_Tag_FW/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,25 @@ void TagAssociated() {

switch (wakeUpReason) {
case WAKEUP_REASON_BUTTON1:
gpioButton1();
externalWakeHandler(CUSTOM_IMAGE_BUTTON1);
fastNextCheckin = true;
break;
case WAKEUP_REASON_BUTTON2:
gpioButton2();
externalWakeHandler(CUSTOM_IMAGE_BUTTON2);
fastNextCheckin = true;
break;
#ifdef ENABLE_GPIO_WAKE
case WAKEUP_REASON_GPIO:
gpioButtonOther();
externalWakeHandler(CUSTOM_IMAGE_GPIO);
fastNextCheckin = true;
break;
case WAKEUP_REASON_RF:
externalWakeHandler(CUSTOM_IMAGE_RF_WAKE);
fastNextCheckin = true;
break;
case WAKEUP_REASON_NFC:
externalWakeHandler(CUSTOM_IMAGE_NFC_WAKE);
fastNextCheckin = true;
break;
#endif
}

if (avail != NULL) {
Expand Down
50 changes: 30 additions & 20 deletions zbs243_Tag_FW/powermgt.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ void doSleep(const uint32_t __xdata t) {
uartActive = false;
eepromActive = false;

capabilities |= CAPABILITY_HAS_WAKE_BUTTON;

if (capabilities & CAPABILITY_HAS_WAKE_BUTTON) {
// Button setup on TEST pin 1.0 (input pullup)
P1FUNC &= ~(1 << 0);
Expand Down Expand Up @@ -324,36 +326,44 @@ void doSleep(const uint32_t __xdata t) {
}

if (tagSettings.enableRFWake) {
// enabled RF wake, adds a little extra energy draw!
// enabled RF wake, adds a little extra energy draw!
RADIO_RadioPowerCtl &= 0xFB;
}

// sleepy time
sleepForMsec(t);
P1INTEN = 0;
P0INTEN = 0;
if ((P1CHSTA & (1 << 0)) && (capabilities & CAPABILITY_HAS_WAKE_BUTTON)) {
wakeUpReason = WAKEUP_REASON_BUTTON1;
P1CHSTA &= ~(1 << 0);
}

if ((P0CHSTA & (1 << 7)) && (capabilities & CAPABILITY_HAS_WAKE_BUTTON)) {
wakeUpReason = WAKEUP_REASON_BUTTON2;
P0CHSTA &= ~(1 << 7);
}

if ((P1CHSTA & (1 << 3)) && (capabilities & CAPABILITY_NFC_WAKE)) {
wakeUpReason = WAKEUP_REASON_NFC;
P1CHSTA &= ~(1 << 3);
}

switch (RADIO_Wake_Reason) {
case RADIO_WAKE_REASON_TIMER:
break;
case RADIO_WAKE_REASON_EXT:
if ((P1CHSTA & (1 << 0)) && (capabilities & CAPABILITY_HAS_WAKE_BUTTON)) {
wakeUpReason = WAKEUP_REASON_BUTTON1;
P1CHSTA &= ~(1 << 0);
}

if ((P0CHSTA & (1 << 7)) && (capabilities & CAPABILITY_HAS_WAKE_BUTTON)) {
wakeUpReason = WAKEUP_REASON_BUTTON2;
P0CHSTA &= ~(1 << 7);
}

if ((P1CHSTA & (1 << 3)) && (capabilities & CAPABILITY_NFC_WAKE)) {
wakeUpReason = WAKEUP_REASON_NFC;
P1CHSTA &= ~(1 << 3);
}
#ifdef ENABLE_GPIO_WAKE
if (P0CHSTA & (1 << 3)) {
wakeUpReason = WAKEUP_REASON_GPIO;
P0CHSTA &= ~(1 << 3);
}
if (P0CHSTA & (1 << 3)) {
wakeUpReason = WAKEUP_REASON_GPIO;
P0CHSTA &= ~(1 << 3);
}
#endif

break;
case RADIO_WAKE_REASON_RF:
wakeUpReason = WAKEUP_REASON_RF;
break;
}
}

void doVoltageReading() {
Expand Down
4 changes: 2 additions & 2 deletions zbs243_Tag_FW/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdint.h>

#define FW_VERSION 22 // version number (max 2.5.5 :) )
#define FW_VERSION_SUFFIX "-BUT" // suffix, like -RC1 or whatever.
#define FW_VERSION_SUFFIX "-RFW" // 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
Expand Down Expand Up @@ -42,4 +42,4 @@ void loadDefaultSettings();
void writeSettings();
void loadSettings();
void loadSettingsFromBuffer(uint8_t* p);
#endif
#endif
46 changes: 6 additions & 40 deletions zbs243_Tag_FW/userinterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ void showSplashScreen() {

#endif
drawWithSleep();
powerUp(INIT_EPD);
powerUp(INIT_EPD);
}

void showApplyUpdate() {
Expand All @@ -327,7 +327,7 @@ void showApplyUpdate() {

void showAPFound() {
if (displayCustomImage(CUSTOM_IMAGE_APFOUND)) return;
powerUp(INIT_EPD | INIT_EEPROM);
powerUp(INIT_EPD | INIT_EEPROM);

clearScreen();
setColorMode(EPD_MODE_NORMAL, EPD_MODE_INVERT);
Expand Down Expand Up @@ -432,8 +432,7 @@ void showAPFound() {
#endif
addOverlay();
drawWithSleep();
powerDown(INIT_EPD | INIT_EEPROM);

powerDown(INIT_EPD | INIT_EEPROM);
}

void showNoAP() {
Expand Down Expand Up @@ -596,8 +595,8 @@ bool displayCustomImage(uint8_t imagetype) {
return false;
}

void gpioButton1() {
if (displayCustomImage(CUSTOM_IMAGE_BUTTON1)) {
void externalWakeHandler(uint8_t type) {
if (displayCustomImage(type)) {
sleepForMsec(2000);

// if something else was previously on the display, draw that
Expand All @@ -610,37 +609,4 @@ void gpioButton1() {
powerDown(INIT_EPD | INIT_EEPROM);
}
}
}

void gpioButton2() {
if (displayCustomImage(CUSTOM_IMAGE_BUTTON1)) {
sleepForMsec(2000);

// if something else was previously on the display, draw that
if (curImgSlot != 0xFF) {
powerUp(INIT_EEPROM);
uint8_t lut = getEepromImageDataArgument(curImgSlot);
lut &= 0x03;
powerUp(INIT_EPD);
drawImageFromEeprom(curImgSlot, lut);
powerDown(INIT_EPD | INIT_EEPROM);
}
}
}

#ifdef ENABLE_GPIO_WAKE
void gpioButtonOther() {
if (displayCustomImage(CUSTOM_IMAGE_GPIO)) {
sleepForMsec(2000);
// if something else was previously on the display, draw that
if (curImgSlot != 0xFF) {
powerUp(INIT_EEPROM);
uint8_t lut = getEepromImageDataArgument(curImgSlot);
lut &= 0x03;
powerUp(INIT_EPD);
drawImageFromEeprom(curImgSlot, lut);
powerDown(INIT_EPD | INIT_EEPROM);
}
}
}
#endif
}
6 changes: 3 additions & 3 deletions zbs243_Tag_FW/userinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ void showNoEEPROM();
void showNoMAC();


void gpioButton1();
void gpioButton2();
void gpioButtonOther();

// wakeups from external stimuli
void externalWakeHandler(uint8_t type);

extern const uint16_t __code fwVersion;
extern const char __code fwVersionSuffix[];
Expand Down
6 changes: 6 additions & 0 deletions zbs243_shared/soc/zbs243/zbs243.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ static __xdata __at (0xdfe2) unsigned char RADIO_unk_E2;
static __xdata __at (0xdff0) unsigned char RADIO_unk_F0;
static __xdata __at (0xdff3) unsigned char RADIO_SleepTimerSettings; //0x16 for one second tick, 0x56 for 1/32k second tick
static __xdata __at (0xdff4) unsigned char RADIO_RadioPowerCtl;
static __xdata __at (0xdffb) unsigned char RADIO_Wake_Reason; // 0x04 ext interrupt, 0x08 timer, 0x02 RF wake
static __xdata __at (0xdffd) unsigned char RADIO_perChannelSetting1; //relevant fo rRX

#define RADIO_CMD_RECEIVE 0xc2 //tx always goes to RX anyways
Expand All @@ -286,4 +287,9 @@ static __xdata __at (0xdffd) unsigned char RADIO_perChannelSetting1; //relevant
#define RADIO_CMD_LOAD_TX_FIFO 0xcb


#define RADIO_WAKE_REASON_RF 0x02
#define RADIO_WAKE_REASON_EXT 0x04
#define RADIO_WAKE_REASON_TIMER 0x08


#endif

0 comments on commit 125922f

Please sign in to comment.