From eb860101766741fd75326577bb779d91cb3afd01 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Thu, 9 Jul 2020 16:45:39 -0400 Subject: Enable RGB Matrix --- ports/stm/common-hal/rgbmatrix/RGBMatrix.c | 5 ++--- ports/stm/mpconfigport.mk | 4 ++-- ports/stm/peripherals/timers.c | 6 ++++++ ports/stm/peripherals/timers.h | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ports/stm/common-hal/rgbmatrix/RGBMatrix.c b/ports/stm/common-hal/rgbmatrix/RGBMatrix.c index 9e60cc3e6..312f15358 100644 --- a/ports/stm/common-hal/rgbmatrix/RGBMatrix.c +++ b/ports/stm/common-hal/rgbmatrix/RGBMatrix.c @@ -27,17 +27,16 @@ #include #include "common-hal/rgbmatrix/RGBMatrix.h" +#include "timers.h" #include STM32_HAL_H extern void _PM_IRQ_HANDLER(void); void *common_hal_rgbmatrix_timer_allocate() { - // TODO(jepler) properly handle resource allocation including never-reset - return TIM6; + return stm_peripherals_find_timer(); } - void common_hal_rgbmatrix_timer_enable(void* ptr) { HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn); } diff --git a/ports/stm/mpconfigport.mk b/ports/stm/mpconfigport.mk index 74ecf656e..896d78bba 100644 --- a/ports/stm/mpconfigport.mk +++ b/ports/stm/mpconfigport.mk @@ -4,8 +4,8 @@ INTERNAL_LIBM ?= 1 USB_SERIAL_NUMBER_LENGTH ?= 24 ifeq ($(MCU_VARIANT),STM32F405xx) - CIRCUITPY_FRAMEBUFFERIO ?= 0 - CIRCUITPY_RGBMATRIX ?= 0 + CIRCUITPY_FRAMEBUFFERIO ?= 1 + CIRCUITPY_RGBMATRIX ?= 1 endif ifeq ($(MCU_SERIES),F4) diff --git a/ports/stm/peripherals/timers.c b/ports/stm/peripherals/timers.c index 589c28310..924d3a16f 100644 --- a/ports/stm/peripherals/timers.c +++ b/ports/stm/peripherals/timers.c @@ -85,6 +85,11 @@ uint32_t stm_peripherals_timer_get_source_freq(TIM_TypeDef * timer) { return source; } +size_t stm_peripherals_timer_get_irqnum(TIM_TypeDef * instance) { + size_t tim_id = stm_peripherals_timer_get_index(instance); + return irq_map[tim_id]; +} + void timers_reset(void) { uint16_t never_reset_mask = 0x00; for (size_t i = 0; i < MP_ARRAY_SIZE(mcu_tim_banks); i++) { @@ -120,6 +125,7 @@ TIM_TypeDef * stm_peripherals_find_timer(void) { return mcu_tim_banks[i]; } } + //TODO: secondary search for timers outside the pins in the board profile // Work backwards - higher index timers have fewer pin allocations for (size_t i = (MP_ARRAY_SIZE(mcu_tim_banks) - 1); i >= 0; i--) { diff --git a/ports/stm/peripherals/timers.h b/ports/stm/peripherals/timers.h index 8c8a80d53..02e4e304e 100644 --- a/ports/stm/peripherals/timers.h +++ b/ports/stm/peripherals/timers.h @@ -41,6 +41,7 @@ void tim_clock_enable(uint16_t mask); void tim_clock_disable(uint16_t mask); uint32_t stm_peripherals_timer_get_source_freq(TIM_TypeDef * timer); +size_t stm_peripherals_timer_get_irqnum(TIM_TypeDef * instance); void timers_reset(void); TIM_TypeDef * stm_peripherals_find_timer(void); void stm_peripherals_timer_preinit(TIM_TypeDef * instance, uint8_t prio, void (*callback)(void)); -- cgit v1.2.3