SY883x_For_Clients_ROCK-A/UsrSrc/userapp/userapp.c

313 lines
6.8 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
******************************************************************************
*
* @file UserApp.c
* @brief UserApp module
*
*
* @version 1.0
* @date 2023/03/27 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 2023/03/27 Alex build this file
******************************************************************************/
/*_____ I N C L U D E S ____________________________________________________*/
#include "userapp.h"
#include "gpio.h"
#include "adc.h"
#include "hall.h"
#include "key.h"
#include "sleep.h"
#include "system.h"
#include "bat.h"
#include "sys_tim.h"
#include "charger_module.h"
#include "discharge_module.h"
#include "led.h"
#include "vox_module.h"
/******************************************************************************\
Macro definitions
\******************************************************************************/
/******************************************************************************\
Variables definitions
\******************************************************************************/
uint8_t LED_On_Timer = 0; //led亮时间计时
bit LED_On_Flag = 0;
/******************************************************************************\
Functions definitions
\******************************************************************************/
/*****************************************************************************
* Function : void LED_Display_App(void)
* Description : 5ms调用周期
* Input : None
* Output : None
* Return : None
* Note : None
*****************************************************************************/
/*
充电:
1、充电中无其它行为打断时开关盒状态下都显示充电常亮灯效1Hz闪烁
2、充满常亮可被其它灯效打断
非充电:
1、首次使用开盖灯效①高电亮4s后灭②低电1Hz闪4s后灭
2、非首次使用开盖灯效①耳机在盒亮4s后灭②耳机不在盒
③充电中,开盖闪一下,如何闪?亮多久后灭?
3、关盖灯效高电亮4s后灭低电1Hz闪4s后灭
4、关盒状态下无灯效显示
*/
#ifdef LED_DISPLAY
void LED_Display_App(void)
{
if ( CHIP_STA4 & 0x80 ) //充电中
{
if ( Charger_Done ) // 充电完成LED绿灯常亮
{
#ifdef BREATHING_LIGHT
BL_LED.Breathing_Light_On[LED_R] = 0; //关呼吸灯
BL_LED.Breathing_Light_On[LED_G] = 0;
#endif
#ifdef LED_DISPLAY
LEDR_ON();
#endif
}
else
{
if( F_batlevel_low ) //低电红灯呼吸
{
#ifdef BREATHING_LIGHT
BL_LED.Breathing_Light_On[LED_R] = 0;
BL_LED.Breathing_Light_On[LED_G] = 1;
#endif
#ifdef LED_DISPLAY
LEDR_OFF();
#endif
}
else //非低电绿灯呼吸
{
#ifdef BREATHING_LIGHT
BL_LED.Breathing_Light_On[LED_R] = 1;
BL_LED.Breathing_Light_On[LED_G] = 0;
#endif
#ifdef LED_DISPLAY
LEDG_OFF();
#endif
}
}
CoverEvent_Flg_led = 0;
Earphone_Chg_Flag = 0;
LED_On_Flag = 1;
}
else
{
if( LED_On_Flag )
{
#ifdef BREATHING_LIGHT
BL_LED.Breathing_Light_On[LED_R] = 0; //关呼吸灯
BL_LED.Breathing_Light_On[LED_G] = 0;
#endif
#ifdef LED_DISPLAY
LEDR_OFF();
LEDG_OFF();
#endif
LED_On_Flag = 0;
}
#ifdef LED_DISPLAY
if ( CoverEvent_Flg_led || Earphone_Chg_Flag ) //开关盖,显示电量
{
if( F_batlevel_low )
{
LEDR_OFF();
if( LED_On_Timer < LED_OFF_CNT )
{
LEDG_OFF();
LED_On_Timer++;
}
else
if( LED_On_Timer < LED_ON_CNT ) //开关盖盒子低电红色LED亮3s后灭。
{
LED_On_Timer++;
LEDG_ON();
}
else
{
LEDG_OFF();
CoverEvent_Flg_led = 0;
Earphone_Chg_Flag = 0;
}
}
else
{
LEDG_OFF();
if( LED_On_Timer < LED_OFF_CNT )
{
LEDR_OFF();
LED_On_Timer++;
}
else
if( LED_On_Timer < LED_ON_CNT ) //开关盖盒子非低电绿色LED亮3s后灭。
{
LED_On_Timer++;
LEDR_ON();
}
else
{
LEDR_OFF();
CoverEvent_Flg_led = 0;
Earphone_Chg_Flag = 0;
}
}
}
#endif
}
}
#endif
/*****************************************************************************
* Function : UserAPP
* Description : 5ms调用周期
* Input : None
* Output : None
* Return : None
* Note : None
*****************************************************************************/
void UserAPP(void)
{
if( F_sys_tim_100ms )
{
F_sys_tim_100ms = 0;
#if ADC_ENABLE
Vbat_Adc = Vbat_Value(); //获取Bat电压
#endif
#if HALL_ENABLE
Hall_Handler(); //开关盖检测
#endif
#if DISCHARGE_ENABLE
DisCharge_Handler(); //放电boost功能
#endif
#if CHARGER_ENABLE
Charger_Handler(); //充电功能
#endif
#if VOX_ENABLE
Vox_Det_Machine(); //开关盖盒子功能逻辑。
#endif
#ifdef LED_DISPLAY
LED_Display_App(); //LED 灯效
#endif
#if BAT_VALUE
check_bat_level(); //电量计
#endif
#if UART0_ENABLE
HandleVoxCommMsg();
#endif
}
if( F_sys_tim_1s )
{
F_sys_tim_1s = 0;
#if SLEEP_ENABLE
/*1、唤醒后工作Ns后进入Sleep Mode。
2、有VIN存在的情况下系不会进入sleep mode。
*/
if( Decnt_SleepDelay > 0 ) /*能否在数字中实现此功能?*/
{
Decnt_SleepDelay--;
/*倒数进Sleep Mode过程中出现了KEY\HALL\Loadon\IOFF中断则重新计时。*/
if( Enter_Sleep_Cnt_Restart_Flag )
{
Enter_Sleep_Cnt_Restart_Flag = 0;
Decnt_SleepDelay = ENTER_STANDBYMODE_CNT;
}
return;
}
if( Check_Require_Sleep() )
{
/* 唤醒中断使能设置 */
SFRADDR = WKUP_EN3; //vox loadon wake up enable
SFRDATA |= 0x3C;
/* Enter Sleep */
/* InSleep Handler */ //Disable All IRQ
#if UART0_ENABLE
ES0 = 0; //UART0 IRQ Disable
#endif
//EX4 = 0;
EX2 = 0;
ET0 = 0; //timer0 IRQ Disable
#if TIMER1_ENABLE
ET1 = 0; //timer1 IRQ Disable
#endif
VOX_CTL0 &= ~0x30; //VOX 5v Off 关功率管
BST_EN = 0;
#if ADC_ENABLE
SFRADDR = ADC_CTL0;
SFRDATA &= ~0x80; //ADC Disable.
SFRADDR = ADCCS_CTL0; //AD0~AD4 GPIO constant 20uA current source disable.
SFRDATA = 0x00;
#endif
SFRADDR = PMU_CTL0; //芯片硬件需求,固定
SFRDATA &= ~0x30;
PCON |= 0x02; //Enter StandbyMode, Only int0 or int1 can wake up system
/* OutSleep Handler */ //Enable IRQ
SFRADDR = PMU_CTL0; //芯片硬件需求,固定
SFRDATA |= 0x30;
SFRADDR = ADCCS_CTL0; //AD0~AD4 GPIO constant 20uA current source enable.
SFRDATA = 0x10;
#if UART0_ENABLE
ES0 = 1; //UART0 IRQ
#endif
//EX4 = 1;
EX2 = 1;
ET0 = 1; //timer0 IRQ
#if TIMER1_ENABLE
ET1 = 1; //timer1 IRQ
#endif
Decnt_SleepDelay = ENTER_STANDBYMODE_CNT;
}
else
{
Decnt_SleepDelay = ENTER_STANDBYMODE_CNT;
}
#endif
}
}