/* ****************************************************************************** * * @file hall.c * @brief hall module * * * @version 1.0 * @date 2022/08/04 15:00:40 * @author Alex Xu * * Copyright (c) 2013-2099,Tkplusemi Technology Co.,Ltd. * All Rights Reserved * * History: * Revision Date Author Desc * 1.0.0 2022/08/04 Alex build this file ******************************************************************************/ /*_____ I N C L U D E S ____________________________________________________*/ #include "hall.h" #include "key.h" #include "led.h" #if KEY_HALL_ENABLE /******************************************************************************\ Macro definitions \******************************************************************************/ /******************************************************************************\ Variables definitions \******************************************************************************/ CoverStatus_E CoverStatus; //bit CoverEvent_Flg = 0; //Hall开关触发事件标志位 /******************************************************************************\ Functions definitions \******************************************************************************/ /* ******************************************************************************* * void Hall_Init(void) * * Description : Hall Initialization * * Arguments : * Returns : * Notes : * ******************************************************************************* */ void Hall_Init(void) { while ( !(CHIP_STA0 & 0x10) ); //Hall analog first detection complete status,hall flag valid only after this bit sets. if(CHIP_STA0 & 0x08) //获取HALL初始状态 { #if HALL_OPEN_LEV_SET CoverStatus = CLOSE; #else CoverStatus = OPEN; #endif } else { #if HALL_OPEN_LEV_SET CoverStatus = OPEN; #else CoverStatus = CLOSE; #endif } } /* ******************************************************************************* * void Hall_Handle(void) * * Description : Hall Handle --- 主循环中调用,调用周期10ms。CoverStatus --- 充电仓盖子状态。 * * Arguments : NONE * Returns : NONE * Notes : NONE * ******************************************************************************* */ void Hall_Handler(void) { if(Hall_Positive_Flg) //Hall status with analog debounce { #if HALL_OPEN_LEV_SET CoverStatus = OPEN; #else CoverStatus = CLOSE; #endif Hall_Positive_Flg = 0; //CoverEvent_Flg = 1; #ifdef LED_DISPLAY LED_B_OFF(); #endif #ifdef _DEBUG_HALL #if HALL_OPEN_LEV_SET printf("Open Hall Status:0x%x\r\n",(uint16_t)CoverStatus); #else printf("Close Hall Status:0x%x\r\n",(uint16_t)CoverStatus); #endif #endif } else if(Hall_Negative_Flg) { #if HALL_OPEN_LEV_SET CoverStatus = CLOSE; #else CoverStatus = OPEN; #endif Hall_Negative_Flg = 0; //CoverEvent_Flg = 1; #ifdef LED_DISPLAY LED_B_ON(); #endif #ifdef _DEBUG_HALL #if HALL_OPEN_LEV_SET printf("Close Hall Status:0x%x\r\n",(uint16_t)CoverStatus); #else printf("Open Hall Status:0x%x\r\n",(uint16_t)CoverStatus); #endif #endif } } #endif