From 5a50f95f0822f8f7da67be77ee24b6468fef0b5e Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Wed, 12 Jun 2024 14:47:44 +0200 Subject: [PATCH] Increase max number of pwm outputs by 1, if a LED pin is defined --- src/main/drivers/pwm_mapping.c | 4 ++-- src/main/drivers/pwm_output.c | 4 ++-- src/main/drivers/pwm_output.h | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/drivers/pwm_mapping.c b/src/main/drivers/pwm_mapping.c index e953c86b96e..5ed17d7bb9a 100644 --- a/src/main/drivers/pwm_mapping.c +++ b/src/main/drivers/pwm_mapping.c @@ -53,8 +53,8 @@ enum { typedef struct { int maxTimMotorCount; int maxTimServoCount; - const timerHardware_t * timMotors[MAX_PWM_OUTPUT_PORTS]; - const timerHardware_t * timServos[MAX_PWM_OUTPUT_PORTS]; + const timerHardware_t * timMotors[MAX_PWM_OUTPUTS]; + const timerHardware_t * timServos[MAX_PWM_OUTPUTS]; } timMotorServoHardware_t; static pwmInitError_e pwmInitError = PWM_INIT_ERROR_NONE; diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c index d48f38679e9..faa9cd373d9 100644 --- a/src/main/drivers/pwm_output.c +++ b/src/main/drivers/pwm_output.c @@ -98,7 +98,7 @@ typedef struct { bool requestTelemetry; } pwmOutputMotor_t; -static DMA_RAM pwmOutputPort_t pwmOutputPorts[MAX_PWM_OUTPUT_PORTS]; +static DMA_RAM pwmOutputPort_t pwmOutputPorts[MAX_PWM_OUTPUTS]; static pwmOutputMotor_t motors[MAX_MOTORS]; static motorPwmProtocolTypes_e initMotorProtocol; @@ -142,7 +142,7 @@ static void pwmOutConfigTimer(pwmOutputPort_t * p, TCH_t * tch, uint32_t hz, uin static pwmOutputPort_t *pwmOutAllocatePort(void) { - if (allocatedOutputPortCount >= MAX_PWM_OUTPUT_PORTS) { + if (allocatedOutputPortCount >= MAX_PWM_OUTPUTS) { LOG_ERROR(PWM, "Attempt to allocate PWM output beyond MAX_PWM_OUTPUT_PORTS"); return NULL; } diff --git a/src/main/drivers/pwm_output.h b/src/main/drivers/pwm_output.h index b3c0fa6be0e..1041ace04fa 100644 --- a/src/main/drivers/pwm_output.h +++ b/src/main/drivers/pwm_output.h @@ -20,6 +20,12 @@ #include "drivers/io_types.h" #include "drivers/time.h" + +#if defined(WS2811_PIN) +#define MAX_PWM_OUTPUTS (MAX_PWM_OUTPUT_PORTS + 1) +#else +#define MAX_PWM_OUTPUTS (MAX_PWM_OUTPUT_PORTS) +#endif typedef enum { DSHOT_CMD_SPIN_DIRECTION_NORMAL = 20, DSHOT_CMD_SPIN_DIRECTION_REVERSED = 21,