Improved stm32_pulse_config_output()
This commit is contained in:
@@ -73,20 +73,8 @@ static void config_ppm_output(uint16_t ppm_delay, bool polarity)
|
|||||||
// AAR register defines duration of each pulse, it is
|
// AAR register defines duration of each pulse, it is
|
||||||
// updated after every pulse in Update interrupt handler.
|
// updated after every pulse in Update interrupt handler.
|
||||||
|
|
||||||
LL_TIM_OC_InitTypeDef ocInit;
|
stm32_pulse_config_output(&extmoduleTimer, !polarity, LL_TIM_OCMODE_PWM1,
|
||||||
LL_TIM_OC_StructInit(&ocInit);
|
ppm_delay * 2);
|
||||||
|
|
||||||
ocInit.OCMode = LL_TIM_OCMODE_PWM1;
|
|
||||||
ocInit.OCState = LL_TIM_OCSTATE_ENABLE;
|
|
||||||
|
|
||||||
if (polarity) {
|
|
||||||
ocInit.OCPolarity = LL_TIM_OCPOLARITY_LOW;
|
|
||||||
} else {
|
|
||||||
ocInit.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
|
|
||||||
}
|
|
||||||
|
|
||||||
ocInit.CompareValue = ppm_delay * 2;
|
|
||||||
stm32_pulse_config_output(&extmoduleTimer, &ocInit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void extmodulePpmStart(uint16_t ppm_delay, bool polarity)
|
void extmodulePpmStart(uint16_t ppm_delay, bool polarity)
|
||||||
@@ -114,28 +102,17 @@ void extmoduleSendNextFramePpm(void* pulses, uint16_t length,
|
|||||||
void extmodulePxx1PulsesStart()
|
void extmodulePxx1PulsesStart()
|
||||||
{
|
{
|
||||||
EXTERNAL_MODULE_ON();
|
EXTERNAL_MODULE_ON();
|
||||||
|
stm32_pulse_config_output(&extmoduleTimer, false, LL_TIM_OCMODE_PWM1, 9 * 2);
|
||||||
LL_TIM_OC_InitTypeDef ocInit;
|
|
||||||
LL_TIM_OC_StructInit(&ocInit);
|
|
||||||
|
|
||||||
ocInit.OCMode = LL_TIM_OCMODE_PWM1;
|
|
||||||
ocInit.OCState = LL_TIM_OCSTATE_ENABLE;
|
|
||||||
ocInit.OCPolarity = LL_TIM_OCPOLARITY_LOW;
|
|
||||||
ocInit.CompareValue = 9 * 2; // 9 uS
|
|
||||||
|
|
||||||
stm32_pulse_config_output(&extmoduleTimer, &ocInit);
|
|
||||||
|
|
||||||
stm32_pulse_init(&extmoduleTimer);
|
stm32_pulse_init(&extmoduleTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void extmoduleSendNextFramePxx1(const void* pulses, uint16_t length)
|
void extmoduleSendNextFramePxx1(const void* pulses, uint16_t length)
|
||||||
{
|
{
|
||||||
if (!stm32_pulse_if_not_running_disable(&extmoduleTimer))
|
if (!stm32_pulse_if_not_running_disable(&extmoduleTimer)) return;
|
||||||
return;
|
|
||||||
|
|
||||||
// Start DMA request and re-enable timer
|
// Start DMA request and re-enable timer
|
||||||
stm32_pulse_start_dma_req(&extmoduleTimer, pulses, length,
|
stm32_pulse_start_dma_req(&extmoduleTimer, pulses, length, LL_TIM_OCMODE_PWM1,
|
||||||
LL_TIM_OCMODE_PWM1, 9 * 2);
|
9 * 2);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -144,16 +121,7 @@ void extmoduleSerialStart()
|
|||||||
{
|
{
|
||||||
EXTERNAL_MODULE_ON();
|
EXTERNAL_MODULE_ON();
|
||||||
stm32_pulse_init(&extmoduleTimer);
|
stm32_pulse_init(&extmoduleTimer);
|
||||||
|
stm32_pulse_config_output(&extmoduleTimer, true, LL_TIM_OCMODE_TOGGLE, 0);
|
||||||
LL_TIM_OC_InitTypeDef ocInit;
|
|
||||||
LL_TIM_OC_StructInit(&ocInit);
|
|
||||||
|
|
||||||
ocInit.OCMode = LL_TIM_OCMODE_TOGGLE;
|
|
||||||
ocInit.OCState = LL_TIM_OCSTATE_ENABLE;
|
|
||||||
ocInit.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
|
|
||||||
ocInit.CompareValue = 0;
|
|
||||||
|
|
||||||
stm32_pulse_config_output(&extmoduleTimer, &ocInit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void extmoduleSendNextFrameSoftSerial(const void* pulses, uint16_t length, bool polarity)
|
void extmoduleSendNextFrameSoftSerial(const void* pulses, uint16_t length, bool polarity)
|
||||||
|
|||||||
@@ -67,9 +67,36 @@ void stm32_pulse_deinit(const stm32_pulse_timer_t* tim)
|
|||||||
LL_GPIO_Init(tim->GPIOx, &pinInit);
|
LL_GPIO_Init(tim->GPIOx, &pinInit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stm32_pulse_config_output(const stm32_pulse_timer_t* tim, LL_TIM_OC_InitTypeDef* ocInit)
|
void stm32_pulse_config_output(const stm32_pulse_timer_t* tim, bool polarity,
|
||||||
|
uint32_t ocmode, uint32_t cmp_val)
|
||||||
{
|
{
|
||||||
LL_TIM_OC_Init(tim->TIMx, tim->TIM_Channel, ocInit);
|
LL_TIM_OC_InitTypeDef ocInit;
|
||||||
|
LL_TIM_OC_StructInit(&ocInit);
|
||||||
|
|
||||||
|
ocInit.OCMode = ocmode;
|
||||||
|
ocInit.CompareValue = cmp_val;
|
||||||
|
|
||||||
|
if (tim->TIM_Channel != LL_TIM_CHANNEL_CH1N) {
|
||||||
|
ocInit.OCState = LL_TIM_OCSTATE_ENABLE;
|
||||||
|
} else {
|
||||||
|
ocInit.OCNState = LL_TIM_OCSTATE_ENABLE;
|
||||||
|
polarity = !polarity;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ll_polarity;
|
||||||
|
if (polarity) {
|
||||||
|
ll_polarity = LL_TIM_OCPOLARITY_HIGH;
|
||||||
|
} else {
|
||||||
|
ll_polarity = LL_TIM_OCPOLARITY_LOW;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tim->TIM_Channel != LL_TIM_CHANNEL_CH1N) {
|
||||||
|
ocInit.OCPolarity = ll_polarity;
|
||||||
|
} else {
|
||||||
|
ocInit.OCNPolarity = ll_polarity;
|
||||||
|
}
|
||||||
|
|
||||||
|
LL_TIM_OC_Init(tim->TIMx, tim->TIM_Channel, &ocInit);
|
||||||
LL_TIM_OC_EnablePreload(tim->TIMx, tim->TIM_Channel);
|
LL_TIM_OC_EnablePreload(tim->TIMx, tim->TIM_Channel);
|
||||||
|
|
||||||
if (IS_TIM_BREAK_INSTANCE(tim->TIMx)) {
|
if (IS_TIM_BREAK_INSTANCE(tim->TIMx)) {
|
||||||
|
|||||||
@@ -43,7 +43,10 @@ struct stm32_pulse_timer_t {
|
|||||||
|
|
||||||
void stm32_pulse_init(const stm32_pulse_timer_t* tim);
|
void stm32_pulse_init(const stm32_pulse_timer_t* tim);
|
||||||
void stm32_pulse_deinit(const stm32_pulse_timer_t* tim);
|
void stm32_pulse_deinit(const stm32_pulse_timer_t* tim);
|
||||||
void stm32_pulse_config_output(const stm32_pulse_timer_t* tim, LL_TIM_OC_InitTypeDef* ocInit);
|
|
||||||
|
void stm32_pulse_config_output(const stm32_pulse_timer_t* tim, bool polarity,
|
||||||
|
uint32_t ocmode, uint32_t cmp_val);
|
||||||
|
|
||||||
void stm32_pulse_set_polarity(const stm32_pulse_timer_t* tim, bool polarity);
|
void stm32_pulse_set_polarity(const stm32_pulse_timer_t* tim, bool polarity);
|
||||||
|
|
||||||
// return true if it could be disabled without interrupting a pulse train, false otherwise
|
// return true if it could be disabled without interrupting a pulse train, false otherwise
|
||||||
|
|||||||
Reference in New Issue
Block a user