File tree Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,9 @@ void pulsein_interrupt_handler(uint8_t channel) {
125
125
}
126
126
127
127
void pulsein_reset () {
128
+ #ifdef SAMD21
129
+ rtc_end_pulsein ();
130
+ #endif
128
131
refcount = 0 ;
129
132
pulsein_tc_index = 0xff ;
130
133
overflow_count = 0 ;
@@ -221,6 +224,10 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self,
221
224
222
225
// Set config will enable the EIC.
223
226
pulsein_set_config (self , true);
227
+ #ifdef SAMD21
228
+ rtc_start_pulsein ();
229
+ #endif
230
+
224
231
}
225
232
226
233
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) {
231
238
if (common_hal_pulseio_pulsein_deinited (self )) {
232
239
return ;
233
240
}
241
+ #ifdef SAMD21
242
+ rtc_end_pulsein ();
243
+ #endif
234
244
set_eic_handler (self -> channel , EIC_HANDLER_NO_INTERRUPT );
235
245
turn_off_eic_channel (self -> channel );
236
246
reset_pin_number (self -> pin );
Original file line number Diff line number Diff line change @@ -50,5 +50,11 @@ void pulsein_reset(void);
50
50
51
51
void pulsein_interrupt_handler (uint8_t channel );
52
52
void pulsein_timer_interrupt_handler (uint8_t index );
53
+ #ifdef SAMD21
54
+ void rtc_set_continuous (void );
55
+ void rtc_start_pulsein (void );
56
+ void rtc_end_pulsein (void );
57
+ #endif
58
+
53
59
54
60
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEIN_H
Original file line number Diff line number Diff line change 91
91
#if CIRCUITPY_PEW
92
92
#include "common-hal/_pew/PewPew.h"
93
93
#endif
94
+ volatile bool hold_interrupt = false;
95
+ #ifdef SAMD21
96
+ void rtc_start_pulsein (void ) {
97
+ rtc_set_continuous ();
98
+ hold_interrupt = true;
99
+ }
100
+
101
+ void rtc_end_pulsein (void ) {
102
+ hold_interrupt = false;
103
+ }
104
+
105
+ void rtc_set_continuous (void ) {
106
+ while (RTC -> MODE0 .STATUS .bit .SYNCBUSY );
107
+ RTC -> MODE0 .READREQ .reg = RTC_READREQ_RREQ | RTC_READREQ_RCONT | 0x0010 ;
108
+ while (RTC -> MODE0 .STATUS .bit .SYNCBUSY );
109
+ }
110
+ #endif
94
111
95
112
extern volatile bool mp_msc_enabled ;
96
113
@@ -489,6 +506,11 @@ void port_interrupt_after_ticks(uint32_t ticks) {
489
506
// We'll interrupt sooner with an overflow.
490
507
return ;
491
508
}
509
+ #ifdef SAMD21
510
+ if (hold_interrupt ) {
511
+ return ;
512
+ }
513
+ #endif
492
514
RTC -> MODE0 .COMP [0 ].reg = current_ticks + (ticks << 4 );
493
515
RTC -> MODE0 .INTFLAG .reg = RTC_MODE0_INTFLAG_CMP0 ;
494
516
RTC -> MODE0 .INTENSET .reg = RTC_MODE0_INTENSET_CMP0 ;
@@ -503,7 +525,7 @@ void port_sleep_until_interrupt(void) {
503
525
}
504
526
#endif
505
527
common_hal_mcu_disable_interrupts ();
506
- if (!tud_task_event_ready ()) {
528
+ if (!tud_task_event_ready () && ! hold_interrupt ) {
507
529
__DSB ();
508
530
__WFI ();
509
531
}
You can’t perform that action at this time.
0 commit comments