Skip to content

Commit

Permalink
FIX: Invalid references when neither DSHOT nor PWM_OUTPUT is defined. (
Browse files Browse the repository at this point in the history
  • Loading branch information
blckmn authored Jan 11, 2025
1 parent 07e4b4f commit c513b10
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
27 changes: 16 additions & 11 deletions src/main/drivers/motor.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,26 +317,31 @@ bool isMotorProtocolBidirDshot(void)

void motorDevInit(const motorDevConfig_t *motorDevConfig, uint16_t idlePulse, uint8_t motorCount)
{
memset(motors, 0, sizeof(motors));

#if defined(USE_PWM_OUTPUT) || defined(USE_DSHOT)
bool useUnsyncedPwm = motorDevConfig->useUnsyncedPwm;
#else
UNUSED(idlePulse);
UNUSED(motorDevConfig);
#endif

if (isMotorProtocolEnabled()) {
if (!isMotorProtocolDshot()) {
motorDevice = motorPwmDevInit(motorDevConfig, idlePulse, motorCount, useUnsyncedPwm);
}
do {
if (!isMotorProtocolDshot()) {
#ifdef USE_PWM_OUTPUT
motorDevice = motorPwmDevInit(motorDevConfig, idlePulse, motorCount, useUnsyncedPwm);
#endif
break;
}
#ifdef USE_DSHOT
else {
#ifdef USE_DSHOT_BITBANG
if (isDshotBitbangActive(motorDevConfig)) {
motorDevice = dshotBitbangDevInit(motorDevConfig, motorCount);
} else
#endif
{
motorDevice = dshotPwmDevInit(motorDevConfig, idlePulse, motorCount, useUnsyncedPwm);
break;
}
}
#endif
motorDevice = dshotPwmDevInit(motorDevConfig, idlePulse, motorCount, useUnsyncedPwm);
#endif
} while(0);
}

if (motorDevice) {
Expand Down
2 changes: 2 additions & 0 deletions src/platform/APM32/pwm_output_apm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ static motorVTable_t motorPwmVTable = {

motorDevice_t *motorPwmDevInit(const motorDevConfig_t *motorConfig, uint16_t idlePulse, uint8_t motorCount, bool useUnsyncedPwm)
{
memset(motors, 0, sizeof(motors));

motorPwmDevice.vTable = motorPwmVTable;

float sMin = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/AT32/dshot_bitbang.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ motorDevice_t *dshotBitbangDevInit(const motorDevConfig_t *motorConfig, uint8_t
IOHi(io);
}

// Fill in motors structure for 4way access (XXX Should be refactored)
// Fill in motors structure for 4way access (TODO: Should be refactored)
motors[motorIndex].io = bbMotors[motorIndex].io;
}

Expand Down
2 changes: 2 additions & 0 deletions src/platform/AT32/pwm_output_at32bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ static motorVTable_t motorPwmVTable = {

motorDevice_t *motorPwmDevInit(const motorDevConfig_t *motorConfig, uint16_t idlePulse, uint8_t motorCount, bool useUnsyncedPwm)
{
memset(motors, 0, sizeof(motors));

motorPwmDevice.vTable = motorPwmVTable;

float sMin = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/platform/STM32/pwm_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ static motorVTable_t motorPwmVTable = {

motorDevice_t *motorPwmDevInit(const motorDevConfig_t *motorConfig, uint16_t idlePulse, uint8_t motorCount, bool useUnsyncedPwm)
{
memset(motors, 0, sizeof(motors));

motorPwmDevice.vTable = motorPwmVTable;

float sMin = 0;
Expand Down

0 comments on commit c513b10

Please sign in to comment.