forked from Elron_dev/elbear_arduino_bsp
в библиотеке заменила некоторые строчки на макросы из wiringLL.h. переименовала обработчик прерываний
This commit is contained in:
1 parent
47c01383e6
commit
978661626c
3 files changed
+38
-38
No files matched your search
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "mik32_hal_timer16.h"
|
||||
#include "mik32_hal_irq.h"
|
||||
#include "wiring_LL.h"
|
||||
|
||||
#include "Servo.h"
|
||||
|
||||
@@ -19,16 +20,16 @@ uint8_t prescaler = TIMER16_PRESCALER_16;
|
||||
#define usToTicks(_us) ((clockCyclesPerMicrosecond() * _us) / ( (1 << prescaler) )) // converts microseconds to ticks (TIMERx_PRESCALER_16)
|
||||
#define ticksToUs(_ticks) (((unsigned) _ticks * ( (1 << prescaler) )) / clockCyclesPerMicrosecond()) // converts from ticks back to microseconds
|
||||
|
||||
#define TRIM_DURATION 5 // compensation ticks to trim adjust for digitalWrite delays
|
||||
#define SERVO_MIN() (MIN_PULSE_WIDTH - this->min * 4) // minimum value in us for this servo
|
||||
#define SERVO_MAX() (MAX_PULSE_WIDTH - this->max * 4) // maximum value in us for this servo
|
||||
|
||||
#define TRIM_DURATION 5 // compensation ticks to trim adjust for digitalWrite delays
|
||||
|
||||
// convenience macros
|
||||
#define SERVO_INDEX_TO_TIMER(_servo_nbr) ((timer16_Sequence_t)(_servo_nbr / SERVOS_PER_TIMER)) // returns the timer controlling this servo
|
||||
#define SERVO_INDEX_TO_CHANNEL(_servo_nbr) (_servo_nbr % SERVOS_PER_TIMER) // returns the index of the servo on this timer
|
||||
#define SERVO_INDEX(_timer,_channel) ((_timer*SERVOS_PER_TIMER) + _channel) // macro to access servo index by timer and channel
|
||||
#define SERVO(_timer,_channel) (servos[SERVO_INDEX(_timer,_channel)]) // macro to access servo class by timer and channel
|
||||
|
||||
#define SERVO_MIN() (MIN_PULSE_WIDTH - this->min * 4) // minimum value in us for this servo
|
||||
#define SERVO_MAX() (MAX_PULSE_WIDTH - this->max * 4) // maximum value in us for this servo
|
||||
#define SERVO_INDEX_TO_TIMER(_servo_nbr) ((timer16_Sequence_t)(_servo_nbr / SERVOS_PER_TIMER)) // returns the timer controlling this servo
|
||||
#define SERVO_INDEX_TO_CHANNEL(_servo_nbr) (_servo_nbr % SERVOS_PER_TIMER) // returns the index of the servo on this timer
|
||||
#define SERVO_INDEX(_timer,_channel) ((_timer*SERVOS_PER_TIMER) + _channel) // macro to access servo index by timer and channel
|
||||
#define SERVO(_timer,_channel) (servos[SERVO_INDEX(_timer,_channel)]) // macro to access servo class by timer and channel
|
||||
|
||||
// timer handler
|
||||
Timer16_HandleTypeDef htimer16;
|
||||
@@ -58,9 +59,9 @@ void Timer16_2_Init()
|
||||
/************ static functions common to all instances ***********************/
|
||||
|
||||
// irq handler
|
||||
extern "C" void servo_handler_wrapper(void)
|
||||
extern "C" void __attribute__((optimize("O3"))) servo_interrupt_handler(void)
|
||||
{
|
||||
if ((htimer16.Instance->ISR & htimer16.Instance->IER) & TIMER16_ISR_ARR_MATCH_M)
|
||||
if (TIM16_GET_ARRM_INT_STATUS(htimer16))
|
||||
{
|
||||
timer16_Sequence_t timer = _timer1;
|
||||
|
||||
@@ -89,7 +90,7 @@ extern "C" void servo_handler_wrapper(void)
|
||||
}
|
||||
|
||||
// reset timer interrupt flags
|
||||
htimer16.Instance->ICR = 0xFFFFFFFF;
|
||||
TIM16_CLEAR_INT_MASK(htimer16, 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
// init isr
|
||||
@@ -108,11 +109,9 @@ static void finISR(timer16_Sequence_t timer)
|
||||
{
|
||||
if (timer == _timer1)
|
||||
{
|
||||
HAL_Timer16_Disable(&htimer16);
|
||||
htimer16.Instance->IER &= ~(TIMER16_IER_ARROKIE_M | TIMER16_IER_CMPOKIE_M
|
||||
| TIMER16_IER_ARRMIE_M | TIMER16_IER_CMPMIE_M);
|
||||
htimer16.Instance->CR &= ~TIMER16_CR_ENABLE_M; // disable timer
|
||||
HAL_EPIC_MaskLevelClear(HAL_EPIC_TIMER16_1_MASK);
|
||||
TIM16_DISABLE(htimer16);
|
||||
TIM16_DISABLE_INT_BY_MASK(htimer16, TIMER16_IER_ARROKIE_M | TIMER16_IER_CMPOKIE_M | TIMER16_IER_ARRMIE_M | TIMER16_IER_CMPMIE_M);
|
||||
EPIC_LEVEL_CLEAR_BY_MASK(HAL_EPIC_TIMER16_1_MASK);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user