functionality: System
api: HAL:HPL:GCLK
configuration:
- $input: 400000
- $input_id: External Crystal Oscillator 0.4-32MHz (XOSC)
- RESERVED_InputFreq: 400000
- RESERVED_InputFreq_id: External Crystal Oscillator 0.4-32MHz (XOSC)
+ $input: 32768
+ $input_id: 32kHz External Crystal Oscillator (XOSC32K)
+ RESERVED_InputFreq: 32768
+ RESERVED_InputFreq_id: 32kHz External Crystal Oscillator (XOSC32K)
_$freq_output_Generic clock generator 0: 4000000
_$freq_output_Generic clock generator 1: 400000
_$freq_output_Generic clock generator 2: 400000
functionality: Calendar
api: HAL:Driver:Calendar
configuration:
- rtc_arch_init_reset: true
+ rtc_arch_init_reset: false
rtc_arch_prescaler: Peripheral clock divided by 1024
rtc_cmpeo0: false
rtc_event_control: false
// <i> Note that the previous power down data in RTC is lost if it's enabled.
// <id> rtc_arch_init_reset
#ifndef CONF_RTC_INIT_RESET
-#define CONF_RTC_INIT_RESET 1
+#define CONF_RTC_INIT_RESET 0
#endif
// <o> Prescaler configuration
<AcmeProjectActionInfo Action="File" Source="config/hpl_osc32kctrl_config.h" IsConfig="true" Hash="LayjFcrIUjhOQ+E6G5sHRA" />\r
<AcmeProjectActionInfo Action="File" Source="config/hpl_oscctrl_config.h" IsConfig="true" Hash="Vc5u27WzT+UPF5aLAxl2lQ" />\r
<AcmeProjectActionInfo Action="File" Source="config/hpl_port_config.h" IsConfig="true" Hash="rMTNR+5FXtu+wfT1NbfRRA" />\r
- <AcmeProjectActionInfo Action="File" Source="config/hpl_rtc_config.h" IsConfig="true" Hash="oTcobT9ydLDOqfpwUidHvg" />\r
+ <AcmeProjectActionInfo Action="File" Source="config/hpl_rtc_config.h" IsConfig="true" Hash="w/iGOvqHWjII6brxzrQCIg" />\r
<AcmeProjectActionInfo Action="File" Source="config/hpl_sercom_config.h" IsConfig="true" Hash="x/EmsaDJwEm2EI8zXUSlWw" />\r
<AcmeProjectActionInfo Action="File" Source="config/hpl_slcd_config.h" IsConfig="true" Hash="dUpqyZg3KRMbt3sjYhNt1Q" />\r
<AcmeProjectActionInfo Action="File" Source="config/hpl_systick_config.h" IsConfig="true" Hash="tlT3lNDKWFe82MiGWfQzcA" />\r
<Value>%24(PackRepoDir)\atmel\SAML22_DFP\1.2.77\include</Value>\r
</ListValues>\r
</armgcc.compiler.directories.IncludePaths>\r
- <armgcc.compiler.optimization.level>Optimize debugging experience (-Og)</armgcc.compiler.optimization.level>\r
<armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>\r
<armgcc.compiler.optimization.DebugLevel>Maximum (-g3)</armgcc.compiler.optimization.DebugLevel>\r
<armgcc.compiler.warnings.AllWarnings>True</armgcc.compiler.warnings.AllWarnings>\r
#include "mars_clock.h"
Watch watch;
-bool locked = true;
+bool local = true;
void calendar_callback(struct calendar_descriptor *const calendar) {
}
static void mode_callback() {
- locked = !locked;
- gpio_set_pin_level(GREEN, !locked);
+ local = !local;
+ struct calendar_date_time date_time;
+ calendar_get_date_time(&CALENDAR_0, &date_time);
+ update_display(&watch, date_time, local);
}
static void light_callback() {
- if (locked) return;
struct calendar_date_time date_time;
calendar_get_date_time(&CALENDAR_0, &date_time);
date_time.time.min = (date_time.time.min + 1) % 60;
watch_set_date_time(date_time);
- update_display(&watch, date_time);
+ update_display(&watch, date_time, local);
}
static void alarm_callback() {
- if (locked) return;
struct calendar_date_time date_time;
calendar_get_date_time(&CALENDAR_0, &date_time);
date_time.time.sec = 0;
watch_set_date_time(date_time);
- update_display(&watch, date_time);
+ update_display(&watch, date_time, local);
}
static void tick_callback() {
struct calendar_date_time date_time;
calendar_get_date_time(&CALENDAR_0, &date_time);
- update_display(&watch, date_time);
+ update_display(&watch, date_time, local);
}
int main(void)
watch_enable_date_time(&watch);
struct calendar_date_time date_time;
- date_time.date.year = 1; // reference year is 2020, add this to that.
+ date_time.date.year = 2021;
date_time.date.month = 5;
- date_time.date.day = 2;
- date_time.time.hour = 7;
- date_time.time.min = 15;
+ date_time.date.day = 6;
+ date_time.time.hour = 23;
+ date_time.time.min = 30;
date_time.time.sec = 0;
watch_set_date_time(date_time);
/* struct calendar_alarm alarm;
alarm.callback = calendar_callback;
calendar_set_alarm(&CALENDAR_0, &alarm, &calendar_callback);
*/
- update_display(&watch, date_time);
+ update_display(&watch, date_time, local);
watch_enable_tick(tick_callback);
while (1) {
#include <math.h>\r
#include "mars_clock.h"\r
\r
-// note: mars time not working, committing just the earth clock.\r
+static unsigned short days[4][12] =\r
+{\r
+ { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335},\r
+ { 366, 397, 425, 456, 486, 517, 547, 578, 609, 639, 670, 700},\r
+ { 731, 762, 790, 821, 851, 882, 912, 943, 974,1004,1035,1065},\r
+ {1096,1127,1155,1186,1216,1247,1277,1308,1339,1369,1400,1430},\r
+};\r
\r
-void update_display(Watch *watch, struct calendar_date_time date_time) {
+unsigned int date_time_to_epoch(struct calendar_date_time date_time)\r
+{\r
+ unsigned int second = date_time.time.sec;\r
+ unsigned int minute = date_time.time.min;\r
+ unsigned int hour = date_time.time.hour;\r
+ unsigned int day = date_time.date.day-1; // 0-30\r
+ unsigned int month = date_time.date.month-1; // 0-11\r
+ unsigned int year = date_time.date.year - 1970; // 0-99\r
+ return (((year/4*(365*4+1)+days[year%4][month]+day)*24+hour)*60+minute)*60+second;\r
+}\r
+\r
+void epoch_to_date_time(struct calendar_date_time date_time, unsigned int epoch)\r
+{\r
+ date_time.time.sec = epoch % 60;\r
+ epoch /= 60;\r
+ date_time.time.min = epoch % 60;\r
+ epoch /= 60;\r
+ date_time.time.hour = epoch % 24;\r
+ epoch /= 24;\r
+\r
+ unsigned int years = epoch/(365*4+1)*4;\r
+ epoch %= 365*4+1;\r
+\r
+ unsigned int year;\r
+ for (year=3; year>0; year--)\r
+ {\r
+ if (epoch >= days[year][0])\r
+ break;\r
+ }\r
+\r
+ unsigned int month;\r
+ for (month=11; month>0; month--)\r
+ {\r
+ if (epoch >= days[year][month])\r
+ break;\r
+ }\r
+\r
+ date_time.date.year = years+year;\r
+ date_time.date.month = month+1;\r
+ date_time.date.day = epoch-days[year][month]+1;\r
+}\r
+\r
+void h_to_hms(struct calendar_date_time *date_time, double h) {\r
+ unsigned int seconds = (unsigned int)(h * 3600.0);\r
+ date_time->time.hour = seconds / 3600;\r
+ seconds = seconds % 3600;\r
+ date_time->time.min = floor(seconds / 60);\r
+ date_time->time.sec = round(seconds % 60);\r
+}\r
+\r
+\r
+void update_display(Watch *watch, struct calendar_date_time date_time, bool local) {
char buf[6];
- sprintf(&buf[0], "TE %02d%02d%02d", date_time.time.hour, date_time.time.min, date_time.time.sec);
+ if (local) {
+ sprintf(&buf[0], "TE %02d%02d%02d", date_time.time.hour, date_time.time.min, date_time.time.sec);
+ } else {
+ unsigned int now = date_time_to_epoch(date_time);
+ double jdut = 2440587.5 + ((double)now / 86400.0);\r
+ double jdtt = jdut + ((37.0 + 32.184) / 86400.0);\r
+ double jd2k = jdtt - 2451545.0;\r
+ double msd = ((jd2k - 4.5) / 1.0274912517) + 44796.0 - 0.0009626;\r
+ double mtc = fmod(24 * msd, 24);\r
+ struct calendar_date_time mars_time;\r
+ h_to_hms(&mars_time, mtc);\r
+ sprintf(&buf[0], "MA %02d%02d%02d", mars_time.time.hour, mars_time.time.min, mars_time.time.sec);
+ }
watch_display_string(watch, buf, 0);
}
#include "hpl_calendar.h"\r
#include "watch-library/watch.h"\r
\r
-void update_display(Watch *watch, struct calendar_date_time date_time);\r
+void update_display(Watch *watch, struct calendar_date_time date_time, bool local);\r
\r
\r
#endif /* MARS_CLOCK_H_ */
\ No newline at end of file