From 94d90742dd02a7d4350a5f712baa81a3ee105fa9 Mon Sep 17 00:00:00 2001 From: DavePutz Date: Sat, 4 Jul 2020 21:15:38 -0500 Subject: [PATCH] Implementation of RTC continuous synchronization during pulsein Flags and code to implement RTC continuous synchronization during pulsein --- ports/atmel-samd/common-hal/pulseio/PulseIn.c | 10 ++++++++++ ports/atmel-samd/common-hal/pulseio/PulseIn.h | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/ports/atmel-samd/common-hal/pulseio/PulseIn.c b/ports/atmel-samd/common-hal/pulseio/PulseIn.c index 7ea20321b2..b825579dbe 100644 --- a/ports/atmel-samd/common-hal/pulseio/PulseIn.c +++ b/ports/atmel-samd/common-hal/pulseio/PulseIn.c @@ -125,6 +125,9 @@ void pulsein_interrupt_handler(uint8_t channel) { } void pulsein_reset() { +#ifdef SAMD21 + rtc_end_pulsein(); +#endif refcount = 0; pulsein_tc_index = 0xff; overflow_count = 0; @@ -221,6 +224,10 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, // Set config will enable the EIC. pulsein_set_config(self, true); +#ifdef SAMD21 + rtc_start_pulsein(); +#endif + } bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t* self) { @@ -231,6 +238,9 @@ void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t* self) { if (common_hal_pulseio_pulsein_deinited(self)) { return; } +#ifdef SAMD21 + rtc_end_pulsein(); +#endif set_eic_handler(self->channel, EIC_HANDLER_NO_INTERRUPT); turn_off_eic_channel(self->channel); reset_pin_number(self->pin); diff --git a/ports/atmel-samd/common-hal/pulseio/PulseIn.h b/ports/atmel-samd/common-hal/pulseio/PulseIn.h index 89b61a83ac..99358178f2 100644 --- a/ports/atmel-samd/common-hal/pulseio/PulseIn.h +++ b/ports/atmel-samd/common-hal/pulseio/PulseIn.h @@ -50,5 +50,11 @@ void pulsein_reset(void); void pulsein_interrupt_handler(uint8_t channel); void pulsein_timer_interrupt_handler(uint8_t index); +#ifdef SAMD21 +void rtc_set_continuous(void); +void rtc_start_pulsein(void); +void rtc_end_pulsein(void); +#endif + #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEIN_H