summaryrefslogtreecommitdiffstats
path: root/main/set-time.patch
diff options
context:
space:
mode:
Diffstat (limited to 'main/set-time.patch')
-rw-r--r--main/set-time.patch83
1 files changed, 83 insertions, 0 deletions
diff --git a/main/set-time.patch b/main/set-time.patch
new file mode 100644
index 0000000..c7d479c
--- /dev/null
+++ b/main/set-time.patch
@@ -0,0 +1,83 @@
+diff --git a/make.mk b/make.mk
+index ee40100..5610c1f 100644
+--- a/make.mk
++++ b/make.mk
+@@ -64,7 +64,7 @@ LDFLAGS += -mcpu=cortex-m0plus -mthumb
+ LDFLAGS += -Wl,--gc-sections
+ LDFLAGS += -Wl,--script=$(TOP)/watch-library/hardware/linker/saml22j18.ld
+ LDFLAGS += -Wl,--print-memory-usage
+-LDFLAGS += -g
++LDFLAGS += -g -u set_time
+
+ LIBS += -lm
+
+diff --git a/movement/make/Makefile b/movement/make/Makefile
+index a336b85..5fa1322 100644
+--- a/movement/make/Makefile
++++ b/movement/make/Makefile
+@@ -51,6 +51,7 @@ SRCS += \
+ ../../littlefs/lfs.c \
+ ../../littlefs/lfs_util.c \
+ ../movement.c \
++ ../set_time.c \
+ ../filesystem.c \
+ ../shell.c \
+ ../shell_cmd_list.c \
+diff --git a/movement/movement.c b/movement/movement.c
+index 230dbe5..8abd6e7 100644
+--- a/movement/movement.c
++++ b/movement/movement.c
+@@ -412,6 +412,7 @@ void app_wake_from_backup(void) {
+
+ void app_setup(void) {
+ watch_store_backup_data(movement_state.settings.reg, 0);
++ set_time();
+
+ static bool is_first_launch = true;
+
+diff --git a/movement/set_time.c b/movement/set_time.c
+new file mode 100644
+index 0000000..27cea25
+--- /dev/null
++++ b/movement/set_time.c
+@@ -0,0 +1,40 @@
++#include <stdio.h>
++#include <string.h>
++#include <limits.h>
++#include <string.h>
++#include <stdlib.h>
++#include <stdio.h>
++#include "watch.h"
++#include "movement.h"
++#include "watch_utility.h"
++
++#define SYS_TIME 0x11
++
++extern movement_state_t movement_state;
++
++static inline int32_t
++get_tz_offset (movement_settings_t * settings)
++{
++ return movement_timezone_offsets[settings->bit.time_zone] * 60;
++}
++
++static int32_t
++sys_time (void)
++{
++ int32_t value = SYS_TIME;
++ asm ("mov r0,%0; bkpt $0xab; mov %0,r0": "+r" (value): :"r0");
++ return value;
++}
++
++void __attribute__((used)) set_time (void)
++{
++ int32_t t;
++
++ t = sys_time ();
++
++ watch_date_time wdt = watch_utility_date_time_from_unix_time (t,
++ get_tz_offset
++ (&movement_state.
++ settings));
++ watch_rtc_set_date_time (wdt);
++}