summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/stm/.gitignore1
-rw-r--r--ports/stm/common-hal/microcontroller/Pin.c4
-rw-r--r--ports/stm/common-hal/microcontroller/Pin.h1
-rw-r--r--ports/stm/common-hal/pulseio/PWMOut.c2
-rw-r--r--ports/stm/common-hal/pulseio/PulseIn.c3
-rw-r--r--ports/stm/common-hal/pulseio/PulseOut.c2
-rw-r--r--ports/stm/common-hal/rgbmatrix/RGBMatrix.c11
-rw-r--r--ports/stm/peripherals/timers.c1
-rw-r--r--ports/stm/peripherals/timers.h8
9 files changed, 16 insertions, 17 deletions
diff --git a/ports/stm/.gitignore b/ports/stm/.gitignore
index e46c927ee..5d645392c 100644
--- a/ports/stm/.gitignore
+++ b/ports/stm/.gitignore
@@ -5,6 +5,5 @@ build-*/
# Reference files
#####################
ref/
-_working*
.gdb_history
diff --git a/ports/stm/common-hal/microcontroller/Pin.c b/ports/stm/common-hal/microcontroller/Pin.c
index d919b07ea..00763208d 100644
--- a/ports/stm/common-hal/microcontroller/Pin.c
+++ b/ports/stm/common-hal/microcontroller/Pin.c
@@ -116,6 +116,10 @@ bool pin_number_is_free(uint8_t pin_port, uint8_t pin_number) {
return !(claimed_pins[pin_port] & 1<<pin_number);
}
+bool pin_number_is_resettable(uint8_t pin_port, uint8_t pin_number) {
+ return !(never_reset_pins[pin_port] & 1<<pin_number);
+}
+
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {
#ifdef MICROPY_HW_NEOPIXEL
if (pin == MICROPY_HW_NEOPIXEL) {
diff --git a/ports/stm/common-hal/microcontroller/Pin.h b/ports/stm/common-hal/microcontroller/Pin.h
index d69ddfb1d..73e5457a5 100644
--- a/ports/stm/common-hal/microcontroller/Pin.h
+++ b/ports/stm/common-hal/microcontroller/Pin.h
@@ -45,6 +45,7 @@ void reset_all_pins(void);
void reset_pin_number(uint8_t pin_port, uint8_t pin_number);
void claim_pin(const mcu_pin_obj_t* pin);
bool pin_number_is_free(uint8_t pin_port, uint8_t pin_number);
+bool pin_number_is_resettable(uint8_t pin_port, uint8_t pin_number)
void never_reset_pin_number(uint8_t pin_port, uint8_t pin_number);
GPIO_TypeDef * pin_port(uint8_t pin_port);
uint16_t pin_mask(uint8_t pin_number);
diff --git a/ports/stm/common-hal/pulseio/PWMOut.c b/ports/stm/common-hal/pulseio/PWMOut.c
index a3c21330e..4df896feb 100644
--- a/ports/stm/common-hal/pulseio/PWMOut.c
+++ b/ports/stm/common-hal/pulseio/PWMOut.c
@@ -244,7 +244,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
//if reserved timer has no active channels, we can disable it
if (!reserved_tim[self->tim->tim_index - 1]) {
tim_frequencies[self->tim->tim_index - 1] = 0x00;
- tim_clock_disable(1 << (self->tim->tim_index - 1));
+ stm_peripherals_timer_free(self->handle.Instance);
}
}
diff --git a/ports/stm/common-hal/pulseio/PulseIn.c b/ports/stm/common-hal/pulseio/PulseIn.c
index db01968c4..811fc8c49 100644
--- a/ports/stm/common-hal/pulseio/PulseIn.c
+++ b/ports/stm/common-hal/pulseio/PulseIn.c
@@ -186,14 +186,13 @@ void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t* self) {
return;
}
//Remove pulsein slot from shared array
- HAL_NVIC_DisableIRQ(self->irq);
_objs[self->pin->number] = NULL;
reset_pin_number(self->pin->port, self->pin->number);
self->pin = NULL;
refcount--;
if (refcount == 0) {
- tim_clock_disable(1<< stm_peripherals_timer_get_index(tim_handle.Instance));
+ stm_peripherals_timer_free(tim_handle.Instance);
}
}
diff --git a/ports/stm/common-hal/pulseio/PulseOut.c b/ports/stm/common-hal/pulseio/PulseOut.c
index 865b41dcf..bf578bed2 100644
--- a/ports/stm/common-hal/pulseio/PulseOut.c
+++ b/ports/stm/common-hal/pulseio/PulseOut.c
@@ -152,7 +152,7 @@ void common_hal_pulseio_pulseout_deinit(pulseio_pulseout_obj_t* self) {
refcount--;
if (refcount == 0) {
- tim_clock_disable(1<< stm_peripherals_timer_get_index(tim_handle.Instance));
+ stm_peripherals_timer_free(tim_handle.Instance);
}
}
diff --git a/ports/stm/common-hal/rgbmatrix/RGBMatrix.c b/ports/stm/common-hal/rgbmatrix/RGBMatrix.c
index 312f15358..3b42631ad 100644
--- a/ports/stm/common-hal/rgbmatrix/RGBMatrix.c
+++ b/ports/stm/common-hal/rgbmatrix/RGBMatrix.c
@@ -34,20 +34,23 @@
extern void _PM_IRQ_HANDLER(void);
void *common_hal_rgbmatrix_timer_allocate() {
- return stm_peripherals_find_timer();
+ TIM_TypeDef * timer = stm_peripherals_find_timer();
+ stm_peripherals_timer_reserve(timer);
+ return timer;
}
void common_hal_rgbmatrix_timer_enable(void* ptr) {
- HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
+ TIM_TypeDef *tim = (TIM_TypeDef*)ptr;
+ HAL_NVIC_EnableIRQ(stm_peripherals_timer_get_irqnum(tim));
}
void common_hal_rgbmatrix_timer_disable(void* ptr) {
TIM_TypeDef *tim = (TIM_TypeDef*)ptr;
tim->DIER &= ~TIM_DIER_UIE;
- HAL_NVIC_DisableIRQ(TIM6_DAC_IRQn);
}
void common_hal_rgbmatrix_timer_free(void* ptr) {
+ TIM_TypeDef *tim = (TIM_TypeDef*)ptr;
+ stm_peripherals_timer_free(tim);
common_hal_rgbmatrix_timer_disable(ptr);
- // TODO(jepler) properly handle resource allocation including never-reset
}
diff --git a/ports/stm/peripherals/timers.c b/ports/stm/peripherals/timers.c
index 7950d8a57..baa81d2b5 100644
--- a/ports/stm/peripherals/timers.c
+++ b/ports/stm/peripherals/timers.c
@@ -233,6 +233,7 @@ void stm_peripherals_timer_set_callback(void(*callback)(void), TIM_TypeDef * tim
void stm_peripherals_timer_free(TIM_TypeDef * instance) {
size_t tim_idx = stm_peripherals_timer_get_index(instance);
+ HAL_NVIC_DisableIRQ(irq_map[tim_idx]);
stm_timer_callback[tim_idx] = NULL;
tim_clock_disable(1 << tim_idx);
stm_timer_reserved[tim_idx] = false;
diff --git a/ports/stm/peripherals/timers.h b/ports/stm/peripherals/timers.h
index 02e4e304e..c4b6c6367 100644
--- a/ports/stm/peripherals/timers.h
+++ b/ports/stm/peripherals/timers.h
@@ -24,14 +24,6 @@
* THE SOFTWARE.
*/
-// typedef struct {
-// TIM_TypeDef * timer;
-// bool reserved;
-// bool never_reset;
-// void (*stm_timer_callback)(void);
-// size_t irq;
-// } stm_timer_t;
-
#include <stdint.h>
#include "py/mphal.h"
#include "peripherals/periph.h"