Changed function pointer semantics.
This commit is contained in:
parent
559079ff31
commit
76869eb3dd
|
@ -31,12 +31,12 @@
|
||||||
#define MULTISHOT_5US_PW (MULTISHOT_TIMER_MHZ * 5)
|
#define MULTISHOT_5US_PW (MULTISHOT_TIMER_MHZ * 5)
|
||||||
#define MULTISHOT_20US_MULT (MULTISHOT_TIMER_MHZ * 20 / 1000.0f)
|
#define MULTISHOT_20US_MULT (MULTISHOT_TIMER_MHZ * 20 / 1000.0f)
|
||||||
|
|
||||||
static pwmWriteFuncPtr pwmWritePtr;
|
static pwmWriteFunc *pwmWrite;
|
||||||
static pwmOutputPort_t motors[MAX_SUPPORTED_MOTORS];
|
static pwmOutputPort_t motors[MAX_SUPPORTED_MOTORS];
|
||||||
static pwmCompleteWriteFuncPtr pwmCompleteWritePtr = NULL;
|
static pwmCompleteWriteFunc *pwmCompleteWrite = NULL;
|
||||||
|
|
||||||
#ifdef USE_DSHOT
|
#ifdef USE_DSHOT
|
||||||
loadDmaBufferFuncPtr loadDmaBufferPtr;
|
loadDmaBufferFunc *loadDmaBuffer;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_SERVOS
|
#ifdef USE_SERVOS
|
||||||
|
@ -189,7 +189,7 @@ static uint8_t loadDmaBufferProshot(motorDmaOutput_t *const motor, uint16_t pack
|
||||||
void pwmWriteMotor(uint8_t index, float value)
|
void pwmWriteMotor(uint8_t index, float value)
|
||||||
{
|
{
|
||||||
if (pwmMotorsEnabled) {
|
if (pwmMotorsEnabled) {
|
||||||
pwmWritePtr(index, value);
|
pwmWrite(index, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ void pwmDisableMotors(void)
|
||||||
void pwmEnableMotors(void)
|
void pwmEnableMotors(void)
|
||||||
{
|
{
|
||||||
/* check motors can be enabled */
|
/* check motors can be enabled */
|
||||||
pwmMotorsEnabled = (pwmWritePtr != pwmWriteUnused);
|
pwmMotorsEnabled = (pwmWrite != &pwmWriteUnused);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pwmAreMotorsEnabled(void)
|
bool pwmAreMotorsEnabled(void)
|
||||||
|
@ -239,7 +239,7 @@ static void pwmCompleteOneshotMotorUpdate(uint8_t motorCount)
|
||||||
|
|
||||||
void pwmCompleteMotorUpdate(uint8_t motorCount)
|
void pwmCompleteMotorUpdate(uint8_t motorCount)
|
||||||
{
|
{
|
||||||
pwmCompleteWritePtr(motorCount);
|
pwmCompleteWrite(motorCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void motorDevInit(const motorDevConfig_t *motorConfig, uint16_t idlePulse, uint8_t motorCount)
|
void motorDevInit(const motorDevConfig_t *motorConfig, uint16_t idlePulse, uint8_t motorCount)
|
||||||
|
@ -253,49 +253,49 @@ void motorDevInit(const motorDevConfig_t *motorConfig, uint16_t idlePulse, uint8
|
||||||
default:
|
default:
|
||||||
case PWM_TYPE_ONESHOT125:
|
case PWM_TYPE_ONESHOT125:
|
||||||
timerMhzCounter = ONESHOT125_TIMER_MHZ;
|
timerMhzCounter = ONESHOT125_TIMER_MHZ;
|
||||||
pwmWritePtr = pwmWriteOneShot125;
|
pwmWrite = &pwmWriteOneShot125;
|
||||||
break;
|
break;
|
||||||
case PWM_TYPE_ONESHOT42:
|
case PWM_TYPE_ONESHOT42:
|
||||||
timerMhzCounter = ONESHOT42_TIMER_MHZ;
|
timerMhzCounter = ONESHOT42_TIMER_MHZ;
|
||||||
pwmWritePtr = pwmWriteOneShot42;
|
pwmWrite = &pwmWriteOneShot42;
|
||||||
break;
|
break;
|
||||||
case PWM_TYPE_MULTISHOT:
|
case PWM_TYPE_MULTISHOT:
|
||||||
timerMhzCounter = MULTISHOT_TIMER_MHZ;
|
timerMhzCounter = MULTISHOT_TIMER_MHZ;
|
||||||
pwmWritePtr = pwmWriteMultiShot;
|
pwmWrite = &pwmWriteMultiShot;
|
||||||
break;
|
break;
|
||||||
case PWM_TYPE_BRUSHED:
|
case PWM_TYPE_BRUSHED:
|
||||||
timerMhzCounter = PWM_BRUSHED_TIMER_MHZ;
|
timerMhzCounter = PWM_BRUSHED_TIMER_MHZ;
|
||||||
pwmWritePtr = pwmWriteBrushed;
|
pwmWrite = &pwmWriteBrushed;
|
||||||
useUnsyncedPwm = true;
|
useUnsyncedPwm = true;
|
||||||
idlePulse = 0;
|
idlePulse = 0;
|
||||||
break;
|
break;
|
||||||
case PWM_TYPE_STANDARD:
|
case PWM_TYPE_STANDARD:
|
||||||
timerMhzCounter = PWM_TIMER_MHZ;
|
timerMhzCounter = PWM_TIMER_MHZ;
|
||||||
pwmWritePtr = pwmWriteStandard;
|
pwmWrite = &pwmWriteStandard;
|
||||||
useUnsyncedPwm = true;
|
useUnsyncedPwm = true;
|
||||||
idlePulse = 0;
|
idlePulse = 0;
|
||||||
break;
|
break;
|
||||||
#ifdef USE_DSHOT
|
#ifdef USE_DSHOT
|
||||||
case PWM_TYPE_PROSHOT1000:
|
case PWM_TYPE_PROSHOT1000:
|
||||||
pwmWritePtr = pwmWriteDigital;
|
pwmWrite = &pwmWriteDigital;
|
||||||
loadDmaBufferPtr = loadDmaBufferProshot;
|
loadDmaBuffer = &loadDmaBufferProshot;
|
||||||
pwmCompleteWritePtr = pwmCompleteDigitalMotorUpdate;
|
pwmCompleteWrite = &pwmCompleteDigitalMotorUpdate;
|
||||||
isDigital = true;
|
isDigital = true;
|
||||||
break;
|
break;
|
||||||
case PWM_TYPE_DSHOT1200:
|
case PWM_TYPE_DSHOT1200:
|
||||||
case PWM_TYPE_DSHOT600:
|
case PWM_TYPE_DSHOT600:
|
||||||
case PWM_TYPE_DSHOT300:
|
case PWM_TYPE_DSHOT300:
|
||||||
case PWM_TYPE_DSHOT150:
|
case PWM_TYPE_DSHOT150:
|
||||||
pwmWritePtr = pwmWriteDigital;
|
pwmWrite = &pwmWriteDigital;
|
||||||
loadDmaBufferPtr = loadDmaBufferDshot;
|
loadDmaBuffer = &loadDmaBufferDshot;
|
||||||
pwmCompleteWritePtr = pwmCompleteDigitalMotorUpdate;
|
pwmCompleteWrite = &pwmCompleteDigitalMotorUpdate;
|
||||||
isDigital = true;
|
isDigital = true;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isDigital) {
|
if (!isDigital) {
|
||||||
pwmCompleteWritePtr = useUnsyncedPwm ? pwmCompleteWriteUnused : pwmCompleteOneshotMotorUpdate;
|
pwmCompleteWrite = useUnsyncedPwm ? &pwmCompleteWriteUnused : &pwmCompleteOneshotMotorUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int motorIndex = 0; motorIndex < MAX_SUPPORTED_MOTORS && motorIndex < motorCount; motorIndex++) {
|
for (int motorIndex = 0; motorIndex < MAX_SUPPORTED_MOTORS && motorIndex < motorCount; motorIndex++) {
|
||||||
|
@ -304,8 +304,8 @@ void motorDevInit(const motorDevConfig_t *motorConfig, uint16_t idlePulse, uint8
|
||||||
|
|
||||||
if (timerHardware == NULL) {
|
if (timerHardware == NULL) {
|
||||||
/* not enough motors initialised for the mixer or a break in the motors */
|
/* not enough motors initialised for the mixer or a break in the motors */
|
||||||
pwmWritePtr = pwmWriteUnused;
|
pwmWrite = &pwmWriteUnused;
|
||||||
pwmCompleteWritePtr = pwmCompleteWriteUnused;
|
pwmCompleteWrite = &pwmCompleteWriteUnused;
|
||||||
/* TODO: block arming and add reason system cannot arm */
|
/* TODO: block arming and add reason system cannot arm */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,8 +133,8 @@ motorDmaOutput_t *getMotorDmaOutput(uint8_t index);
|
||||||
extern bool pwmMotorsEnabled;
|
extern bool pwmMotorsEnabled;
|
||||||
|
|
||||||
struct timerHardware_s;
|
struct timerHardware_s;
|
||||||
typedef void(*pwmWriteFuncPtr)(uint8_t index, float value); // function pointer used to write motors
|
typedef void pwmWriteFunc(uint8_t index, float value); // function pointer used to write motors
|
||||||
typedef void(*pwmCompleteWriteFuncPtr)(uint8_t motorCount); // function pointer used after motors are written
|
typedef void pwmCompleteWriteFunc(uint8_t motorCount); // function pointer used after motors are written
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
volatile timCCR_t *ccr;
|
volatile timCCR_t *ccr;
|
||||||
|
@ -167,11 +167,11 @@ void servoDevInit(const servoDevConfig_t *servoDevConfig);
|
||||||
void pwmServoConfig(const struct timerHardware_s *timerHardware, uint8_t servoIndex, uint16_t servoPwmRate, uint16_t servoCenterPulse);
|
void pwmServoConfig(const struct timerHardware_s *timerHardware, uint8_t servoIndex, uint16_t servoPwmRate, uint16_t servoCenterPulse);
|
||||||
|
|
||||||
#ifdef USE_DSHOT
|
#ifdef USE_DSHOT
|
||||||
typedef uint8_t(*loadDmaBufferFuncPtr)(motorDmaOutput_t *const motor, uint16_t packet); // function pointer used to encode a digital motor value into the DMA buffer representation
|
typedef uint8_t loadDmaBufferFunc(motorDmaOutput_t *const motor, uint16_t packet); // function pointer used to encode a digital motor value into the DMA buffer representation
|
||||||
|
|
||||||
uint16_t prepareDshotPacket(motorDmaOutput_t *const motor, uint16_t value);
|
uint16_t prepareDshotPacket(motorDmaOutput_t *const motor, uint16_t value);
|
||||||
|
|
||||||
extern loadDmaBufferFuncPtr loadDmaBufferPtr;
|
extern loadDmaBufferFunc *loadDmaBuffer;
|
||||||
|
|
||||||
uint32_t getDshotHz(motorPwmProtocolTypes_e pwmProtocolType);
|
uint32_t getDshotHz(motorPwmProtocolTypes_e pwmProtocolType);
|
||||||
void pwmWriteDshotCommand(uint8_t index, uint8_t command);
|
void pwmWriteDshotCommand(uint8_t index, uint8_t command);
|
||||||
|
|
|
@ -64,7 +64,7 @@ void pwmWriteDigitalInt(uint8_t index, uint16_t value)
|
||||||
|
|
||||||
uint16_t packet = prepareDshotPacket(motor, value);
|
uint16_t packet = prepareDshotPacket(motor, value);
|
||||||
|
|
||||||
uint8_t bufferSize = loadDmaBufferPtr(motor, packet);
|
uint8_t bufferSize = loadDmaBuffer(motor, packet);
|
||||||
|
|
||||||
DMA_SetCurrDataCounter(motor->timerHardware->dmaRef, bufferSize);
|
DMA_SetCurrDataCounter(motor->timerHardware->dmaRef, bufferSize);
|
||||||
DMA_Cmd(motor->timerHardware->dmaRef, ENABLE);
|
DMA_Cmd(motor->timerHardware->dmaRef, ENABLE);
|
||||||
|
|
|
@ -59,7 +59,7 @@ void pwmWriteDigitalInt(uint8_t index, uint16_t value)
|
||||||
|
|
||||||
uint16_t packet = prepareDshotPacket(motor, value);
|
uint16_t packet = prepareDshotPacket(motor, value);
|
||||||
|
|
||||||
uint8_t bufferSize = loadDmaBufferPtr(motor, packet);
|
uint8_t bufferSize = loadDmaBuffer(motor, packet);
|
||||||
|
|
||||||
if (motor->timerHardware->output & TIMER_OUTPUT_N_CHANNEL) {
|
if (motor->timerHardware->output & TIMER_OUTPUT_N_CHANNEL) {
|
||||||
if (HAL_TIMEx_PWMN_Start_DMA(&motor->TimHandle, motor->timerHardware->channel, motor->dmaBuffer, bufferSize) != HAL_OK) {
|
if (HAL_TIMEx_PWMN_Start_DMA(&motor->TimHandle, motor->timerHardware->channel, motor->dmaBuffer, bufferSize) != HAL_OK) {
|
||||||
|
|
Loading…
Reference in New Issue