diff --git a/firmware/p417_SWTL.X/nbproject/Makefile-genesis.properties b/firmware/p417_SWTL.X/nbproject/Makefile-genesis.properties index 3fc172c..f2b6ffb 100644 --- a/firmware/p417_SWTL.X/nbproject/Makefile-genesis.properties +++ b/firmware/p417_SWTL.X/nbproject/Makefile-genesis.properties @@ -1,9 +1,9 @@ # -#Tue Aug 20 14:39:42 CST 2024 +#Sat Aug 24 10:49:00 CST 2024 mcal.com-microchip-mplab-nbide-toolchain-xc32-XC32LanguageToolchain.md5=1eaf555a844840d91945cb14109201c3 conf.ids=mcal mcal.languagetoolchain.version=4.10 -host.id=10k5-yicy-7x +host.id=124p-5vo2-40 configurations-xml=82d12c4bf5f229226e945ddd8fae0eb3 mcal.Pack.dfplocation=E\:\\Program Files\\Microchip\\MPLABX\\v6.20\\packs\\Microchip\\SAME51_DFP\\3.7.242 com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=f612087c95360c842296d189edfe3321 diff --git a/firmware/src/RTE/RTE.c b/firmware/src/RTE/RTE.c index f96bc6d..339ba83 100644 --- a/firmware/src/RTE/RTE.c +++ b/firmware/src/RTE/RTE.c @@ -685,7 +685,7 @@ uint8_t RTE_Get_TouchBoard_XY_Touch_And_Below_1N(void) // 0 false 1 true X_count++; } // 触发的通道数量 //连续触发的通道数量 - if ((Two_Finger_Y_count > 4 && Two_Finger_X_data[0]>th_x[0]) || Y_count != Two_Finger_Y_count || Two_Finger_X_count > 4 || X_count == Two_Finger_X_count) + if ((Two_Finger_Y_count > 4 && Two_Finger_X_data[0]>th_x[0]) || Y_count != Two_Finger_Y_count || Two_Finger_X_count > 4 || X_count != Two_Finger_X_count) { //满足防误触 Allow_Touch_counter++; @@ -1395,6 +1395,7 @@ void RTE_Set_All_Test_Value(void) { baseline_error_repeat_counter = 55000; // 110S ADC0_Initialize(); + ADC0_Enable(); } } break; diff --git a/firmware/src/Speaker/Speaker.c b/firmware/src/Speaker/Speaker.c index 0b873e4..3ea133f 100644 --- a/firmware/src/Speaker/Speaker.c +++ b/firmware/src/Speaker/Speaker.c @@ -167,6 +167,8 @@ void speaker_MainTask(void) //SA51024_Set_State(SA51024_STOP,speaker_ctrl_buf_str.strenght); PORT_PinWrite(PORT_PIN_PA13,0);/*SHUTDOWN = 1,turn on chip*/ PORT_PinWrite(PORT_PIN_PA25,0); + PORT_PinPeripheralFunctionConfig(PORT_PIN_PA02,PERIPHERAL_FUNCTION_B); + DAC_REGS->DAC_CTRLA |= DAC_CTRLA_ENABLE_Msk; speaker_set_strenght(SA51024_STRENGTH_LEVEL0); speaker_main_state_str = SPEAKER_INIT_CYCLE; speaker_cycle_u16 = 0; @@ -179,7 +181,7 @@ void speaker_MainTask(void) if(speaker_cycle_u16++ >= ((SPEAKER_INTERVAL_CYCLE_TIMES)/(SPEAKER_TASK_PERIOD))) { - DAC_REGS->DAC_CTRLA &= ~DAC_CTRLA_ENABLE_Msk; + //DAC_REGS->DAC_CTRLA &= ~DAC_CTRLA_ENABLE_Msk; PORT_PinGPIOConfig(PORT_PIN_PA02); speaker_main_state_str = SPEAKER_IDLE; } @@ -212,9 +214,9 @@ void speaker_MainTask(void) case SPEAKER_START: { - PORT_PinPeripheralFunctionConfig(PORT_PIN_PA02,PERIPHERAL_FUNCTION_B); + PORT_PinWrite(PORT_PIN_PA25,0); - DAC_REGS->DAC_CTRLA |= DAC_CTRLA_ENABLE_Msk; + SA51024_Set_State(SA51024_WORKING,speaker_ctrl_buf_str.strenght); speaker_cycle_u16 = 0; speaker_main_state_str = SPEAKER_UPDATE_CYCLE; @@ -248,7 +250,7 @@ void speaker_MainTask(void) /* Disable DAC */ // DAC_REGS->DAC_CTRLA &= ~DAC_CTRLA_ENABLE_Msk; - PORT_PinGPIOConfig(PORT_PIN_PA02); + //PORT_PinGPIOConfig(PORT_PIN_PA02); } break; diff --git a/firmware/src/TouchPanel/TouchPanel.c b/firmware/src/TouchPanel/TouchPanel.c index c301bad..744e308 100644 --- a/firmware/src/TouchPanel/TouchPanel.c +++ b/firmware/src/TouchPanel/TouchPanel.c @@ -1,16 +1,15 @@ #include "TouchPanel.h" -//#include "TouchPanel_Cfg.h" +// #include "TouchPanel_Cfg.h" #include "Std_Types.h" -#include "device.h" +#include "device.h" #include "touch/touch.h" #include "math.h" #include "stdlib.h" - -#include // Defines NULL -#include // Defines true -#include // Defines EXIT_FAILURE -#include "definitions.h" // SYS function prototypes +#include // Defines NULL +#include // Defines true +#include // Defines EXIT_FAILURE +#include "definitions.h" // SYS function prototypes #include "OsekCom/OsekCom.h" #include "Speaker/Speaker.h" #include "P417_SWTL_App_ert_rtw/P417_SWTL_App.h" @@ -20,348 +19,333 @@ #include "RTE.h" #include "calib_public.h" #include "smartee.h" -#include "SysDiagDetect.h" +#include "SysDiagDetect.h" - -static uint16 sensor_signal[DEF_NUM_CHANNELS] = {0}; -static uint16 sensor_reference[DEF_NUM_CHANNELS] = {0}; static TouchButtons_type key_status[BTN_MAX_CH_NUM - 5U] = {0}; static TouchSurface_type TouchSurface; static Buttons_SignalType Buttons_Signal[BTN_MAX_CH_NUM] = {BUTTON_RELEASE}; -static TouchSlideEvent_type TouchSlideEvent; + TouchSurface_Convert_type Surface_Convert; static PanelPress_LevelType TouchPanel_PressLevel = PANEL_PRESS_LEVEL0; -static float32 TouchPanel_PressNValue = 0.0f;//0N -static uint8 TouchPanel_SurfaceStatus = 0; +static float32 TouchPanel_PressNValue = 0.0f; // 0N +static uint8 TouchPanel_SurfaceStatus = 0; static uint16 TouchPanel_PressRawData = 0; -//kailong add -volatile uint16 g_Trig_Threshold=350; -volatile uint16 g_Release_Threshold=175; -volatile uint8 K_Vibra_Trig_pad=0; +// kailong add +volatile uint16 g_Trig_Threshold = 350; +volatile uint16 g_Release_Threshold = 175; +volatile uint8 K_Vibra_Trig_pad = 0; volatile uint8 Reach2_flag = 0x00; -volatile uint8 Vibra_force_level=0; -volatile uint8 last_Vibra_force_level=0; +volatile uint8 Vibra_force_level = 0; +volatile uint8 last_Vibra_force_level = 0; volatile uint8 Over3N_vibra_req = 0x00; volatile uint8 Below1P5N_vibra_req = 0x00; - uint8 UDS_Vibration_Gain = 0; uint8 UDS_DAC_Timer_Period = 80; uint8 Touch_Flag = TOUCH_KET_OFF; - -uint8 CurrentPosition = 0xff;//0xff no position 1:fun1 2:fun2 3:fun3 4:up 5:down 6:left 7:right 8:ok +uint8 CurrentPosition = 0xff; // 0xff no position 1:fun1 2:fun2 3:fun3 4:up 5:down 6:left 7:right 8:ok uint8 Surface_Button = 0xff; - - -#define RESUME1_DEFAULT 339 -#define ADAS1_DEFAULT 412 -#define CANCEL1_DEFAULT 576 -#define BTN_UP_DEFAULT 269 -#define BTN_DOWN_DEFAULT 398 -#define BTN_LEFT_DEFAULT 261 -#define BTN_RIGHT_DEFAULT 372 +#define RESUME1_DEFAULT 339 +#define ADAS1_DEFAULT 412 +#define CANCEL1_DEFAULT 576 +#define BTN_UP_DEFAULT 269 +#define BTN_DOWN_DEFAULT 398 +#define BTN_LEFT_DEFAULT 261 +#define BTN_RIGHT_DEFAULT 372 #define BTN_CONFIRM_DEFAULT 303 -//force Trig threshold +// force Trig threshold static uint16 Button0_GetRESUME1_Trig_Threshold(void) { - uint16 temp = Calib_GetData(0U); + uint16 temp = Calib_GetData(0U); uint16 rtn = 0; - if(temp == 0) + if (temp == 0) { - rtn=RESUME1_DEFAULT; + rtn = RESUME1_DEFAULT; } else { - rtn=Calib_GetData(0U); + rtn = Calib_GetData(0U); } - + return rtn; // return 800; } -//static uint16 Button1_GetVoice2_Trig_Threshold(void) +// static uint16 Button1_GetVoice2_Trig_Threshold(void) //{ // return 400; -//} +// } -//static uint16 Button2_GetVol2_Trig_Threshold(void) +// static uint16 Button2_GetVol2_Trig_Threshold(void) //{ // return 1600; -//} +// } static uint16 Button3_GetADAS1_Trig_Threshold(void) { - uint16 temp = Calib_GetData(1U); + uint16 temp = Calib_GetData(1U); uint16 rtn = 0; - if(temp == 0) + if (temp == 0) { - rtn=ADAS1_DEFAULT; + rtn = ADAS1_DEFAULT; } else { - rtn=Calib_GetData(1U); + rtn = Calib_GetData(1U); } - + return rtn; } -//static uint16 Button4_GetMenu2_Trig_Threshold(void) +// static uint16 Button4_GetMenu2_Trig_Threshold(void) //{ // return 1600; -//} +// } static uint16 Button5_GetCANCEL1_Trig_Threshold(void) { - uint16 temp = Calib_GetData(2U); + uint16 temp = Calib_GetData(2U); uint16 rtn = 0; - if(temp == 0) + if (temp == 0) { - rtn=CANCEL1_DEFAULT; + rtn = CANCEL1_DEFAULT; } else { - rtn=Calib_GetData(2U); + rtn = Calib_GetData(2U); } - + return rtn; } static uint16 Button6_GetBTN_UP_Trig_Threshold(void) { - uint16 temp = Calib_GetData(3U); + uint16 temp = Calib_GetData(3U); uint16 rtn = 0; - if(temp == 0) + if (temp == 0) { - rtn=BTN_UP_DEFAULT; + rtn = BTN_UP_DEFAULT; } else { - rtn=Calib_GetData(3U); + rtn = Calib_GetData(3U); } - + return rtn; } static uint16 Button7_GetBTN_DOWN_Trig_Threshold(void) { - uint16 temp = Calib_GetData(4U); + uint16 temp = Calib_GetData(4U); uint16 rtn = 0; - if(temp == 0) + if (temp == 0) { - rtn=BTN_DOWN_DEFAULT; + rtn = BTN_DOWN_DEFAULT; } else { - rtn=Calib_GetData(4U); + rtn = Calib_GetData(4U); } - + return rtn; } static uint16 Button8_GetBTN_LEFT_Trig_Threshold(void) { - uint16 temp = Calib_GetData(5U); + uint16 temp = Calib_GetData(5U); uint16 rtn = 0; - if(temp == 0) + if (temp == 0) { - rtn=BTN_LEFT_DEFAULT; + rtn = BTN_LEFT_DEFAULT; } else { - rtn=Calib_GetData(5U); + rtn = Calib_GetData(5U); } - + return rtn; } static uint16 Button9_GetBTN_RIGHT_Trig_Threshold(void) { - uint16 temp = Calib_GetData(6U); + uint16 temp = Calib_GetData(6U); uint16 rtn = 0; - if(temp == 0) + if (temp == 0) { - rtn=BTN_RIGHT_DEFAULT; + rtn = BTN_RIGHT_DEFAULT; } else { - rtn=Calib_GetData(6U); + rtn = Calib_GetData(6U); } - + return rtn; } static uint16 Button10_GetBTN_CONFIRM_Trig_Threshold(void) { - uint16 temp = Calib_GetData(7U); + uint16 temp = Calib_GetData(7U); uint16 rtn = 0; - if(temp == 0) + if (temp == 0) { - rtn=BTN_CONFIRM_DEFAULT; + rtn = BTN_CONFIRM_DEFAULT; } else { - rtn=Calib_GetData(7U); + rtn = Calib_GetData(7U); } - + return rtn; } -//force Release threshold +// force Release threshold static uint16 Button0_GetRESUME1_Release_Threshold(void) { - uint16 temp = Calib_GetData(0U); + uint16 temp = Calib_GetData(0U); uint16 rtn = 0; - if(temp == 0) + if (temp == 0) { - rtn=RESUME1_DEFAULT/2; + rtn = RESUME1_DEFAULT / 2; } else { - rtn=Calib_GetData(0U)/2; + rtn = Calib_GetData(0U) / 2; } - + return rtn; } -//static uint16 Button1_GetVoice2_Release_Threshold(void) +// static uint16 Button1_GetVoice2_Release_Threshold(void) //{ // return 200; -//} +// } -//static uint16 Button2_GetVol2_Release_Threshold(void) +// static uint16 Button2_GetVol2_Release_Threshold(void) //{ // return 400; -//} +// } static uint16 Button3_GetADAS1_Release_Threshold(void) { - uint16 temp = Calib_GetData(1U); + uint16 temp = Calib_GetData(1U); uint16 rtn = 0; - if(temp == 0) + if (temp == 0) { - rtn=ADAS1_DEFAULT/2; + rtn = ADAS1_DEFAULT / 2; } else { - rtn=Calib_GetData(1U)/2; + rtn = Calib_GetData(1U) / 2; } - + return rtn; } -//static uint16 Button4_GetMenu2_Release_Threshold(void) +// static uint16 Button4_GetMenu2_Release_Threshold(void) //{ // return 400; -//} +// } static uint16 Button5_GetCANCEL1_Release_Threshold(void) { - uint16 temp = Calib_GetData(2U); + uint16 temp = Calib_GetData(2U); uint16 rtn = 0; - if(temp == 0) + if (temp == 0) { - rtn=CANCEL1_DEFAULT/2; + rtn = CANCEL1_DEFAULT / 2; } else { - rtn=Calib_GetData(2U)/2; + rtn = Calib_GetData(2U) / 2; } - + return rtn; } static uint16 Button6_GetBTN_UP_Release_Threshold(void) { - uint16 temp = Calib_GetData(3U); + uint16 temp = Calib_GetData(3U); uint16 rtn = 0; - if(temp == 0) + if (temp == 0) { - rtn=BTN_UP_DEFAULT/2; + rtn = BTN_UP_DEFAULT / 2; } else { - rtn=Calib_GetData(3U)/2; + rtn = Calib_GetData(3U) / 2; } - + return rtn; } static uint16 Button7_GetBTN_DOWN_Release_Threshold(void) { - uint16 temp = Calib_GetData(4U); + uint16 temp = Calib_GetData(4U); uint16 rtn = 0; - if(temp == 0) + if (temp == 0) { - rtn=BTN_DOWN_DEFAULT/2; + rtn = BTN_DOWN_DEFAULT / 2; } else { - rtn=Calib_GetData(4U)/2; + rtn = Calib_GetData(4U) / 2; } - + return rtn; } static uint16 Button8_GetBTN_LEFT_Release_Threshold(void) { - uint16 temp = Calib_GetData(5U); + uint16 temp = Calib_GetData(5U); uint16 rtn = 0; - if(temp == 0) + if (temp == 0) { - rtn=BTN_LEFT_DEFAULT/2; + rtn = BTN_LEFT_DEFAULT / 2; } else { - rtn=Calib_GetData(5U)/2; + rtn = Calib_GetData(5U) / 2; } - + return rtn; } static uint16 Button9_GetBTN_RIGHT_Release_Threshold(void) { - uint16 temp = Calib_GetData(6U); + uint16 temp = Calib_GetData(6U); uint16 rtn = 0; - if(temp == 0) + if (temp == 0) { - rtn=BTN_RIGHT_DEFAULT/2; + rtn = BTN_RIGHT_DEFAULT / 2; } else { - rtn=Calib_GetData(6U)/2; + rtn = Calib_GetData(6U) / 2; } - + return rtn; } static uint16 Button10_GetBTN_CONFIRM_Release_Threshold(void) { - uint16 temp = Calib_GetData(7U); + uint16 temp = Calib_GetData(7U); uint16 rtn = 0; - if(temp == 0) + if (temp == 0) { - rtn=BTN_CONFIRM_DEFAULT/2; + rtn = BTN_CONFIRM_DEFAULT / 2; } else { - rtn=Calib_GetData(7U)/2; + rtn = Calib_GetData(7U) / 2; } - + return rtn; } - - - - - - - - /** * \brief Sets buffers to a specified byte value. * \param pDestP buffer with set value @@ -369,17 +353,17 @@ static uint16 Button10_GetBTN_CONFIRM_Release_Threshold(void) * \param BytesCountP number of bytes * \return None */ -static void LIB_Mem_MemSet (void * const pDestP, const uint8 u8ValueP, const uint32 u32BytesCountP) +static void LIB_Mem_MemSet(void *const pDestP, const uint8 u8ValueP, const uint32 u32BytesCountP) { - uint8 * pu8BufL = (uint8 *)pDestP; + uint8 *pu8BufL = (uint8 *)pDestP; uint32 u32IdxL; - if( (NULL_PTR != pu8BufL) ) + if ((NULL_PTR != pu8BufL)) { u32IdxL = u32BytesCountP; - while( u32IdxL > (uint32)0 ) + while (u32IdxL > (uint32)0) { --u32IdxL; @@ -391,535 +375,538 @@ static void LIB_Mem_MemSet (void * const pDestP, const uint8 u8ValueP, const uin static float32 AlideAverage_Filter(uint8 mode, float32 RawData) { - #define MAX_ALIDE_AVG_NUM 8 - static uint16 CalcAverageNum = 0; - static uint16 DIndex = 0; - static uint16 Mode_Status = 0; - static float32 RawData_Table[MAX_ALIDE_AVG_NUM] = {0}; - uint16 i; - float32 Sum = 0; - float32 AverageValue = 0; - if(mode == 0x00){ - CalcAverageNum = 0; - DIndex = 0; - Mode_Status = 0; - for(i=0; i= MAX_ALIDE_AVG_NUM) - { - Mode_Status = 0x01; - DIndex = 0; - } - AverageValue = Sum/((float32)CalcAverageNum + 0.000001f); - } - else - { - RawData_Table[DIndex++] = RawData; - if(DIndex >= MAX_ALIDE_AVG_NUM){ - DIndex = 0x00; - } - for(i=0; i= MAX_ALIDE_AVG_NUM) + { + Mode_Status = 0x01; + DIndex = 0; + } + AverageValue = Sum / ((float32)CalcAverageNum + 0.000001f); + } + else + { + RawData_Table[DIndex++] = RawData; + if (DIndex >= MAX_ALIDE_AVG_NUM) + { + DIndex = 0x00; + } + for (i = 0; i < MAX_ALIDE_AVG_NUM; i++) + { + Sum += RawData_Table[i]; + } + AverageValue = Sum / MAX_ALIDE_AVG_NUM; + } + } return AverageValue; } - void TouchPanel_init(void) { - uint8 index; - //touch_init(); + uint8 index; + // touch_init(); uint8_t eedata[5]; - LIB_Mem_MemSet(&TouchSurface, 0x00U, sizeof(TouchSurface_type)); - LIB_Mem_MemSet(&TouchSlideEvent, 0x00U, sizeof(TouchSlideEvent_type)); - LIB_Mem_MemSet(&Surface_Convert, 0x00U, sizeof(TouchSurface_Convert_type)); - SmartEE_Read(0x780, eedata, 3); - if(eedata[0]< 4) + LIB_Mem_MemSet(&TouchSurface, 0x00U, sizeof(TouchSurface_type)); + LIB_Mem_MemSet(&Surface_Convert, 0x00U, sizeof(TouchSurface_Convert_type)); + SmartEE_Read(0x780, eedata, 3); + if (eedata[0] < 4) { UDS_Vibration_Gain = eedata[0]; - }else + } + else { UDS_Vibration_Gain = SA51024_STRENGTH_LEVEL0; } - if(eedata[2] < 255 && eedata[2] >= 40) + if (eedata[2] < 255 && eedata[2] >= 40) { - UDS_DAC_Timer_Period = eedata[2]; + UDS_DAC_Timer_Period = eedata[2]; } else { UDS_DAC_Timer_Period = 110; } TC2_REGS->COUNT16.TC_CC[0U] = UDS_DAC_Timer_Period; - AlideAverage_Filter(0, 0); - TouchPanel_PressLevel = PANEL_PRESS_LEVEL0; - TouchPanel_PressNValue = 0.0f;//0N + AlideAverage_Filter(0, 0); + TouchPanel_PressLevel = PANEL_PRESS_LEVEL0; + TouchPanel_PressNValue = 0.0f; // 0N TouchPanel_SurfaceStatus = 0; - TouchPanel_PressRawData = 0; - for(index = 0; index< DEF_NUM_CHANNELS; index++) - { - sensor_signal[index] = 0x00; - sensor_reference[index] = 0x00; - if(index < (BTN_MAX_CH_NUM-5u)){ - key_status[index].status = 0x00; - key_status[index].RunCycle = 0x00; - } - if(index < BTN_MAX_CH_NUM ){ - Buttons_Signal[index] = BUTTON_RELEASE; - } - } + TouchPanel_PressRawData = 0; + for (index = 0; index < DEF_NUM_CHANNELS; index++) + { + if (index < (BTN_MAX_CH_NUM - 5u)) + { + key_status[index].status = 0x00; + key_status[index].RunCycle = 0x00; + } + if (index < BTN_MAX_CH_NUM) + { + Buttons_Signal[index] = BUTTON_RELEASE; + } + } } void GetSurface_Position(uint8 *x, uint8 *y) { - if(x != NULL_PTR){ - *x = Surface_Convert.convert_x; - } - if(y != NULL_PTR){ - *y = Surface_Convert.convert_y; - } + if (x != NULL_PTR) + { + *x = Surface_Convert.convert_x; + } + if (y != NULL_PTR) + { + *y = Surface_Convert.convert_y; + } } - - TP_SlideDirection_Enum TouchPanel_SlideEventRead(void) { - TP_SlideDirection_Enum Dir = TP_SlideDirection_NONE; - if(TouchSlideEvent.Event == TRUE){ - Dir = TouchSlideEvent.Direction; - //TouchSlideEvent.Event = FALSE; - } - return Dir; + TP_SlideDirection_Enum Dir = TP_SlideDirection_NONE; + + return Dir; } Buttons_SignalType TouchPanel_BtnSignalRead(Buttons_ChType ChId) { - Buttons_SignalType Signal = BUTTON_RELEASE; + Buttons_SignalType Signal = BUTTON_RELEASE; - if(ChId < BTN_MAX_CH_NUM) - { - Signal = Buttons_Signal[ChId]; - } + if (ChId < BTN_MAX_CH_NUM) + { + Signal = Buttons_Signal[ChId]; + } - return Signal; + return Signal; } PanelPress_LevelType TouchPanel_PressLevelRead(void) { - return TouchPanel_PressLevel; + return TouchPanel_PressLevel; } boolean TouchSurface_is_TouchActive(void) { - boolean ret = FALSE; - if (TouchPanel_SurfaceStatus & TOUCH_ACTIVE) - { - ret = TRUE; - } + boolean ret = FALSE; + if (TouchPanel_SurfaceStatus & TOUCH_ACTIVE && CurrentPosition>0 && CurrentPosition<9) + { + ret = TRUE; + } - return ret; + return ret; } Buttons_SignalType TouchSurface_XY_StsRead(void) { - Buttons_SignalType XY_Sts = BUTTON_RELEASE; - - if (TouchPanel_SurfaceStatus & TOUCH_ACTIVE) + Buttons_SignalType XY_Sts = BUTTON_RELEASE; + + if (TouchPanel_SurfaceStatus & TOUCH_ACTIVE && CurrentPosition>0 && CurrentPosition<9) { - + switch (TouchPanel_PressLevel) - { - case PANEL_PRESS_LEVEL0: - XY_Sts = BUTTON_TOUCH; - break; - case PANEL_PRESS_LEVEL1: - XY_Sts = BUTTON_TOUCH; - break; - case PANEL_PRESS_LEVEL2: - XY_Sts = BUTTON_TOUCH_AND_PRESS; - break; - default: - break; - } - - + { + case PANEL_PRESS_LEVEL0: + XY_Sts = BUTTON_TOUCH; + break; + case PANEL_PRESS_LEVEL1: + XY_Sts = BUTTON_TOUCH; + break; + case PANEL_PRESS_LEVEL2: + XY_Sts = BUTTON_TOUCH_AND_PRESS; + break; + default: + break; + } } - return XY_Sts; + return XY_Sts; } - - - static PanelPress_LevelType TouchPanel_PressCheck(void) { - //static uint16 ForceHcount = 0; - //static uint16 ForceMcount = 0; - //static uint16 ForceLcount = 0; - - static uint16 tempForcePress = 0; - static uint16 tempForceRelease = 0; - - uint16 RawData = 0; - uint16 temp_RawData = 0; - static uint16 LastRawData = 0; - static PanelPress_LevelType Last_PressLevel = PANEL_PRESS_LEVEL0; + // static uint16 ForceHcount = 0; + // static uint16 ForceMcount = 0; + // static uint16 ForceLcount = 0; + + static uint16 tempForcePress = 0; + static uint16 tempForceRelease = 0; + + uint16 RawData = 0; + uint16 temp_RawData = 0; + static uint16 LastRawData = 0; + static PanelPress_LevelType Last_PressLevel = PANEL_PRESS_LEVEL0; static uint8 P_force_Reach2_flag = 0; - PanelPress_LevelType ret_Press = PANEL_PRESS_LEVEL0; - float32 FilterValue; + PanelPress_LevelType ret_Press = PANEL_PRESS_LEVEL0; + float32 FilterValue; uint16 Backup_Force_Value; - Backup_Force_Value=Touch_Sensor_delta03+Touch_Sensor_delta04+Touch_Sensor_delta05+Touch_Sensor_delta06+Touch_Sensor_delta07+ - +Touch_Sensor_delta08+Touch_Sensor_delta09+Touch_Sensor_delta10+Touch_Sensor_delta11+Touch_Sensor_delta12; - //float32 PressNValueTable[3][2] = { - // {1.21f, 1.73f}, - // {0.5f, 3.0f}, - // {1.0f, 1.8f} - //}; - - if(CurrentPosition != 0xff) + Backup_Force_Value = Touch_Sensor_delta03 + Touch_Sensor_delta04 + Touch_Sensor_delta05 + Touch_Sensor_delta06 + Touch_Sensor_delta07 + + +Touch_Sensor_delta08 + Touch_Sensor_delta09 + Touch_Sensor_delta10 + Touch_Sensor_delta11 + Touch_Sensor_delta12; + // float32 PressNValueTable[3][2] = { + // {1.21f, 1.73f}, + // {0.5f, 3.0f}, + // {1.0f, 1.8f} + // }; + + if (CurrentPosition != 0xff) { tempForcePress = g_Trig_Threshold; tempForceRelease = g_Release_Threshold; } - - if(Last_PressLevel > PANEL_PRESS_LEVEL2){ Last_PressLevel = PANEL_PRESS_LEVEL0;} + + if (Last_PressLevel > PANEL_PRESS_LEVEL2) + { + Last_PressLevel = PANEL_PRESS_LEVEL0; + } ////if(TRUE == GET_TouchPanel_is_Press()) - temp_RawData = (0xfff & Get_forcedetect_force_value()); - if(SPEAKER_UPDATE_CYCLE == Get_Speaker_Main_State() || SPEAKER_START == Get_Speaker_Main_State()) - { - RawData = LastRawData; - } - else - { - if(temp_RawData&0x800)//negative - { - RawData = 0x00; - }else{ - RawData = temp_RawData; - } - - if(abs(RawData - LastRawData) > (10*0xF2)) - { - RawData = LastRawData; - } - } - - TouchPanel_PressRawData = RawData; - TouchPanel_PressNValue = ((float32)RawData / (float32)0xF2); - FilterValue = AlideAverage_Filter(1, TouchPanel_PressNValue); - - if(Force_Sens_Err == 0) + temp_RawData = (0xfff & Get_forcedetect_force_value()); + if (SPEAKER_UPDATE_CYCLE == Get_Speaker_Main_State() || SPEAKER_START == Get_Speaker_Main_State()) { - if(FilterValue <= ((float32)tempForceRelease/ (float32)0xF2)){//< 1.5N - // ForceHcount = 0; - // ForceMcount = 0; - //ForceLcount++; - P_force_Reach2_flag = 0; - // if(ForceLcount > 40) - //{ - // ForceLcount = 40; - + RawData = LastRawData; + } + else + { + if (temp_RawData & 0x800) // negative + { + RawData = 0x00; + } + else + { + RawData = temp_RawData; + } + + if (abs(RawData - LastRawData) > (10 * 0xF2)) + { + RawData = LastRawData; + } + } + + TouchPanel_PressRawData = RawData; + TouchPanel_PressNValue = ((float32)RawData / (float32)0xF2); + FilterValue = AlideAverage_Filter(1, TouchPanel_PressNValue); + + if (Force_Sens_Err == 0) + { + if (FilterValue <= ((float32)tempForceRelease / (float32)0xF2)) + { //< 1.5N + // ForceHcount = 0; + // ForceMcount = 0; + // ForceLcount++; + P_force_Reach2_flag = 0; + // if(ForceLcount > 40) + //{ + // ForceLcount = 40; + ret_Press = PANEL_PRESS_LEVEL0; - - - // } - - Vibra_force_level=PANEL_PRESS_LEVEL0; - } - else if(FilterValue >= ((float32)tempForceRelease/ (float32)0xF2) && - FilterValue < ((float32)tempForcePress/ (float32)0xF2)){//1.5N~~3N - //ForceHcount = 0; - // ForceMcount++; - // ForceLcount = 0; - // if(ForceMcount > 40) - // { - // ForceMcount = 40; - if(P_force_Reach2_flag==1) + + // } + + Vibra_force_level = PANEL_PRESS_LEVEL0; + } + else if (FilterValue >= ((float32)tempForceRelease / (float32)0xF2) && + FilterValue < ((float32)tempForcePress / (float32)0xF2)) + { // 1.5N~~3N + // ForceHcount = 0; + // ForceMcount++; + // ForceLcount = 0; + // if(ForceMcount > 40) + // { + // ForceMcount = 40; + if (P_force_Reach2_flag == 1) { - //if(TOUCH_SCREEN_CONTACT_AREA_INVALID_NUM > get_contact_size()) - //{ - - Vibra_force_level=PANEL_PRESS_LEVEL2; - ret_Press = PANEL_PRESS_LEVEL2; - //} - //else - //{ - // ret_Press = PANEL_PRESS_LEVEL0; - // Vibra_force_level=PANEL_PRESS_LEVEL0; - //} + // if(TOUCH_SCREEN_CONTACT_AREA_INVALID_NUM > get_contact_size()) + //{ + + Vibra_force_level = PANEL_PRESS_LEVEL2; + ret_Press = PANEL_PRESS_LEVEL2; + //} + // else + //{ + // ret_Press = PANEL_PRESS_LEVEL0; + // Vibra_force_level=PANEL_PRESS_LEVEL0; + //} } else { - //if(TOUCH_SCREEN_CONTACT_AREA_INVALID_NUM > get_contact_size()) - //{ - - Vibra_force_level=PANEL_PRESS_LEVEL1; - ret_Press = PANEL_PRESS_LEVEL1; - //} - //else - //{ - // ret_Press = PANEL_PRESS_LEVEL0; - // Vibra_force_level=PANEL_PRESS_LEVEL0; - //} - } + // if(TOUCH_SCREEN_CONTACT_AREA_INVALID_NUM > get_contact_size()) + //{ + + Vibra_force_level = PANEL_PRESS_LEVEL1; + ret_Press = PANEL_PRESS_LEVEL1; + //} + // else + //{ + // ret_Press = PANEL_PRESS_LEVEL0; + // Vibra_force_level=PANEL_PRESS_LEVEL0; + //} + } + } + + else + { //>=3 + // ForceHcount++; + // ForceMcount = 0; + // ForceLcount = 0; + P_force_Reach2_flag = 1; + // if(ForceHcount > 40) + // { + // ForceHcount = 40; + + // if(TOUCH_SCREEN_CONTACT_AREA_INVALID_NUM > get_contact_size()) + //{ + ret_Press = PANEL_PRESS_LEVEL2; + + //} + // else + //{ + // ret_Press = PANEL_PRESS_LEVEL0; + // Vibra_force_level=PANEL_PRESS_LEVEL0; + //} + + Vibra_force_level = PANEL_PRESS_LEVEL2; } - - - else {//>=3 - //ForceHcount++; - //ForceMcount = 0; - // ForceLcount = 0; - P_force_Reach2_flag = 1; - // if(ForceHcount > 40) - // { - // ForceHcount = 40; - - //if(TOUCH_SCREEN_CONTACT_AREA_INVALID_NUM > get_contact_size()) - //{ - ret_Press = PANEL_PRESS_LEVEL2; - - //} - //else - //{ - // ret_Press = PANEL_PRESS_LEVEL0; - // Vibra_force_level=PANEL_PRESS_LEVEL0; - //} - - Vibra_force_level=PANEL_PRESS_LEVEL2; - } } - else //backup When force sensor error happened + else // backup When force sensor error happened { - if(Backup_Force_Value <= 100){//< 1.5N - // ForceHcount = 0; - // ForceMcount = 0; - //ForceLcount++; - P_force_Reach2_flag = 0; - // if(ForceLcount > 40) - //{ - // ForceLcount = 40; - + if (Backup_Force_Value <= 100) + { //< 1.5N + // ForceHcount = 0; + // ForceMcount = 0; + // ForceLcount++; + P_force_Reach2_flag = 0; + // if(ForceLcount > 40) + //{ + // ForceLcount = 40; + ret_Press = PANEL_PRESS_LEVEL0; - - - // } - - Vibra_force_level=PANEL_PRESS_LEVEL0; - } - else if(Backup_Force_Value >= 100 && - Backup_Force_Value < 200){//1.5N~~3N - //ForceHcount = 0; - // ForceMcount++; - // ForceLcount = 0; - // if(ForceMcount > 40) - // { - // ForceMcount = 40; - if(P_force_Reach2_flag==1) + + // } + + Vibra_force_level = PANEL_PRESS_LEVEL0; + } + else if (Backup_Force_Value >= 100 && + Backup_Force_Value < 200) + { // 1.5N~~3N + // ForceHcount = 0; + // ForceMcount++; + // ForceLcount = 0; + // if(ForceMcount > 40) + // { + // ForceMcount = 40; + if (P_force_Reach2_flag == 1) { - //if(TOUCH_SCREEN_CONTACT_AREA_INVALID_NUM > get_contact_size()) - //{ - - Vibra_force_level=PANEL_PRESS_LEVEL2; - ret_Press = PANEL_PRESS_LEVEL2; - //} - //else - //{ - // ret_Press = PANEL_PRESS_LEVEL0; - // Vibra_force_level=PANEL_PRESS_LEVEL0; - //} + // if(TOUCH_SCREEN_CONTACT_AREA_INVALID_NUM > get_contact_size()) + //{ + + Vibra_force_level = PANEL_PRESS_LEVEL2; + ret_Press = PANEL_PRESS_LEVEL2; + //} + // else + //{ + // ret_Press = PANEL_PRESS_LEVEL0; + // Vibra_force_level=PANEL_PRESS_LEVEL0; + //} } else { - //if(TOUCH_SCREEN_CONTACT_AREA_INVALID_NUM > get_contact_size()) - //{ - - Vibra_force_level=PANEL_PRESS_LEVEL1; - ret_Press = PANEL_PRESS_LEVEL1; - //} - //else - //{ - // ret_Press = PANEL_PRESS_LEVEL0; - // Vibra_force_level=PANEL_PRESS_LEVEL0; - //} - } + // if(TOUCH_SCREEN_CONTACT_AREA_INVALID_NUM > get_contact_size()) + //{ + + Vibra_force_level = PANEL_PRESS_LEVEL1; + ret_Press = PANEL_PRESS_LEVEL1; + //} + // else + //{ + // ret_Press = PANEL_PRESS_LEVEL0; + // Vibra_force_level=PANEL_PRESS_LEVEL0; + //} + } + } + + else + { //>=3 + // ForceHcount++; + // ForceMcount = 0; + // ForceLcount = 0; + P_force_Reach2_flag = 1; + // if(ForceHcount > 40) + // { + // ForceHcount = 40; + + // if(TOUCH_SCREEN_CONTACT_AREA_INVALID_NUM > get_contact_size()) + //{ + ret_Press = PANEL_PRESS_LEVEL2; + + //} + // else + //{ + // ret_Press = PANEL_PRESS_LEVEL0; + // Vibra_force_level=PANEL_PRESS_LEVEL0; + //} + + Vibra_force_level = PANEL_PRESS_LEVEL2; } - - - else {//>=3 - //ForceHcount++; - //ForceMcount = 0; - // ForceLcount = 0; - P_force_Reach2_flag = 1; - // if(ForceHcount > 40) - // { - // ForceHcount = 40; - - //if(TOUCH_SCREEN_CONTACT_AREA_INVALID_NUM > get_contact_size()) - //{ - ret_Press = PANEL_PRESS_LEVEL2; - - //} - //else - //{ - // ret_Press = PANEL_PRESS_LEVEL0; - // Vibra_force_level=PANEL_PRESS_LEVEL0; - //} - - Vibra_force_level=PANEL_PRESS_LEVEL2; - } } - LastRawData = RawData; - Last_PressLevel = ret_Press; + LastRawData = RawData; + Last_PressLevel = ret_Press; - - - - - - return ret_Press; + return ret_Press; } static Buttons_SignalType TouchSurface_BntCheck(Buttons_ChType ChId, TouchPanel_EventType TP_Event) { - Buttons_SignalType BSignal = BUTTON_RELEASE; - //static uint8 PB_force_Reach2_flag = 0; - //uint8 x_pos = 0, y_pos = 0; - uint8 data_ready = 0x00; - //GetSurface_Position(&x_pos, &y_pos); - switch(ChId) - { - case BTN_UP: - if (Surface_Button ==1)//37 - { - data_ready = 0x01; - } - break; - case BTN_DOWN: - if (Surface_Button ==2)//223 - { - data_ready = 0x01; - } - break; - case BTN_LEFT: - if (Surface_Button ==3) - { - data_ready = 0x01; - } - break; - case BTN_RIGHT: - if (Surface_Button ==4) - { - data_ready = 0x01; - } - break; - case BTN_CONFIRM: - if (Surface_Button ==5) - { - data_ready = 0x01; - } - break; - default: break; - } - - if(data_ready != 0x00) - { - if(TP_Event == TOUCH_PANEL_PRESS_EVENT) - { - - switch (TouchPanel_PressLevel) - { - case PANEL_PRESS_LEVEL0: - BSignal = BUTTON_TOUCH; - break; - case PANEL_PRESS_LEVEL1: - BSignal = BUTTON_TOUCH; - break; - case PANEL_PRESS_LEVEL2: - BSignal = BUTTON_TOUCH_AND_PRESS; - break; - default: - break; - } - - - - }else if(TP_Event == TOUCH_PANEL_BERR_EVENT){ - BSignal = BUTTON_RELEASE;//////////////BUTTON_INVALID; - } - } + Buttons_SignalType BSignal = BUTTON_RELEASE; + // static uint8 PB_force_Reach2_flag = 0; + // uint8 x_pos = 0, y_pos = 0; + uint8 data_ready = 0x00; + // GetSurface_Position(&x_pos, &y_pos); + switch (ChId) + { + case BTN_UP: + if (Surface_Button == 1) // 37 + { + data_ready = 0x01; + } + break; + case BTN_DOWN: + if (Surface_Button == 2) // 223 + { + data_ready = 0x01; + } + break; + case BTN_LEFT: + if (Surface_Button == 3) + { + data_ready = 0x01; + } + break; + case BTN_RIGHT: + if (Surface_Button == 4) + { + data_ready = 0x01; + } + break; + case BTN_CONFIRM: + if (Surface_Button == 5) + { + data_ready = 0x01; + } + break; + default: + break; + } - return BSignal; + if (data_ready != 0x00) + { + if (TP_Event == TOUCH_PANEL_PRESS_EVENT) + { + + switch (TouchPanel_PressLevel) + { + case PANEL_PRESS_LEVEL0: + BSignal = BUTTON_TOUCH; + break; + case PANEL_PRESS_LEVEL1: + BSignal = BUTTON_TOUCH; + break; + case PANEL_PRESS_LEVEL2: + BSignal = BUTTON_TOUCH_AND_PRESS; + break; + default: + break; + } + } + else if (TP_Event == TOUCH_PANEL_BERR_EVENT) + { + BSignal = BUTTON_RELEASE; //////////////BUTTON_INVALID; + } + } + + return BSignal; } static Buttons_SignalType TouchButton_BntCheck(Buttons_ChType ChId) { - Buttons_SignalType BSignal = BUTTON_RELEASE; - //static uint8 TB_force_Reach2_flag = 0; - if(ChId == BTN_RESUME1 || ChId == BTN_ADAS1 || ChId == BTN_CANCEL1) - { - key_status[ChId].status = get_sensor_state(ChId); + Buttons_SignalType BSignal = BUTTON_RELEASE; + // static uint8 TB_force_Reach2_flag = 0; + if (ChId == BTN_RESUME1 || ChId == BTN_ADAS1 || ChId == BTN_CANCEL1) + { + key_status[ChId].status = get_sensor_state(ChId); if (ChId == BTN_CANCEL1) { - key_status[ChId].status = (get_sensor_state(ChId) == QTM_KEY_STATE_DETECT || get_sensor_state(ChId+13) == QTM_KEY_STATE_DETECT)?QTM_KEY_STATE_DETECT:get_sensor_state(ChId); + key_status[ChId].status = (get_sensor_state(ChId) == QTM_KEY_STATE_DETECT || get_sensor_state(ChId + 13) == QTM_KEY_STATE_DETECT) ? QTM_KEY_STATE_DETECT : get_sensor_state(ChId); } - - if (QTM_KEY_STATE_DETECT == (key_status[ChId].status)) {//KEY_TOUCHED_MASK - //Touch detect - key_status[ChId].RunCycle++; - if(TP_RUNNING_ERROR_CYCLE <= key_status[ChId].RunCycle){ - key_status[ChId].RunCycle = TP_RUNNING_ERROR_CYCLE; - BSignal = BUTTON_RELEASE;//BUTTON_INVALID; - }else{ - - if(Force_Sens_Err == 0) - { + + if (QTM_KEY_STATE_DETECT == (key_status[ChId].status)) + { // KEY_TOUCHED_MASK + // Touch detect + key_status[ChId].RunCycle++; + if (TP_RUNNING_ERROR_CYCLE <= key_status[ChId].RunCycle) + { + key_status[ChId].RunCycle = TP_RUNNING_ERROR_CYCLE; + BSignal = BUTTON_RELEASE; // BUTTON_INVALID; + } + else + { + + if (Force_Sens_Err == 0) + { switch (TouchPanel_PressLevel) { - case PANEL_PRESS_LEVEL0: - BSignal = BUTTON_TOUCH; - case PANEL_PRESS_LEVEL1: - BSignal = BUTTON_TOUCH; + case PANEL_PRESS_LEVEL0: + BSignal = BUTTON_TOUCH; + case PANEL_PRESS_LEVEL1: + BSignal = BUTTON_TOUCH; // } - break; - case PANEL_PRESS_LEVEL2: - BSignal = BUTTON_TOUCH_AND_PRESS; - break; - default: + break; + case PANEL_PRESS_LEVEL2: + BSignal = BUTTON_TOUCH_AND_PRESS; + break; + default: break; } } - else //backup When force sensor error happened - { + else // backup When force sensor error happened + { BSignal = BUTTON_TOUCH; } - - } - } else { - //Touch No detect - key_status[ChId].RunCycle = 0x00; - } - } - return BSignal; + } + } + else + { + // Touch No detect + key_status[ChId].RunCycle = 0x00; + } + } + return BSignal; } -static float32 GetSlide_Angle(float32 dx, float32 dy) +static float32 GetSlide_Angle(float32 dx, float32 dy) { - return(atan2(dy, dx) * 180 / PI); + return (atan2(dy, dx) * 180 / PI); } /**************************************************************/ @@ -929,79 +916,29 @@ static float32 GetSlide_Angle(float32 dx, float32 dy) // | =======> | // | | // | X(-y)<-------|(0,0) -/*************************************************************/ -static TP_SlideDirection_Enum GetSlide_Direction(uint8 startX, uint8 startY, uint8 endX, uint8 endY) +/*************************************************************/ +static TP_SlideDirection_Enum GetSlide_Direction(uint8 startX, uint8 startY, uint8 endX, uint8 endY) { TP_SlideDirection_Enum result = TP_SlideDirection_NONE; - sint32 CoordMapping_sx,CoordMapping_sy; - sint32 CoordMapping_ex,CoordMapping_ey; - uint16 absx,absy; - sint32 dy,dx; - float32 angle; - - CoordMapping_sx = (-1u * (sint32)startX); - CoordMapping_sy = (-1u * (sint32)startY); - CoordMapping_ex = (-1u * (sint32)endX); - CoordMapping_ey = (-1u * (sint32)(endY)); - dx = CoordMapping_ex - CoordMapping_sx; - dy = CoordMapping_ey - CoordMapping_sy; - - absx = abs(dx); - absy = abs(dy); - if(TouchSurface.Event == TOUCH_PANEL_MOVE_EVENT && (absx > SLIDE_LR_MIN_DISTANCE || absy > SLIDE_UD_MIN_DISTANCE) ) - { - /*Ignore small Slide*/ - angle = GetSlide_Angle(dx, dy); - if (angle >= -45.0 && angle < 45.0) - { - if(absx > SLIDE_LR_SHORT_DISTANCE_NUM){ - result = TP_SlideDirection_LongRIGHT; - }else{ - result = TP_SlideDirection_ShortRIGHT; - } - } - else if (angle >= 45.0 && angle < 135.0) - { - if(absy > SLIDE_UD_SHORT_DISTANCE_NUM){ - result = TP_SlideDirection_LongUP; - }else{ - result = TP_SlideDirection_ShortUP; - } - } else if (angle >= -135.0 && angle < -45.0) - { - if(absy > SLIDE_UD_SHORT_DISTANCE_NUM){ - result = TP_SlideDirection_LongDOWN; - }else{ - result = TP_SlideDirection_ShortDOWN; - } - } - else if ((angle >= 135.0 && angle <= 180.0) || (angle >= -180.0 && angle < -135.0)) - { - if(absx > SLIDE_LR_SHORT_DISTANCE_NUM){ - result = TP_SlideDirection_LongLEFT; - }else{ - result = TP_SlideDirection_ShortLEFT; - } - } - } - return result; } - - -struct Point { +struct Point +{ float x; float y; }; // ~{EP6OR;8v5cJG7qTZH}=GPNDZ2?~} -uint8_t point_in_triangle(struct Point p, struct Point p1, struct Point p2, struct Point p3) { +uint8_t point_in_triangle(struct Point p, struct Point p1, struct Point p2, struct Point p3) +{ float s = p1.y * p3.x - p1.x * p3.y + (p3.y - p1.y) * p.x + (p1.x - p3.x) * p.y; float t = p1.x * p2.y - p1.y * p2.x + (p1.y - p2.y) * p.x + (p2.x - p1.x) * p.y; - if ((s < 0) != (t < 0)) return 0; + if ((s < 0) != (t < 0)) + return 0; float A = -p2.y * p3.x + p1.y * (p3.x - p2.x) + p1.x * (p2.y - p3.y) + p2.x * p3.y; - if (A < 0.0) { + if (A < 0.0) + { s = -s; t = -t; A = -A; @@ -1010,741 +947,611 @@ uint8_t point_in_triangle(struct Point p, struct Point p1, struct Point p2, stru } // ~{EP6OR;8v5cJG7qTZKD1_PNDZ2?~} -uint8_t point_in_quadrilateral(struct Point p, struct Point q1, struct Point q2, struct Point q3, struct Point q4) { +uint8_t point_in_quadrilateral(struct Point p, struct Point q1, struct Point q2, struct Point q3, struct Point q4) +{ return point_in_triangle(p, q1, q2, q3) || point_in_triangle(p, q1, q3, q4); } static void TouchPanel_XY_Convert(uint8 origin_x, uint8 origin_y) { -#define Y_OFFSET 40 -#define START_X 95 -#define START_Y 240 -#define END_X 255 -#define END_Y 197 - TouchXY_type start,end; - float32 k,b,y; +#define Y_OFFSET 40 +#define START_X 95 +#define START_Y 240 +#define END_X 255 +#define END_Y 197 + TouchXY_type start, end; + float32 k, b, y; - uint8 temp_x, temp_y; - uint8 convert_x,convert_y; - float32 f_x; - temp_x = origin_y; - f_x = (((float32)temp_x)/(255.0f/160.0f));// 255u-95u - if(f_x - (uint32)(f_x) < 0.5f){ - convert_x = (uint8)f_x + 95u; - }else{ convert_x = (uint8)f_x + 1u + 95u;} - - temp_y = origin_x; - /*******************************************/ + uint8 temp_x, temp_y; + uint8 convert_x, convert_y; + float32 f_x; + temp_x = origin_y; + f_x = (((float32)temp_x) / (255.0f / 160.0f)); // 255u-95u + if (f_x - (uint32)(f_x) < 0.5f) + { + convert_x = (uint8)f_x + 95u; + } + else + { + convert_x = (uint8)f_x + 1u + 95u; + } - start.x = START_X; - start.y = START_Y; - end.x = END_X; - end.y = END_Y; + temp_y = origin_x; + /*******************************************/ - k = ((end.y - start.y)/(end.x - start.x)); - b = (start.y - k * start.x); - y = k*convert_x + b; - convert_y =(uint8)(((float32)temp_y * (y - Y_OFFSET))/255 + Y_OFFSET); + start.x = START_X; + start.y = START_Y; + end.x = END_X; + end.y = END_Y; - Surface_Convert.convert_x = convert_x; //KalmanFilter(convert_x, 0); - Surface_Convert.convert_y = convert_y; //KalmanFilter(convert_y, 0); + k = ((end.y - start.y) / (end.x - start.x)); + b = (start.y - k * start.x); + y = k * convert_x + b; + convert_y = (uint8)(((float32)temp_y * (y - Y_OFFSET)) / 255 + Y_OFFSET); + + Surface_Convert.convert_x = convert_x; // KalmanFilter(convert_x, 0); + Surface_Convert.convert_y = convert_y; // KalmanFilter(convert_y, 0); } - - void touch_test(void) { - - - } extern uint8_t Allow_Touch_flag; -//static uint16_t touch_delay = 500; +// static uint16_t touch_delay = 500; void TouchPanel_MainFunction(void) { - uint8 index; - uint8 x1,y1, x2,y2, Temp_x,Temp_y; - uint8 touchEnd_flag = 0x00; - - - uint8 pad_trig_x,pad_trig_y;//by kailong - + uint8 index; + uint8 Temp_x, Temp_y; + + + uint8 pad_trig_x, pad_trig_y; // by kailong + uint8 count = 0; - - uint8 K_Vibra_Trig_adas=0; - uint8 K_Vibra_Trig_cancel=0; - uint8 K_Vibra_Trig_resume=0; - - static uint8 threshold_select_resume = 0; - static uint8 threshold_select_adas = 0; - static uint8 threshold_select_cancel = 0; - static uint8 threshold_select_up = 0; - static uint8 threshold_select_down = 0; - static uint8 threshold_select_left = 0; - static uint8 threshold_select_right = 0; - static uint8 threshold_select_confirm = 0; + uint8 K_Vibra_Trig_adas = 0; + uint8 K_Vibra_Trig_cancel = 0; + uint8 K_Vibra_Trig_resume = 0; - - touch_process(); - - //kailong add - if (QTM_KEY_STATE_DETECT == get_sensor_state(BTN_ADAS1) && QTM_KEY_STATE_DETECT == get_sensor_state(BTN_ADAS1+13)) + static uint8 threshold_select_resume = 0; + static uint8 threshold_select_adas = 0; + static uint8 threshold_select_cancel = 0; + static uint8 threshold_select_up = 0; + static uint8 threshold_select_down = 0; + static uint8 threshold_select_left = 0; + static uint8 threshold_select_right = 0; + static uint8 threshold_select_confirm = 0; + + touch_process(); + + // kailong add + if (QTM_KEY_STATE_DETECT == get_sensor_state(BTN_ADAS1) && QTM_KEY_STATE_DETECT == get_sensor_state(BTN_ADAS1 + 13)) { CurrentPosition = 2; - threshold_select_adas=1; + threshold_select_adas = 1; } else { - threshold_select_adas=0; + threshold_select_adas = 0; } - if (QTM_KEY_STATE_DETECT == get_sensor_state(BTN_RESUME1) && QTM_KEY_STATE_DETECT == get_sensor_state(BTN_RESUME1+13)) - { + if (QTM_KEY_STATE_DETECT == get_sensor_state(BTN_RESUME1) && QTM_KEY_STATE_DETECT == get_sensor_state(BTN_RESUME1 + 13)) + { CurrentPosition = 1; - threshold_select_resume=1; - + threshold_select_resume = 1; } else { - threshold_select_resume=0; + threshold_select_resume = 0; } - if (QTM_KEY_STATE_DETECT == get_sensor_state(BTN_CANCEL1) || QTM_KEY_STATE_DETECT == get_sensor_state(BTN_CANCEL1+13)) + if (QTM_KEY_STATE_DETECT == get_sensor_state(BTN_CANCEL1) || QTM_KEY_STATE_DETECT == get_sensor_state(BTN_CANCEL1 + 13)) { CurrentPosition = 3; - threshold_select_cancel=1; - - } + threshold_select_cancel = 1; + } else { - threshold_select_cancel=0; + threshold_select_cancel = 0; } - - if((TouchPanel_SurfaceStatus & TOUCH_ACTIVE) == 1) - { - struct Point Current_XY; - -#if 1 - struct Point Point_Up[4] = { - {76,0}, - {255,41}, - {206,87}, - {135,87}, - }; - - struct Point Point_Down[4] = { - {135,169}, - {206,169}, - {255,199}, - {106,255}, - }; - - struct Point Point_Right[4] = { - {76,21}, - {135,87}, - {135,169}, - {96,255}, - }; - - struct Point Point_Left[4] = { - {206,87}, - {255,48}, - {255,183}, - {206,169}, - }; - - struct Point Point_Confirm[4] = { - {140,92}, - {206,92}, - {206,164}, - {140,164}, - }; + if ((TouchPanel_SurfaceStatus & TOUCH_ACTIVE) == 1) + { + struct Point Current_XY; + +#if 1 + struct Point Point_Up[4] = { + {76, 0}, + {255, 41}, + {206, 87}, + {135, 87}, + }; + + struct Point Point_Down[4] = { + {135, 169}, + {206, 169}, + {255, 199}, + {106, 255}, + }; + + struct Point Point_Right[4] = { + {76, 21}, + {135, 87}, + {135, 169}, + {96, 255}, + }; + + struct Point Point_Left[4] = { + {206, 87}, + {255, 48}, + {255, 183}, + {206, 169}, + }; + + struct Point Point_Confirm[4] = { + {140, 92}, + {206, 92}, + {206, 164}, + {140, 164}, + }; #endif - //point_in_quadrilateral(Current_XY,Point_Up[0],Point_Up[1],Point_Up[2],Point_Up[3]) - - GetSurface_Position(&pad_trig_x, &pad_trig_y); - Current_XY.x = (float)pad_trig_x; - Current_XY.y = (float)pad_trig_y; - - - if(point_in_quadrilateral(Current_XY,Point_Up[0],Point_Up[1],Point_Up[2],Point_Up[3])) + // point_in_quadrilateral(Current_XY,Point_Up[0],Point_Up[1],Point_Up[2],Point_Up[3]) + + GetSurface_Position(&pad_trig_x, &pad_trig_y); + Current_XY.x = (float)pad_trig_x; + Current_XY.y = (float)pad_trig_y; + + if (point_in_quadrilateral(Current_XY, Point_Up[0], Point_Up[1], Point_Up[2], Point_Up[3])) { - if(CurrentPosition != 1 && CurrentPosition != 2 && CurrentPosition != 3 ) - { + if (CurrentPosition != 1 && CurrentPosition != 2 && CurrentPosition != 3) + { CurrentPosition = 4; - K_Vibra_Trig_pad=1; - threshold_select_up=1; + K_Vibra_Trig_pad = 1; + threshold_select_up = 1; Surface_Button = 1; } } - - else if(point_in_quadrilateral(Current_XY,Point_Down[0],Point_Down[1],Point_Down[2],Point_Down[3])) + + else if (point_in_quadrilateral(Current_XY, Point_Down[0], Point_Down[1], Point_Down[2], Point_Down[3])) { - if(CurrentPosition != 1 && CurrentPosition != 2 && CurrentPosition != 3 ) - { + if (CurrentPosition != 1 && CurrentPosition != 2 && CurrentPosition != 3) + { CurrentPosition = 5; - K_Vibra_Trig_pad=1; - threshold_select_down=1; + K_Vibra_Trig_pad = 1; + threshold_select_down = 1; Surface_Button = 2; } } - - else if(point_in_quadrilateral(Current_XY,Point_Right[0],Point_Right[1],Point_Right[2],Point_Right[3])) + + else if (point_in_quadrilateral(Current_XY, Point_Right[0], Point_Right[1], Point_Right[2], Point_Right[3])) { - if(CurrentPosition != 1 && CurrentPosition != 2 && CurrentPosition != 3 ) - { + if (CurrentPosition != 1 && CurrentPosition != 2 && CurrentPosition != 3) + { CurrentPosition = 7; - K_Vibra_Trig_pad=1; - threshold_select_right=1; + K_Vibra_Trig_pad = 1; + threshold_select_right = 1; Surface_Button = 4; - } + } } - - else if(point_in_quadrilateral(Current_XY,Point_Left[0],Point_Left[1],Point_Left[2],Point_Left[3])) + + else if (point_in_quadrilateral(Current_XY, Point_Left[0], Point_Left[1], Point_Left[2], Point_Left[3])) { - if(CurrentPosition != 1 && CurrentPosition != 2 && CurrentPosition != 3 ) - { + if (CurrentPosition != 1 && CurrentPosition != 2 && CurrentPosition != 3) + { CurrentPosition = 6; - K_Vibra_Trig_pad=1; - threshold_select_left=1; + K_Vibra_Trig_pad = 1; + threshold_select_left = 1; Surface_Button = 3; - } + } } - - - else if(point_in_quadrilateral(Current_XY,Point_Confirm[0],Point_Confirm[1],Point_Confirm[2],Point_Confirm[3])) + + else if (point_in_quadrilateral(Current_XY, Point_Confirm[0], Point_Confirm[1], Point_Confirm[2], Point_Confirm[3])) { - if(CurrentPosition != 1 && CurrentPosition != 2 && CurrentPosition != 3 ) - { + if (CurrentPosition != 1 && CurrentPosition != 2 && CurrentPosition != 3) + { CurrentPosition = 8; - K_Vibra_Trig_pad=1; - threshold_select_confirm=1; + K_Vibra_Trig_pad = 1; + threshold_select_confirm = 1; Surface_Button = 5; } } - - - - } - else - { - - K_Vibra_Trig_pad=0; - threshold_select_up=0; - threshold_select_down=0; - threshold_select_right=0; - threshold_select_left=0; - threshold_select_confirm=0; - Surface_Button = 0; - } - switch (CurrentPosition) - { - case 1: - g_Trig_Threshold=Button0_GetRESUME1_Trig_Threshold(); - g_Release_Threshold=Button0_GetRESUME1_Release_Threshold(); - break; - case 2: - g_Trig_Threshold= Button3_GetADAS1_Trig_Threshold(); - g_Release_Threshold= Button3_GetADAS1_Release_Threshold(); - break; - case 3: - g_Trig_Threshold=Button5_GetCANCEL1_Trig_Threshold(); - g_Release_Threshold= Button5_GetCANCEL1_Release_Threshold(); - break; - case 4: - g_Trig_Threshold=Button6_GetBTN_UP_Trig_Threshold(); - g_Release_Threshold= Button6_GetBTN_UP_Release_Threshold(); - break; - case 5: - g_Trig_Threshold=Button7_GetBTN_DOWN_Trig_Threshold(); - g_Release_Threshold= Button7_GetBTN_DOWN_Release_Threshold(); - break; - case 6: - g_Trig_Threshold=Button8_GetBTN_LEFT_Trig_Threshold(); - g_Release_Threshold= Button8_GetBTN_LEFT_Release_Threshold(); - break; - case 7: - g_Trig_Threshold=Button9_GetBTN_RIGHT_Trig_Threshold(); - g_Release_Threshold= Button9_GetBTN_RIGHT_Release_Threshold(); - break; - case 8: - g_Trig_Threshold=Button10_GetBTN_CONFIRM_Trig_Threshold(); - g_Release_Threshold= Button10_GetBTN_CONFIRM_Release_Threshold(); - break; - default: - break; - } - /* - if(threshold_select_resume == 1 && threshold_select_adas==0 && threshold_select_cancel==0 && threshold_select_up==0 && threshold_select_down==0 && threshold_select_left==0 && threshold_select_right==0 && threshold_select_confirm==0 ) - { - g_Trig_Threshold=Button0_GetRESUME1_Trig_Threshold(); - g_Release_Threshold=Button0_GetRESUME1_Release_Threshold(); - } - else if(threshold_select_resume == 0 && threshold_select_adas==1 && threshold_select_cancel==0 && threshold_select_up==0 && threshold_select_down==0 && threshold_select_left==0 && threshold_select_right==0 && threshold_select_confirm==0 ) - { - g_Trig_Threshold= Button3_GetADAS1_Trig_Threshold(); - g_Release_Threshold= Button3_GetADAS1_Release_Threshold(); - } - else if(threshold_select_resume == 0 && threshold_select_adas==0 && threshold_select_cancel==1 && threshold_select_up==0 && threshold_select_down==0 && threshold_select_left==0 && threshold_select_right==0 && threshold_select_confirm==0 ) - { - g_Trig_Threshold=Button5_GetCANCEL1_Trig_Threshold(); - g_Release_Threshold= Button5_GetCANCEL1_Release_Threshold(); - } - else if(threshold_select_resume == 0 && threshold_select_adas==0 && threshold_select_cancel==0 && threshold_select_up==1 && threshold_select_down==0 && threshold_select_left==0 && threshold_select_right==0 && threshold_select_confirm==0 ) - { - g_Trig_Threshold=Button6_GetBTN_UP_Trig_Threshold(); - g_Release_Threshold= Button6_GetBTN_UP_Release_Threshold(); - } - else if(threshold_select_resume == 0 && threshold_select_adas==0 && threshold_select_cancel==0 && threshold_select_up==0 && threshold_select_down==1 && threshold_select_left==0 && threshold_select_right==0 && threshold_select_confirm==0 ) - { - g_Trig_Threshold=Button7_GetBTN_DOWN_Trig_Threshold(); - g_Release_Threshold= Button7_GetBTN_DOWN_Release_Threshold(); - } - else if(threshold_select_resume == 0 && threshold_select_adas==0 && threshold_select_cancel==0 && threshold_select_up==0 && threshold_select_down==0 && threshold_select_left==1 && threshold_select_right==0 && threshold_select_confirm==0 ) - { - g_Trig_Threshold=Button8_GetBTN_LEFT_Trig_Threshold(); - g_Release_Threshold= Button8_GetBTN_LEFT_Release_Threshold(); - } - else if(threshold_select_resume == 0 && threshold_select_adas==0 && threshold_select_cancel==0 && threshold_select_up==0 && threshold_select_down==0 && threshold_select_left==0 && threshold_select_right==1 && threshold_select_confirm==0 ) - { - g_Trig_Threshold=Button9_GetBTN_RIGHT_Trig_Threshold(); - g_Release_Threshold= Button9_GetBTN_RIGHT_Release_Threshold(); - } - else if(threshold_select_resume == 0 && threshold_select_adas==0 && threshold_select_cancel==0 && threshold_select_up==0 && threshold_select_down==0 && threshold_select_left==0 && threshold_select_right==0 && threshold_select_confirm==1 ) - { - g_Trig_Threshold=Button10_GetBTN_CONFIRM_Trig_Threshold(); - g_Release_Threshold= Button10_GetBTN_CONFIRM_Release_Threshold(); } else { - g_Trig_Threshold=Button10_GetBTN_CONFIRM_Trig_Threshold(); - g_Release_Threshold= Button10_GetBTN_CONFIRM_Release_Threshold(); - } - */ - //InitMessage(SIG_SWTLSENSOR1_BASELINE, &g_Trig_Threshold); - - TouchPanel_PressLevel = TouchPanel_PressCheck(); - - - - if(measurement_done_touch == 1) + + K_Vibra_Trig_pad = 0; + threshold_select_up = 0; + threshold_select_down = 0; + threshold_select_right = 0; + threshold_select_left = 0; + threshold_select_confirm = 0; + Surface_Button = 0; + } + switch (CurrentPosition) { - // process touch data - for(index = 0; index< DEF_NUM_CHANNELS; index++){ - sensor_signal[index] = get_sensor_node_signal(index); - sensor_reference[index] = get_sensor_node_reference(index); - } + case 1: + g_Trig_Threshold = Button0_GetRESUME1_Trig_Threshold(); + g_Release_Threshold = Button0_GetRESUME1_Release_Threshold(); + break; + case 2: + g_Trig_Threshold = Button3_GetADAS1_Trig_Threshold(); + g_Release_Threshold = Button3_GetADAS1_Release_Threshold(); + break; + case 3: + g_Trig_Threshold = Button5_GetCANCEL1_Trig_Threshold(); + g_Release_Threshold = Button5_GetCANCEL1_Release_Threshold(); + break; + case 4: + g_Trig_Threshold = Button6_GetBTN_UP_Trig_Threshold(); + g_Release_Threshold = Button6_GetBTN_UP_Release_Threshold(); + break; + case 5: + g_Trig_Threshold = Button7_GetBTN_DOWN_Trig_Threshold(); + g_Release_Threshold = Button7_GetBTN_DOWN_Release_Threshold(); + break; + case 6: + g_Trig_Threshold = Button8_GetBTN_LEFT_Trig_Threshold(); + g_Release_Threshold = Button8_GetBTN_LEFT_Release_Threshold(); + break; + case 7: + g_Trig_Threshold = Button9_GetBTN_RIGHT_Trig_Threshold(); + g_Release_Threshold = Button9_GetBTN_RIGHT_Release_Threshold(); + break; + case 8: + g_Trig_Threshold = Button10_GetBTN_CONFIRM_Trig_Threshold(); + g_Release_Threshold = Button10_GetBTN_CONFIRM_Release_Threshold(); + break; + default: + break; + } - TouchPanel_SurfaceStatus = get_surface_status(); - if (TouchPanel_SurfaceStatus & TOUCH_ACTIVE) - { - Temp_x = get_surface_position(HOR_POS); - Temp_y = get_surface_position(VER_POS); - TouchPanel_XY_Convert(Temp_x, Temp_y); - TouchSurface.x_position = Surface_Convert.convert_x; - TouchSurface.y_position = Surface_Convert.convert_y; - - if(TouchSurface.end_x_pos == 0x00 && TouchSurface.end_y_pos == 0x00){ - TouchSurface.end_x_pos = TouchSurface.x_position; - TouchSurface.end_y_pos = TouchSurface.y_position; - } + TouchPanel_PressLevel = TouchPanel_PressCheck(); - if(TouchSurface.Event == TOUCH_PANEL_NONE_EVENT){ - x1 = TouchSurface.end_x_pos; y1 = TouchSurface.end_y_pos; - x2 = TouchSurface.x_position; y2 = TouchSurface.y_position; - }else{ - x1 = TouchSurface.origin_x_pos; y1 = TouchSurface.origin_y_pos; - x2 = TouchSurface.x_position; y2 = TouchSurface.y_position; - } + if (measurement_done_touch == 1) + { - TouchSurface.CheckCycle++; - TouchSurface.TouchCycle++; - if((abs(x2-x1) < TP_ERR_RANGE) && (abs(y2-y1) < TP_ERR_RANGE)) - { - // sampling error <= +- TP_ERR_RANGE - if (TouchSurface.CheckCycle >= TP_DEBOUNCE_CYCLE) - { - if(TOUCH_PANEL_NONE_EVENT == TouchSurface.Event){ - TouchSurface.origin_x_pos = (x1+x2)/2; - TouchSurface.origin_y_pos = (y1+y2)/2; - TouchSurface.Event = TOUCH_PANEL_PRESS_EVENT; - } - TouchSurface.CheckCycle = TP_DEBOUNCE_CYCLE; - } - TouchSurface.end_x_pos = x2; - TouchSurface.end_y_pos = y2; - } - else - { - if(TOUCH_PANEL_PRESS_EVENT == TouchSurface.Event || TOUCH_PANEL_MOVE_EVENT == TouchSurface.Event) - { - TouchSurface.Event = TOUCH_PANEL_MOVE_EVENT; - }else{ - TouchSurface.Event = TOUCH_PANEL_NONE_EVENT; - TouchSurface.origin_x_pos = 0x00; - TouchSurface.origin_y_pos = 0x00; - } - TouchSurface.end_x_pos = x2; - TouchSurface.end_y_pos = y2; - } - } - else - { - x1 = TouchSurface.origin_x_pos; y1 = TouchSurface.origin_y_pos; - x2 = TouchSurface.end_x_pos; y2 = TouchSurface.end_y_pos; - if(TOUCH_PANEL_MOVE_EVENT == TouchSurface.Event) - { - if((abs(x2-x1) < TP_ERR_RANGE) && (abs(y2-y1) < TP_ERR_RANGE)) - { - TouchSurface.Event = TOUCH_PANEL_RES_EVENT; - }else{ - TouchSurface.Event = TOUCH_PANEL_MOVE_EVENT; - TouchSlideEvent.Direction = GetSlide_Direction(x1, y1, x2, y2); - if(TouchSlideEvent.Direction != TP_SlideDirection_NONE){ - TouchSlideEvent.keep_cycle = SLIDE_CAN_EVENT_KEEP_CYCLE; - TouchSlideEvent.Event = TRUE; - } - } - } - else if(TOUCH_PANEL_PRESS_EVENT == TouchSurface.Event) - { - //do nothing - } - else - { - TouchSurface.Event = TOUCH_PANEL_NONE_EVENT; - } - - TouchSurface.end_x_pos = 0x00; - TouchSurface.end_y_pos = 0x00; - TouchSurface.CheckCycle = 0x00; - TouchSurface.origin_x_pos = 0x00; - TouchSurface.origin_y_pos = 0x00; - TouchSurface.x_position = 0; - TouchSurface.y_position = 0; - TouchSurface.TouchCycle = 0; - Surface_Convert.convert_x = 0x00; - Surface_Convert.convert_y = 0x00; - touchEnd_flag = 0x01; - } - - if(TouchSurface.TouchCycle >= TP_RUNNING_ERROR_CYCLE){ - TouchSurface.TouchCycle = TP_RUNNING_ERROR_CYCLE; - TouchSurface.Event = TOUCH_PANEL_BERR_EVENT; - } - - for(index = 0; index< BTN_MAX_CH_NUM; index++) - { - if(index< (BTN_MAX_CH_NUM - 5U)){ - Buttons_Signal[index] = TouchButton_BntCheck(index); - }else{ - Buttons_Signal[index] = TouchSurface_BntCheck(index, 1); - } - } - - switch(CurrentPosition) + TouchPanel_SurfaceStatus = get_surface_status(); + if (TouchPanel_SurfaceStatus & TOUCH_ACTIVE) + { + Temp_x = get_surface_position(HOR_POS); + Temp_y = get_surface_position(VER_POS); + TouchPanel_XY_Convert(Temp_x, Temp_y); + } + else { - case 1:{ - Buttons_Signal[BTN_RESUME1] = TouchButton_BntCheck(BTN_RESUME1); - if(Buttons_Signal[BTN_RESUME1] >= BUTTON_TOUCH) - { - break; - }else - { - for(index = 0; index< BTN_MAX_CH_NUM; index++) - { - if(index< (BTN_MAX_CH_NUM - 5U)){ - Buttons_Signal[index] = TouchButton_BntCheck(index); - }else{ - Buttons_Signal[index] = TouchSurface_BntCheck(index, 1); - } - if(Buttons_Signal[index] < BUTTON_TOUCH) - { - count++; - } - } - } - break; - } - case 2:{ - Buttons_Signal[BTN_ADAS1] = TouchButton_BntCheck(BTN_ADAS1); - if(Buttons_Signal[BTN_ADAS1] >= BUTTON_TOUCH) - { - break; - }else - { - for(index = 0; index< BTN_MAX_CH_NUM; index++) - { - if(index< (BTN_MAX_CH_NUM - 5U)){ - Buttons_Signal[index] = TouchButton_BntCheck(index); - }else{ - Buttons_Signal[index] = TouchSurface_BntCheck(index, 1); - } + Surface_Convert.convert_x = 0x00; + Surface_Convert.convert_y = 0x00; + } - if(Buttons_Signal[index] < BUTTON_TOUCH) - { - count++; - } - } - } - break; - } - case 3:{ - Buttons_Signal[BTN_CANCEL1] = TouchButton_BntCheck(BTN_CANCEL1); - if(Buttons_Signal[BTN_CANCEL1] >= BUTTON_TOUCH) - { - break; - }else - { - for(index = 0; index< BTN_MAX_CH_NUM; index++) - { - if(index< (BTN_MAX_CH_NUM - 5U)){ - Buttons_Signal[index] = TouchButton_BntCheck(index); - }else{ - Buttons_Signal[index] = TouchSurface_BntCheck(index, 1); - } + for (index = 0; index < BTN_MAX_CH_NUM; index++) + { + if (index < (BTN_MAX_CH_NUM - 5U)) + { + Buttons_Signal[index] = TouchButton_BntCheck(index); + } + else + { + Buttons_Signal[index] = TouchSurface_BntCheck(index, 1); + } + } - if(Buttons_Signal[index] < BUTTON_TOUCH) - { - count++; - } - } - } + switch (CurrentPosition) + { + case 1: + { + Buttons_Signal[BTN_RESUME1] = TouchButton_BntCheck(BTN_RESUME1); + if (Buttons_Signal[BTN_RESUME1] >= BUTTON_TOUCH) + { break; - } - case 4:{ - Buttons_Signal[BTN_UP] = TouchSurface_BntCheck(BTN_UP, 1); - if(Buttons_Signal[BTN_UP] >= BUTTON_TOUCH) + } + else + { + for (index = 0; index < BTN_MAX_CH_NUM; index++) { - break; - }else - { - for(index = 0; index< BTN_MAX_CH_NUM; index++) - { - if(index< (BTN_MAX_CH_NUM - 5U)){ - Buttons_Signal[index] = TouchButton_BntCheck(index); - }else{ - Buttons_Signal[index] = TouchSurface_BntCheck(index, 1); - } - - if(Buttons_Signal[index] < BUTTON_TOUCH) - { - count++; - } - } - } - break; - } - case 5:{ - Buttons_Signal[BTN_DOWN] = TouchSurface_BntCheck(BTN_DOWN, 1); - if(Buttons_Signal[BTN_DOWN] >= BUTTON_TOUCH) - { - break; - }else - { - for(index = 0; index< BTN_MAX_CH_NUM; index++) - { - if(index< (BTN_MAX_CH_NUM - 5U)){ - Buttons_Signal[index] = TouchButton_BntCheck(index); - }else{ - Buttons_Signal[index] = TouchSurface_BntCheck(index, 1); - } - - if(Buttons_Signal[index] < BUTTON_TOUCH) - { - count++; - } - } - } - break; - } - case 6:{ - Buttons_Signal[BTN_LEFT] = TouchSurface_BntCheck(BTN_LEFT, 1); - if(Buttons_Signal[BTN_LEFT] >= BUTTON_TOUCH) - { - break; - }else - { - for(index = 0; index< BTN_MAX_CH_NUM; index++) - { - if(index< (BTN_MAX_CH_NUM - 5U)){ - Buttons_Signal[index] = TouchButton_BntCheck(index); - }else{ - Buttons_Signal[index] = TouchSurface_BntCheck(index, 1); - } - - if(Buttons_Signal[index] < BUTTON_TOUCH) - { - count++; - } - } - } - break; - } - case 7:{ - Buttons_Signal[BTN_RIGHT] = TouchSurface_BntCheck(BTN_RIGHT, 1); - if(Buttons_Signal[BTN_RIGHT] >= BUTTON_TOUCH) - { - break; - }else - { - for(index = 0; index< BTN_MAX_CH_NUM; index++) - { - if(index< (BTN_MAX_CH_NUM - 5U)){ - Buttons_Signal[index] = TouchButton_BntCheck(index); - }else{ - Buttons_Signal[index] = TouchSurface_BntCheck(index, 1); - } - - if(Buttons_Signal[index] < BUTTON_TOUCH) - { - count++; - } - } - } - break; - } - case 8:{ - Buttons_Signal[BTN_CONFIRM] = TouchSurface_BntCheck(BTN_CONFIRM, 1); - if(Buttons_Signal[BTN_CONFIRM] >= BUTTON_TOUCH) - { - break; - }else - { - for(index = 0; index< BTN_MAX_CH_NUM; index++) - { - if(index< (BTN_MAX_CH_NUM - 5U)){ - Buttons_Signal[index] = TouchButton_BntCheck(index); - }else{ - Buttons_Signal[index] = TouchSurface_BntCheck(index, 1); - } - - if(Buttons_Signal[index] < BUTTON_TOUCH) - { - count++; - } - } - } - break; - } - default:{ - for(index = 0; index< BTN_MAX_CH_NUM; index++) - { - if(index< (BTN_MAX_CH_NUM - 5U)){ + if (index < (BTN_MAX_CH_NUM - 5U)) + { Buttons_Signal[index] = TouchButton_BntCheck(index); - }else{ + } + else + { Buttons_Signal[index] = TouchSurface_BntCheck(index, 1); } - if(Buttons_Signal[index] < BUTTON_TOUCH) + if (Buttons_Signal[index] < BUTTON_TOUCH) { count++; } } - break; - } + } + break; } - - if(count == BTN_MAX_CH_NUM) + case 2: + { + Buttons_Signal[BTN_ADAS1] = TouchButton_BntCheck(BTN_ADAS1); + if (Buttons_Signal[BTN_ADAS1] >= BUTTON_TOUCH) + { + break; + } + else + { + for (index = 0; index < BTN_MAX_CH_NUM; index++) + { + if (index < (BTN_MAX_CH_NUM - 5U)) + { + Buttons_Signal[index] = TouchButton_BntCheck(index); + } + else + { + Buttons_Signal[index] = TouchSurface_BntCheck(index, 1); + } + + if (Buttons_Signal[index] < BUTTON_TOUCH) + { + count++; + } + } + } + break; + } + case 3: + { + Buttons_Signal[BTN_CANCEL1] = TouchButton_BntCheck(BTN_CANCEL1); + if (Buttons_Signal[BTN_CANCEL1] >= BUTTON_TOUCH) + { + break; + } + else + { + for (index = 0; index < BTN_MAX_CH_NUM; index++) + { + if (index < (BTN_MAX_CH_NUM - 5U)) + { + Buttons_Signal[index] = TouchButton_BntCheck(index); + } + else + { + Buttons_Signal[index] = TouchSurface_BntCheck(index, 1); + } + + if (Buttons_Signal[index] < BUTTON_TOUCH) + { + count++; + } + } + } + break; + } + case 4: + { + Buttons_Signal[BTN_UP] = TouchSurface_BntCheck(BTN_UP, 1); + if (Buttons_Signal[BTN_UP] >= BUTTON_TOUCH) + { + break; + } + else + { + for (index = 0; index < BTN_MAX_CH_NUM; index++) + { + if (index < (BTN_MAX_CH_NUM - 5U)) + { + Buttons_Signal[index] = TouchButton_BntCheck(index); + } + else + { + Buttons_Signal[index] = TouchSurface_BntCheck(index, 1); + } + + if (Buttons_Signal[index] < BUTTON_TOUCH) + { + count++; + } + } + } + break; + } + case 5: + { + Buttons_Signal[BTN_DOWN] = TouchSurface_BntCheck(BTN_DOWN, 1); + if (Buttons_Signal[BTN_DOWN] >= BUTTON_TOUCH) + { + break; + } + else + { + for (index = 0; index < BTN_MAX_CH_NUM; index++) + { + if (index < (BTN_MAX_CH_NUM - 5U)) + { + Buttons_Signal[index] = TouchButton_BntCheck(index); + } + else + { + Buttons_Signal[index] = TouchSurface_BntCheck(index, 1); + } + + if (Buttons_Signal[index] < BUTTON_TOUCH) + { + count++; + } + } + } + break; + } + case 6: + { + Buttons_Signal[BTN_LEFT] = TouchSurface_BntCheck(BTN_LEFT, 1); + if (Buttons_Signal[BTN_LEFT] >= BUTTON_TOUCH) + { + break; + } + else + { + for (index = 0; index < BTN_MAX_CH_NUM; index++) + { + if (index < (BTN_MAX_CH_NUM - 5U)) + { + Buttons_Signal[index] = TouchButton_BntCheck(index); + } + else + { + Buttons_Signal[index] = TouchSurface_BntCheck(index, 1); + } + + if (Buttons_Signal[index] < BUTTON_TOUCH) + { + count++; + } + } + } + break; + } + case 7: + { + Buttons_Signal[BTN_RIGHT] = TouchSurface_BntCheck(BTN_RIGHT, 1); + if (Buttons_Signal[BTN_RIGHT] >= BUTTON_TOUCH) + { + break; + } + else + { + for (index = 0; index < BTN_MAX_CH_NUM; index++) + { + if (index < (BTN_MAX_CH_NUM - 5U)) + { + Buttons_Signal[index] = TouchButton_BntCheck(index); + } + else + { + Buttons_Signal[index] = TouchSurface_BntCheck(index, 1); + } + + if (Buttons_Signal[index] < BUTTON_TOUCH) + { + count++; + } + } + } + break; + } + case 8: + { + Buttons_Signal[BTN_CONFIRM] = TouchSurface_BntCheck(BTN_CONFIRM, 1); + if (Buttons_Signal[BTN_CONFIRM] >= BUTTON_TOUCH) + { + break; + } + else + { + for (index = 0; index < BTN_MAX_CH_NUM; index++) + { + if (index < (BTN_MAX_CH_NUM - 5U)) + { + Buttons_Signal[index] = TouchButton_BntCheck(index); + } + else + { + Buttons_Signal[index] = TouchSurface_BntCheck(index, 1); + } + + if (Buttons_Signal[index] < BUTTON_TOUCH) + { + count++; + } + } + } + break; + } + default: + { + for (index = 0; index < BTN_MAX_CH_NUM; index++) + { + if (index < (BTN_MAX_CH_NUM - 5U)) + { + Buttons_Signal[index] = TouchButton_BntCheck(index); + } + else + { + Buttons_Signal[index] = TouchSurface_BntCheck(index, 1); + } + + if (Buttons_Signal[index] < BUTTON_TOUCH) + { + count++; + } + } + break; + } + } + + if (count == BTN_MAX_CH_NUM) { CurrentPosition = 0xff; - //Allow_Touch_flag=1; - } - - - - if(touchEnd_flag != 0x00){ - TouchSurface.Event = TOUCH_PANEL_NONE_EVENT; - } + // Allow_Touch_flag=1; + } - touch_test(); - + touch_test(); + measurement_done_touch = 0; } - if(TouchSlideEvent.Event == TRUE) - { - if(TouchSlideEvent.keep_cycle != 0x00){ - TouchSlideEvent.keep_cycle--; - } - if(TouchSlideEvent.keep_cycle == 0x00){ - TouchSlideEvent.Direction = TP_SlideDirection_NONE; - TouchSlideEvent.Event = FALSE; - } - } - if(TouchSurface.Event == TOUCH_PANEL_BERR_EVENT) - { - TouchSurface.Event = TOUCH_PANEL_NONE_EVENT; - } - - - - - if (threshold_select_adas == 1) { - K_Vibra_Trig_adas=1; + K_Vibra_Trig_adas = 1; } else { - K_Vibra_Trig_adas=0; + K_Vibra_Trig_adas = 0; } - + if (threshold_select_cancel == 1) { - K_Vibra_Trig_cancel=1; + K_Vibra_Trig_cancel = 1; } else { - K_Vibra_Trig_cancel=0; + K_Vibra_Trig_cancel = 0; } - + if (threshold_select_resume == 1) { - K_Vibra_Trig_resume=1; + K_Vibra_Trig_resume = 1; } else { - K_Vibra_Trig_resume=0; + K_Vibra_Trig_resume = 0; } - - - if(Vibra_force_level == 2 && last_Vibra_force_level != 2 - &&Allow_Touch_flag == 1) + + if (Vibra_force_level == 2 && last_Vibra_force_level != 2 && Allow_Touch_flag == 1) { - Over3N_vibra_req = 1; - Below1P5N_vibra_req = 0; + Over3N_vibra_req = 1; + Below1P5N_vibra_req = 0; } - else if(Vibra_force_level == 0 && last_Vibra_force_level != 0) + else if (Vibra_force_level == 0 && last_Vibra_force_level != 0) { - Below1P5N_vibra_req = 1; - Over3N_vibra_req = 0; + Below1P5N_vibra_req = 1; + Over3N_vibra_req = 0; } - last_Vibra_force_level=Vibra_force_level; - - if((K_Vibra_Trig_pad==1||K_Vibra_Trig_adas==1||K_Vibra_Trig_cancel==1||K_Vibra_Trig_resume==1)&&Vibra_force_level==2&&Allow_Touch_flag==1) + last_Vibra_force_level = Vibra_force_level; + + if ((K_Vibra_Trig_pad == 1 || K_Vibra_Trig_adas == 1 || K_Vibra_Trig_cancel == 1 || K_Vibra_Trig_resume == 1) && Vibra_force_level == 2 && Allow_Touch_flag == 1) { - Reach2_flag=1; + Reach2_flag = 1; } - - //add by kailong - //Vibra_force_level=Vibra_PressCheck(); - - - if((K_Vibra_Trig_pad==1||K_Vibra_Trig_adas==1||K_Vibra_Trig_cancel==1||K_Vibra_Trig_resume==1)&&Over3N_vibra_req == 1&&Allow_Touch_flag==1) + + // add by kailong + // Vibra_force_level=Vibra_PressCheck(); + + if ((K_Vibra_Trig_pad == 1 || K_Vibra_Trig_adas == 1 || K_Vibra_Trig_cancel == 1 || K_Vibra_Trig_resume == 1) && Over3N_vibra_req == 1 && Allow_Touch_flag == 1) { Touch_Flag = TOUCH_KET_ON; speeker_Tig_Once(49, UDS_Vibration_Gain); Over3N_vibra_req = 0; } - else if(Below1P5N_vibra_req ==1&&Reach2_flag==1) + else if (Below1P5N_vibra_req == 1 && Reach2_flag == 1) { - if(TOUCH_KET_ON == Touch_Flag) + if (TOUCH_KET_ON == Touch_Flag) { Touch_Flag = TOUCH_KET_OFF; speeker_Tig_Once(49, UDS_Vibration_Gain); @@ -1752,14 +1559,9 @@ void TouchPanel_MainFunction(void) Below1P5N_vibra_req = 0; Reach2_flag = 0; } - + if (CurrentPosition == 0xff) { - Allow_Touch_flag=1; + Allow_Touch_flag = 1; } - - - - - } diff --git a/firmware/src/config/mcal/touch/touch.h b/firmware/src/config/mcal/touch/touch.h index b79701f..74aafd7 100644 --- a/firmware/src/config/mcal/touch/touch.h +++ b/firmware/src/config/mcal/touch/touch.h @@ -196,97 +196,97 @@ SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES #define KEY_0_PARAMS \ { \ - 48u, (uint8_t)HYST_12_5, (uint8_t)NO_AKS_GROUP \ + 40u, (uint8_t)HYST_12_5, (uint8_t)NO_AKS_GROUP \ } #define KEY_1_PARAMS \ { \ - 48u, (uint8_t)HYST_12_5, (uint8_t)NO_AKS_GROUP \ + 40u, (uint8_t)HYST_12_5, (uint8_t)NO_AKS_GROUP \ } #define KEY_2_PARAMS \ { \ - 54u, (uint8_t)HYST_12_5, (uint8_t)NO_AKS_GROUP \ + 40u, (uint8_t)HYST_12_5, (uint8_t)NO_AKS_GROUP \ } #define KEY_3_PARAMS \ { \ - 61u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ + 40u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ } #define KEY_4_PARAMS \ { \ - 60u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ + 40u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ } #define KEY_5_PARAMS \ { \ - 57u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ + 40u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ } #define KEY_6_PARAMS \ { \ - 63u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ + 40u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ } #define KEY_7_PARAMS \ { \ - 72u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ + 40u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ } #define KEY_8_PARAMS \ { \ - 49u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ + 40u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ } #define KEY_9_PARAMS \ { \ - 54u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ + 40u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ } #define KEY_10_PARAMS \ { \ - 47u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ + 40u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ } #define KEY_11_PARAMS \ { \ - 55u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ + 40u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ } #define KEY_12_PARAMS \ { \ - 59u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ + 40u, (uint8_t)HYST_12_5, (uint8_t)AKS_GROUP_1 \ } #define KEY_13_PARAMS \ { \ - 48u, (uint8_t)HYST_12_5, (uint8_t)NO_AKS_GROUP \ + 40u, (uint8_t)HYST_12_5, (uint8_t)NO_AKS_GROUP \ } #define KEY_14_PARAMS \ { \ - 48u, (uint8_t)HYST_12_5, (uint8_t)NO_AKS_GROUP \ + 40u, (uint8_t)HYST_12_5, (uint8_t)NO_AKS_GROUP \ } #define KEY_15_PARAMS \ { \ - 60u, (uint8_t)HYST_12_5, (uint8_t)NO_AKS_GROUP \ + 40u, (uint8_t)HYST_12_5, (uint8_t)NO_AKS_GROUP \ } diff --git a/firmware/src/main.c b/firmware/src/main.c index 1d5f22e..7ee97b4 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -93,22 +93,25 @@ void ADC1_ConversionCallback(ADC_STATUS status, uintptr_t context) switch (adc_ch_sel) { - case ADC1_CH_AD_LDO_SNS: - ADC1_ChannelSelect(ADC_POSINPUT_AIN6, ADC_NEGINPUT_GND); - adc_ch_sel = ADC1_CH_LD_OUT_SNS; - break; - case ADC1_CH_LD_OUT_SNS: - ADC1_ChannelSelect(ADC_POSINPUT_AIN7, ADC_NEGINPUT_GND); - adc_ch_sel = ADC1_CH_AD_LDO_SNS; - break; - default: - break; - } - // adc_ch_sel++; - // if (adc_ch_sel > ADC1_CH_MAX) { - // adc_ch_sel = ADC1_CH_AD_LDO_SNS + 1; - // } - ADC1_ConversionStart(); + case ADC1_CH_AD_LDO_SNS: + ADC1_ChannelSelect(ADC_POSINPUT_AIN6, ADC_NEGINPUT_GND); + adc_ch_sel= ADC1_CH_LD_OUT_SNS; + ADC1_ConversionStart(); + break; + case ADC1_CH_LD_OUT_SNS: + ADC1_ChannelSelect(ADC_POSINPUT_AIN7, ADC_NEGINPUT_GND); + adc_ch_sel= ADC1_CH_AD_LDO_SNS; + //ADC1_Disable(); + ADC1_ConversionStart(); + break; + default: + break; + } + //adc_ch_sel++; + //if (adc_ch_sel > ADC1_CH_MAX) { + // adc_ch_sel = ADC1_CH_AD_LDO_SNS + 1; + //} + } }