Skip to content

Commit 777d79a

Browse files
committed
Switch to finaliser for PWMOut and audiopwmio
Fixes #8726 which was caused by a mix of bulk reset and finaliser use. Work towards #8960.
1 parent 33b5cc6 commit 777d79a

File tree

55 files changed

+48
-675
lines changed

Some content is hidden

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

55 files changed

+48
-675
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: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,6 @@ void pulsein_interrupt_handler(uint8_t channel) {
140140
common_hal_mcu_enable_interrupts();
141141
}
142142

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-
152143
void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
153144
const mcu_pin_obj_t *pin, uint16_t maxlen, bool idle_state) {
154145
if (!pin->has_extint) {
@@ -243,7 +234,6 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
243234
#ifdef SAMD21
244235
rtc_start_pulse();
245236
#endif
246-
247237
}
248238

249239
bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t *self) {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ typedef struct {
4646
volatile bool errored_too_fast;
4747
} pulseio_pulsein_obj_t;
4848

49-
void pulsein_reset(void);
50-
5149
void pulsein_interrupt_handler(uint8_t channel);
5250
void pulsein_timer_interrupt_handler(uint8_t index);
5351
#ifdef SAMD21

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,6 @@ void pulseout_interrupt_handler(uint8_t index) {
9292
tc->COUNT16.INTFLAG.reg = TC_INTFLAG_MC0;
9393
}
9494

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-
10495
void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t *self,
10596
const mcu_pin_obj_t *pin,
10697
uint32_t frequency,

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.

ports/atmel-samd/shared_timers.h

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

ports/atmel-samd/supervisor/port.c

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,6 @@
7777

7878
#include "common-hal/microcontroller/Pin.h"
7979

80-
#if CIRCUITPY_PULSEIO
81-
#include "common-hal/pulseio/PulseIn.h"
82-
#include "common-hal/pulseio/PulseOut.h"
83-
#endif
84-
85-
#if CIRCUITPY_PWMIO
86-
#include "common-hal/pwmio/PWMOut.h"
87-
#endif
88-
8980
#if CIRCUITPY_PS2IO
9081
#include "common-hal/ps2io/Ps2.h"
9182
#endif
@@ -111,9 +102,7 @@
111102
#include "samd/dma.h"
112103
#include "shared-bindings/microcontroller/__init__.h"
113104
#include "shared-bindings/rtc/__init__.h"
114-
#include "shared_timers.h"
115105
#include "reset.h"
116-
#include "common-hal/pulseio/PulseIn.h"
117106

118107
#include "supervisor/background_callback.h"
119108
#include "supervisor/shared/safe_mode.h"
@@ -412,19 +401,6 @@ void reset_port(void) {
412401

413402
eic_reset();
414403

415-
#if CIRCUITPY_PULSEIO
416-
pulsein_reset();
417-
pulseout_reset();
418-
#endif
419-
420-
#if CIRCUITPY_PWMIO
421-
pwmout_reset();
422-
#endif
423-
424-
#if CIRCUITPY_PWMIO || CIRCUITPY_AUDIOIO || CIRCUITPY_FREQUENCYIO
425-
reset_timers();
426-
#endif
427-
428404
#if CIRCUITPY_ANALOGIO
429405
analogin_reset();
430406
analogout_reset();

0 commit comments

Comments
 (0)