diff options
-rw-r--r-- | watch-library/watch/watch_deepsleep.c | 4 | ||||
-rw-r--r-- | watch-library/watch/watch_rtc.c | 22 | ||||
-rw-r--r-- | watch-library/watch/watch_rtc.h | 27 |
3 files changed, 28 insertions, 25 deletions
diff --git a/watch-library/watch/watch_deepsleep.c b/watch-library/watch/watch_deepsleep.c index 1f3ae7fb..b7da82ee 100644 --- a/watch-library/watch/watch_deepsleep.c +++ b/watch-library/watch/watch_deepsleep.c @@ -164,7 +164,7 @@ void watch_enter_shallow_sleep(char *message) { _watch_disable_all_peripherals_except_slcd(); // disable tick interrupt - watch_rtc_disable_all_tick_callbacks(); + watch_rtc_disable_all_periodic_callbacks(); // disable brownout detector interrupt, which could inadvertently wake us up. SUPC->INTENCLR.bit.BOD33DET = 1; @@ -190,7 +190,7 @@ void watch_enter_deep_sleep() { // so let's do it! watch_register_extwake_callback(BTN_ALARM, NULL, true); - watch_rtc_disable_all_tick_callbacks(); + watch_rtc_disable_all_periodic_callbacks(); _watch_disable_all_peripherals_except_slcd(); slcd_sync_deinit(&SEGMENT_LCD_0); hri_mclk_clear_APBCMASK_SLCD_bit(SLCD); diff --git a/watch-library/watch/watch_rtc.c b/watch-library/watch/watch_rtc.c index 519a1f00..a50da7c4 100644 --- a/watch-library/watch/watch_rtc.c +++ b/watch-library/watch/watch_rtc.c @@ -70,20 +70,20 @@ watch_date_time watch_rtc_get_date_time() { return retval; } -void watch_rtc_register_1Hz_callback(ext_irq_cb_t callback) { - watch_rtc_register_tick_callback(callback, 1); +void watch_rtc_register_tick_callback(ext_irq_cb_t callback) { + watch_rtc_register_periodic_callback(callback, 1); } -void watch_rtc_disable_1Hz_callback() { - watch_rtc_disable_tick_callback(1); +void watch_rtc_disable_tick_callback() { + watch_rtc_disable_periodic_callback(1); } -void watch_rtc_register_tick_callback(ext_irq_cb_t callback, uint8_t period) { +void watch_rtc_register_periodic_callback(ext_irq_cb_t callback, uint8_t frequency) { // we told them, it has to be a power of 2. - if (__builtin_popcount(period) != 1) return; + if (__builtin_popcount(frequency) != 1) return; // this left-justifies the period in a 32-bit integer. - uint32_t tmp = period << 24; + uint32_t tmp = frequency << 24; // now we can count the leading zeroes to get the value we need. // 0x01 (1 Hz) will have 7 leading zeros for PER7. 0xF0 (128 Hz) will have no leading zeroes for PER0. uint8_t per_n = __builtin_clz(tmp); @@ -96,13 +96,13 @@ void watch_rtc_register_tick_callback(ext_irq_cb_t callback, uint8_t period) { RTC->MODE2.INTENSET.reg = 1 << per_n; } -void watch_rtc_disable_tick_callback(uint8_t period) { - if (__builtin_popcount(period) != 1) return; - uint8_t per_n = __builtin_clz(period << 24); +void watch_rtc_disable_periodic_callback(uint8_t frequency) { + if (__builtin_popcount(frequency) != 1) return; + uint8_t per_n = __builtin_clz(frequency << 24); RTC->MODE2.INTENCLR.reg = 1 << per_n; } -void watch_rtc_disable_all_tick_callbacks() { +void watch_rtc_disable_all_periodic_callbacks() { RTC->MODE2.INTENCLR.reg = 0xFF; } diff --git a/watch-library/watch/watch_rtc.h b/watch-library/watch/watch_rtc.h index f6b6329e..1776a712 100644 --- a/watch-library/watch/watch_rtc.h +++ b/watch-library/watch/watch_rtc.h @@ -105,18 +105,21 @@ void watch_rtc_disable_alarm_callback(); /** @brief Registers a "tick" callback that will be called once per second. * @param callback The function you wish to have called when the clock ticks. If you pass in NULL, the tick * interrupt will still be enabled, but no callback function will be called. + * @note this is equivalent to calling watch_rtc_register_periodic_callback with a frequency of 1. It can be + * disabled with either watch_rtc_disable_tick_callback() or watch_rtc_disable_periodic_callback(1), + * and will also be disabled when watch_rtc_disable_all_periodic_callbacks is called. */ -void watch_rtc_register_1Hz_callback(ext_irq_cb_t callback); +void watch_rtc_register_tick_callback(ext_irq_cb_t callback); /** @brief Disables the tick callback for the given period. */ -void watch_rtc_disable_1Hz_callback(); +void watch_rtc_disable_tick_callback(); -/** @brief Registers a "tick" callback that will be called at a configurable period. - * @param callback The function you wish to have called when the clock ticks. If you pass in NULL, the tick +/** @brief Registers a callback that will be called at a configurable period. + * @param callback The function you wish to have called at the specified period. If you pass in NULL, the periodic * interrupt will still be enabled, but no callback function will be called. - * @param period The frequency of the tick in Hz. **Must be a power of 2**, from 1 to 128 inclusive. - * @note A 1 Hz tick (@see watch_rtc_register_1Hz_callback) is suitable for most applications, in that it gives you a + * @param frequency The frequency of the tick in Hz. **Must be a power of 2**, from 1 to 128 inclusive. + * @note A 1 Hz tick (@see watch_rtc_register_tick_callback) is suitable for most applications, in that it gives you a * chance to update the display once a second — an ideal update rate for a watch! If however you are displaying * a value (such as an accelerometer output) that updates more frequently than once per second, you may want to * tick at 16 or 32 Hz to update the screen more quickly. Just remember that the more frequent the tick, the more @@ -127,16 +130,16 @@ void watch_rtc_disable_1Hz_callback(); * the system will not have any way of telling you where you are within a given second; watch_rtc_get_date_time * will return the exact same timestamp until the second ticks over. */ -void watch_rtc_register_tick_callback(ext_irq_cb_t callback, uint8_t period); +void watch_rtc_register_periodic_callback(ext_irq_cb_t callback, uint8_t frequency); /** @brief Disables the tick callback for the given period. - * @param period The frequency of the tick you wish to disable, in Hz. **Must be a power of 2**, from 1 to 128. + * @param frequency The frequency of the tick you wish to disable, in Hz. **Must be a power of 2**, from 1 to 128. */ -void watch_rtc_disable_tick_callback(uint8_t period); +void watch_rtc_disable_periodic_callback(uint8_t frequency); -/** @brief Disables all tick callbacks. +/** @brief Disables all periodic callbacks, including the once-per-second tick callback. */ -void watch_rtc_disable_all_tick_callbacks(); +void watch_rtc_disable_all_periodic_callbacks(); /** @brief Sets the system date and time. * @param date_time A struct representing the date and time you wish to set. @@ -154,7 +157,7 @@ void watch_get_date_time(struct calendar_date_time *date_time); * @param callback The function you wish to have called when the clock ticks. If you pass in NULL, the tick * interrupt will still be enabled, but no callback function will be called. */ -__attribute__((deprecated("Use the watch_rtc_register_1Hz_callback function instead"))) +__attribute__((deprecated("Use the watch_rtc_register_tick_callback function instead"))) void watch_register_tick_callback(ext_irq_cb_t callback); /// @} |