mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-24 08:45:36 +03:00
Some simple changes to allow for Proshot (Another digital protocol).
This commit is contained in:
parent
51f607fdfc
commit
b4d2388103
4 changed files with 114 additions and 33 deletions
|
@ -54,13 +54,8 @@ uint8_t getTimerIndex(TIM_TypeDef *timer)
|
|||
return dmaMotorTimerCount-1;
|
||||
}
|
||||
|
||||
void pwmWriteDigital(uint8_t index, uint16_t value)
|
||||
void pwmWriteDshot(uint8_t index, uint16_t value)
|
||||
{
|
||||
|
||||
if (!pwmMotorsEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
motorDmaOutput_t * const motor = &dmaMotors[index];
|
||||
|
||||
if (!motor->timerHardware || !motor->timerHardware->dmaRef) {
|
||||
|
@ -86,7 +81,39 @@ void pwmWriteDigital(uint8_t index, uint16_t value)
|
|||
packet <<= 1;
|
||||
}
|
||||
|
||||
DMA_SetCurrDataCounter(motor->timerHardware->dmaRef, MOTOR_DMA_BUFFER_SIZE);
|
||||
DMA_SetCurrDataCounter(motor->timerHardware->dmaRef, DSHOT_DMA_BUFFER_SIZE);
|
||||
DMA_Cmd(motor->timerHardware->dmaRef, ENABLE);
|
||||
}
|
||||
|
||||
void pwmWriteProShot(uint8_t index, uint16_t value)
|
||||
{
|
||||
motorDmaOutput_t * const motor = &dmaMotors[index];
|
||||
|
||||
if (!motor->timerHardware || !motor->timerHardware->dmaRef) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t packet = (value << 1) | (motor->requestTelemetry ? 1 : 0);
|
||||
motor->requestTelemetry = false; // reset telemetry request to make sure it's triggered only once in a row
|
||||
|
||||
// compute checksum
|
||||
int csum = 0;
|
||||
int csum_data = packet;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
csum ^= csum_data; // xor data by nibbles
|
||||
csum_data >>= 4;
|
||||
}
|
||||
csum &= 0xf;
|
||||
// append checksum
|
||||
packet = (packet << 4) | csum;
|
||||
|
||||
// generate pulses for Proshot
|
||||
for (int i = 0; i < 4; i++) {
|
||||
motor->dmaBuffer[i] = PROSHOT_BASE_SYMBOL + ((packet & 0xF000) >> 12) * PROSHOT_BIT_WIDTH; // Most significant nibble first
|
||||
packet <<= 4; // Shift 4 bits
|
||||
}
|
||||
|
||||
DMA_SetCurrDataCounter(motor->timerHardware->dmaRef, PROSHOT_DMA_BUFFER_SIZE);
|
||||
DMA_Cmd(motor->timerHardware->dmaRef, ENABLE);
|
||||
}
|
||||
|
||||
|
@ -139,7 +166,7 @@ void pwmDigitalMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t
|
|||
TIM_Cmd(timer, DISABLE);
|
||||
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)((timerClock(timer) / getDshotHz(pwmProtocolType)) - 1);
|
||||
TIM_TimeBaseStructure.TIM_Period = MOTOR_BITLENGTH;
|
||||
TIM_TimeBaseStructure.TIM_Period = pwmProtocolType == PWM_TYPE_PROSHOT1000 ? MOTOR_NIBBLE_LENGTH_PROSHOT : MOTOR_BITLENGTH;
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
||||
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
|
@ -205,7 +232,7 @@ void pwmDigitalMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t
|
|||
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
|
||||
#endif
|
||||
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)timerChCCR(timerHardware);
|
||||
DMA_InitStructure.DMA_BufferSize = MOTOR_DMA_BUFFER_SIZE;
|
||||
DMA_InitStructure.DMA_BufferSize = pwmProtocolType == PWM_TYPE_PROSHOT1000 ? PROSHOT_DMA_BUFFER_SIZE : DSHOT_DMA_BUFFER_SIZE;
|
||||
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
|
||||
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
|
||||
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue