| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- /*********************************************************************************************************
- * Module : detection
- * Abstract :
- * Version : 1.0.0
- * Author : Leopul(COPYRIGHT 2025 ~ 2027 Leopul. All rights reserved.)
- * Complete : 2025-04-08
- * Content : None
- * Note : None
- *********************************************************************************************************/
- #include "detection.h"
- #include "gd32e23x.h"
- #include "common.h"
- #include "board_cfg.h"
- #include "relay.h"
- #define DERECTION_GPIO GPIOB
- #define DETECTION_1 GPIO_PIN_8
- #define DETECTION_2 GPIO_PIN_9
- static board_t *board = 0;
- static void get_detection(void);
- static void detection_opt(void);
- void detection_init(void)
- {
- board = get_board();
-
- rcu_periph_clock_enable(RCU_GPIOB);
- gpio_mode_set(DERECTION_GPIO, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, DETECTION_1 | DETECTION_2);
- board->detection = get_detection;
- board->opt_detection = detection_opt;
-
- }
- void key_init(void)
- {
- }
- static void get_detection()
- {
- if(board)
- {
- uint16_t data = 0;
- uint8_t val = 0;
- val = gpio_input_bit_get(DERECTION_GPIO,DETECTION_1);
- if(val== 0)
- {
- data |= (1 << 0);
- }
- #if SURPPORT_2_PT
- val = gpio_input_bit_get(DERECTION_GPIO,DETECTION_2);
- if(val== 0)
- {
- data |= (1 << 1);
- }
- #endif
- board->md_data.r_data.detection = data;
- }
- }
- static void detection_opt(void)
- {
- if(board)
- {
- #if RELAY_REMENBER
- if(board->md_data.r_data.detection & 0x1)
- {
- if(board->handle_input_pt[0] == 0)
- {
- board->handle_input_pt[0] = 1;
- for(uint8_t k = 0; k < PT_SUB_COUNT;k++)
- {
- async_data da = {0};
- da.channel =k;
- da.fire_or_zero = _FIRE;
- da.method = DELAY_CTRL;
- da.reg = &board->relay_staging_staus[k];
- da.status = board->handle_status[k];
- da.w_eep_flag = FLAG_N_W_EEP;
- set_relay_sta_async(&da);
- }
- }
- }else
- {
- if(board->handle_input_pt[0] == 1)
- {
- for(uint8_t k = 0; k < PT_SUB_COUNT;k++)
- {
- board->handle_status[k] = board->md_data.r_data.state.state[k].state;
- async_data da = {0};
- da.channel =k;
- da.fire_or_zero = _FIRE;
- da.method = PROMPT_CTRL;
- da.reg = &board->relay_staging_staus[k];
- da.status = RELAY_CLOSE;
- da.w_eep_flag = FLAG_N_W_EEP;
- set_relay_sta_async(&da);
- }
- board->handle_input_pt[0] = 0;
- }
- }
- #if SURPPORT_2_PT
- if(board->md_data.r_data.detection & 0x2)
- {
- if(board->handle_input_pt[1] == 0)
- {
- board->handle_input_pt[1] = 1;
- for(uint8_t k = PT_SUB_COUNT; k < RelaySlaveChaNum;k++)
- {
- async_data da = {0};
- da.channel =k;
- da.fire_or_zero = _FIRE;
- da.method = DELAY_CTRL;
- da.reg = &board->relay_staging_staus[k];
- da.status = board->handle_status[k];
- da.w_eep_flag = FLAG_N_W_EEP;
- set_relay_sta_async(&da);
- }
- }
- }else
- {
- if(board->handle_input_pt[1] == 1)
- {
- for(uint8_t k = PT_SUB_COUNT; k < RelaySlaveChaNum;k++)
- {
- board->handle_status[k] = board->md_data.r_data.state.state[k].state;
- async_data da = {0};
- da.channel =k;
- da.fire_or_zero = _FIRE;
- da.method = PROMPT_CTRL;
- da.reg = &board->relay_staging_staus[k];
- da.status = RELAY_CLOSE;
- da.w_eep_flag = FLAG_N_W_EEP;
- set_relay_sta_async(&da);
- }
- board->handle_input_pt[1] = 0;
- }
- }
- #endif
- #endif
- }
- }
|