#include "FreeRTOS.h"
#include "queue.h"
#include "task.h"
#include "timers.h"
#include "pwm_rgb.h"
#include "color_light_control.h"
#include "ci130x_pwm.h"
#include "ci130x_scu.h"
#include "ci130x_gpio.h"
#include "ci130x_dpmu.h"

TimerHandle_t rgb_time_Handle;

void RGB_TIMEOUT_CallBack( TimerHandle_t xTimer );
void warm_light_TIMEOUT_CallBack( TimerHandle_t xTimer );

void pwm_rgb_init(void)
{
	pwm_init_t pwm_config;

	dpmu_osc_pad_for_gpio(ENABLE);
	scu_set_device_gate(LIGHT_R_PWM_BASE,ENABLE); //PWM5 PA0
	scu_set_device_gate(LIGHT_G_PWM_BASE,ENABLE); //PWM4 PA6
	scu_set_device_gate(LIGHT_B_PWM_BASE,ENABLE); //PWM3 PA5

	/*R PWM5 PA0*/
	dpmu_set_adio_reuse(LIGHT_R_PAD_NAME,DIGITAL_MODE);
	dpmu_set_io_reuse(LIGHT_R_PAD_NAME,SECOND_FUNCTION);              //设置引脚功能复用
	dpmu_set_io_direction(LIGHT_R_PAD_NAME,DPMU_IO_DIRECTION_OUTPUT); //设置引脚功能为输出模式
	dpmu_set_io_pull(LIGHT_R_PAD_NAME,DPMU_IO_PULL_DISABLE);          //设置关闭上下拉
	pwm_init_t pwm_5_init;
	pwm_5_init.clk_sel = 0;
	pwm_5_init.freq = 10000;
	pwm_5_init.duty = 500;
	pwm_5_init.duty_max = 1000;
	pwm_set_restart_md(LIGHT_R_PWM_NAME,1);
	pwm_init(LIGHT_R_PWM_NAME,pwm_5_init);
	pwm_stop(LIGHT_R_PWM_NAME);

	/*G PWM4 PA6*/
	dpmu_set_io_reuse(LIGHT_G_PAD_NAME,FIFTH_FUNCTION);                //设置引脚功能复用
	dpmu_set_io_direction(LIGHT_G_PAD_NAME,DPMU_IO_DIRECTION_OUTPUT); //设置引脚功能为输出模式
	dpmu_set_io_pull(LIGHT_G_PAD_NAME,DPMU_IO_PULL_DISABLE);          //设置关闭上下拉
	pwm_init_t pwm_4_init;
	pwm_4_init.clk_sel = 0;
	pwm_4_init.freq = 10000;
	pwm_4_init.duty = 500;
	pwm_4_init.duty_max = 1000;
	pwm_set_restart_md(LIGHT_G_PWM_NAME,1);
	pwm_init(LIGHT_G_PWM_NAME,pwm_4_init);
	pwm_stop(LIGHT_G_PWM_NAME);

	/*B PWM3 PA5*/
	dpmu_set_io_reuse(LIGHT_B_PAD_NAME,FIFTH_FUNCTION);                //设置引脚功能复用
	dpmu_set_io_direction(LIGHT_B_PAD_NAME,DPMU_IO_DIRECTION_OUTPUT); //设置引脚功能为输出模式
	dpmu_set_io_pull(LIGHT_B_PAD_NAME,DPMU_IO_PULL_DISABLE);          //设置关闭上下拉
	pwm_init_t pwm_3_init;
	pwm_3_init.clk_sel = 0;
	pwm_3_init.freq = 10000;
	pwm_3_init.duty = 500;
	pwm_3_init.duty_max = 1000;
	pwm_set_restart_md(LIGHT_B_PWM_NAME,1);
	pwm_init(LIGHT_B_PWM_NAME,pwm_3_init);
	pwm_stop(LIGHT_B_PWM_NAME);

}

void set_rgb_colour_t(uint16_t colour_r,uint16_t colour_g,uint16_t colour_b,uint16_t max)
{
	pwm_start(LIGHT_R_PWM_NAME);
	pwm_start(LIGHT_G_PWM_NAME);
	pwm_start(LIGHT_B_PWM_NAME);
	pwm_set_duty(LIGHT_R_PWM_NAME,colour_r,max);
	pwm_set_duty(LIGHT_G_PWM_NAME,colour_g,max);
	pwm_set_duty(LIGHT_B_PWM_NAME,colour_b,max);
}

void rgb_off(void)
{
	xTimerStop(rgb_time_Handle,0);
	pwm_set_duty(LIGHT_R_PWM_NAME,0,500);
	pwm_set_duty(LIGHT_G_PWM_NAME,0,500);
	pwm_set_duty(LIGHT_B_PWM_NAME,0,500);
	// pwm_stop(LIGHT_R_PWM_NAME);
	// pwm_stop(LIGHT_G_PWM_NAME);
	// pwm_stop(LIGHT_B_PWM_NAME);
}

void rgb_on(void)
{
	// pwm_rgb_init();
	rgb_time_Handle = xTimerCreate("rgb_time", pdMS_TO_TICKS(10), pdTRUE, (void *)1,RGB_TIMEOUT_CallBack);
	xTimerStart(rgb_time_Handle,0);
}

void night_light_on(void)
{
	xTimerStop(rgb_time_Handle,0);//关闭RGB
	set_rgb_colour_t(174,255,0,500);
}

void warm_light_off_callback(TimerHandle_t xTimer)
{
	rgb_off();
}

void warm_light_TIMEOUT_CallBack( TimerHandle_t xTimer )
{
	rgb_off();
}

void RGB_TIMEOUT_CallBack( TimerHandle_t xTimer )
{
static uint8_t blink_state = 0;

if(blink_state == 0) //红灯开
{
set_rgb_colour_t(255, 0, 0, 500); //设置红灯为最亮
blink_state = 1;
}
else //红灯关
{
rgb_off(); //关闭所有灯
blink_state = 0;
}
}
你能把这个程序实现呼吸灯功能的部分改成实现红灯一直持续不断地闪烁的功能的程序吗