Skip to content

Commit 58101c3

Browse files
committed
platform/cplus: don't invert LED PWMs
This removes the inversion on the LED PWM channels. This way we don't have to compute the inverse when setting the PWM duty cycle. Also divide by 256 instead of 255 to further reduce firmware size.
1 parent 05a3e50 commit 58101c3

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

lib/pbio/drv/cplus_hub/light.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ pbio_error_t pbdrv_light_set_rgb(pbio_port_t port, const pbdrv_light_raw_rgb_t *
2121

2222
pbdrv_pwm_dev_t *dev;
2323
if (pbdrv_pwm_get_dev(1, &dev) == PBIO_SUCCESS) {
24-
pbdrv_pwm_set_duty(dev, 2, 10000 - raw->r * 2000 / 255);
24+
pbdrv_pwm_set_duty(dev, 2, raw->r * 2000 / 256);
2525
}
2626
if (pbdrv_pwm_get_dev(0, &dev) == PBIO_SUCCESS) {
27-
pbdrv_pwm_set_duty(dev, 4, 10000 - raw->g * 2000 / 255);
27+
pbdrv_pwm_set_duty(dev, 4, raw->g * 2000 / 256);
2828
}
2929
if (pbdrv_pwm_get_dev(2, &dev) == PBIO_SUCCESS) {
30-
pbdrv_pwm_set_duty(dev, 1, 10000 - raw->b * 2000 / 255);
30+
pbdrv_pwm_set_duty(dev, 1, raw->b * 2000 / 256);
3131
}
3232

3333
return PBIO_SUCCESS;

lib/pbio/platform/cplus_hub/platform.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const pbdrv_pwm_stm32_tim_platform_data_t
103103
.channels = PBDRV_PWM_STM32_TIM_CHANNEL_1_ENABLE | PBDRV_PWM_STM32_TIM_CHANNEL_2_ENABLE
104104
| PBDRV_PWM_STM32_TIM_CHANNEL_3_ENABLE | PBDRV_PWM_STM32_TIM_CHANNEL_4_ENABLE
105105
| PBDRV_PWM_STM32_TIM_CHANNEL_1_INVERT | PBDRV_PWM_STM32_TIM_CHANNEL_2_INVERT
106-
| PBDRV_PWM_STM32_TIM_CHANNEL_3_INVERT | PBDRV_PWM_STM32_TIM_CHANNEL_4_INVERT
106+
| PBDRV_PWM_STM32_TIM_CHANNEL_3_INVERT
107107
| PBDRV_PWM_STM32_TIM_CHANNEL_1_COMPLEMENT | PBDRV_PWM_STM32_TIM_CHANNEL_2_COMPLEMENT
108108
| PBDRV_PWM_STM32_TIM_CHANNEL_3_COMPLEMENT,
109109
},
@@ -114,16 +114,15 @@ const pbdrv_pwm_stm32_tim_platform_data_t
114114
.period = 10000, // 12MHz divided by 10k makes 1 kHz PWM
115115
.id = PWM_DEV_1,
116116
.channels = PBDRV_PWM_STM32_TIM_CHANNEL_1_ENABLE | PBDRV_PWM_STM32_TIM_CHANNEL_2_ENABLE
117-
| PBDRV_PWM_STM32_TIM_CHANNEL_1_INVERT | PBDRV_PWM_STM32_TIM_CHANNEL_2_INVERT
118-
| PBDRV_PWM_STM32_TIM_CHANNEL_1_COMPLEMENT,
117+
| PBDRV_PWM_STM32_TIM_CHANNEL_1_INVERT | PBDRV_PWM_STM32_TIM_CHANNEL_1_COMPLEMENT,
119118
},
120119
{
121120
.platform_init = pwm_dev_2_platform_init,
122121
.TIMx = TIM16,
123122
.prescalar = 8, // results in 10 MHz clock
124123
.period = 10000, // 12MHz divided by 10k makes 1 kHz PWM
125124
.id = PWM_DEV_2,
126-
.channels = PBDRV_PWM_STM32_TIM_CHANNEL_1_ENABLE | PBDRV_PWM_STM32_TIM_CHANNEL_1_INVERT,
125+
.channels = PBDRV_PWM_STM32_TIM_CHANNEL_1_ENABLE,
127126
},
128127
};
129128

0 commit comments

Comments
 (0)