34 #include <nuttx/config.h> 38 #include <arch/board/board.h> 39 #include "hardware/stm32_tim.h" 44 void rgb_led(
int r,
int g,
int b,
int freqs)
49 long p1s = fosc / prescale;
51 stm32_tim_channel_t
mode = (stm32_tim_channel_t)(STM32_TIM_CH_OUTPWM | STM32_TIM_CH_POLARITY_NEG);
52 static struct stm32_tim_dev_s *tim = 0;
55 tim = stm32_tim_init(3);
56 STM32_TIM_SETMODE(tim, STM32_TIM_MODE_UP);
57 STM32_TIM_SETCLOCK(tim, p1s - 8);
58 STM32_TIM_SETPERIOD(tim, p1s);
59 STM32_TIM_SETCOMPARE(tim, 1, 0);
60 STM32_TIM_SETCOMPARE(tim, 2, 0);
61 STM32_TIM_SETCOMPARE(tim, 3, 0);
62 STM32_TIM_SETCHANNEL(tim, 1, mode);
63 STM32_TIM_SETCHANNEL(tim, 2, mode);
64 STM32_TIM_SETCHANNEL(tim, 3, mode);
67 long p = freqs == 0 ? p1s : p1s / freqs;
68 STM32_TIM_SETPERIOD(tim, p);
70 p = freqs == 0 ? p1s + 1 : p0p5s / freqs;
72 STM32_TIM_SETCOMPARE(tim, 1, (r * p) / 255);
73 STM32_TIM_SETCOMPARE(tim, 2, (g * p) / 255);
74 STM32_TIM_SETCOMPARE(tim, 3, (b * p) / 255);
void rgb_led(int r, int g, int b, int freqs)