Skip to content

Commit 135f4f9

Browse files
authored
Merge pull request #8966 from tannewt/samd_pulsein_reset
Switch to finaliser for PWMOut and audiopwmio
2 parents 89437cf + 421eff9 commit 135f4f9

File tree

57 files changed

+83
-682
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+83
-682
lines changed

ports/atmel-samd/Makefile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,6 @@ $(BUILD)/lib/tlsf/tlsf.o: CFLAGS += -Wno-cast-align
309309

310310
$(BUILD)/lib/tinyusb/src/portable/microchip/samd/dcd_samd.o: CFLAGS += -Wno-missing-prototypes
311311

312-
# This is an OR because it filters to any 1s and then checks to see if it is not
313-
# empty.
314-
ifneq (,$(filter 1,$(CIRCUITPY_PWMIO) $(CIRCUITPY_AUDIOIO) $(CIRCUITPY_RGBMATRIX)))
315-
SRC_C += shared_timers.c
316-
endif
317-
318312
ifeq ($(CIRCUITPY_SAMD),1)
319313
SRC_C += bindings/samd/Clock.c bindings/samd/__init__.c
320314
endif

ports/atmel-samd/common-hal/pulseio/PulseIn.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "shared-bindings/microcontroller/__init__.h"
4444
#include "shared-bindings/microcontroller/Pin.h"
4545
#include "shared-bindings/pulseio/PulseIn.h"
46+
#include "supervisor/samd_prevent_sleep.h"
4647
#include "supervisor/shared/tick.h"
4748
#include "supervisor/port.h"
4849

@@ -140,15 +141,6 @@ void pulsein_interrupt_handler(uint8_t channel) {
140141
common_hal_mcu_enable_interrupts();
141142
}
142143

143-
void pulsein_reset() {
144-
#ifdef SAMD21
145-
rtc_end_pulse();
146-
#endif
147-
refcount = 0;
148-
pulsein_tc_index = 0xff;
149-
overflow_count = 0;
150-
}
151-
152144
void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
153145
const mcu_pin_obj_t *pin, uint16_t maxlen, bool idle_state) {
154146
if (!pin->has_extint) {
@@ -241,9 +233,8 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
241233
// Set config will enable the EIC.
242234
pulsein_set_config(self, true);
243235
#ifdef SAMD21
244-
rtc_start_pulse();
236+
samd_prevent_sleep();
245237
#endif
246-
247238
}
248239

249240
bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t *self) {
@@ -255,7 +246,7 @@ void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t *self) {
255246
return;
256247
}
257248
#ifdef SAMD21
258-
rtc_end_pulse();
249+
samd_allow_sleep();
259250
#endif
260251
set_eic_handler(self->channel, EIC_HANDLER_NO_INTERRUPT);
261252
turn_off_eic_channel(self->channel);
@@ -273,7 +264,7 @@ void common_hal_pulseio_pulsein_pause(pulseio_pulsein_obj_t *self) {
273264
uint32_t mask = 1 << self->channel;
274265
EIC->INTENCLR.reg = mask << EIC_INTENSET_EXTINT_Pos;
275266
#ifdef SAMD21
276-
rtc_end_pulse();
267+
samd_allow_sleep();
277268
#endif
278269
}
279270

@@ -303,7 +294,7 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t *self,
303294
EIC->INTENSET.reg = mask << EIC_INTENSET_EXTINT_Pos;
304295

305296
#ifdef SAMD21
306-
rtc_start_pulse();
297+
samd_prevent_sleep();
307298
#endif
308299
pulsein_set_config(self, true);
309300
}

ports/atmel-samd/common-hal/pulseio/PulseIn.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEIN_H
28-
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEIN_H
27+
#pragma once
2928

3029
#include "common-hal/microcontroller/Pin.h"
3130

@@ -46,14 +45,5 @@ typedef struct {
4645
volatile bool errored_too_fast;
4746
} pulseio_pulsein_obj_t;
4847

49-
void pulsein_reset(void);
50-
5148
void pulsein_interrupt_handler(uint8_t channel);
5249
void pulsein_timer_interrupt_handler(uint8_t index);
53-
#ifdef SAMD21
54-
void rtc_start_pulse(void);
55-
void rtc_end_pulse(void);
56-
#endif
57-
58-
59-
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEIN_H

ports/atmel-samd/common-hal/pulseio/PulseOut.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "py/gc.h"
3737
#include "py/runtime.h"
3838
#include "shared-bindings/pulseio/PulseOut.h"
39+
#include "supervisor/samd_prevent_sleep.h"
3940
#include "timer_handler.h"
4041

4142
// This timer is shared amongst all PulseOut objects under the assumption that
@@ -92,15 +93,6 @@ void pulseout_interrupt_handler(uint8_t index) {
9293
tc->COUNT16.INTFLAG.reg = TC_INTFLAG_MC0;
9394
}
9495

95-
void pulseout_reset() {
96-
refcount = 0;
97-
pulseout_tc_index = 0xff;
98-
active_pincfg = NULL;
99-
#ifdef SAMD21
100-
rtc_end_pulse();
101-
#endif
102-
}
103-
10496
void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t *self,
10597
const mcu_pin_obj_t *pin,
10698
uint32_t frequency,
@@ -168,9 +160,8 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t *self,
168160
// Turn off the pinmux which should connect the port output.
169161
turn_off(self->pincfg);
170162
#ifdef SAMD21
171-
rtc_start_pulse();
163+
samd_prevent_sleep();
172164
#endif
173-
174165
}
175166

176167
bool common_hal_pulseio_pulseout_deinited(pulseio_pulseout_obj_t *self) {
@@ -194,7 +185,7 @@ void common_hal_pulseio_pulseout_deinit(pulseio_pulseout_obj_t *self) {
194185
self->pin = NO_PIN;
195186
common_hal_pwmio_pwmout_deinit(&self->pwmout);
196187
#ifdef SAMD21
197-
rtc_end_pulse();
188+
samd_allow_sleep();
198189
#endif
199190
}
200191

ports/atmel-samd/common-hal/pulseio/PulseOut.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEOUT_H
28-
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEOUT_H
27+
#pragma once
2928

3029
#include "common-hal/microcontroller/Pin.h"
3130

@@ -41,9 +40,3 @@ typedef struct {
4140

4241
void pulseout_reset(void);
4342
void pulseout_interrupt_handler(uint8_t index);
44-
#ifdef SAMD21
45-
void rtc_start_pulse(void);
46-
void rtc_end_pulse(void);
47-
#endif
48-
49-
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PULSEOUT_H

ports/atmel-samd/common-hal/pwmio/PWMOut.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "common-hal/pwmio/PWMOut.h"
3232
#include "shared-bindings/pwmio/PWMOut.h"
3333
#include "shared-bindings/microcontroller/Processor.h"
34-
#include "shared_timers.h"
3534
#include "timer_handler.h"
3635

3736
#include "atmel_start_pins.h"
@@ -61,25 +60,9 @@ uint8_t tcc_channels[5]; // Set by pwmout_reset() to {0xc0, 0xf0, 0xf8, 0xfc,
6160

6261

6362
void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) {
64-
timer_never_reset(self->timer->index, self->timer->is_tc);
65-
6663
never_reset_pin_number(self->pin->number);
6764
}
6865

69-
void pwmout_reset(void) {
70-
// Reset all timers
71-
for (int i = 0; i < TCC_INST_NUM; i++) {
72-
target_tcc_frequencies[i] = 0;
73-
tcc_refcount[i] = 0;
74-
}
75-
for (int i = 0; i < TCC_INST_NUM; i++) {
76-
if (!timer_ok_to_reset(i, false)) {
77-
continue;
78-
}
79-
tcc_channels[i] = 0xff << tcc_cc_num[i];
80-
}
81-
}
82-
8366
static uint8_t tcc_channel(const pin_timer_t *t) {
8467
// For the SAMD51 this hardcodes the use of OTMX == 0x0, the output matrix mapping, which uses
8568
// SAMD21-style modulo mapping.
@@ -97,7 +80,6 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
9780
uint16_t duty,
9881
uint32_t frequency,
9982
bool variable_frequency) {
100-
self->pin = pin;
10183
self->variable_frequency = variable_frequency;
10284
self->duty_cycle = duty;
10385

@@ -242,6 +224,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
242224
}
243225

244226
self->timer = timer;
227+
self->pin = pin;
245228

246229
gpio_set_pin_function(pin->number, GPIO_PIN_FUNCTION_E + mux_position);
247230

@@ -257,7 +240,6 @@ void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t *self) {
257240
if (common_hal_pwmio_pwmout_deinited(self)) {
258241
return;
259242
}
260-
timer_reset_ok(self->timer->index, self->timer->is_tc);
261243
const pin_timer_t *t = self->timer;
262244
if (t->is_tc) {
263245
Tc *tc = tc_insts[t->index];

ports/atmel-samd/common-hal/pwmio/PWMOut.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PWMIO_PWMOUT_H
28-
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PWMIO_PWMOUT_H
27+
#pragma once
2928

3029
#include "common-hal/microcontroller/Pin.h"
3130

@@ -38,7 +37,3 @@ typedef struct {
3837
bool variable_frequency;
3938
uint16_t duty_cycle;
4039
} pwmio_pwmout_obj_t;
41-
42-
void pwmout_reset(void);
43-
44-
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PWMIO_PWMOUT_H

ports/atmel-samd/common-hal/rgbmatrix/RGBMatrix.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@
2929
#include "common-hal/rgbmatrix/RGBMatrix.h"
3030

3131
#include "samd/timers.h"
32-
#include "shared_timers.h"
3332
#include "timer_handler.h"
3433

3534
void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self) {
3635
uint8_t timer_index = find_free_timer();
3736
if (timer_index == 0xff) {
3837
return NULL;
3938
}
40-
timer_never_reset(timer_index, true);
4139
return tc_insts[timer_index];
4240
}
4341

@@ -75,5 +73,4 @@ void common_hal_rgbmatrix_timer_free(void *ptr) {
7573
}
7674
tc_set_enable(ptr, false);
7775
tc_reset(ptr);
78-
timer_reset_ok(timer_index, true);
7976
}

ports/atmel-samd/shared_timers.c

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)