添加led
This commit is contained in:
parent
e6a370793d
commit
3d6efbed18
17
Core/Inc/led.h
Normal file
17
Core/Inc/led.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef __LED_H
|
||||||
|
#define __LED_H
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
#define LED_R 1
|
||||||
|
#define LED_G 2
|
||||||
|
#define LED_B 4
|
||||||
|
#define LED_ALL 7
|
||||||
|
|
||||||
|
void LED_Start(uint8_t led);
|
||||||
|
void LED_Stop(uint8_t led);
|
||||||
|
|
||||||
|
// duty in [0, 100]
|
||||||
|
void LED_SetDuty(uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
|
||||||
|
#endif
|
34
Core/Src/led.c
Normal file
34
Core/Src/led.c
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#include "led.h"
|
||||||
|
#include "tim.h"
|
||||||
|
|
||||||
|
#define LED_TIM (&htim3)
|
||||||
|
#define LED_R_CHAN TIM_CHANNEL_4
|
||||||
|
#define LED_G_CHAN TIM_CHANNEL_3
|
||||||
|
#define LED_B_CHAN TIM_CHANNEL_2
|
||||||
|
|
||||||
|
void LED_Start(uint8_t led)
|
||||||
|
{
|
||||||
|
if (led & LED_R)
|
||||||
|
HAL_TIM_PWM_Start(LED_TIM, LED_R_CHAN);
|
||||||
|
if (led & LED_G)
|
||||||
|
HAL_TIM_PWM_Start(LED_TIM, LED_G_CHAN);
|
||||||
|
if (led & LED_B)
|
||||||
|
HAL_TIM_PWM_Start(LED_TIM, LED_B_CHAN);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LED_Stop(uint8_t led)
|
||||||
|
{
|
||||||
|
if (led & LED_R)
|
||||||
|
HAL_TIM_PWM_Stop(LED_TIM, LED_R_CHAN);
|
||||||
|
if (led & LED_G)
|
||||||
|
HAL_TIM_PWM_Stop(LED_TIM, LED_G_CHAN);
|
||||||
|
if (led & LED_B)
|
||||||
|
HAL_TIM_PWM_Stop(LED_TIM, LED_B_CHAN);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LED_SetDuty(uint8_t r, uint8_t g, uint8_t b)
|
||||||
|
{
|
||||||
|
__HAL_TIM_SetCompare(LED_TIM, LED_R_CHAN, r);
|
||||||
|
__HAL_TIM_SetCompare(LED_TIM, LED_G_CHAN, g);
|
||||||
|
__HAL_TIM_SetCompare(LED_TIM, LED_B_CHAN, b);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user