mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 16:25:31 +03:00
Fixup Dshot / Proshot implementation.
This commit is contained in:
parent
7b762e640c
commit
559079ff31
5 changed files with 78 additions and 131 deletions
|
@ -54,70 +54,19 @@ uint8_t getTimerIndex(TIM_TypeDef *timer)
|
|||
return dmaMotorTimerCount-1;
|
||||
}
|
||||
|
||||
void pwmWriteDshot(uint8_t index, float value)
|
||||
void pwmWriteDigitalInt(uint8_t index, uint16_t value)
|
||||
{
|
||||
const uint16_t digitalValue = lrintf(value);
|
||||
|
||||
motorDmaOutput_t * const motor = &dmaMotors[index];
|
||||
motorDmaOutput_t *const motor = &dmaMotors[index];
|
||||
|
||||
if (!motor->timerHardware || !motor->timerHardware->dmaRef) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t packet = (digitalValue << 1) | (motor->requestTelemetry ? 1 : 0);
|
||||
motor->requestTelemetry = false; // reset telemetry request to make sure it's triggered only once in a row
|
||||
uint16_t packet = prepareDshotPacket(motor, value);
|
||||
|
||||
// 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 whole packet
|
||||
for (int i = 0; i < 16; i++) {
|
||||
motor->dmaBuffer[i] = (packet & 0x8000) ? MOTOR_BIT_1 : MOTOR_BIT_0; // MSB first
|
||||
packet <<= 1;
|
||||
}
|
||||
uint8_t bufferSize = loadDmaBufferPtr(motor, packet);
|
||||
|
||||
DMA_SetCurrDataCounter(motor->timerHardware->dmaRef, DSHOT_DMA_BUFFER_SIZE);
|
||||
DMA_Cmd(motor->timerHardware->dmaRef, ENABLE);
|
||||
}
|
||||
|
||||
void pwmWriteProShot(uint8_t index, float value)
|
||||
{
|
||||
const uint16_t digitalValue = lrintf(value);
|
||||
|
||||
motorDmaOutput_t * const motor = &dmaMotors[index];
|
||||
|
||||
if (!motor->timerHardware || !motor->timerHardware->dmaRef) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t packet = (digitalValue << 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_SetCurrDataCounter(motor->timerHardware->dmaRef, bufferSize);
|
||||
DMA_Cmd(motor->timerHardware->dmaRef, ENABLE);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue