_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;
// 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);
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);
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;
}
/** @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
* 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.
* @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);
/// @}