From 13fbb7c1a07562ebfd25391afff2607eeade9596 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 16 Mar 2021 11:50:05 +0100 Subject: [PATCH] cpu/sam0_common: add rtc_tamper_pin_mask() --- cpu/sam0_common/include/periph_cpu_common.h | 12 ++++++++++++ cpu/sam0_common/periph/rtc_rtt.c | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/cpu/sam0_common/include/periph_cpu_common.h b/cpu/sam0_common/include/periph_cpu_common.h index 9953d8aad6..39bd90840d 100644 --- a/cpu/sam0_common/include/periph_cpu_common.h +++ b/cpu/sam0_common/include/periph_cpu_common.h @@ -1153,6 +1153,18 @@ void rtc_tamper_enable(void); * pin index inside the @ref rtc_tamper_pins array. */ uint8_t rtc_get_tamper_event(void); + +/** + * @brief Get the tamper event mask for a certain pin. + * Can be used together with @ref rtc_get_tamper_event to + * check which RTC pin caused the tamper event. + * + * @param pin Pin to query + * + * @return Bit mask with the bit corresponding to @p pin set + * 0 if @p pin is no RTC tamper pin + */ +uint8_t rtc_tamper_pin_mask(gpio_t pin); /** @} */ /** diff --git a/cpu/sam0_common/periph/rtc_rtt.c b/cpu/sam0_common/periph/rtc_rtt.c index 54c16ec734..407314c18c 100644 --- a/cpu/sam0_common/periph/rtc_rtt.c +++ b/cpu/sam0_common/periph/rtc_rtt.c @@ -394,6 +394,16 @@ uint8_t rtc_get_tamper_event(void) return ret & RTC_TAMPID_TAMPID_Msk; } + +uint8_t rtc_tamper_pin_mask(gpio_t pin) +{ + int idx = _rtc_pin(pin); + if (idx < 0) { + return 0; + } + + return 1 << idx; +} #endif /* RTC_NUM_OF_TAMPERS */ void rtt_set_overflow_cb(rtt_cb_t cb, void *arg)