summaryrefslogtreecommitdiff
path: root/ports/stm/peripherals/timers.c
diff options
context:
space:
mode:
Diffstat (limited to 'ports/stm/peripherals/timers.c')
-rw-r--r--ports/stm/peripherals/timers.c92
1 files changed, 46 insertions, 46 deletions
diff --git a/ports/stm/peripherals/timers.c b/ports/stm/peripherals/timers.c
index 7bc5ea495..6121deab1 100644
--- a/ports/stm/peripherals/timers.c
+++ b/ports/stm/peripherals/timers.c
@@ -41,8 +41,8 @@
static bool stm_timer_reserved[MP_ARRAY_SIZE(mcu_tim_banks)];
static bool stm_timer_never_reset[MP_ARRAY_SIZE(mcu_tim_banks)];
-static void (*stm_timer_callback[MP_ARRAY_SIZE(mcu_tim_banks)])(void);
-static size_t irq_map[] = {
+static void (*stm_timer_callback[MP_ARRAY_SIZE (mcu_tim_banks)])(void);
+ static size_t irq_map[] = {
#ifdef TIM1
TIM1_CC_IRQn,
#else
@@ -69,11 +69,11 @@ static size_t irq_map[] = {
NULL_IRQ,
#endif
#ifdef TIM6
- #if !defined(DAC_BASE) && !defined(DAC1_BASE)
- TIM6_IRQn,
- #else
- TIM6_DAC_IRQn,
- #endif
+ #if !defined(DAC_BASE) && !defined(DAC1_BASE)
+ TIM6_IRQn,
+ #else
+ TIM6_DAC_IRQn,
+ #endif
#else
NULL_IRQ,
#endif
@@ -139,7 +139,7 @@ static size_t irq_map[] = {
// If the APB prescaler is 1, then the timer clock is equal to its respective
// APB clock. Otherwise (APB prescaler > 1) the timer clock is twice its
// respective APB clock. See DM00031020 Rev 4, page 115.
-uint32_t stm_peripherals_timer_get_source_freq(TIM_TypeDef * timer) {
+ uint32_t stm_peripherals_timer_get_source_freq(TIM_TypeDef *timer) {
size_t tim_id = stm_peripherals_timer_get_index(timer);
uint32_t source, clk_div;
if (tim_id == 1 || (8 <= tim_id && tim_id <= 11)) {
@@ -158,12 +158,12 @@ 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 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) {
+ void timers_reset(void) {
uint16_t never_reset_mask = 0x00;
for (size_t i = 0; i < MP_ARRAY_SIZE(mcu_tim_banks); i++) {
if (!stm_timer_never_reset[i]) {
@@ -175,18 +175,18 @@ void timers_reset(void) {
tim_clock_disable(ALL_CLOCKS & ~(never_reset_mask));
}
-TIM_TypeDef * stm_peripherals_find_timer(void) {
+ TIM_TypeDef *stm_peripherals_find_timer(void) {
// Check for timers on pins outside the package size
for (size_t i = 0; i < MP_ARRAY_SIZE(mcu_tim_banks); i++) {
bool timer_in_package = false;
// Find each timer instance on the given bank
for (size_t j = 0; j < MP_ARRAY_SIZE(mcu_tim_pin_list); j++) {
// If a pin is claimed, we skip it
- if ( (mcu_tim_pin_list[j].tim_index == i + 1)
- && (common_hal_mcu_pin_is_free(mcu_tim_pin_list[j].pin) == true) ) {
+ if ((mcu_tim_pin_list[j].tim_index == i + 1)
+ && (common_hal_mcu_pin_is_free(mcu_tim_pin_list[j].pin) == true)) {
// Search whether any pins in the package array match it
for (size_t k = 0; k < mcu_pin_globals.map.alloc; k++) {
- if ( (mcu_tim_pin_list[j].pin == (mcu_pin_obj_t*)(mcu_pin_globals.map.table[k].value)) ) {
+ if ((mcu_tim_pin_list[j].pin == (mcu_pin_obj_t *)(mcu_pin_globals.map.table[k].value))) {
timer_in_package = true;
}
}
@@ -198,7 +198,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
+ // 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--) {
@@ -210,7 +210,7 @@ TIM_TypeDef * stm_peripherals_find_timer(void) {
return NULL;
}
-void stm_peripherals_timer_preinit(TIM_TypeDef * instance, uint8_t prio, void (*callback)(void)) {
+ void stm_peripherals_timer_preinit(TIM_TypeDef *instance, uint8_t prio, void (*callback)(void)) {
size_t tim_idx = stm_peripherals_timer_get_index(instance);
stm_timer_callback[tim_idx] = callback;
tim_clock_enable(1 << tim_idx);
@@ -218,16 +218,16 @@ void stm_peripherals_timer_preinit(TIM_TypeDef * instance, uint8_t prio, void (*
HAL_NVIC_EnableIRQ(irq_map[tim_idx]);
}
-void stm_peripherals_timer_reserve(TIM_TypeDef * instance) {
+ void stm_peripherals_timer_reserve(TIM_TypeDef *instance) {
size_t tim_idx = stm_peripherals_timer_get_index(instance);
stm_timer_reserved[tim_idx] = true;
}
-void stm_peripherals_timer_set_callback(void(*callback)(void), TIM_TypeDef * timer) {
+ void stm_peripherals_timer_set_callback(void (*callback)(void), TIM_TypeDef *timer) {
stm_timer_callback[stm_peripherals_timer_get_index(timer)] = callback;
}
-void stm_peripherals_timer_free(TIM_TypeDef * instance) {
+ 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;
@@ -236,24 +236,24 @@ void stm_peripherals_timer_free(TIM_TypeDef * instance) {
stm_timer_never_reset[tim_idx] = false;
}
-void stm_peripherals_timer_never_reset(TIM_TypeDef * instance) {
+ void stm_peripherals_timer_never_reset(TIM_TypeDef *instance) {
size_t tim_idx = stm_peripherals_timer_get_index(instance);
stm_timer_never_reset[tim_idx] = true;
}
-void stm_peripherals_timer_reset_ok(TIM_TypeDef * instance) {
+ void stm_peripherals_timer_reset_ok(TIM_TypeDef *instance) {
size_t tim_idx = stm_peripherals_timer_get_index(instance);
stm_timer_never_reset[tim_idx] = false;
}
-bool stm_peripherals_timer_is_never_reset(TIM_TypeDef * instance){
+ bool stm_peripherals_timer_is_never_reset(TIM_TypeDef *instance) {
size_t tim_idx = stm_peripherals_timer_get_index(instance);
return stm_timer_never_reset[tim_idx];
}
-bool stm_peripherals_timer_is_reserved(TIM_TypeDef * instance) {
+ bool stm_peripherals_timer_is_reserved(TIM_TypeDef *instance) {
size_t tim_idx = stm_peripherals_timer_get_index(instance);
return stm_timer_reserved[tim_idx];
}
-size_t stm_peripherals_timer_get_index(TIM_TypeDef * instance) {
+ size_t stm_peripherals_timer_get_index(TIM_TypeDef *instance) {
for (size_t i = 0; i < MP_ARRAY_SIZE(mcu_tim_banks); i++) {
if (instance == mcu_tim_banks[i]) {
return i;
@@ -262,7 +262,7 @@ size_t stm_peripherals_timer_get_index(TIM_TypeDef * instance) {
return ~(size_t)0;
}
-void tim_clock_enable(uint16_t mask) {
+ void tim_clock_enable(uint16_t mask) {
#ifdef TIM1
if (mask & (1 << 0)) {
__HAL_RCC_TIM1_CLK_ENABLE();
@@ -288,7 +288,7 @@ void tim_clock_enable(uint16_t mask) {
__HAL_RCC_TIM5_CLK_ENABLE();
}
#endif
- //6 and 7 are reserved ADC timers
+ // 6 and 7 are reserved ADC timers
#ifdef TIM8
if (mask & (1 << 7)) {
__HAL_RCC_TIM8_CLK_ENABLE();
@@ -326,7 +326,7 @@ void tim_clock_enable(uint16_t mask) {
#endif
}
-void tim_clock_disable(uint16_t mask) {
+ void tim_clock_disable(uint16_t mask) {
#ifdef TIM1
if (mask & (1 << 0)) {
__HAL_RCC_TIM1_CLK_DISABLE();
@@ -352,7 +352,7 @@ void tim_clock_disable(uint16_t mask) {
__HAL_RCC_TIM5_CLK_DISABLE();
}
#endif
- //6 and 7 are reserved ADC timers
+ // 6 and 7 are reserved ADC timers
#ifdef TIM8
if (mask & (1 << 7)) {
__HAL_RCC_TIM8_CLK_DISABLE();
@@ -390,65 +390,65 @@ void tim_clock_disable(uint16_t mask) {
#endif
}
-STATIC void callback_router(size_t index) {
+ STATIC void callback_router(size_t index) {
if (stm_timer_callback[index - 1]) {
(*stm_timer_callback[index - 1])();
}
}
-void TIM1_CC_IRQHandler(void) { // Advanced timer
+ void TIM1_CC_IRQHandler(void) { // Advanced timer
callback_router(1);
}
-void TIM2_IRQHandler(void) {
+ void TIM2_IRQHandler(void) {
callback_router(2);
}
-void TIM3_IRQHandler(void) {
+ void TIM3_IRQHandler(void) {
callback_router(3);
}
-void TIM4_IRQHandler(void) {
+ void TIM4_IRQHandler(void) {
callback_router(4);
}
-void TIM5_IRQHandler(void) {
+ void TIM5_IRQHandler(void) {
callback_router(5);
}
-void TIM6_DAC_IRQHandler(void) { // Basic timer (DAC)
+ void TIM6_DAC_IRQHandler(void) { // Basic timer (DAC)
callback_router(6);
}
-void TIM7_IRQHandler(void) { // Basic timer
+ void TIM7_IRQHandler(void) { // Basic timer
callback_router(7);
}
-void TIM8_CC_IRQHandler(void) { // Advanced timer
+ void TIM8_CC_IRQHandler(void) { // Advanced timer
callback_router(8);
}
// Advanced timer interrupts are currently unused.
-void TIM1_BRK_TIM9_IRQHandler(void) {
+ void TIM1_BRK_TIM9_IRQHandler(void) {
callback_router(9);
}
-void TIM1_UP_TIM10_IRQHandler(void) {
+ void TIM1_UP_TIM10_IRQHandler(void) {
callback_router(10);
}
-void TIM1_TRG_COM_TIM11_IRQHandler(void) {
+ void TIM1_TRG_COM_TIM11_IRQHandler(void) {
callback_router(11);
}
-void TIM8_BRK_TIM12_IRQHandler(void) {
+ void TIM8_BRK_TIM12_IRQHandler(void) {
callback_router(12);
}
-void TIM8_UP_TIM13_IRQHandler(void) {
+ void TIM8_UP_TIM13_IRQHandler(void) {
callback_router(13);
}
-void TIM8_TRG_COM_TIM14_IRQHandler(void) {
+ void TIM8_TRG_COM_TIM14_IRQHandler(void) {
callback_router(14);
}
#if (CPY_STM32H7)
-void TIM15_IRQHandler(void) {
+ void TIM15_IRQHandler(void) {
callback_router(15);
}
-void TIM16_IRQHandler(void) {
+ void TIM16_IRQHandler(void) {
callback_router(16);
}
-void TIM17_IRQHandler(void) {
+ void TIM17_IRQHandler(void) {
callback_router(17);
}
#endif