bring in stock stopwatch face, refactor to use TC1
This commit is contained in:
parent
e2ac434c3b
commit
e21561b330
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
const watch_face_t watch_faces[] = {
|
const watch_face_t watch_faces[] = {
|
||||||
clock_face,
|
clock_face,
|
||||||
simple_clock_face,
|
stock_stopwatch_face,
|
||||||
beats_face,
|
beats_face,
|
||||||
world_clock_face,
|
world_clock_face,
|
||||||
countdown_face,
|
countdown_face,
|
||||||
|
|||||||
@ -29,6 +29,7 @@
|
|||||||
#include "beats_face.h"
|
#include "beats_face.h"
|
||||||
#include "world_clock_face.h"
|
#include "world_clock_face.h"
|
||||||
#include "countdown_face.h"
|
#include "countdown_face.h"
|
||||||
|
#include "stock_stopwatch_face.h"
|
||||||
#include "set_time_face.h"
|
#include "set_time_face.h"
|
||||||
#include "preferences_face.h"
|
#include "preferences_face.h"
|
||||||
// New includes go above this line.
|
// New includes go above this line.
|
||||||
|
|||||||
@ -4,5 +4,6 @@ SRCS += \
|
|||||||
./watch-faces/clock/beats_face.c \
|
./watch-faces/clock/beats_face.c \
|
||||||
./watch-faces/clock/world_clock_face.c \
|
./watch-faces/clock/world_clock_face.c \
|
||||||
./watch-faces/complication/countdown_face.c \
|
./watch-faces/complication/countdown_face.c \
|
||||||
|
./watch-faces/complication/stock_stopwatch_face.c \
|
||||||
./watch-faces/settings/set_time_face.c \
|
./watch-faces/settings/set_time_face.c \
|
||||||
./watch-faces/settings/preferences_face.c \
|
./watch-faces/settings/preferences_face.c \
|
||||||
|
|||||||
@ -43,9 +43,7 @@
|
|||||||
#include <emscripten.h>
|
#include <emscripten.h>
|
||||||
#include <emscripten/html5.h>
|
#include <emscripten/html5.h>
|
||||||
#else
|
#else
|
||||||
#include "../../../watch-library/hardware/include/saml22j18a.h"
|
#include "tc.h"
|
||||||
#include "../../../watch-library/hardware/include/component/tc.h"
|
|
||||||
#include "../../../watch-library/hardware/hri/hri_tc_l22.h"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// distant future for background task: January 1, 2083
|
// distant future for background task: January 1, 2083
|
||||||
@ -88,37 +86,34 @@ static inline void _cb_start() {
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
static inline void _cb_start() {
|
static inline void _cb_start() {
|
||||||
// start the TC2 timer
|
// start the TC1 timer
|
||||||
hri_tc_set_CTRLA_ENABLE_bit(TC2);
|
tc_enable(1);
|
||||||
_is_running = true;
|
_is_running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void _cb_stop() {
|
static inline void _cb_stop() {
|
||||||
// stop the TC2 timer
|
// stop the TC1 timer
|
||||||
hri_tc_clear_CTRLA_ENABLE_bit(TC2);
|
tc_disable(1);
|
||||||
_is_running = false;
|
_is_running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _cb_initialize() {
|
static void _cb_initialize() {
|
||||||
// setup and initialize TC2 for a 64 Hz interrupt
|
tc_init(1, GENERIC_CLOCK_3, TC_PRESCALER_DIV4);
|
||||||
hri_mclk_set_APBCMASK_TC2_bit(MCLK);
|
tc_set_counter_mode(1, TC_COUNTER_MODE_8BIT);
|
||||||
hri_gclk_write_PCHCTRL_reg(GCLK, TC2_GCLK_ID, GCLK_PCHCTRL_GEN_GCLK3 | GCLK_PCHCTRL_CHEN);
|
tc_set_run_in_standby(1, true);
|
||||||
_cb_stop();
|
_cb_stop();
|
||||||
hri_tc_write_CTRLA_reg(TC2, TC_CTRLA_SWRST);
|
tc_count8_set_period(1, 1); // 1024 Hz divided by 4 divided by 2 results in a 128 Hz interrupt
|
||||||
hri_tc_wait_for_sync(TC2, TC_SYNCBUSY_SWRST);
|
/// FIXME: #SecondMovement, we need a gossamer wrapper for interrupts.
|
||||||
hri_tc_write_CTRLA_reg(TC2, TC_CTRLA_PRESCALER_DIV64 | // 32 Khz divided by 64 divided by 4 results in a 128 Hz interrupt
|
TC1->COUNT8.INTENSET.bit.OVF = 1;
|
||||||
TC_CTRLA_MODE_COUNT8 |
|
NVIC_ClearPendingIRQ(TC1_IRQn);
|
||||||
TC_CTRLA_RUNSTDBY);
|
NVIC_EnableIRQ (TC1_IRQn);
|
||||||
hri_tccount8_write_PER_reg(TC2, 3);
|
|
||||||
hri_tc_set_INTEN_OVF_bit(TC2);
|
|
||||||
NVIC_ClearPendingIRQ(TC2_IRQn);
|
|
||||||
NVIC_EnableIRQ (TC2_IRQn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TC2_Handler(void) {
|
void irq_handler_tc1(void);
|
||||||
// interrupt handler for TC2 (globally!)
|
void irq_handler_tc1(void) {
|
||||||
|
// interrupt handler for TC1 (globally!)
|
||||||
_ticks++;
|
_ticks++;
|
||||||
TC2->COUNT8.INTFLAG.reg |= TC_INTFLAG_OVF;
|
TC1->COUNT8.INTFLAG.reg |= TC_INTFLAG_OVF;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -273,7 +268,7 @@ bool stock_stopwatch_face_loop(movement_event_t event, void *context) {
|
|||||||
movement_cancel_background_task();
|
movement_cancel_background_task();
|
||||||
}
|
}
|
||||||
_draw();
|
_draw();
|
||||||
_button_beep(settings);
|
_button_beep();
|
||||||
break;
|
break;
|
||||||
case EVENT_LIGHT_BUTTON_DOWN:
|
case EVENT_LIGHT_BUTTON_DOWN:
|
||||||
if (state->light_on_button) movement_illuminate_led();
|
if (state->light_on_button) movement_illuminate_led();
|
||||||
@ -295,7 +290,7 @@ bool stock_stopwatch_face_loop(movement_event_t event, void *context) {
|
|||||||
} else if (_ticks) {
|
} else if (_ticks) {
|
||||||
// reset stopwatch
|
// reset stopwatch
|
||||||
_ticks = _lap_ticks = _blink_ticks = _old_minutes = _old_seconds = _hours = 0;
|
_ticks = _lap_ticks = _blink_ticks = _old_minutes = _old_seconds = _hours = 0;
|
||||||
_button_beep(settings);
|
_button_beep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_display_ticks(_ticks);
|
_display_ticks(_ticks);
|
||||||
Loading…
x
Reference in New Issue
Block a user