|
@ -15,6 +15,7 @@ static uint32_t s_timing_time; // |
|
|
static uint32_t s_interval_period = 0; //间歇功能的周期 |
|
|
static uint32_t s_interval_period = 0; //间歇功能的周期 |
|
|
static uint8_t s_now_interval_duty = 0; //间歇功能的占空比 |
|
|
static uint8_t s_now_interval_duty = 0; //间歇功能的占空比 |
|
|
static uint8_t s_intervalkey_press_count = 0; //间歇按键按下的次数 |
|
|
static uint8_t s_intervalkey_press_count = 0; //间歇按键按下的次数 |
|
|
|
|
|
uint8_t rgb_ticket_count = 3; |
|
|
|
|
|
|
|
|
WORK_LEVEL_T now_level; //现在的档位 |
|
|
WORK_LEVEL_T now_level; //现在的档位 |
|
|
WORK_LEVEL_T shutdown_before_level; //关机前的档位 |
|
|
WORK_LEVEL_T shutdown_before_level; //关机前的档位 |
|
@ -42,6 +43,8 @@ bool HOOK_pwm_is_enable(void) { return pwm_modble_enable_falg; } |
|
|
void process_intervalkey_press_even(void) { |
|
|
void process_intervalkey_press_even(void) { |
|
|
s_intervalkey_press_count++; |
|
|
s_intervalkey_press_count++; |
|
|
if (s_intervalkey_press_count == 1) { |
|
|
if (s_intervalkey_press_count == 1) { |
|
|
|
|
|
//间歇功能开启后rgb亮三秒灭一秒,为了让用户更快的知道间歇功能已经开启,所以rgb_ticket_count设置3,先让rgb灭1s |
|
|
|
|
|
rgb_ticket_count = 3; |
|
|
update_interval_period_duty(50); |
|
|
update_interval_period_duty(50); |
|
|
} else { |
|
|
} else { |
|
|
update_interval_period_duty(100); // 调用update_interval_period_duty(100)后将s_intervalkey_press_count=0 |
|
|
update_interval_period_duty(100); // 调用update_interval_period_duty(100)后将s_intervalkey_press_count=0 |
|
@ -94,7 +97,6 @@ void restore_the_mode_before_intermittent_work(void) { |
|
|
*/ |
|
|
*/ |
|
|
void process_rgb_flicker(void) { |
|
|
void process_rgb_flicker(void) { |
|
|
static uint32_t rgb_ticket = 0; |
|
|
static uint32_t rgb_ticket = 0; |
|
|
static uint8_t rgb_ticket_count = 0; |
|
|
|
|
|
if (port_haspassedms(rgb_ticket) > 1000) { |
|
|
if (port_haspassedms(rgb_ticket) > 1000) { |
|
|
rgb_ticket = get_sys_ticket(); |
|
|
rgb_ticket = get_sys_ticket(); |
|
|
if (rgb_ticket_count < 3) { |
|
|
if (rgb_ticket_count < 3) { |
|
@ -405,6 +407,74 @@ void process_error_even(void) { |
|
|
* =======================================================测试======================================================== |
|
|
* =======================================================测试======================================================== |
|
|
** |
|
|
** |
|
|
***********************************************************************************************************************/ |
|
|
***********************************************************************************************************************/ |
|
|
|
|
|
void test_adc(void) { |
|
|
|
|
|
while (1) { |
|
|
|
|
|
ADC_InitStruType x; |
|
|
|
|
|
GPIO_InitSettingType y; |
|
|
|
|
|
y.Signal = GPIO_Pin_Signal_Analog; //模拟 |
|
|
|
|
|
y.Dir = GPIO_Direction_Input; //输入 |
|
|
|
|
|
y.Func = GPIO_Reuse_Func0; |
|
|
|
|
|
// x.CHS设置adc采集的通道每个引脚对应一个通道 |
|
|
|
|
|
GPIO_Init(GPIO_Pin_A2, &y); |
|
|
|
|
|
|
|
|
|
|
|
//经过分频以后Tadclk=1/(PCLK/4)约等于0.083us |
|
|
|
|
|
x.CLKS = ADC_CLKS_PCLK; |
|
|
|
|
|
x.CLKDIV = ADC_CLKDIV_1_32; /* ADC时钟源预分频 */ |
|
|
|
|
|
|
|
|
|
|
|
//采集到的模拟量*3.3/4096=现在的电压 |
|
|
|
|
|
|
|
|
|
|
|
x.VREF_SEL = ADC_VREF_SEL_0; /* 内部参考电压2.048v,仅设置内部参考电压为多少 */ |
|
|
|
|
|
x.VREFP = ADC_VREFP_VDD; /* 选择芯片的工作电压VDD,这个是设置adc具体是要哪个电压来做参考adc的参考电压为多少 */ |
|
|
|
|
|
x.VREFN = ADC_VREFN_VSS; /* 负向参考电压选择 */ |
|
|
|
|
|
x.CHS = ADC_CHS_AIN8; |
|
|
|
|
|
x.SMPS = ADC_SMPS_SOFT; /* AD采样模式为软件控制 */ |
|
|
|
|
|
//采样时间st*2+1(个Tadclk)=1.743us |
|
|
|
|
|
x.ST = 10; /* AD硬件采样时间选择 */ |
|
|
|
|
|
x.BITSEL = ADC_BITSEL_12; /* AD分辨率12位 */ |
|
|
|
|
|
ADC_Init(&x); |
|
|
|
|
|
uint32_t pa2_adc_val = 0; |
|
|
|
|
|
ADC_SoftStart(); |
|
|
|
|
|
ADC_SoftStop(); |
|
|
|
|
|
//正在转换 |
|
|
|
|
|
while (ADC_GetConvStatus() != RESET) |
|
|
|
|
|
; |
|
|
|
|
|
pa2_adc_val = ADC_GetConvValue(); |
|
|
|
|
|
printf("%d\r\n", pa2_adc_val); |
|
|
|
|
|
printf("pa2_adc_valpa2_val:%lf\r\n", pa2_adc_val * 3.3 / 4096); |
|
|
|
|
|
|
|
|
|
|
|
y.Signal = GPIO_Pin_Signal_Analog; //模拟 |
|
|
|
|
|
y.Dir = GPIO_Direction_Input; //输入 |
|
|
|
|
|
y.Func = GPIO_Reuse_Func0; |
|
|
|
|
|
// x.CHS设置adc采集的通道每个引脚对应一个通道 |
|
|
|
|
|
GPIO_Init(GPIO_Pin_B8, &y); |
|
|
|
|
|
|
|
|
|
|
|
//经过分频以后Tadclk=1/(PCLK/4)约等于0.083us |
|
|
|
|
|
x.CLKS = ADC_CLKS_PCLK; |
|
|
|
|
|
x.CLKDIV = ADC_CLKDIV_1_32; /* ADC时钟源预分频 */ |
|
|
|
|
|
|
|
|
|
|
|
//采集到的模拟量*3.3/4096=现在的电压 |
|
|
|
|
|
|
|
|
|
|
|
x.VREF_SEL = ADC_VREF_SEL_0; /* 内部参考电压2.048v,仅设置内部参考电压为多少 */ |
|
|
|
|
|
x.VREFP = ADC_VREFP_VDD; /* 选择芯片的工作电压VDD,这个是设置adc具体是要哪个电压来做参考adc的参考电压为多少 */ |
|
|
|
|
|
x.VREFN = ADC_VREFN_VSS; /* 负向参考电压选择 */ |
|
|
|
|
|
x.CHS = ADC_CHS_AIN3; |
|
|
|
|
|
x.SMPS = ADC_SMPS_SOFT; /* AD采样模式为软件控制 */ |
|
|
|
|
|
//采样时间st*2+1(个Tadclk)=1.743us |
|
|
|
|
|
x.ST = 10; /* AD硬件采样时间选择 */ |
|
|
|
|
|
x.BITSEL = ADC_BITSEL_12; /* AD分辨率12位 */ |
|
|
|
|
|
ADC_Init(&x); |
|
|
|
|
|
uint32_t pb8_adc_val = 0; |
|
|
|
|
|
ADC_SoftStart(); |
|
|
|
|
|
ADC_SoftStop(); |
|
|
|
|
|
//正在转换 |
|
|
|
|
|
while (ADC_GetConvStatus() != RESET) |
|
|
|
|
|
; |
|
|
|
|
|
pb8_adc_val = ADC_GetConvValue(); |
|
|
|
|
|
printf("pb8_adc_val%d\r\n", pb8_adc_val); |
|
|
|
|
|
printf("pb8_val:%lf\r\n", pb8_adc_val * 3.3 / 4096); |
|
|
|
|
|
Delayms(1000); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
void test(void) { |
|
|
void test(void) { |
|
|
port_fan_set(false); |
|
|
port_fan_set(false); |
|
|
Delayms(10000); |
|
|
Delayms(10000); |
|
@ -464,12 +534,13 @@ int main(void) { |
|
|
// iwdt_init(); |
|
|
// iwdt_init(); |
|
|
power_on_ozone_working_status(); |
|
|
power_on_ozone_working_status(); |
|
|
printf("Initialization completed\r\n"); |
|
|
printf("Initialization completed\r\n"); |
|
|
//test(); |
|
|
|
|
|
|
|
|
// test(); |
|
|
|
|
|
// test_adc(); |
|
|
while (true) { |
|
|
while (true) { |
|
|
port_do_debug_light_state(); |
|
|
port_do_debug_light_state(); |
|
|
// feed_iwdt(); |
|
|
// feed_iwdt(); |
|
|
static uint32_t keylastprocess = 0; |
|
|
static uint32_t keylastprocess = 0; |
|
|
if (port_haspassedms(keylastprocess) > 20) { |
|
|
|
|
|
|
|
|
if (port_haspassedms(keylastprocess) > 40) { |
|
|
keylastprocess = get_sys_ticket(); |
|
|
keylastprocess = get_sys_ticket(); |
|
|
zkey_do_loop_in_each_period(NULL); |
|
|
zkey_do_loop_in_each_period(NULL); |
|
|
} |
|
|
} |
|
|