hpw421初始版本
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
#include "pwm.h"
|
||||
#include "xc_drv_pwm.h"
|
||||
#include "rgblight.h"
|
||||
#include "mode.h"
|
||||
#include "math.h"
|
||||
#include <stdint.h>
|
||||
#include "timer.h"
|
||||
|
||||
|
||||
|
||||
// 定义一个变量来保存当前的 PWM 输出管脚设置
|
||||
uint8_t pwm_red_idx = PWM2_IDX;
|
||||
uint8_t pwm_green_idx = PWM3_IDX;
|
||||
uint8_t pwm_blue_idx = PWM5_IDX;
|
||||
/*------------------------------------------------------------------------------------
|
||||
TypeDef
|
||||
-------------------------------------------------------------------------------------*/
|
||||
|
||||
uint16_t ch0_capture_data[CAPTURE_DATA_MAX];
|
||||
uint16_t ch1_capture_data[CAPTURE_DATA_MAX];
|
||||
uint16_t ch2_capture_data[CAPTURE_DATA_MAX];
|
||||
|
||||
PWM_CAP_STA_TypeDef pwm_cap_state = PWM_CAP_IDLE;
|
||||
PWM_BRK_STA_TypeDef pwm_brk_state = PWM_BRK_IDLE;
|
||||
PWM_BRK_CAP_STA_TypeDef pwm_brk_cap_state = PWM_BRK_CAP_VALID;
|
||||
pwm_ch_cap_dutycycle_t pwm_ch_cap_dutycycle;
|
||||
pwm_ch_cap_freq_t pwm_ch_cap_freq;
|
||||
pwm_ch_cap_type_t pwm_ch_cap_type;
|
||||
|
||||
uint8_t Brightness=100; //100级
|
||||
PWM_Channel_t PWM_WarmLight_t={100,127,0,1}; // 暖光PWM
|
||||
PWM_Channel_t PWM_CoolLight_t={100,127,0,1}; // 冷光PWM
|
||||
|
||||
|
||||
// 切换 PWM 输出管脚,蓝牙调用此方法,切换设备输出线序
|
||||
void switch_pwm_pins(uint8_t red_pwm, uint8_t green_pwm, uint8_t blue_pwm)
|
||||
{
|
||||
pwm_red_idx = red_pwm;
|
||||
pwm_green_idx = green_pwm;
|
||||
pwm_blue_idx = blue_pwm;
|
||||
}
|
||||
|
||||
|
||||
|
||||
float brightness_table[101] = {
|
||||
0.006f, 0.006f, 0.006f, 0.006f, 0.006f,
|
||||
0.006f, 0.006f, 0.006f, 0.007f, 0.008f,
|
||||
0.009f, 0.010f, 0.011f, 0.013f, 0.015f,
|
||||
0.018f, 0.020f, 0.023f, 0.026f, 0.029f,
|
||||
0.032f, 0.036f, 0.039f, 0.043f, 0.047f,
|
||||
0.052f, 0.056f, 0.061f, 0.066f, 0.071f,
|
||||
0.076f, 0.082f, 0.087f, 0.093f, 0.099f,
|
||||
0.106f, 0.112f, 0.119f, 0.126f, 0.133f,
|
||||
0.141f, 0.148f, 0.156f, 0.164f, 0.173f,
|
||||
0.181f, 0.190f, 0.199f, 0.208f, 0.218f,
|
||||
0.227f, 0.237f, 0.247f, 0.258f, 0.268f,
|
||||
0.279f, 0.290f, 0.302f, 0.313f, 0.325f,
|
||||
0.337f, 0.349f, 0.362f, 0.375f, 0.388f,
|
||||
0.401f, 0.414f, 0.428f, 0.442f, 0.456f,
|
||||
0.471f, 0.485f, 0.500f, 0.516f, 0.531f,
|
||||
0.547f, 0.563f, 0.579f, 0.595f, 0.612f,
|
||||
0.629f, 0.646f, 0.664f, 0.681f, 0.699f,
|
||||
0.718f, 0.736f, 0.755f, 0.774f, 0.793f,
|
||||
0.813f, 0.832f, 0.852f, 0.873f, 0.893f,
|
||||
0.914f, 0.935f, 0.957f, 0.978f, 1.000f,1.000f
|
||||
};
|
||||
|
||||
|
||||
|
||||
void _PWM_INIT(){
|
||||
|
||||
GPIO_InitCfg_t GPIO_InitCfg = { 0 }; // 清零初始化配置结构体
|
||||
GPIO_InitCfg.Mux = GPIO_Mux0; // 选择功能复用器0
|
||||
GPIO_InitCfg.FunSel = GPIO_Dx; // 选择GPIO功能(非特殊功能)
|
||||
GPIO_InitCfg.Pull = GPIO_PULLUP; // 上拉电阻使能
|
||||
|
||||
GPIO_InitCfg.Dir = GPIO_DIR_OUTPUT; // 输出方向
|
||||
GPIO_InitCfg.Int = NOT_INT; // 不使能中断
|
||||
GPIO_InitCfg.Pin = _PWM_W; // 设置LED1引脚
|
||||
xc_gpio_init(&GPIO_InitCfg); // 初始化GPIO
|
||||
|
||||
GPIO_InitCfg.Dir = GPIO_DIR_OUTPUT; // 输出方向
|
||||
GPIO_InitCfg.Int = NOT_INT; // 不使能中断
|
||||
GPIO_InitCfg.Pin = _PWM_C; // 设置LED1引脚
|
||||
xc_gpio_init(&GPIO_InitCfg); // 初始化GPIO
|
||||
|
||||
|
||||
}
|
||||
|
||||
void PWM_SetDuty(uint8_t PWMX ,uint8_t duty) {
|
||||
if(PWMX==_PWM_W){
|
||||
PWM_WarmLight_t.duty_cycle=duty;
|
||||
}else if(PWMX ==_PWM_C){
|
||||
PWM_CoolLight_t.duty_cycle=duty;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateDisplay(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief app_pwm_init
|
||||
* @details
|
||||
* @param void
|
||||
* @retval void
|
||||
*/
|
||||
void app_pwm_init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user