Official STMicroelectronics Arduino Core STM32F4 HAL compatibility (#11006)
This commit is contained in:
committed by
Scott Lahteine
parent
4dbec774b5
commit
e0276d2f32
@@ -63,27 +63,38 @@
|
||||
|
||||
// TODO change this
|
||||
|
||||
#ifdef STM32GENERIC
|
||||
extern void TC5_Handler();
|
||||
extern void TC7_Handler();
|
||||
#define HAL_STEP_TIMER_ISR void TC5_Handler()
|
||||
#define HAL_TEMP_TIMER_ISR void TC7_Handler()
|
||||
#else
|
||||
extern void TC5_Handler(stimer_t *htim);
|
||||
extern void TC7_Handler(stimer_t *htim);
|
||||
#define HAL_STEP_TIMER_ISR void TC5_Handler(stimer_t *htim)
|
||||
#define HAL_TEMP_TIMER_ISR void TC7_Handler(stimer_t *htim)
|
||||
#endif
|
||||
|
||||
extern void TC5_Handler();
|
||||
extern void TC7_Handler();
|
||||
#define HAL_STEP_TIMER_ISR void TC5_Handler()
|
||||
#define HAL_TEMP_TIMER_ISR void TC7_Handler()
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Types
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
typedef struct {
|
||||
TIM_HandleTypeDef timerdef;
|
||||
IRQn_Type IRQ_Id;
|
||||
uint32_t callback;
|
||||
} tTimerConfig;
|
||||
#ifdef STM32GENERIC
|
||||
typedef struct {
|
||||
TIM_HandleTypeDef handle;
|
||||
uint32_t callback;
|
||||
} tTimerConfig;
|
||||
typedef tTimerConfig stm32f4_timer_t;
|
||||
#else
|
||||
typedef stimer_t stm32f4_timer_t;
|
||||
#endif
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Public Variables
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
//extern const tTimerConfig timerConfig[];
|
||||
extern stm32f4_timer_t TimerHandle[];
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Public functions
|
||||
@@ -94,12 +105,35 @@ void HAL_timer_enable_interrupt(const uint8_t timer_num);
|
||||
void HAL_timer_disable_interrupt(const uint8_t timer_num);
|
||||
bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
|
||||
|
||||
void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare);
|
||||
hal_timer_t HAL_timer_get_compare(const uint8_t timer_num);
|
||||
uint32_t HAL_timer_get_count(const uint8_t timer_num);
|
||||
void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks);
|
||||
FORCE_INLINE static uint32_t HAL_timer_get_count(const uint8_t timer_num) {
|
||||
return __HAL_TIM_GET_COUNTER(&TimerHandle[timer_num].handle);
|
||||
}
|
||||
|
||||
FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare) {
|
||||
__HAL_TIM_SET_AUTORELOAD(&TimerHandle[timer_num].handle, compare);
|
||||
if (HAL_timer_get_count(timer_num) >= compare)
|
||||
TimerHandle[timer_num].handle.Instance->EGR |= TIM_EGR_UG; // Generate an immediate update interrupt
|
||||
}
|
||||
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
|
||||
return __HAL_TIM_GET_AUTORELOAD(&TimerHandle[timer_num].handle);
|
||||
}
|
||||
|
||||
FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) {
|
||||
const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks;
|
||||
if (HAL_timer_get_compare(timer_num) < mincmp)
|
||||
HAL_timer_set_compare(timer_num, mincmp);
|
||||
}
|
||||
|
||||
#ifdef STM32GENERIC
|
||||
FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {
|
||||
if (__HAL_TIM_GET_FLAG(&TimerHandle[timer_num].handle, TIM_FLAG_UPDATE) == SET)
|
||||
__HAL_TIM_CLEAR_FLAG(&TimerHandle[timer_num].handle, TIM_FLAG_UPDATE);
|
||||
}
|
||||
#else
|
||||
#define HAL_timer_isr_prologue(TIMER_NUM)
|
||||
#endif
|
||||
|
||||
void HAL_timer_isr_prologue(const uint8_t timer_num);
|
||||
#define HAL_timer_isr_epilogue(TIMER_NUM)
|
||||
|
||||
#endif // _HAL_TIMERS_STM32F4_H
|
||||
|
||||
Reference in New Issue
Block a user