Merge branch 'main' of github.com:joeycastillo/Sensor-Watch

This commit is contained in:
Joey Castillo 2022-02-01 00:24:20 -05:00
commit a3085cb136
4 changed files with 18 additions and 10 deletions

View file

@ -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(0xFE);
movement_state.subsecond = 0;
movement_state.tick_frequency = freq;

View file

@ -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) {

View file

@ -137,6 +137,12 @@ 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.
* The 128 Hz callback is 0b1, the 64 Hz callback is 0b10, the 32 Hz callback is 0b100, etc.
*/
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);

View file

@ -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 << (7 - 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();
}