1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-14 03:50:02 +03:00

Refactoring motor to simplify implementation on other platforms (#14156)

This commit is contained in:
Jay Blackman 2025-01-24 18:37:20 +11:00 committed by GitHub
parent 7ed1b4b71f
commit c2768d0409
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
62 changed files with 975 additions and 810 deletions

View file

@ -30,13 +30,9 @@
#include "drivers/io.h"
#include "drivers/motor.h"
#include "drivers/time.h"
#include "drivers/timer.h"
#include "drivers/dshot.h"
#include "drivers/dshot_dpwm.h"
#include "drivers/pwm_output.h"
#include "dshot_command.h"
#include "drivers/dshot_command.h"
#define DSHOT_PROTOCOL_DETECTION_DELAY_MS 3000
#define DSHOT_INITIAL_DELAY_US 10000
@ -143,8 +139,7 @@ static dshotCommandControl_t* addCommand(void)
static bool allMotorsAreIdle(void)
{
for (unsigned i = 0; i < motorDeviceCount(); i++) {
const motorDmaOutput_t *motor = getMotorDmaOutput(i);
if (motor->protocolControl.value) {
if (!motorIsMotorIdle(i)) {
return false;
}
}
@ -182,7 +177,7 @@ void dshotCommandWrite(uint8_t index, uint8_t motorCount, uint8_t command, dshot
uint8_t repeats = 1;
timeUs_t delayAfterCommandUs = DSHOT_COMMAND_DELAY_US;
motorVTable_t *vTable = motorGetVTable();
const motorVTable_t *vTable = motorGetVTable();
switch (command) {
case DSHOT_CMD_SPIN_DIRECTION_1:
@ -232,8 +227,7 @@ void dshotCommandWrite(uint8_t index, uint8_t motorCount, uint8_t command, dshot
}
for (uint8_t i = 0; i < motorDeviceCount(); i++) {
motorDmaOutput_t *const motor = getMotorDmaOutput(i);
motor->protocolControl.requestTelemetry = true;
vTable->requestTelemetry(i);
vTable->writeInt(i, (i == index || index == ALL_MOTORS) ? command : DSHOT_CMD_MOTOR_STOP);
}
@ -280,7 +274,7 @@ void dshotCommandWrite(uint8_t index, uint8_t motorCount, uint8_t command, dshot
}
}
uint8_t dshotCommandGetCurrent(uint8_t index)
uint8_t dshotCommandGetCurrent(unsigned index)
{
return commandQueue[commandQueueTail].command[index];
}
@ -290,7 +284,7 @@ uint8_t dshotCommandGetCurrent(uint8_t index)
// allows the motor output to be sent, "false" means delay until next loop. So take
// the example of a dshot command that needs to repeat 10 times at 1ms intervals.
// If we have a 8KHz PID loop we'll end up sending the dshot command every 8th motor output.
FAST_CODE_NOINLINE bool dshotCommandOutputIsEnabled(uint8_t motorCount)
FAST_CODE_NOINLINE bool dshotCommandOutputIsEnabled(unsigned motorCount)
{
UNUSED(motorCount);