Skip to content

Commit

Permalink
Implement wake logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Feb 12, 2019
1 parent 7e96e1c commit 95d964e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
1 change: 1 addition & 0 deletions bl.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ void screen_sleep();
void screen_init();
void draw_drag();
void draw_hf2();
void draw_hold_menu();
void print(int x, int y, int col, const char *text);
void draw_screen();
void print4(int x, int y, int col, const char *text);
Expand Down
33 changes: 26 additions & 7 deletions main_f4.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ static void board_init(void);
#define POWER_DOWN_RTC_SIGNATURE 0x5019684f // Written by app fw to not re-power on.
#define HF2_RTC_SIGNATURE 0x39a63a78
#define SLEEP_RTC_ARG 0x10b37889
#define SLEEP2_RTC_ARG 0x7e3353b7

#define BOOT_RTC_REG MMIO32(RTC_BASE + 0x50)
#define ARG_RTC_REG MMIO32(RTC_BASE + 0x54)
Expand Down Expand Up @@ -196,10 +197,8 @@ board_get_rtc_signature(uint32_t *arg)
RCC_BDCR |= RCC_BDCR_RTCEN;

uint32_t result = BOOT_RTC_REG;
if (arg) {
if (arg)
*arg = ARG_RTC_REG;
ARG_RTC_REG = 0;
}

/* disable the backup registers */
RCC_BDCR &= RCC_BDCR_RTCEN;
Expand Down Expand Up @@ -533,7 +532,6 @@ void warning_screen(uint32_t);

#define PWR_CR_LPLVDS (1 << 10)
void deepsleep() {
board_set_rtc_signature(APP_RTC_SIGNATURE, 0);

setup_output_pin(CFG_PIN_JACK_BZEN);
setup_output_pin(CFG_PIN_JACK_HPEN);
Expand Down Expand Up @@ -580,8 +578,9 @@ void deepsleep() {
if (d > 1000)
pin_set(CFG_PIN_DISPLAY_BL, 1);
}
if (d > 1000)
scb_reset_system();
if (d > 1000) {
resetIntoApp();
}
}
}

Expand Down Expand Up @@ -629,8 +628,28 @@ main(void)
DMESG("bootsig: %p", bootSig);


if (bootSig == APP_RTC_SIGNATURE && bootArg == SLEEP_RTC_ARG)
if (bootSig == APP_RTC_SIGNATURE && bootArg == SLEEP_RTC_ARG) {
// next time show instructions
board_set_rtc_signature(APP_RTC_SIGNATURE, SLEEP2_RTC_ARG);
deepsleep();
}

if (bootSig == APP_RTC_SIGNATURE && bootArg == SLEEP2_RTC_ARG) {
screen_init();
draw_hold_menu();
setup_input_pin(CFG_PIN_BTN_MENU);
for (int i = 0; i < 200; ++i) {
screen_delay(10);
// if they touch MENU while the instruction screen is on,
// just stop the sleep and boot into app
if (pin_get(CFG_PIN_BTN_MENU) == 0) {
bootArg = 0;
break;
}
}
if (bootArg)
deepsleep();
}

/*
* Clear the signature so that if someone resets us while we're
Expand Down
6 changes: 6 additions & 0 deletions screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ void draw_hf2() {
draw_screen();
}

void draw_hold_menu() {
print4(20, 22, 6, "MENU");
print(10, 110, 1, "hold MENU to wake");
draw_screen();
}

void draw_drag() {
drawBar(0, 52, 10);
drawBar(52, 55, 8);
Expand Down
2 changes: 1 addition & 1 deletion uf2cfg.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define UF2_VERSION "2.4.1"
#define UF2_VERSION "2.4.2"
#ifndef BOARD_ID
#define BOARD_ID "STM32F4xx-Arcade-Generic"
#endif
Expand Down

0 comments on commit 95d964e

Please sign in to comment.