summaryrefslogtreecommitdiffstats
path: root/main/set-time.patch
blob: c7d479ce232773fd8ec97c2973ed9105dceb34ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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);
+}