summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobert-hh <robert@hammelrath.com>2024-01-22 18:04:44 +0100
committerDamien George <damien@micropython.org>2024-03-26 16:41:08 +1100
commit4dd288ff62a14d973166ef3b041ab0fe7c78863c (patch)
tree8437cc6473ec528b3e1846895c0f8f65e3fddd80
parent5e926b222259cb38db5c044b2f7656e2bdba2513 (diff)
nrf/modules/machine/pwm: Tag a PWM device as used in the constructor.
When PWM constructor was created without specifying a device or setting both freq and duty rate, it was not tagged as used, and further calls to get a PWM object may get the same PWM device assigned. Fixes #13494. Signed-off-by: robert-hh <robert@hammelrath.com>
-rw-r--r--ports/nrf/modules/machine/pwm.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/ports/nrf/modules/machine/pwm.c b/ports/nrf/modules/machine/pwm.c
index 393d10617..8145509c7 100644
--- a/ports/nrf/modules/machine/pwm.c
+++ b/ports/nrf/modules/machine/pwm.c
@@ -233,6 +233,11 @@ static mp_obj_t mp_machine_pwm_make_new(const mp_obj_type_t *type, size_t n_args
self->p_config->mode[pwm_channel] = MODE_HIGH_LOW;
self->p_config->defer_start = false;
+ // Allocate the device if it was not used before.
+ if (hard_configs[pwm_id].active == FREE) {
+ hard_configs[pwm_id].active = STOPPED;
+ }
+
// start the PWM running for this channel
mp_map_t kw_args;
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);