summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexsander Akers <me@a2.io>2022-01-27 11:23:14 -0500
committerAlexsander Akers <me@a2.io>2022-01-27 12:06:06 -0500
commita559d089f1845fb23434739f66b7bb5288191139 (patch)
tree7c1f628826078f2c604c86d4917ab36153917be3
parentd3e484dc989a6e3a040b5b1092340973d9b4e22f (diff)
downloadSensor-Watch-a559d089f1845fb23434739f66b7bb5288191139.tar.gz
Sensor-Watch-a559d089f1845fb23434739f66b7bb5288191139.tar.bz2
Sensor-Watch-a559d089f1845fb23434739f66b7bb5288191139.zip
Add new function to disable certain RTC periodic callbacks
-rw-r--r--movement/movement.c8
-rw-r--r--watch-library/hardware/watch/watch_rtc.c6
-rw-r--r--watch-library/shared/watch/watch_rtc.h5
-rw-r--r--watch-library/simulator/watch/watch_rtc.c8
4 files changed, 17 insertions, 10 deletions
diff --git a/movement/movement.c b/movement/movement.c
index d15c349f..1c8e641c 100644
--- a/movement/movement.c
+++ b/movement/movement.c
@@ -155,13 +155,7 @@ void movement_request_tick_frequency(uint8_t freq) {
if (freq == 128) return; // Movement uses the 128 Hz tick internally
// disable all callbacks except the 128 Hz one
-#if __EMSCRIPTEN__
- for (int i = 1; i < 128; i = i << 1) {
- watch_rtc_disable_periodic_callback(i);
- }
-#else
- RTC->MODE2.INTENCLR.reg = 0xFE;
-#endif
+ watch_rtc_disable_matching_periodic_callbacks(0b01111111);
movement_state.subsecond = 0;
movement_state.tick_frequency = freq;
diff --git a/watch-library/hardware/watch/watch_rtc.c b/watch-library/hardware/watch/watch_rtc.c
index 14a968c4..28360523 100644
--- a/watch-library/hardware/watch/watch_rtc.c
+++ b/watch-library/hardware/watch/watch_rtc.c
@@ -102,8 +102,12 @@ void watch_rtc_disable_periodic_callback(uint8_t frequency) {
RTC->MODE2.INTENCLR.reg = 1 << per_n;
}
+void watch_rtc_disable_matching_periodic_callbacks(uint8_t mask) {
+ RTC->MODE2.INTENCLR.reg = mask;
+}
+
void watch_rtc_disable_all_periodic_callbacks(void) {
- RTC->MODE2.INTENCLR.reg = 0xFF;
+ watch_rtc_disable_matching_periodic_callbacks(0xFF);
}
void watch_rtc_register_alarm_callback(ext_irq_cb_t callback, watch_date_time alarm_time, watch_rtc_alarm_match mask) {
diff --git a/watch-library/shared/watch/watch_rtc.h b/watch-library/shared/watch/watch_rtc.h
index 6dac63f5..b51d6c48 100644
--- a/watch-library/shared/watch/watch_rtc.h
+++ b/watch-library/shared/watch/watch_rtc.h
@@ -137,6 +137,11 @@ void watch_rtc_register_periodic_callback(ext_irq_cb_t callback, uint8_t frequen
*/
void watch_rtc_disable_periodic_callback(uint8_t frequency);
+/** @brief Disables tick callbacks for the given periods (as a bitmask).
+ * @param mask The frequencies of tick callbacks you wish to disable, in Hz. To disable the 2 and 4 Hz callbacks, pass 0b00000110;
+ */
+void watch_rtc_disable_matching_periodic_callbacks(uint8_t mask);
+
/** @brief Disables all periodic callbacks, including the once-per-second tick callback.
*/
void watch_rtc_disable_all_periodic_callbacks(void);
diff --git a/watch-library/simulator/watch/watch_rtc.c b/watch-library/simulator/watch/watch_rtc.c
index 1fe6a78b..2cae701d 100644
--- a/watch-library/simulator/watch/watch_rtc.c
+++ b/watch-library/simulator/watch/watch_rtc.c
@@ -113,15 +113,19 @@ void watch_rtc_disable_periodic_callback(uint8_t frequency) {
}
}
-void watch_rtc_disable_all_periodic_callbacks(void) {
+void watch_rtc_disable_matching_periodic_callbacks(uint8_t mask) {
for (int i = 0; i < 8; i++) {
- if (tick_callbacks[i] != -1) {
+ if (tick_callbacks[i] != -1 && (mask & (1 << i)) != 0) {
emscripten_clear_interval(tick_callbacks[i]);
tick_callbacks[i] = -1;
}
}
}
+void watch_rtc_disable_all_periodic_callbacks(void) {
+ watch_rtc_disable_matching_periodic_callbacks(0xFF);
+}
+
static void watch_invoke_alarm_interval_callback(void *userData) {
if (alarm_callback) alarm_callback();
}