mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-26 01:35:41 +03:00
Refactoring motor to simplify implementation on other platforms (#14156)
This commit is contained in:
parent
7ed1b4b71f
commit
c2768d0409
62 changed files with 975 additions and 810 deletions
|
@ -42,15 +42,15 @@
|
|||
|
||||
#include "drivers/pwm_output.h"
|
||||
#include "drivers/dshot.h"
|
||||
#include "drivers/dshot_dpwm.h"
|
||||
#include "dshot_dpwm.h"
|
||||
#include "drivers/dshot_command.h"
|
||||
#include "drivers/pwm_output_dshot_shared.h"
|
||||
#include "pwm_output_dshot_shared.h"
|
||||
|
||||
#ifdef USE_DSHOT_TELEMETRY
|
||||
|
||||
void dshotEnableChannels(uint8_t motorCount)
|
||||
void dshotEnableChannels(unsigned motorCount)
|
||||
{
|
||||
for (int i = 0; i < motorCount; i++) {
|
||||
for (unsigned i = 0; i < motorCount; i++) {
|
||||
if (dmaMotors[i].output & TIMER_OUTPUT_N_CHANNEL) {
|
||||
TIM_CCxNCmd(dmaMotors[i].timerHardware->tim, dmaMotors[i].timerHardware->channel, TIM_CCxN_Enable);
|
||||
} else {
|
||||
|
@ -144,7 +144,7 @@ void pwmCompleteDshotMotorUpdate(void)
|
|||
{
|
||||
/* If there is a dshot command loaded up, time it correctly with motor update*/
|
||||
if (!dshotCommandQueueEmpty()) {
|
||||
if (!dshotCommandOutputIsEnabled(dshotPwmDevice.count)) {
|
||||
if (!dshotCommandOutputIsEnabled(pwmMotorCount)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ FAST_CODE static void motor_DMA_IRQHandler(dmaChannelDescriptor_t *descriptor)
|
|||
}
|
||||
}
|
||||
|
||||
bool pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, uint8_t reorderedMotorIndex, motorPwmProtocolTypes_e pwmProtocolType, uint8_t output)
|
||||
bool pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, uint8_t reorderedMotorIndex, motorProtocolTypes_e pwmProtocolType, uint8_t output)
|
||||
{
|
||||
#ifdef USE_DSHOT_TELEMETRY
|
||||
#define OCINIT motor->ocInitStruct
|
||||
|
@ -299,7 +299,7 @@ bool pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m
|
|||
TIM_Cmd(timer, DISABLE);
|
||||
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(lrintf((float) timerClock(timer) / getDshotHz(pwmProtocolType) + 0.01f) - 1);
|
||||
TIM_TimeBaseStructure.TIM_Period = (pwmProtocolType == PWM_TYPE_PROSHOT1000 ? (MOTOR_NIBBLE_LENGTH_PROSHOT) : MOTOR_BITLENGTH) - 1;
|
||||
TIM_TimeBaseStructure.TIM_Period = (pwmProtocolType == MOTOR_PROTOCOL_PROSHOT1000 ? (MOTOR_NIBBLE_LENGTH_PROSHOT) : MOTOR_BITLENGTH) - 1;
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
||||
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
|
@ -359,7 +359,7 @@ bool pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m
|
|||
DMAINIT.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
|
||||
|
||||
DMAINIT.DMA_PeripheralBaseAddr = (uint32_t)&timerHardware->tim->DMAR;
|
||||
DMAINIT.DMA_BufferSize = (pwmProtocolType == PWM_TYPE_PROSHOT1000) ? PROSHOT_DMA_BUFFER_SIZE : DSHOT_DMA_BUFFER_SIZE; // XXX
|
||||
DMAINIT.DMA_BufferSize = (pwmProtocolType == MOTOR_PROTOCOL_PROSHOT1000) ? PROSHOT_DMA_BUFFER_SIZE : DSHOT_DMA_BUFFER_SIZE; // XXX
|
||||
DMAINIT.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
||||
DMAINIT.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
||||
DMAINIT.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
|
||||
|
@ -396,7 +396,7 @@ bool pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m
|
|||
#ifdef USE_DSHOT_TELEMETRY
|
||||
motor->dshotTelemetryDeadtimeUs = DSHOT_TELEMETRY_DEADTIME_US + 1000000 *
|
||||
(16 * MOTOR_BITLENGTH) / getDshotHz(pwmProtocolType);
|
||||
motor->timer->outputPeriod = (pwmProtocolType == PWM_TYPE_PROSHOT1000 ? (MOTOR_NIBBLE_LENGTH_PROSHOT) : MOTOR_BITLENGTH) - 1;
|
||||
motor->timer->outputPeriod = (pwmProtocolType == MOTOR_PROTOCOL_PROSHOT1000 ? (MOTOR_NIBBLE_LENGTH_PROSHOT) : MOTOR_BITLENGTH) - 1;
|
||||
pwmDshotSetDirectionOutput(motor);
|
||||
#else
|
||||
pwmDshotSetDirectionOutput(motor, &OCINIT, &DMAINIT);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue