Browse Source

update

master
zhaohe 3 years ago
parent
commit
2df73f77e2
  1. 2
      .clang-format
  2. 183
      APP/adc.c
  3. 33
      APP/adc.h
  4. 12
      APP/board.h
  5. 67
      APP/key.c
  6. 29
      APP/key.h
  7. 194
      APP/light.c
  8. 38
      APP/light.h
  9. 688
      APP/main.c
  10. 2
      APP/main.h
  11. 6
      APP/ozone_pwm_control.c
  12. 3
      APP/ozone_pwm_control.h
  13. 20
      project_ozone/Listings/project_o.map
  14. 2
      project_ozone/Listings/startup_es8p5066.lst
  15. 1878
      project_ozone/project_o.uvgui.zel
  16. 4
      project_ozone/project_o.uvopt
  17. 7
      project_ozone/project_o.uvproj

2
.clang-format

@ -2,4 +2,4 @@
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
Language: Cpp
BasedOnStyle: Google
ColumnLimit: 120
ColumnLimit: 150

183
APP/adc.c

@ -1,59 +1,7 @@
#include "adc.h"
static adc_t s_adc[] = {
{.port = "A", .pin = 2},
{.port = "B", .pin = 8},
{.port = "B", .pin = 9},
};
/***********************************************************************************************************************
* =====================================================adc======================================================
**
***********************************************************************************************************************/
// uint16_t meanvalue;
adc_t adc = {0};
void ADCInit(uint8_t *port, uint8_t pin) {
// GPIO_PIN(A, 28);
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_B9, &y);
if (pin == 2) {
GPIO_Init(GPIO_Pin_A2, &y);
x.CHS = ADC_CHS_AIN8;
printf("A4\r\n");
} else if (pin == 8) {
GPIO_Init(GPIO_Pin_B8, &y);
x.CHS = ADC_CHS_AIN3;
printf("B8\r\n");
} else if (pin == 9) {
GPIO_Init(GPIO_Pin_B9, &y);
x.CHS = ADC_CHS_AIN4;
printf("B9\r\n");
}
//Tadclk=1/(PCLK/4)0.083us
x.CLKS = ADC_CLKS_PCLK;
x.CLKDIV = ADC_CLKDIV_1_4; /* 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_AIN4;
// 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);
}
//adc采集的电压值
void ADCPA2Init() {
// uint16_t meanvalue;
static void prv_adc_pa2_init() {
ADC_InitStruType x;
GPIO_InitSettingType y;
y.Signal = GPIO_Pin_Signal_Analog; //
@ -77,22 +25,9 @@ void ADCPA2Init() {
x.ST = 10; /* AD硬件采样时间选择 */
x.BITSEL = ADC_BITSEL_12; /* AD分辨率12位 */
ADC_Init(&x);
prv_adc_get_value();
}
void get_pa2_adc_value(void) {
volatile uint32_t pa2_adc_val = 0;
ADCPA2Init();
ADC_SoftStart();
//
while (ADC_GetConvStatus() != RESET)
;
pa2_adc_val = ADC_GetConvValue();
ADC_SoftStop();
printf("%d\r\n", pa2_adc_val);
printf("pa2_val:%lf\r\n", pa2_adc_val * 3.3 / 4096);
}
void ADCPB8Init() {
static void prv_adc_pb8_init() {
ADC_InitStruType x;
GPIO_InitSettingType y;
y.Signal = GPIO_Pin_Signal_Analog; //
@ -116,22 +51,10 @@ void ADCPB8Init() {
x.ST = 10; /* AD硬件采样时间选择 */
x.BITSEL = ADC_BITSEL_12; /* AD分辨率12位 */
ADC_Init(&x);
prv_adc_get_value();
}
void get_pb8_adc_value(void) {
volatile uint32_t pb8_adc_val = 0;
ADCPB8Init();
ADC_SoftStart();
//
while (ADC_GetConvStatus() != RESET)
;
pb8_adc_val = ADC_GetConvValue();
ADC_SoftStop();
printf("%d\r\n", pb8_adc_val);
printf("pb8_val:%lf\r\n", pb8_adc_val * 3.3 / 4096);
}
void ADCPB9Init() {
static void prv_adc_pb9_init() {
ADC_InitStruType x;
GPIO_InitSettingType y;
y.Signal = GPIO_Pin_Signal_Analog; //
@ -156,89 +79,39 @@ void ADCPB9Init() {
x.ST = 10; /* AD硬件采样时间选择 */
x.BITSEL = ADC_BITSEL_12; /* AD分辨率12位 */
ADC_Init(&x);
prv_adc_get_value();
}
void get_pb9_adc_value(void) {
volatile uint32_t pb9_adc_val = 0;
ADCPB9Init();
static float prv_adc_get_value() {
ADC_SoftStart();
//
while (ADC_GetConvStatus() != RESET)
;
pb9_adc_val = ADC_GetConvValue();
uint16_t adcv = ADC_GetConvValue();
ADC_SoftStop();
printf("%d\r\n", pb9_adc_val);
printf("pb9_val:%lf\r\n", pb9_adc_val * 3.3 / 4096);
printf("%d\r\n", adcv);
return adcv * 3.3 / 4096;
}
void try_adc_gather(void) {
static uint32_t adc_ticket = 0;
// static uint32_t adc_ticket_count = 0;
if (port_haspassedms(adc_ticket) > 1000) {
// adc_ticket_count++;
adc_ticket = get_sys_ticket();
// if (adc_ticket_count < 5) {
get_pb8_adc_value();
get_pa2_adc_value();
get_pb9_adc_value();
// }
// get_adc_value();
// if (adc_ticket_count >= 5) {
// if (adc_ticket_count == 10) {
// adc_ticket_count = 0;
// }
// ADC_Disable();
// get_pa2_adc_value();
// }
static float prv_adc_get_value_average(int average) {
if (average == 0) {
average = 1;
}
}
void get_adc_value(void) {
// uint16_t adc_value = 0;
for (int i = 0; i < 3; i++) {
ADCInit(s_adc[i].port, s_adc[i].pin);
ADC_SoftStart();
while (ADC_GetConvStatus() == SET)
; //
s_adc[i].adc_just_now_gather_val = ADC_GetConvValue();
ADC_SoftStop();
// record_adc_gather_value(s_adc[i].adc_just_now_gather_val);
printf("%d\r\n", s_adc[i].adc_just_now_gather_val);
printf("voltage:%lf\r\n", (s_adc[i].adc_just_now_gather_val) * 3.3 / 4096);
float value = 0;
for (size_t i = 0; i < average; i++) {
value += prv_adc_get_value();
}
return value / average;
}
void record_adc_gather_value(uint16_t adc_value) {
/**
* @brief adc各个通道采集到的数据
*
*/
for (int i = 0; i < 3; i++) {
s_adc[i].adc_value_buff[s_adc[i].adc_value_count++] = adc_value;
if (s_adc[i].adc_value_count == 5) {
s_adc[i].past_count_reached_five = true;
s_adc[i].adc_value_count = 0;
}
if (s_adc[i].past_count_reached_five == true) {
beg_average_value(s_adc[i].adc_value_buff);
}
}
float adc_get_value_pa2(void) {
prv_adc_pa2_init();
return prv_adc_get_value_average(AVERAGE_TABLE_SIZE);
}
void beg_average_value(uint16_t *adc_buff) {
// uint16_t adc_average_value = 0;
// uint32_t adc_sum_value = 0;
// for (int i = 0; i < 5; i++) {
// adc_sum_value += *adc_buff;
// adc_buff++;
// }
// adc_average_value = adc_sum_value / 5;
// if (adc_average_value <= 16 || adc.abnormal_state == true) {
// adc.abnormal_state = true;
// process_voltage_abnormal();
// // printf("short out%d\r\n", adc_average_value); //
// } else {
// //adc_value=1700=1700/4096=1.369
// printf("adc_value_t%d\r\n", adc_average_value);
// }
float adc_get_value_pb8(void) {
prv_adc_pb8_init();
return prv_adc_get_value_average(AVERAGE_TABLE_SIZE);
}
float adc_get_value_pb9(void) {
prv_adc_pb9_init();
return prv_adc_get_value_average(AVERAGE_TABLE_SIZE);
}

33
APP/adc.h

@ -1,33 +1,10 @@
#ifndef _ADC_H_
#define _ADC_H_
#pragma once
#include "port.h"
#include "systick.h"
void ADCInit(uint8_t *port, uint8_t pin);
void ADCPA2Init();
void get_adc_value(void);
void get_pa2_adc_value(void);
void try_adc_gather(void);
void beg_average_value(uint16_t *adc_buff);
typedef struct {
bool abnormal_state;
bool past_count_reached_five;
bool first_detection_abnormal;
uint16_t adc_value_buff[5];
uint8_t adc_value_count;
uint16_t adc_just_now_gather_val;
uint8_t *port;
uint8_t pin;
} adc_t;
void record_adc_gather_value(uint16_t adc_value);
// typedef struct {
// uint16_t adc_value_buff[5];
// uint8_t adc_value_count;
// bool abnormal_state;
// bool past_count_reached_five; //ÏûʹÓÃ
// } adc_t;
#define AVERAGE_TABLE_SIZE 30
#endif
float adc_get_value_pa2(void);
float adc_get_value_pb8(void);
float adc_get_value_pb9(void);

12
APP/board.h

@ -0,0 +1,12 @@
#pragma once
#define VERSION "1.0"
#define KEY_PERIOD 20
#define EXCEPTION_CHECK_PERIOD 50
//
#define AUTO_SHUTDOWN_ONE_LIGHT_EQ_TIME_S 20
//
#define INTERVAL_WORK_PERIOD_MS (60 * 1000)
//
#define INTERVAL_WORK_DUTY (50)

67
APP/key.c

@ -1,4 +1,30 @@
#include "key.h"
static zkey_module_t *s_module;
static bool s_inited;
static void prv_zkey_process_each_after_filter(zkey_t *each, bool now_io_state) {
if (now_io_state != each->last_io_state) {
if (now_io_state) {
each->keep_state_count = 0;
each->hasProcessed = false;
each->cur_state = zks_rising_edge;
s_module->onkey(each, each->cur_state);
} else {
each->cur_state = zks_falling_edge;
s_module->onkey(each, each->cur_state);
each->keep_state_count = 0;
}
each->last_io_state = now_io_state;
} else {
each->cur_state = zks_keep;
if (now_io_state) {
s_module->onkey(each, each->cur_state);
}
}
}
void zkey_process_each(zkey_t *each);
void zkey_init(zkey_module_t *module) {
/**
* @brief
@ -13,18 +39,6 @@ void zkey_init(zkey_module_t *module) {
s_module->keys[i].after_filter_state = s_module->keys[i].get_key_state();
}
}
void zkey_do_loop_in_each_period(void *_null) { /**
* @brief
*
*/
if (!s_inited) return;
for (int i = 0; i < s_module->nkey; i++) //
{
zkey_process_each(&s_module->keys[i]);
}
}
void zkey_process_each(zkey_t *each) {
/**
* @brief
@ -46,27 +60,16 @@ void zkey_process_each(zkey_t *each) {
each->after_filter_state = now_io_state;
}
each->last_real_state = now_io_state;
zkey_process_each_after_filter(each, each->after_filter_state);
prv_zkey_process_each_after_filter(each, each->after_filter_state);
}
void zkey_process_each_after_filter(zkey_t *each, bool now_io_state) {
if (now_io_state != each->last_io_state) {
if (now_io_state) {
each->keep_state_count = 0;
each->hasProcessed = false;
each->cur_state = zks_rising_edge;
s_module->onkey(each, each->cur_state);
} else {
each->cur_state = zks_falling_edge;
s_module->onkey(each, each->cur_state);
each->keep_state_count = 0;
}
each->last_io_state = now_io_state;
} else {
each->cur_state = zks_keep;
if (now_io_state) {
s_module->onkey(each, each->cur_state);
}
void zkey_do_loop_in_each_period(void *_null) { /**
* @brief
*
*/
if (!s_inited) return;
for (int i = 0; i < s_module->nkey; i++) //
{
zkey_process_each(&s_module->keys[i]);
}
}

29
APP/key.h

@ -3,6 +3,8 @@
#include "port.h"
#include "pwm.h"
#define POWER_KEY_TRIGGER_TIME 3000
#define KEY_SCAN_PERIOD 20 //扫描周期20ms
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#define ZKEY_INIT(_name, _get_key_state) \
{ .name = _name, .get_key_state = _get_key_state }
@ -13,6 +15,8 @@
.onkey = _onkey /**/ \
}
typedef bool (*get_key_state_t)(void);
typedef enum {
// mode1
zks_keep,
@ -22,11 +26,11 @@ typedef enum {
// mode2
zks_trigger_event, //
zks_longtime_trigger_event, //
} zkey_event_t;
typedef zkey_event_t zkey_state_t;
typedef bool (*get_key_state_t)(void);
} zkey_state_t;
/**
* @brief zkey
*/
typedef struct {
const char *name;
get_key_state_t get_key_state;
@ -40,28 +44,17 @@ typedef struct {
uint32_t currentstatekeep_count; //使
bool last_real_state; //使
} zkey_t;
static uint16_t s_key_press_state;
static uint16_t s_key_long_press_time_ms = 3000; //
#define KEY_SCAN_PERIOD 20 //扫描周期20ms
/**
* @brief zkey_module
*/
typedef struct {
zkey_t *keys;
int nkey;
void (*onkey)(zkey_t *key, zkey_state_t key_state);
} zkey_module_t;
static zkey_module_t *s_module;
static bool s_inited;
void zkey_init(zkey_module_t *module);
void zkey_do_loop_in_each_period(void *_null);
void zkey_process_each(zkey_t *each);
void zkey_process_each_after_filter(zkey_t *each, bool now_io_state);
void read_key_state(void);
void onkey(zkey_t *key, zkey_state_t key_state);
void port_key_state(void);
#endif

194
APP/light.c

@ -1,70 +1,38 @@
#include "light.h"
rgb_message_t rgb_message;
TIMING_MODE_T timing_mode;
timing_message_t timing_message;
static bool s_flicker;
static rgb_light_mode_t s_rgb_now_state;
static rgb_light_mode_t s_rgb_light_mode_config;
static int s_errornum = 0;
static bool s_errorlight_display_state;
static bool s_autoshutdown_light_state;
static timing_light_mode_t get_timing_light_mode_by_errornum(int errornum) { return (timing_light_mode_t)errornum; }
/**
* @brief ,
* 绿
*/
void light_module_set_rgb_mode(RGB_MODE_T mode) {
static void prv_light_module_set_rgb_mode(rgb_light_mode_t mode) {
if (mode == RGB_COLOR_RED) {
port_led_r_set(true);
port_led_g_set(false);
port_led_b_set(false);
rgb_message.turn_off_the_mode_before_rgb = RGB_COLOR_RED;
} else if (mode == RGB_COLOR_BLUE) {
port_led_r_set(false);
port_led_g_set(false);
port_led_b_set(true);
rgb_message.turn_off_the_mode_before_rgb = RGB_COLOR_BLUE;
} else if (mode == RGB_COLOR_GERRN) {
port_led_r_set(false);
port_led_g_set(true);
port_led_b_set(false);
rgb_message.turn_off_the_mode_before_rgb = RGB_COLOR_GERRN;
} else if (mode == RGB_CLOSE) {
// rgb_message.turn_off_the_mode_before_rgb = RGB_CLOSE;
port_led_r_set(false);
port_led_g_set(false);
port_led_b_set(false);
}
}
/**
* @brief rgb闪烁或者不闪烁
*
* @param mode
*/
void light_module_set_rgb_flicker_mode(bool state) {
if (state == false) {
rgb_message.rgb_flicker_mode = false;
} else if (state == true) {
rgb_message.rgb_flicker_mode = true;
}
s_rgb_now_state = mode;
}
void process_rgb_flicker_mode() {
static uint32_t rgb_flicker_ticket = 0;
static uint8_t rgb_ticket_count = 0;
if (port_haspassedms(rgb_flicker_ticket) > 1000) {
rgb_flicker_ticket = get_sys_ticket();
if (rgb_ticket_count < 3) {
// turn_off_the_mode_before_rgb保存了关闭之前的RGB亮灯的模式
light_module_set_rgb_mode(rgb_message.turn_off_the_mode_before_rgb);
} else {
light_module_set_rgb_mode(RGB_CLOSE);
rgb_ticket_count = 0;
}
rgb_ticket_count++;
}
}
/**
* @brief 30min 60min 90min 120min分别打开led3 led2 led1 led0灯
*
* @param mode
*/
void light_module_set_timing_light_mode(TIMING_MODE_T mode) {
static void prv_set_timing_light_mode(timing_light_mode_t mode) {
if (mode == OPEN_ONE_LED) {
port_led0_set(true);
port_led1_set(false);
@ -91,78 +59,96 @@ void light_module_set_timing_light_mode(TIMING_MODE_T mode) {
port_led2_set(false);
port_led3_set(false);
}
timing_message.now_timing_mode = mode;
}
void prv_light_module_rgb_light_control_schedule() {
if (s_rgb_light_mode_config == RGB_CLOSE) {
prv_light_module_set_rgb_mode(RGB_CLOSE);
return;
}
/**
* @brief rgbled0~led3
*
*/
void light_module_close_all_light(void) {
light_module_set_rgb_mode(RGB_CLOSE);
light_module_set_timing_light_mode(CLOSE_ALL_LED);
light_module_set_rgb_flicker_mode(false);
}
if (!s_flicker) {
prv_light_module_set_rgb_mode(s_rgb_light_mode_config);
return;
}
/**
* @brief RGB的亮灭
*
*/
void test_set_rgb_mode(void) {
printf("try_test_set_rgb_mode\r\n");
static int i = 0;
if (i == 0) {
i = 1;
light_module_set_rgb_mode(RGB_COLOR_RED);
} else if (i == 1) {
i = 2;
light_module_set_rgb_mode(RGB_COLOR_BLUE);
} else if (i == 2) {
i = 3;
light_module_set_rgb_mode(RGB_COLOR_GERRN);
} else if (i == 3) {
i = 0;
light_module_set_rgb_mode(RGB_CLOSE);
/**
* @brief
*/
if (s_flicker) {
static uint32_t rgb_flicker_ticket = 0;
static uint8_t rgb_ticket_count = 0;
if (port_haspassedms(rgb_flicker_ticket) > 1000) {
rgb_flicker_ticket = get_sys_ticket();
if (s_rgb_now_state == RGB_CLOSE) {
prv_light_module_set_rgb_mode(s_rgb_light_mode_config);
} else {
prv_light_module_set_rgb_mode(RGB_CLOSE);
}
}
}
}
/**
* @brief led0~led3的亮灭
*
* @brief
*/
void test_set_led_mode(void) {
printf("try_test_set_led_mode\r\n");
static int j = 0;
if (j == 0) {
j = 1;
light_module_set_timing_light_mode(OPEN_ONE_LED);
} else if (j == 1) {
j = 2;
light_module_set_timing_light_mode(OPEN_TWO_LED);
} else if (j == 2) {
j = 3;
light_module_set_timing_light_mode(OPEN_THREE_LED);
} else if (j == 3) {
j = 4;
light_module_set_timing_light_mode(OPEN_FOUR_LED);
} else if (j == 4) {
j = 0;
light_module_set_timing_light_mode(CLOSE_ALL_LED);
static void prv_time_light_control_schedule() {
if (s_autoshutdown_light_state) {
/**
* @brief
*/
int lightnum = hook_get_autoshutdown_timecount() / AUTO_SHUTDOWN_ONE_LIGHT_EQ_TIME_S;
prv_set_timing_light_mode( //
get_timing_light_mode_by_lightnum(lightnum));
} else if (s_errorlight_display_state) {
/**
* @brief
*/
static uint32_t ticket = 0;
static bool state;
if (port_haspassedms(ticket) > 300) {
ticket = get_sys_ticket();
state = !state;
if (state) {
prv_set_timing_light_mode(get_timing_light_mode_by_errornum(s_errornum));
} else {
prv_set_timing_light_mode(CLOSE_ALL_LED);
}
}
}
}
/**
* @brief rgb闪烁或者不闪烁
*
*/
void test_set_rgb_flicker_mode(void) {
printf("test_light_module_set_rgb_flicker_mode\r\n");
static bool m = false;
if (m == 0) {
light_module_set_rgb_flicker_mode(true);
} else if (m == 1) {
light_module_set_rgb_flicker_mode(false);
}
m = !m;
/***********************************************************************************************************************
* ======================================================Extern======================================================= *
***********************************************************************************************************************/
void light_module_set_rgb_mode(rgb_light_mode_t mode) {
printf("light_module_set_rgb_mode %d\n", mode);
s_rgb_light_mode_config = RGB_COLOR_BLUE;
prv_light_module_set_rgb_mode(mode);
}
void light_module_set_rgb_flicker_mode(bool state) {
printf("light_module_set_rgb_flicker_mode %d\n", state);
s_flicker = state;
}
void light_module_set_autoshutdown_indicator_light(bool open) { s_autoshutdown_light_state = open; }
void light_module_set_error_light_mode(bool open, uint8_t error_mode) {
printf("light_module_set_error_light_mode %d\n", error_mode);
s_errorlight_display_state = open;
s_errornum = error_mode;
}
void light_module_close_all_light(void) {
printf("light_module_close_all_light\n");
light_module_set_rgb_mode(RGB_CLOSE);
light_module_set_timing_light_mode(CLOSE_ALL_LED);
light_module_set_rgb_flicker_mode(false);
s_errornum = 0;
s_flicker = false;
s_autoshutdown_light_state = false;
s_errorlight_display_state = false;
}
void light_module_schedule(void) {
prv_light_module_rgb_light_control_schedule();
prv_time_light_control_schedule();
}

38
APP/light.h

@ -5,19 +5,14 @@
#include "port.h"
#include "system_ES8P5066.h"
#include "systick.h"
#include "board.h"
typedef enum {
RGB_CLOSE = 0, /*关闭灯*/
RGB_COLOR_RED = 1, /*打开红灯*/
RGB_COLOR_GERRN = 2, /*打开绿灯*/
RGB_COLOR_BLUE = 3, /*打开蓝灯*/
} RGB_MODE_T;
typedef struct {
RGB_MODE_T turn_off_the_mode_before_rgb;
bool rgb_flicker_mode;
bool already_set_rgb_mode;
} rgb_message_t;
} rgb_light_mode_t;
typedef enum {
CLOSE_ALL_LED = 0, /*关闭定时指示灯LED0 LED1 LED2 LED3*/
@ -25,29 +20,18 @@ typedef enum {
OPEN_TWO_LED = 2, /*打开LED0 打开LED1*/
OPEN_THREE_LED = 3, /*打开LED0 打开LED1 打开LED2*/
OPEN_FOUR_LED = 4, /*打开LED0 打开LED1 打开LED2 打开LED3*/
} TIMING_MODE_T;
typedef struct {
TIMING_MODE_T now_timing_mode;
} timing_message_t;
// typedef enum {
// ERROR_MODE0 = 0, /*打开LED0*/
// ERROR_MODE1 = 1, /*打开LED1*/
// ERROR_MODE2 = 2, /*打开LED2*/
// ERROR_MODE3 = 3, /*打开LED3*/
// } ERROR_MODE_T;
} timing_light_mode_t;
void light_module_set_rgb_mode(RGB_MODE_T mode);
void light_module_set_timing_light_mode(TIMING_MODE_T mode);
void light_module_set_error_light_mode(uint8_t error_mode);
void light_module_set_rgb_mode(rgb_light_mode_t mode);
void light_module_set_error_light_mode(bool open, uint8_t error_mode);
void light_module_set_autoshutdown_indicator_light(bool light);
void light_module_set_rgb_flicker_mode(bool state);
void light_module_close_all_light(void);
void process_rgb_flicker_mode(void);
static timing_light_mode_t get_timing_light_mode_by_lightnum(int number) { return (timing_light_mode_t)number; }
void light_module_schedule(void);
void test_set_rgb_mode(void);
void test_set_led_mode(void);
void test_set_rgb_flicker_mode(void);
//
int hook_get_autoshutdown_timecount();
#endif

688
APP/main.c

@ -1,37 +1,52 @@
#include "main.h"
#include <stdbool.h> //定义布尔
#define TIMING_TICK 20000
#define INTERVAL_PERIOD 10000
#include "board.h"
/***********************************************************************************************************************
* =========================================================================================================== *
***********************************************************************************************************************/
void onkey(zkey_t *key, zkey_state_t key_state);
/***********************************************************************************************************************
* =========================================================================================================== *
***********************************************************************************************************************/
bool starting_up_state = false; //
bool timing_function_enable_falg = false; //使
static uint32_t s_timing_shutdown_begin_ticket = 0; //
static uint32_t s_timing_time; //
static zkey_t s_keys[] = {
ZKEY_INIT("timerkey", port_gpio_get_timer_key_state),
ZKEY_INIT("gearskey", port_gpio_get_gears_key_state),
ZKEY_INIT("intervalkey", port_gpio_get_interval_key_state),
ZKEY_INIT("switchkey", port_gpio_get_switch_key_state),
};
zkey_module_t key_module = ZMODULE_INIT(s_keys, onkey);
static uint32_t s_interval_period = 0; //
static uint8_t s_now_interval_duty = 0; //
static uint8_t s_intervalkey_press_count = 0; //
uint8_t rgb_ticket_count = 3;
/***********************************************************************************************************************
* =========================================================================================================== *
***********************************************************************************************************************/
static bool error_even_trigger_after_stop_ozone_work_state; //
WORK_LEVEL_T now_level; //
WORK_LEVEL_T shutdown_before_level; //
//
bool g_setting_interval_work_flag = false; //
WORK_LEVEL_T g_setting_level = WORK_LEVEL_LOW; //
error_state_t error_state; //
static bool error_even_trigger_after_stop_ozone_work_state; //
//
bool g_power_flag = false; //
static int g_error_num;
bool g_auto_shutdown_flag = false; //使
static uint32_t g_auto_shutdown_countdown_s; //
//
static bool pwm_modble_enable_falg; //pwm使能标志位
//####################### HOOK实现 ################################//
/***********************************************************************************************************************
* =======================================================HOOK======================================================== *
***********************************************************************************************************************/
void HOOK_pwm_module_set_pwm_duty(uint32_t frequency, uint32_t duty) {
set_pwm_modbul_freq_duty(frequency, duty);
port_fan_set(true); //
pwm_modble_enable_falg = true;
printf("work\r\n");
}
void HOOK_pwm_stop(void) {
set_pwm_modbul_freq_duty(1, 0); //PWM输出
port_fan_set(false); //
@ -39,316 +54,66 @@ void HOOK_pwm_stop(void) {
printf("rest\r\n");
}
bool HOOK_pwm_is_enable(void) { return pwm_modble_enable_falg; }
//####################### ################################//
void process_intervalkey_press_even(void) {
s_intervalkey_press_count++;
if (s_intervalkey_press_count == 1) {
//rgb亮三秒灭一秒,rgb_ticket_count设置3rgb灭1s
rgb_ticket_count = 3;
update_interval_period_duty(50);
} else {
update_interval_period_duty(100); // update_interval_period_duty100s_intervalkey_press_count=0
}
}
/**
* @brief
*
*/
void update_interval_period_duty(uint8_t interval_duty) {
if (interval_duty == 100) { //100
printf("duty 100\r\n");
s_interval_period = 0;
s_now_interval_duty = 100;
s_intervalkey_press_count = 0;
ozone_pwm_control_disable();
restore_the_mode_before_intermittent_work();
} else if (interval_duty == 50) {
printf("duty 50\r\n");
s_interval_period = INTERVAL_PERIOD;
s_now_interval_duty = 50;
ozone_pwm_control_enable();
}
ozone_pwm_control_module_set_pwm_output_1(s_interval_period, s_now_interval_duty);
}
/**
* @brief
*
*/
void restore_the_mode_before_intermittent_work(void) {
if (now_level == WORK_LEVEL_LOW) {
light_module_set_rgb_mode(RGB_COLOR_GERRN);
set_pwm_modbul_freq_duty(1, 25);
port_fan_set(true); //
} else if (now_level == WORK_LEVEL_MIDDLE) {
light_module_set_rgb_mode(RGB_COLOR_BLUE);
set_pwm_modbul_freq_duty(1, 50);
port_fan_set(true); //
} else if (now_level == WORK_LEVEL_HIGHT) {
light_module_set_rgb_mode(RGB_COLOR_RED);
set_pwm_modbul_freq_duty(1, 100);
port_fan_set(true); //
}
}
/**
* @brief rgb亮3s灭1s
*
*/
void process_rgb_flicker(void) {
static uint32_t rgb_ticket = 0;
if (port_haspassedms(rgb_ticket) > 1000) {
rgb_ticket = get_sys_ticket();
if (rgb_ticket_count < 3) {
if (now_level == WORK_LEVEL_LOW) {
light_module_set_rgb_mode(RGB_COLOR_GERRN);
} else if (now_level == WORK_LEVEL_MIDDLE) {
light_module_set_rgb_mode(RGB_COLOR_BLUE);
} else if (now_level == WORK_LEVEL_HIGHT) {
light_module_set_rgb_mode(RGB_COLOR_RED);
}
} else {
light_module_set_rgb_mode(RGB_CLOSE);
rgb_ticket_count = 0;
}
rgb_ticket_count++;
}
}
int hook_get_autoshutdown_timecount() { return g_auto_shutdown_countdown_s; }
/***********************************************************************************************************************
* =============================================================================================================== *
* =================================================INTERNAL_FUNCTION================================================= *
***********************************************************************************************************************/
static zkey_t s_keys[] = {
ZKEY_INIT("timerkey", port_gpio_get_timer_key_state),
ZKEY_INIT("gearskey", port_gpio_get_gears_key_state),
ZKEY_INIT("intervalkey", port_gpio_get_interval_key_state),
ZKEY_INIT("switchkey", port_gpio_get_switch_key_state),
};
zkey_module_t key_module = ZMODULE_INIT(s_keys, onkey);
void onkey(zkey_t *key, zkey_state_t key_state) {
/**
* @brief
*
* @param key
* @param key_state
*/
if (starting_up_state) { //
if (error_state.fan_error_status == false && error_state.way_circuit_error_status == false) { //
if (key == &s_keys[0] && //
key->cur_state == zks_keep && //
!key->hasProcessed && //
key->keep_state_count >= POWER_KEY_TRIGGER_TIME / KEY_SCAN_PERIOD) //3s
{
key->hasProcessed = true;
} else if (key == &s_keys[0] && //
key->cur_state == zks_falling_edge && //沿
!key->hasProcessed && key->keep_state_count <= POWER_KEY_TRIGGER_TIME / KEY_SCAN_PERIOD) //3s
{
key->hasProcessed = true;
printf("key0 zks_falling_edge\r\n");
update_timing_time();
updae_led_light_mode();
} else if (key == &s_keys[1] && //
key->cur_state == zks_rising_edge && //
!key->hasProcessed && //
key->keep_state_count <= POWER_KEY_TRIGGER_TIME / KEY_SCAN_PERIOD) {
key->hasProcessed = true;
printf("key1 zks_rising_edge\r\n");
process_gearskey_press_even();
} else if (key == &s_keys[2] && //
key->cur_state == zks_rising_edge && //
!key->hasProcessed && //
key->keep_state_count <= POWER_KEY_TRIGGER_TIME / KEY_SCAN_PERIOD) {
key->hasProcessed = true;
printf("key2 zks_rising_edge\r\n");
process_intervalkey_press_even();
} else if (key == &s_keys[3] && //
key->cur_state == zks_rising_edge && //
!key->hasProcessed && //
key->keep_state_count <= POWER_KEY_TRIGGER_TIME / KEY_SCAN_PERIOD) {
key->hasProcessed = true;
printf("key2 zks_rising_edge\r\n");
shutdown();
}
} else if (error_state.fan_error_status == true || error_state.way_circuit_error_status == true) { //
if (key == &s_keys[3] && //
key->cur_state == zks_rising_edge && //
!key->hasProcessed && //
key->keep_state_count <= POWER_KEY_TRIGGER_TIME / KEY_SCAN_PERIOD) {
key->hasProcessed = true;
printf("key2 zks_rising_edge\r\n");
shutdown();
}
}
} else { //
if (key == &s_keys[3] && //
key->cur_state == zks_rising_edge && //
!key->hasProcessed && //
key->keep_state_count <= POWER_KEY_TRIGGER_TIME / KEY_SCAN_PERIOD) {
key->hasProcessed = true;
printf("key zks_rising_edge\r\n");
starting_up();
}
}
}
/**
* @brief ,
*
*/
void power_on_ozone_working_status(void) {
update_ozone_work_gears(WORK_LEVEL_CLOSE);
light_module_set_timing_light_mode(CLOSE_ALL_LED);
port_fan_set(false); //
}
//####################### #######################/
/**
* @brief pwm输出rgb的颜色
*
* @param gears
*/
void update_ozone_work_gears(WORK_LEVEL_T level) {
void update_ozone_work_level(bool interval_work, WORK_LEVEL_T level) {
printf("update_ozone_work_level(interval_work:%d,level:%d)\n", interval_work, level);
rgb_light_mode_t lightmode;
int duty = 0;
if (level == WORK_LEVEL_CLOSE) {
ozone_pwm_control_module_set_pwm_output_2(1, 0, s_interval_period, s_now_interval_duty);
light_module_set_rgb_mode(RGB_CLOSE);
duty = 0;
lightmode = RGB_CLOSE;
} else if (level == WORK_LEVEL_LOW) {
ozone_pwm_control_module_set_pwm_output_2(1, 25, s_interval_period, s_now_interval_duty);
light_module_set_rgb_mode(RGB_COLOR_GERRN);
duty = 25;
lightmode = RGB_COLOR_GERRN;
} else if (level == WORK_LEVEL_MIDDLE) {
ozone_pwm_control_module_set_pwm_output_2(1, 50, s_interval_period, s_now_interval_duty);
light_module_set_rgb_mode(RGB_COLOR_BLUE);
duty = 50;
lightmode = RGB_COLOR_BLUE;
} else if (level == WORK_LEVEL_HIGHT) {
ozone_pwm_control_module_set_pwm_output_2(1, 100, s_interval_period, s_now_interval_duty);
light_module_set_rgb_mode(RGB_COLOR_RED);
duty = 100;
lightmode = RGB_COLOR_RED;
}
now_level = level;
}
void process_gearskey_press_even(void) {
static uint8_t gearskey_press_count;
gearskey_press_count++;
if (gearskey_press_count == 1) {
update_ozone_work_gears(WORK_LEVEL_MIDDLE);
} else if (gearskey_press_count == 2) {
update_ozone_work_gears(WORK_LEVEL_LOW);
} else if (gearskey_press_count == 3) {
gearskey_press_count = 0;
update_ozone_work_gears(WORK_LEVEL_HIGHT);
}
}
//####################### #######################/
void shutdown(void) {
ozone_pwm_control_disable();
error_state.fan_error_status = false;
error_state.way_circuit_error_status = false;
s_intervalkey_press_count = 0;
shutdown_before_level = now_level;
starting_up_state = false;
update_ozone_work_gears(WORK_LEVEL_CLOSE);
light_module_set_timing_light_mode(CLOSE_ALL_LED);
port_fan_set(false); //
}
/**
* @brief
*
*/
void starting_up(void) {
//100
update_interval_period_duty(100);
// timing_function_enable_falg = false; s_timing_time = 0;
timing_function_enable_falg = false;
s_timing_time = 0;
starting_up_state = true;
if (shutdown_before_level == WORK_LEVEL_CLOSE) {
update_ozone_work_gears(WORK_LEVEL_HIGHT);
if (interval_work) {
ozone_pwm_control_module_set_pwm_output_2(1, 0, INTERVAL_WORK_DUTY, INTERVAL_WORK_PERIOD_MS);
} else {
update_ozone_work_gears(shutdown_before_level);
}
port_fan_set(true); //
}
void process_switchkey(void) {
static bool switchkey_press_count = 0;
switchkey_press_count = !switchkey_press_count;
if (switchkey_press_count) { //
starting_up();
} else { //
shutdown();
}
}
//####################### #######################/
/**
* @brief
*
*/
void updae_led_light_mode(void) {
if ((s_timing_time / TIMING_TICK) == 0) {
light_module_set_timing_light_mode(CLOSE_ALL_LED);
} else if ((s_timing_time / TIMING_TICK) == 1) {
light_module_set_timing_light_mode(OPEN_ONE_LED);
} else if ((s_timing_time / TIMING_TICK) == 2) {
light_module_set_timing_light_mode(OPEN_TWO_LED);
} else if ((s_timing_time / TIMING_TICK) == 3) {
light_module_set_timing_light_mode(OPEN_THREE_LED);
} else if ((s_timing_time / TIMING_TICK) == 4) {
light_module_set_timing_light_mode(OPEN_FOUR_LED);
set_pwm_modbul_freq_duty(1, duty);
}
light_module_set_rgb_mode(lightmode);
light_module_set_rgb_flicker_mode(interval_work);
}
/**
* @brief timing_time=timing_time+TIMING_TICK
* timing_time==timing_time = 4 * TIMING_TICK;
* timing_time = 0;
*
* @brief
*/
void update_timing_time(void) {
s_timing_shutdown_begin_ticket = get_sys_ticket(); //
update_begin_ticket(); //
timing_function_enable_falg = true; //使
if (s_timing_time == 0) {
s_timing_time = 1 * TIMING_TICK;
} else if ((s_timing_time / TIMING_TICK) == 1) {
s_timing_time = 2 * TIMING_TICK;
} else if ((s_timing_time / TIMING_TICK) == 2) {
s_timing_time = 3 * TIMING_TICK;
} else if ((s_timing_time / TIMING_TICK) == 3) {
s_timing_time = 4 * TIMING_TICK;
} else if ((s_timing_time / TIMING_TICK) == 4) {
s_timing_time = 0 * TIMING_TICK;
timing_function_enable_falg = false;
update_interval_period_duty(100);
}
printf("timing time:%d\r\n", s_timing_time);
}
void shutdown(void) {
printf("shutdown\n");
g_power_flag = false;
g_error_num = 0;
g_auto_shutdown_flag = false;
g_auto_shutdown_countdown_s = 0;
/**
* @brief TIMING_TICK timing_time=timing_time-TIMING_TICK
* TIMING_TICK==0
*
*/
void try_shutdown(void) {
if (port_haspassedms(s_timing_shutdown_begin_ticket) > TIMING_TICK) {
s_timing_shutdown_begin_ticket = get_sys_ticket();
printf("time minus %dms", TIMING_TICK);
s_timing_time -= TIMING_TICK;
updae_led_light_mode();
}
if (s_timing_time == 0) { //
timing_function_enable_falg = false; //
shutdown();
}
update_ozone_work_level(false, WORK_LEVEL_CLOSE);
port_fan_set(false); //
light_module_close_all_light();
}
bool timing_function_is_enable(void) { return timing_function_enable_falg; }
/***********************************************************************************************************************
* ============================================================================================================= *
***********************************************************************************************************************/
void iwdt_init(void) {
/**
* @brief 0+1
* 2
* 4
*
*/
IWDT_InitStruType x;
@ -357,165 +122,99 @@ void iwdt_init(void) {
x.WDT_Rst = Enable; /* IWDT复位使能 */
x.WDT_Clock = IWDT_CLOCK_WDT; /* LRC */
IWDT_Init(&x);
/* 使能IWDT */
IWDT_Enable();
}
void feed_iwdt(void) {
//
if (0x01 == IWDT_GetFlagStatus()) //
{
if (0x01 == IWDT_GetFlagStatus()) {
IWDT_Clear();
// printf("喂狗\r\n");
}
}
void process_error_even(void) {
if (error_state.fan_error_status == false && error_state.way_circuit_error_status == false) { //
return;
} else {
if (!error_even_trigger_after_stop_ozone_work_state) {
error_even_trigger_after_stop_ozone_work_state = true;
set_pwm_modbul_freq_duty(1, 0);
light_module_set_rgb_mode(RGB_CLOSE);
light_module_set_timing_light_mode(CLOSE_ALL_LED);
port_fan_set(false); //
}
if (error_state.fan_error_status == true) { //
static uint32_t error_even_fan_ticket = 0;
static uint8_t one_led_flicker_state = 1;
if (port_haspassedms(error_even_fan_ticket) > 500) {
error_even_fan_ticket = get_sys_ticket();
one_led_flicker_state = !one_led_flicker_state;
port_led0_set(one_led_flicker_state);
}
} else if (error_state.way_circuit_error_status == true) { //
static uint32_t error_even_way_circuit = 0;
static uint8_t two_led_flicker_state = 1;
if (port_haspassedms(error_even_way_circuit) > 500) {
error_even_way_circuit = get_sys_ticket();
two_led_flicker_state = !two_led_flicker_state;
port_led0_set(two_led_flicker_state);
port_led1_set(two_led_flicker_state);
}
void onkey(zkey_t *key, zkey_state_t key_state) {
if (key->hasProcessed) return;
/**
* @brief
*/
if (!g_power_flag) {
if (key == &s_keys[3] && key->cur_state == zks_falling_edge) {
key->hasProcessed = true;
printf("key zks_rising_edge\r\n");
/**
* @brief
* 1.
* 2.
* 3.
*/
g_power_flag = true; //
g_error_num = 0;
g_auto_shutdown_flag = false; //使
g_auto_shutdown_countdown_s = 0; //
port_fan_set(true); //
update_ozone_work_level(g_setting_interval_work_flag, g_setting_level);
}
return;
}
}
/***********************************************************************************************************************
* ===============================================================================================================
**
***********************************************************************************************************************/
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) {
port_fan_set(false);
Delayms(10000);
port_fan_set(true);
printf("open\r\n");
Delayms(10000);
while (1) {
// unused_gpio_init();
// gpio_init();
// port_fan_set(false);
// printf("close\r\n");
// Delayms(30000);
// port_fan_set(true);
// printf("open\r\n");
// Delayms(10000);
/**
* @brief
*/
if (g_error_num != 0) { //
if (key == &s_keys[3] && key->cur_state == zks_falling_edge) {
key->hasProcessed = true;
printf("process key[2] event\r\n");
/**
* @brief
*/
shutdown();
}
return;
}
error_state.way_circuit_error_status = true;
error_state.fan_error_status = true;
// while (1) {
// port_fan_set(true); //
// printf("open\r\n");
// Delayms(50000);
// port_fan_set(false); //
// printf("close\r\n");
// Delayms(50000);
// port_do_debug_light_state();
// printf("Initialization completed\r\n");
// }
// while (1) {
// port_do_debug_light_state();
// printf("Initialization completed\r\n");
// }
if (key == &s_keys[0] && key->cur_state == zks_falling_edge) //3s
{
printf("process key[0] event\r\n");
/**
* @brief
*/
if (!g_auto_shutdown_flag) {
g_auto_shutdown_flag = true;
g_auto_shutdown_countdown_s = 0;
}
g_auto_shutdown_countdown_s += AUTO_SHUTDOWN_ONE_LIGHT_EQ_TIME_S;
} else if (key == &s_keys[1] && key->cur_state == zks_falling_edge) {
/**
* @brief
*/
printf("process key[1] event\r\n");
if (g_setting_level == WORK_LEVEL_HIGHT) {
update_ozone_work_level(g_setting_interval_work_flag, WORK_LEVEL_LOW);
} else if (g_setting_level == WORK_LEVEL_MIDDLE) {
update_ozone_work_level(g_setting_interval_work_flag, WORK_LEVEL_HIGHT);
} else if (g_setting_level == WORK_LEVEL_LOW) {
update_ozone_work_level(g_setting_interval_work_flag, WORK_LEVEL_MIDDLE);
}
} else if (key == &s_keys[2] && key->cur_state == zks_falling_edge) {
printf("process key[2] event\r\n");
/**
* @brief
*/
g_setting_interval_work_flag = !g_setting_interval_work_flag;
update_ozone_work_level(g_setting_interval_work_flag, g_setting_level);
} else if (key == &s_keys[3] && key->cur_state == zks_falling_edge) {
printf("process key[2] event\r\n");
/**
* @brief
*/
shutdown();
}
}
/**
* @brief 使rgb闪烁
*
*/
/***********************************************************************************************************************
* =============================================================================================================
**
***********************************************************************************************************************/
int main(void) {
HRC_Config(Enable, SCU_HRC_48M, Enable); //SCU_CLK_HRC
@ -523,50 +222,89 @@ int main(void) {
DeviceClockAllEnable(); //
User_SysTickInit(); //(1ms中断)
SysTick_Enable();
// all_gpio_reset();
//
unused_gpio_init();
gpio_init();
uart0_init();
zkey_init(&key_module);
t16_pa4_init();
// iwdt_init();
power_on_ozone_working_status();
//
zkey_init(&key_module);
//
shutdown();
//
printf("Initialization completed\r\n");
// test();
// test_adc();
while (true) {
/*******************************************************************************************************************
* ===================================================================================================== *
*******************************************************************************************************************/
port_do_debug_light_state();
// feed_iwdt();
static uint32_t keylastprocess = 0;
if (port_haspassedms(keylastprocess) > 40) {
keylastprocess = get_sys_ticket();
zkey_do_loop_in_each_period(NULL);
/***********************************************************************************************************************
* =================================================================================================== *
***********************************************************************************************************************/
{
static uint32_t keylastprocess = 0;
if (port_haspassedms(keylastprocess) > KEY_PERIOD) {
keylastprocess = get_sys_ticket();
zkey_do_loop_in_each_period(NULL);
}
}
if (starting_up_state) { //
port_do_debug_light_state();
process_error_even();
try_adc_gather();
if (timing_function_is_enable()) { //
try_shutdown();
/***********************************************************************************************************************
* =============================================================================================== *
***********************************************************************************************************************/
light_module_schedule();
/***********************************************************************************************************************
* =============================================================================================== *
***********************************************************************************************************************/
ozone_pwm_control_module_loop();
/***********************************************************************************************************************
* ======================================================================================================= *
***********************************************************************************************************************/
//
if (g_power_flag && g_auto_shutdown_flag) {
static uint32_t ticket = 0;
ticket = get_sys_ticket();
//
if (port_haspassedms(ticket) > 1000) {
ticket = get_sys_ticket();
if (g_auto_shutdown_countdown_s > 0) {
g_auto_shutdown_countdown_s -= 1;
} else {
g_auto_shutdown_flag = false;
/**
* @brief
*/
shutdown();
}
}
if (ozone_pwm_control_is_enable() == true) {
ozone_pwm_control_module_loop();
process_rgb_flicker();
//
}
/***********************************************************************************************************************
* =======================================================================================================
***********************************************************************************************************************/
updae_timing_light_state();
/***********************************************************************************************************************
* =======================================================================================================
***********************************************************************************************************************/
{
static uint32_t ticket = 0;
if (port_haspassedms(ticket) > EXCEPTION_CHECK_PERIOD) {
ticket = get_sys_ticket();
/**
* @brief
* ADC的数值是否超出规定范围
*/
if (false) {
}
}
} else { //
}
// End..................................
}
}
/**
*
*
*
*
*
* led0闪烁测试通过
* led0led1闪烁测试通过
*
*/
}

2
APP/main.h

@ -49,7 +49,7 @@ void process_gearskey_press_even(void);
void shutdown(void);
void starting_up(void);
void process_switchkey(void);
void updae_led_light_mode(void);
void updae_timing_light_state(void);
void update_timing_time(void);
void try_shutdown(void);
bool timing_function_is_enable(void);

6
APP/ozone_pwm_control.c

@ -11,7 +11,7 @@ void HOOK_pwm_module_set_pwm_duty(uint32_t frequency, uint32_t duty);
void HOOK_pwm_stop(void);
bool HOOK_pwm_is_enable(void);
void update_begin_ticket(void) {
static void prv_update_begin_ticket(void) {
begin_ticket = get_sys_ticket(); //
}
@ -28,7 +28,7 @@ bool ozone_pwm_control_is_enable(void) { return ozone_pwm_control_enable_falg; }
void ozone_pwm_control_module_set_pwm_output_1(uint32_t large_period, uint8_t large_duty) {
s_large_period = large_period;
s_large_duty = large_duty;
update_begin_ticket();
prv_update_begin_ticket();
ozone_pwm_control_enable();
if (large_duty == 100) {
ozone_pwm_control_disable();
@ -48,7 +48,7 @@ void ozone_pwm_control_module_set_pwm_output_2(uint32_t hardware_period, uint8_t
s_hardware_duty = hardware_duty;
s_large_period = large_period;
s_large_duty = large_duty;
update_begin_ticket();
prv_update_begin_ticket();
ozone_pwm_control_enable();
HOOK_pwm_module_set_pwm_duty(hardware_period, hardware_duty);
if (large_duty == 100) {

3
APP/ozone_pwm_control.h

@ -1,7 +1,6 @@
#ifndef _OZONE_PWM_CONTROL_H_
#define _OZONE_PWM_CONTROL_H_
#include <stdbool.h>
#include <stdint.h>
@ -16,7 +15,7 @@ void ozone_pwm_control_module_set_pwm_output_2(uint32_t hardware_period, uint8_t
void ozone_pwm_control_module_set_pwm(uint32_t frequency, uint32_t duty);
void ozone_pwm_control_module_stop_pwm(void);
void ozone_pwm_control_module_loop(void);
void update_begin_ticket(void);
void ozone_pwm_control_enable(void);
void ozone_pwm_control_disable(void);
bool ozone_pwm_control_is_enable(void);

20
project_ozone/Listings/project_o.map

@ -38,7 +38,7 @@ Section Cross References
main.o(i.main) refers to main.o(.data) for .data
main.o(i.onkey) refers to printfa.o(i.__0printf) for __2printf
main.o(i.onkey) refers to main.o(i.update_timing_time) for update_timing_time
main.o(i.onkey) refers to main.o(i.updae_led_light_mode) for updae_led_light_mode
main.o(i.onkey) refers to main.o(i.updae_timing_light_state) for updae_timing_light_state
main.o(i.onkey) refers to main.o(i.process_gearskey_press_even) for process_gearskey_press_even
main.o(i.onkey) refers to main.o(i.process_intervalkey_press_even) for process_intervalkey_press_even
main.o(i.onkey) refers to main.o(i.shutdown) for shutdown
@ -98,11 +98,11 @@ Section Cross References
main.o(i.try_shutdown) refers to systick.o(i.port_haspassedms) for port_haspassedms
main.o(i.try_shutdown) refers to systick.o(i.get_sys_ticket) for get_sys_ticket
main.o(i.try_shutdown) refers to printfa.o(i.__0printf) for __2printf
main.o(i.try_shutdown) refers to main.o(i.updae_led_light_mode) for updae_led_light_mode
main.o(i.try_shutdown) refers to main.o(i.updae_timing_light_state) for updae_timing_light_state
main.o(i.try_shutdown) refers to main.o(i.shutdown) for shutdown
main.o(i.try_shutdown) refers to main.o(.data) for .data
main.o(i.updae_led_light_mode) refers to light.o(i.light_module_set_timing_light_mode) for light_module_set_timing_light_mode
main.o(i.updae_led_light_mode) refers to main.o(.data) for .data
main.o(i.updae_timing_light_state) refers to light.o(i.light_module_set_timing_light_mode) for light_module_set_timing_light_mode
main.o(i.updae_timing_light_state) refers to main.o(.data) for .data
main.o(i.update_interval_period_duty) refers to printfa.o(i.__0printf) for __2printf
main.o(i.update_interval_period_duty) refers to ozone_pwm_control.o(i.ozone_pwm_control_disable) for ozone_pwm_control_disable
main.o(i.update_interval_period_duty) refers to main.o(i.restore_the_mode_before_intermittent_work) for restore_the_mode_before_intermittent_work
@ -1179,7 +1179,7 @@ Image Symbol Table
i.try_shutdown 0x00002534 Section 0 main.o(i.try_shutdown)
i.uart0_init 0x00002584 Section 0 uart0.o(i.uart0_init)
i.unused_gpio_init 0x00002610 Section 0 port.o(i.unused_gpio_init)
i.updae_led_light_mode 0x000026a0 Section 0 main.o(i.updae_led_light_mode)
i.updae_timing_light_state 0x000026a0 Section 0 main.o(i.updae_timing_light_state)
i.update_begin_ticket 0x000026fc Section 0 ozone_pwm_control.o(i.update_begin_ticket)
i.update_interval_period_duty 0x0000270c Section 0 main.o(i.update_interval_period_duty)
i.update_ozone_work_gears 0x00002770 Section 0 main.o(i.update_ozone_work_gears)
@ -1204,7 +1204,7 @@ Image Symbol Table
error_even_fan_ticket 0x2000001c Data 4 main.o(.data)
error_even_way_circuit 0x20000020 Data 4 main.o(.data)
keylastprocess 0x20000024 Data 4 main.o(.data)
s_timing_time 0x20000028 Data 4 main.o(.data)
s_auto_shutdown_countdown_s 0x20000028 Data 4 main.o(.data)
s_keys 0x2000002c Data 112 main.o(.data)
.data 0x200000a8 Section 8 systick.o(.data)
debug_led_state 0x200000a8 Data 1 systick.o(.data)
@ -1450,7 +1450,7 @@ Image Symbol Table
try_shutdown 0x00002535 Thumb Code 56 main.o(i.try_shutdown)
uart0_init 0x00002585 Thumb Code 134 uart0.o(i.uart0_init)
unused_gpio_init 0x00002611 Thumb Code 144 port.o(i.unused_gpio_init)
updae_led_light_mode 0x000026a1 Thumb Code 70 main.o(i.updae_led_light_mode)
updae_timing_light_state 0x000026a1 Thumb Code 70 main.o(i.updae_timing_light_state)
update_begin_ticket 0x000026fd Thumb Code 12 ozone_pwm_control.o(i.update_begin_ticket)
update_interval_period_duty 0x0000270d Thumb Code 68 main.o(i.update_interval_period_duty)
update_ozone_work_gears 0x00002771 Thumb Code 80 main.o(i.update_ozone_work_gears)
@ -1461,8 +1461,8 @@ Image Symbol Table
zkey_process_each_after_filter 0x00002909 Thumb Code 70 key.o(i.zkey_process_each_after_filter)
Region$$Table$$Base 0x00002984 Number 0 anon$$obj.o(Region$$Table)
Region$$Table$$Limit 0x000029a4 Number 0 anon$$obj.o(Region$$Table)
starting_up_state 0x20000000 Data 1 main.o(.data)
timing_function_enable_falg 0x20000001 Data 1 main.o(.data)
g_power_flag 0x20000000 Data 1 main.o(.data)
g_auto_shutdown_flag 0x20000001 Data 1 main.o(.data)
rgb_ticket_count 0x20000004 Data 1 main.o(.data)
now_level 0x20000009 Data 1 main.o(.data)
shutdown_before_level 0x2000000a Data 1 main.o(.data)
@ -1639,7 +1639,7 @@ Memory Map of the image
0x00002534 0x00002534 0x00000050 Code RO 22 i.try_shutdown main.o
0x00002584 0x00002584 0x0000008c Code RO 478 i.uart0_init uart0.o
0x00002610 0x00002610 0x00000090 Code RO 275 i.unused_gpio_init port.o
0x000026a0 0x000026a0 0x0000005c Code RO 23 i.updae_led_light_mode main.o
0x000026a0 0x000026a0 0x0000005c Code RO 23 i.updae_timing_light_state main.o
0x000026fc 0x000026fc 0x00000010 Code RO 695 i.update_begin_ticket ozone_pwm_control.o
0x0000270c 0x0000270c 0x00000064 Code RO 24 i.update_interval_period_duty main.o
0x00002770 0x00002770 0x00000054 Code RO 25 i.update_ozone_work_gears main.o

2
project_ozone/Listings/startup_es8p5066.lst

@ -304,7 +304,7 @@ ARM Macro Assembler Page 5
Command Line: --debug --xref --diag_suppress=9931 --cpu=Cortex-M0 --apcs=interw
ork --depend=.\objects\startup_es8p5066.d -o.\objects\startup_es8p5066.o -IC:\K
eil_v5\ARM\RV31\INC -IC:\Keil_v5\ARM\CMSIS\Include -IC:\Keil_v5\ARM\INC\HR --pr
edefine="__MICROLIB SETA 1" --predefine="__UVISION_VERSION SETA 527" --list=.\l
edefine="__MICROLIB SETA 1" --predefine="__UVISION_VERSION SETA 536" --list=.\l
istings\startup_es8p5066.lst ..\MDK_StartUp\startup_ES8P5066.s

1878
project_ozone/project_o.uvgui.zel
File diff suppressed because it is too large
View File

4
project_ozone/project_o.uvopt

@ -10,7 +10,7 @@
<aExt>*.s*; *.src; *.a*</aExt>
<oExt>*.obj; *.o</oExt>
<lExt>*.lib</lExt>
<tExt>*.txt; *.h; *.inc</tExt>
<tExt>*.txt; *.h; *.inc; *.md</tExt>
<pExt>*.plm</pExt>
<CppX>*.cpp</CppX>
<nMigrate>0</nMigrate>
@ -103,7 +103,7 @@
<bEvRecOn>1</bEvRecOn>
<bSchkAxf>0</bSchkAxf>
<bTchkAxf>0</bTchkAxf>
<nTsel>3</nTsel>
<nTsel>12</nTsel>
<sDll></sDll>
<sDllPa></sDllPa>
<sDlgDll></sDlgDll>

7
project_ozone/project_o.uvproj

@ -10,7 +10,7 @@
<TargetName>Target 1</TargetName>
<ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName>
<pCCUsed>5060750::V5.06 update 6 (build 750)::ARMCC</pCCUsed>
<pCCUsed>5060960::V5.06 update 7 (build 960)::ARMCC</pCCUsed>
<uAC6>0</uAC6>
<TargetOption>
<TargetCommonOption>
@ -149,7 +149,7 @@
<RestoreSysVw>1</RestoreSysVw>
</Target>
<RunDebugAfterBuild>0</RunDebugAfterBuild>
<TargetSelection>3</TargetSelection>
<TargetSelection>12</TargetSelection>
<SimDlls>
<CpuDll></CpuDll>
<CpuDllArguments></CpuDllArguments>
@ -224,6 +224,7 @@
<uocXRam>0</uocXRam>
<RvdsVP>0</RvdsVP>
<RvdsMve>0</RvdsMve>
<RvdsCdeCp>0</RvdsCdeCp>
<hadIRAM2>0</hadIRAM2>
<hadIROM2>0</hadIROM2>
<StupSel>8</StupSel>
@ -390,7 +391,7 @@
<NoWarn>0</NoWarn>
<uSurpInc>0</uSurpInc>
<useXO>0</useXO>
<uClangAs>0</uClangAs>
<ClangAsOpt>4</ClangAsOpt>
<VariousControls>
<MiscControls></MiscControls>
<Define></Define>

Loading…
Cancel
Save