279 lines
7.4 KiB
C
279 lines
7.4 KiB
C
#include "fpc.h"
|
||
#include <stdio.h>
|
||
#include "public.h"
|
||
#include "ST7735S.h"
|
||
#include "sim_eeprom.h"
|
||
#include "adc_anychannel_continuousscan_interrupt.h"
|
||
|
||
void FPC_Init(void)
|
||
{
|
||
EXTI_InitTypeDef EXTI_InitStruct;
|
||
GPIO_InitTypeDef GPIO_InitStruct;
|
||
NVIC_InitTypeDef NVIC_InitStruct;
|
||
|
||
RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOB, ENABLE);
|
||
RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOA, ENABLE);
|
||
|
||
GPIO_StructInit(&GPIO_InitStruct);
|
||
GPIO_InitStruct.GPIO_Pin = FPC_KEY_GPIO_Pin ;//KEY
|
||
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_FLOATING;
|
||
GPIO_Init(FPC_KEY_GPIO_Port, &GPIO_InitStruct);
|
||
|
||
GPIO_StructInit(&GPIO_InitStruct);
|
||
GPIO_InitStruct.GPIO_Pin = FPC_IR_TX_GPIO_Pin ;//IR_TX
|
||
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
||
GPIO_Init(FPC_IR_TX_GPIO_Port, &GPIO_InitStruct);
|
||
|
||
GPIO_StructInit(&GPIO_InitStruct);
|
||
GPIO_InitStruct.GPIO_Pin = FPC_IR_RX_GPIO_Pin ;//IR_RX
|
||
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_FLOATING;
|
||
GPIO_Init(FPC_IR_RX_GPIO_Port, &GPIO_InitStruct);
|
||
|
||
GPIO_StructInit(&GPIO_InitStruct);
|
||
GPIO_InitStruct.GPIO_Pin = FPC_Touch_GPIO_Pin ;//TOUCH
|
||
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_FLOATING;
|
||
GPIO_Init(FPC_Touch_GPIO_Port, &GPIO_InitStruct);
|
||
|
||
GPIO_StructInit(&GPIO_InitStruct);
|
||
GPIO_InitStruct.GPIO_Pin = CHARGE_5V_GPIO_Pin ;//5v_test
|
||
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_FLOATING;
|
||
GPIO_Init(CHARGE_5V_GPIO_Port, &GPIO_InitStruct);
|
||
|
||
GPIO_StructInit(&GPIO_InitStruct);
|
||
GPIO_InitStruct.GPIO_Pin = STB_GPIO_Pin ;//STANBY
|
||
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPD;
|
||
GPIO_Init(STB_GPIO_Port, &GPIO_InitStruct);
|
||
|
||
GPIO_StructInit(&GPIO_InitStruct);
|
||
GPIO_InitStruct.GPIO_Pin = CHARGE_CON_GPIO_Pin ;//charge_con
|
||
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
||
GPIO_Init(CHARGE_CON_GPIO_Port, &GPIO_InitStruct);
|
||
|
||
GPIO_StructInit(&GPIO_InitStruct);
|
||
GPIO_InitStruct.GPIO_Pin = BEEP_GPIO_Pin ;//beep
|
||
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
||
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
||
GPIO_Init(BEEP_GPIO_Port, &GPIO_InitStruct);
|
||
|
||
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource0);//KEY
|
||
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource5);//TOUCH
|
||
SYSCFG_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource3);//5V<35><56><EFBFBD><EFBFBD>
|
||
|
||
EXTI_StructInit(&EXTI_InitStruct);
|
||
EXTI_InitStruct.EXTI_Line = EXTI_Line0;
|
||
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
|
||
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
||
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
|
||
EXTI_Init(&EXTI_InitStruct);
|
||
|
||
EXTI_StructInit(&EXTI_InitStruct);
|
||
EXTI_InitStruct.EXTI_Line = EXTI_Line5;
|
||
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
|
||
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;
|
||
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
|
||
EXTI_Init(&EXTI_InitStruct);
|
||
|
||
EXTI_StructInit(&EXTI_InitStruct);
|
||
EXTI_InitStruct.EXTI_Line = EXTI_Line3;
|
||
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
|
||
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
||
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
|
||
EXTI_Init(&EXTI_InitStruct);
|
||
|
||
NVIC_InitStruct.NVIC_IRQChannel = EXTI0_1_IRQn;
|
||
NVIC_InitStruct.NVIC_IRQChannelPriority = 0x01;
|
||
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
|
||
NVIC_Init(&NVIC_InitStruct);
|
||
|
||
NVIC_InitStruct.NVIC_IRQChannel = EXTI2_3_IRQn;
|
||
NVIC_InitStruct.NVIC_IRQChannelPriority = 0x01;
|
||
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
|
||
NVIC_Init(&NVIC_InitStruct);
|
||
|
||
NVIC_InitStruct.NVIC_IRQChannel = EXTI4_15_IRQn;
|
||
NVIC_InitStruct.NVIC_IRQChannelPriority = 0x01;
|
||
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
|
||
NVIC_Init(&NVIC_InitStruct);
|
||
}
|
||
|
||
static void EXTI_Config(void)
|
||
{
|
||
EXTI_InitTypeDef EXTI_InitStruct;
|
||
EXTI_StructInit(&EXTI_InitStruct);
|
||
//External interrupt Mode
|
||
SYSCFG_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource0); // <20><><EFBFBD><EFBFBD>
|
||
//Interrupt threads where pins are located
|
||
EXTI_InitStruct.EXTI_Line = EXTI_Line0;
|
||
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
|
||
//rising trigger
|
||
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
||
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
|
||
EXTI_Init(&EXTI_InitStruct);
|
||
|
||
SYSCFG_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource3); // 5V<35><56><EFBFBD><EFBFBD>
|
||
//Interrupt threads where pins are located
|
||
EXTI_InitStruct.EXTI_Line = EXTI_Line3;
|
||
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
|
||
//rising trigger
|
||
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
||
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
|
||
EXTI_Init(&EXTI_InitStruct);
|
||
|
||
SYSCFG_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource5); // <20><><EFBFBD><EFBFBD>
|
||
//Interrupt threads where pins are located
|
||
EXTI_InitStruct.EXTI_Line = EXTI_Line5;
|
||
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
|
||
//rising trigger
|
||
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
||
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
|
||
EXTI_Init(&EXTI_InitStruct);
|
||
|
||
|
||
}
|
||
|
||
void EXTI0_1_IRQHandler(void)
|
||
{
|
||
/* K1 */
|
||
if (RESET != EXTI_GetITStatus(EXTI_Line0))
|
||
{
|
||
OFF_delay_time = 5000;
|
||
EXTI_ClearITPendingBit(EXTI_Line0);
|
||
}
|
||
}
|
||
|
||
void EXTI2_3_IRQHandler(void)
|
||
{
|
||
/* TOUCH */
|
||
if (RESET != EXTI_GetITStatus(EXTI_Line3))
|
||
{
|
||
OFF_delay_time = 5000;
|
||
EXTI_ClearITPendingBit(EXTI_Line3);
|
||
}
|
||
}
|
||
|
||
|
||
void EXTI4_15_IRQHandler(void)
|
||
{
|
||
/* TOUCH */
|
||
if (RESET != EXTI_GetITStatus(EXTI_Line5))
|
||
{
|
||
OFF_delay_time = 5000;
|
||
EXTI_ClearITPendingBit(EXTI_Line5);
|
||
}
|
||
}
|
||
|
||
void FPC_Scan(void)
|
||
{
|
||
static bool key_down_flag = 0;
|
||
u8 v_buffer;
|
||
v_buffer = V_Condition_new();
|
||
if(bat_v_delay >0)
|
||
{
|
||
if(v_buffer>=4)
|
||
{
|
||
v_buffer -= 4;//<2F><><EFBFBD><EFBFBD><D7BC>Ⱥ<EFBFBD><C8BA><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>
|
||
}
|
||
}
|
||
g_work.m_conditon.m_conditon.V_conditon = v_buffer;
|
||
#ifdef IR_ENABLE
|
||
if(Key_READ == 0)//<2F><><EFBFBD><EFBFBD>
|
||
{
|
||
OFF_delay_time = 5000;
|
||
if(GPIO_ReadOutputDataBit(FPC_IR_TX_GPIO_Port,FPC_IR_TX_GPIO_Pin) == 1)//<2F><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F2BFAABA><EFBFBD><EFBFBD><EFBFBD>
|
||
{
|
||
IR_ON();
|
||
IR_delay = 10;//<2F><><EFBFBD>ⷢ<EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>10ms
|
||
}
|
||
if(IR_READ == 1 && IR_delay == 0 && g_work.m_conditon.m_conditon.V_conditon <15)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
{
|
||
work_mode = 2;//<2F><><EFBFBD><EFBFBD>״̬
|
||
}
|
||
else
|
||
{
|
||
work_mode = 1;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(OFF_delay_time>0)
|
||
{
|
||
work_mode = 1;
|
||
}
|
||
else
|
||
{
|
||
work_mode = 0 ;
|
||
}
|
||
}
|
||
#else
|
||
if(TOUCH_READ == 1)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˯<EFBFBD><CBAF>
|
||
{
|
||
OFF_delay_time = 5000;
|
||
}
|
||
|
||
if(Key_READ == 0)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>50ms
|
||
{
|
||
OFF_delay_time = 5000;
|
||
if(key_down_flag == 0)
|
||
{
|
||
key_delay = 50;
|
||
key_down_flag = 1;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(key_down_flag == 1)
|
||
{
|
||
key_down_flag = 0;
|
||
}
|
||
}
|
||
|
||
if( key_down_flag == 1&& key_delay == 0 && g_work.m_conditon.m_conditon.V_conditon <15 )//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><D6A7><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
||
{
|
||
work_mode = 2;
|
||
}
|
||
else
|
||
{
|
||
if(OFF_delay_time>0)
|
||
{
|
||
work_mode = 1;
|
||
}
|
||
else
|
||
{
|
||
work_mode = 0 ;
|
||
}
|
||
}
|
||
#endif
|
||
|
||
if(CHARGE5V_READ == 1)//<2F><>5V<35><56><EFBFBD>룬<EFBFBD><EBA3AC>Ҫ<EFBFBD><D2AA><EFBFBD>ݹ<EFBFBD><DDB9><EFBFBD>״̬<D7B4>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||
{
|
||
OFF_delay_time = 5000;//ֻҪ<D6BB><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߾Ͳ<DFBE>Ϩ<EFBFBD><CFA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿ<EFBFBD><D6BF><EFBFBD>
|
||
if(work_mode==2)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
{
|
||
is_charging = 0;//<2F><><EFBFBD>Ȳ<EFBFBD><C8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
if(GPIO_ReadOutputDataBit(CHARGE_CON_GPIO_Port,CHARGE_CON_GPIO_Pin)==0)
|
||
{
|
||
Charge_OFF();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
is_charging = 1;//<2F><><EFBFBD>Ȳ<EFBFBD><C8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
if(GPIO_ReadOutputDataBit(CHARGE_CON_GPIO_Port,CHARGE_CON_GPIO_Pin)==1)
|
||
{
|
||
Charge_ON();
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
is_charging = 0;
|
||
}
|
||
|
||
} |