Merge pull request #8722 from jflyper/bfdev-isolate-msp-from-pwm_output

Isolate MSP_MOTOR from pwm_output (pwmGetMotors)
This commit is contained in:
jflyper 2019-08-17 11:19:20 +09:00 committed by GitHub
commit f1cd99e6b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 2 deletions

View File

@ -122,6 +122,11 @@ static bool dshotPwmEnableMotors(void)
return true;
}
static bool dshotPwmIsMotorEnabled(uint8_t index)
{
return motors[index].enabled;
}
static FAST_CODE void dshotWriteInt(uint8_t index, uint16_t value)
{
pwmWriteDshotInt(index, value);
@ -135,6 +140,7 @@ static FAST_CODE void dshotWrite(uint8_t index, float value)
static motorVTable_t dshotPwmVTable = {
.enable = dshotPwmEnableMotors,
.disable = dshotPwmDisableMotors,
.isMotorEnabled = dshotPwmIsMotorEnabled,
.updateStart = motorUpdateStartNull, // May be updated after copying
.write = dshotWrite,
.writeInt = dshotWriteInt,

View File

@ -246,6 +246,11 @@ bool motorIsEnabled(void)
return motorDevice->enabled;
}
bool motorIsMotorEnabled(uint8_t index)
{
return motorDevice->vTable.isMotorEnabled(index);
}
bool isMotorProtocolDshot(void)
{
return isDshot;

View File

@ -45,6 +45,7 @@ typedef struct motorVTable_s {
uint16_t (*convertMotorToExternal)(float motorValue);
bool (*enable)(void);
void (*disable)(void);
bool (*isMotorEnabled)(uint8_t index);
bool (*updateStart)(void);
void (*write)(uint8_t index, float value);
void (*writeInt)(uint8_t index, uint16_t value);
@ -80,4 +81,5 @@ bool isMotorProtocolDshot(void);
void motorDisable(void);
void motorEnable(void);
bool motorIsEnabled(void);
bool motorIsMotorEnabled(uint8_t index);
void motorShutdown(void); // Replaces stopPwmAllMotors

View File

@ -144,6 +144,11 @@ bool pwmEnableMotors(void)
return (motorPwmVTable.write != &pwmWriteUnused);
}
bool pwmIsMotorEnabled(uint8_t index)
{
return motors[index].enabled;
}
static void pwmCompleteOneshotMotorUpdate(void)
{
for (int index = 0; index < motorPwmDevice.count; index++) {
@ -169,6 +174,7 @@ static uint16_t pwmConvertToExternal(float motorValue)
static motorVTable_t motorPwmVTable = {
.enable = pwmEnableMotors,
.disable = pwmDisableMotors,
.isMotorEnabled = pwmIsMotorEnabled,
.shutdown = pwmShutdownPulsesForAllMotors,
.convertExternalToMotor = pwmConvertFromExternal,
.convertMotorToExternal = pwmConvertToExternal,

View File

@ -962,8 +962,8 @@ static bool mspProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst)
case MSP_MOTOR:
for (unsigned i = 0; i < 8; i++) {
#ifdef USE_PWM_OUTPUT
if (i >= MAX_SUPPORTED_MOTORS || !pwmGetMotors()[i].enabled) {
#ifdef USE_MOTOR
if (i >= MAX_SUPPORTED_MOTORS || !motorIsMotorEnabled(i)) {
sbufWriteU16(dst, 0);
continue;
}