1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-19 22:35:23 +03:00

Dshot bidir inverted (#8146)

Dshot bidir inverted
This commit is contained in:
Michael Keller 2019-05-04 18:02:03 +12:00 committed by GitHub
commit ba95968e08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 46 deletions

View file

@ -673,8 +673,11 @@ FAST_CODE uint16_t prepareDshotPacket(motorDmaOutput_t *const motor)
csum ^= csum_data; // xor data by nibbles csum ^= csum_data; // xor data by nibbles
csum_data >>= 4; csum_data >>= 4;
} }
csum &= 0xf;
// append checksum // append checksum
if (useDshotTelemetry) {
csum = ~csum;
}
csum &= 0xf;
packet = (packet << 4) | csum; packet = (packet << 4) | csum;
return packet; return packet;

View file

@ -269,14 +269,12 @@ void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m
const bool configureTimer = (timerIndex == dmaMotorTimerCount-1); const bool configureTimer = (timerIndex == dmaMotorTimerCount-1);
uint8_t pupMode = 0; uint8_t pupMode = 0;
pupMode = (output & TIMER_OUTPUT_INVERTED) ? GPIO_PuPd_DOWN : GPIO_PuPd_UP;
#ifdef USE_DSHOT_TELEMETRY #ifdef USE_DSHOT_TELEMETRY
if (!useDshotTelemetry) { if (useDshotTelemetry) {
pupMode = (output & TIMER_OUTPUT_INVERTED) ? GPIO_PuPd_DOWN : GPIO_PuPd_UP; output ^= TIMER_OUTPUT_INVERTED;
} else
#endif
{
pupMode = (output & TIMER_OUTPUT_INVERTED) ? GPIO_PuPd_UP : GPIO_PuPd_DOWN;
} }
#endif
IOConfigGPIOAF(motorIO, IO_CONFIG(GPIO_Mode_AF, GPIO_Speed_50MHz, GPIO_OType_PP, pupMode), timerHardware->alternateFunction); IOConfigGPIOAF(motorIO, IO_CONFIG(GPIO_Mode_AF, GPIO_Speed_50MHz, GPIO_OType_PP, pupMode), timerHardware->alternateFunction);
@ -395,6 +393,10 @@ void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m
( 2 + (motor->useProshot ? 4 * MOTOR_NIBBLE_LENGTH_PROSHOT : 16 * MOTOR_BITLENGTH)) ( 2 + (motor->useProshot ? 4 * MOTOR_NIBBLE_LENGTH_PROSHOT : 16 * MOTOR_BITLENGTH))
/ getDshotHz(pwmProtocolType); / getDshotHz(pwmProtocolType);
pwmDshotSetDirectionOutput(motor, true); pwmDshotSetDirectionOutput(motor, true);
if (useDshotTelemetry) {
// avoid high line during startup to prevent bootloader activation
*timerChCCR(timerHardware) = 0xffff;
}
#else #else
pwmDshotSetDirectionOutput(motor, true, &OCINIT, &DMAINIT); pwmDshotSetDirectionOutput(motor, true, &OCINIT, &DMAINIT);
#endif #endif

View file

@ -241,16 +241,12 @@ void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m
const uint8_t timerIndex = getTimerIndex(timer); const uint8_t timerIndex = getTimerIndex(timer);
const bool configureTimer = (timerIndex == dmaMotorTimerCount - 1); const bool configureTimer = (timerIndex == dmaMotorTimerCount - 1);
uint8_t pupMode = 0; uint8_t pupMode = (output & TIMER_OUTPUT_INVERTED) ? GPIO_PULLDOWN : GPIO_PULLUP;
#ifdef USE_DSHOT_TELEMETRY #ifdef USE_DSHOT_TELEMETRY
if (!useDshotTelemetry) { if (useDshotTelemetry) {
pupMode = (output & TIMER_OUTPUT_INVERTED) ? GPIO_PULLDOWN : GPIO_PULLUP; output ^= TIMER_OUTPUT_INVERTED;
} else
#endif
{
pupMode = (output & TIMER_OUTPUT_INVERTED) ? GPIO_PULLUP : GPIO_PULLDOWN;
} }
#endif
IOConfigGPIOAF(motorIO, IO_CONFIG(GPIO_MODE_AF_PP, GPIO_SPEED_FREQ_VERY_HIGH, pupMode), timerHardware->alternateFunction); IOConfigGPIOAF(motorIO, IO_CONFIG(GPIO_MODE_AF_PP, GPIO_SPEED_FREQ_VERY_HIGH, pupMode), timerHardware->alternateFunction);
@ -358,6 +354,10 @@ void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m
( 2 + (motor->useProshot ? 4 * MOTOR_NIBBLE_LENGTH_PROSHOT : 16 * MOTOR_BITLENGTH)) ( 2 + (motor->useProshot ? 4 * MOTOR_NIBBLE_LENGTH_PROSHOT : 16 * MOTOR_BITLENGTH))
/ getDshotHz(pwmProtocolType); / getDshotHz(pwmProtocolType);
pwmDshotSetDirectionOutput(motor, true); pwmDshotSetDirectionOutput(motor, true);
if (useDshotTelemetry) {
// avoid high line during startup to prevent bootloader activation
*timerChCCR(timerHardware) = 0xffff;
}
#else #else
pwmDshotSetDirectionOutput(motor, true, &OCINIT, &DMAINIT); pwmDshotSetDirectionOutput(motor, true, &OCINIT, &DMAINIT);
#endif #endif

View file

@ -150,7 +150,7 @@ static uint16_t decodeDshotPacket(uint32_t buffer[])
csum = csum ^ (csum >> 8); // xor bytes csum = csum ^ (csum >> 8); // xor bytes
csum = csum ^ (csum >> 4); // xor nibbles csum = csum ^ (csum >> 4); // xor nibbles
if (csum & 0xf) { if ((csum & 0xf) != 0xf) {
return 0xffff; return 0xffff;
} }
return value >> 4; return value >> 4;
@ -176,7 +176,7 @@ static uint16_t decodeProshotPacket(uint32_t buffer[])
csum = csum ^ (csum >> 8); // xor bytes csum = csum ^ (csum >> 8); // xor bytes
csum = csum ^ (csum >> 4); // xor nibbles csum = csum ^ (csum >> 4); // xor nibbles
if (csum & 0xf) { if ((csum & 0xf) != 0xf) {
return 0xffff; return 0xffff;
} }
return value >> 4; return value >> 4;

View file

@ -414,14 +414,6 @@ void tryArm(void)
return; return;
} }
#ifdef USE_DSHOT_TELEMETRY
if (isMotorProtocolDshot()) {
pwmWriteDshotCommand(
255, getMotorCount(), motorConfig()->dev.useDshotTelemetry ?
DSHOT_CMD_SIGNAL_LINE_CONTINUOUS_ERPM_TELEMETRY : DSHOT_CMD_SIGNAL_LINE_TELEMETRY_DISABLE, false);
}
#endif
if (isMotorProtocolDshot() && isModeActivationConditionPresent(BOXFLIPOVERAFTERCRASH)) { if (isMotorProtocolDshot() && isModeActivationConditionPresent(BOXFLIPOVERAFTERCRASH)) {
if (!(IS_RC_MODE_ACTIVE(BOXFLIPOVERAFTERCRASH) || (tryingToArm == ARMING_DELAYED_CRASHFLIP))) { if (!(IS_RC_MODE_ACTIVE(BOXFLIPOVERAFTERCRASH) || (tryingToArm == ARMING_DELAYED_CRASHFLIP))) {
flipOverAfterCrashActive = false; flipOverAfterCrashActive = false;

View file

@ -209,20 +209,6 @@ static IO_t busSwitchResetPin = IO_NONE;
} }
#endif #endif
#ifdef USE_DSHOT_TELEMETRY
void activateDshotTelemetry(struct dispatchEntry_s* self)
{
if (!ARMING_FLAG(ARMED) && !isDshotTelemetryActive()) {
pwmWriteDshotCommand(ALL_MOTORS, getMotorCount(), DSHOT_CMD_SIGNAL_LINE_CONTINUOUS_ERPM_TELEMETRY, false);
dispatchAdd(self, 1e6); // check again in 1 second
}
}
dispatchEntry_t activateDshotTelemetryEntry =
{
activateDshotTelemetry, 0, NULL, false
};
#endif
void init(void) void init(void)
{ {
@ -794,13 +780,6 @@ void init(void)
setArmingDisabled(ARMING_DISABLED_BOOT_GRACE_TIME); setArmingDisabled(ARMING_DISABLED_BOOT_GRACE_TIME);
#ifdef USE_DSHOT_TELEMETRY
if (motorConfig()->dev.useDshotTelemetry) {
dispatchEnable();
dispatchAdd(&activateDshotTelemetryEntry, 5000000);
}
#endif
fcTasksInit(); fcTasksInit();
systemState |= SYSTEM_STATE_READY; systemState |= SYSTEM_STATE_READY;