From 7e9ef16a18ce8dfcb9f2950eb2fb327886d33480 Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Sun, 9 May 2021 12:19:40 -0400 Subject: [PATCH] More low power work --- .../.atmelstart/atmel_start_config.atstart | 14 ++--- .../My Project/Config/hpl_mclk_config.h | 2 +- .../My Project/My Project.cproj | 3 +- Smol Watch Project/My Project/main.c | 51 +++++++------------ .../My Project/watch-library/watch.c | 4 ++ 5 files changed, 33 insertions(+), 41 deletions(-) diff --git a/Smol Watch Project/My Project/.atmelstart/atmel_start_config.atstart b/Smol Watch Project/My Project/.atmelstart/atmel_start_config.atstart index 741d407..1bcb6bc 100644 --- a/Smol Watch Project/My Project/.atmelstart/atmel_start_config.atstart +++ b/Smol Watch Project/My Project/.atmelstart/atmel_start_config.atstart @@ -517,10 +517,10 @@ drivers: functionality: System api: HAL:HPL:GCLK configuration: - $input: 32768 - $input_id: 32kHz External Crystal Oscillator (XOSC32K) - RESERVED_InputFreq: 32768 - RESERVED_InputFreq_id: 32kHz External Crystal Oscillator (XOSC32K) + $input: 400000 + $input_id: External Crystal Oscillator 0.4-32MHz (XOSC) + RESERVED_InputFreq: 400000 + RESERVED_InputFreq_id: External Crystal Oscillator 0.4-32MHz (XOSC) _$freq_output_Generic clock generator 0: 4000000 _$freq_output_Generic clock generator 1: 400000 _$freq_output_Generic clock generator 2: 400000 @@ -594,7 +594,7 @@ drivers: cpu_clock_source: Generic clock generator 0 cpu_div: '1' enable_cpu_clock: true - mclk_arch_bupdiv: Divide by 8 + mclk_arch_bupdiv: Divide by 1 nvm_wait_states: '0' optional_signals: [] variant: null @@ -646,9 +646,9 @@ drivers: functionality: System api: HAL:HPL:OSCCTRL configuration: - $input: 32768 + $input: 16000000 $input_id: 32kHz External Crystal Oscillator (XOSC32K) - RESERVED_InputFreq: 32768 + RESERVED_InputFreq: 16000000 RESERVED_InputFreq_id: 32kHz External Crystal Oscillator (XOSC32K) _$freq_output_16MHz Internal Oscillator (OSC16M): 4000000 _$freq_output_Digital Frequency Locked Loop (DFLL48M): 48000000 diff --git a/Smol Watch Project/My Project/Config/hpl_mclk_config.h b/Smol Watch Project/My Project/Config/hpl_mclk_config.h index be1cd54..3358edc 100644 --- a/Smol Watch Project/My Project/Config/hpl_mclk_config.h +++ b/Smol Watch Project/My Project/Config/hpl_mclk_config.h @@ -48,7 +48,7 @@ // Divide by 128 // mclk_arch_bupdiv #ifndef CONF_MCLK_BUPDIV -#define CONF_MCLK_BUPDIV MCLK_BUPDIV_BUPDIV_DIV8_Val +#define CONF_MCLK_BUPDIV MCLK_BUPDIV_BUPDIV_DIV1_Val #endif // diff --git a/Smol Watch Project/My Project/My Project.cproj b/Smol Watch Project/My Project/My Project.cproj index af621b7..65dcb05 100644 --- a/Smol Watch Project/My Project/My Project.cproj +++ b/Smol Watch Project/My Project/My Project.cproj @@ -196,7 +196,7 @@ - + @@ -409,6 +409,7 @@ %24(PackRepoDir)\atmel\SAML22_DFP\1.2.77\include + Optimize debugging experience (-Og) True Maximum (-g3) True diff --git a/Smol Watch Project/My Project/main.c b/Smol Watch Project/My Project/main.c index b803fb6..053840a 100644 --- a/Smol Watch Project/My Project/main.c +++ b/Smol Watch Project/My Project/main.c @@ -11,9 +11,6 @@ void calendar_callback(struct calendar_descriptor *const calendar) { static void mode_callback() { 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() { @@ -21,7 +18,6 @@ static void light_callback() { 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, local); } static void alarm_callback() { @@ -29,19 +25,29 @@ static void alarm_callback() { calendar_get_date_time(&CALENDAR_0, &date_time); date_time.time.sec = 0; watch_set_date_time(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, local); } int main(void) { atmel_start_init(); + watch_init(&watch); + + watch_enable_date_time(&watch); + struct calendar_date_time date_time; + date_time.date.year = 2021; + date_time.date.month = 5; + date_time.date.day = 8; + date_time.time.hour = 19; + date_time.time.min = 40; + date_time.time.sec = 0; + watch_set_date_time(date_time); + update_display(&watch, date_time, local); + watch_enable_tick(tick_callback); + gpio_set_pin_level(RED, false); gpio_set_pin_direction(RED, GPIO_DIRECTION_OUT); gpio_set_pin_function(RED, GPIO_PIN_FUNCTION_OFF); @@ -49,38 +55,19 @@ int main(void) gpio_set_pin_direction(GREEN, GPIO_DIRECTION_OUT); gpio_set_pin_function(GREEN, GPIO_PIN_FUNCTION_OFF); - watch_init(&watch); - - watch_enable_display(&watch); - watch_display_pixel(&watch, 1, 16); - watch_enable_buttons(&watch); watch_register_button_callback(&watch, BTN_MODE, &mode_callback); watch_register_button_callback(&watch, BTN_ALARM, &alarm_callback); watch_register_button_callback(&watch, BTN_LIGHT, &light_callback); - watch_enable_date_time(&watch); - struct calendar_date_time date_time; - date_time.date.year = 2021; - date_time.date.month = 5; - 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.cal_alarm.mode = REPEAT; - alarm.cal_alarm.datetime = date_time; - alarm.cal_alarm.datetime.time.sec = 0; - alarm.cal_alarm.option = CALENDAR_ALARM_MATCH_SEC; - alarm.callback = calendar_callback; - calendar_set_alarm(&CALENDAR_0, &alarm, &calendar_callback); -*/ - update_display(&watch, date_time, local); - watch_enable_tick(tick_callback); + watch_enable_display(&watch); + watch_display_pixel(&watch, 1, 16); while (1) { sleep(4); + struct calendar_date_time date_time; + calendar_get_date_time(&CALENDAR_0, &date_time); + update_display(&watch, date_time, local); } return 0; diff --git a/Smol Watch Project/My Project/watch-library/watch.c b/Smol Watch Project/My Project/watch-library/watch.c index cb12b28..121f15c 100644 --- a/Smol Watch Project/My Project/watch-library/watch.c +++ b/Smol Watch Project/My Project/watch-library/watch.c @@ -12,8 +12,12 @@ void watch_init(Watch *watch) { memset(watch, 0, sizeof(*watch)); + // use switching regulator SUPC->VREG.bit.SEL = 1; while(!SUPC->STATUS.bit.VREGRDY); + // TODO: use performance level 0 +// _set_performance_level(0); +// hri_pm_write_PLCFG_PLDIS_bit(PM, true); } const uint8_t Character_Set[] =