修复马达噪声,修复触摸BUG

This commit is contained in:
sunbeam 2024-08-24 11:54:45 +08:00
parent c84832bdd1
commit 6ab6df5370
4 changed files with 24 additions and 368 deletions

View File

@ -1,9 +1,9 @@
#
#Mon Aug 19 22:53:46 CST 2024
#Sat Aug 24 10:49:01 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=3c603a65e149702643d6cf2071da16f0
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

View File

@ -120,7 +120,7 @@ void speaker_Init(void)
}
/*
para level 0~~3,other value force set to 3
para level 0~3,other value force set to 3
return void
*/
/*level ->0 ------ 1 ----------2 ---------3*/
@ -129,7 +129,7 @@ return void
void speaker_set_strenght(FA51024_ctrl_e_typ level)
{
//PORT_PinWrite(PORT_PIN_PA13,1);/*SHUTDOWN = 1~{o< t~}urn on chip*/
//PORT_PinWrite(PORT_PIN_PA13,1);/*SHUTDOWN = 1turn on chip*/
if(level == SA51024_STRENGTH_LEVEL0)
{
@ -165,8 +165,10 @@ void speaker_MainTask(void)
{
case SPEAKER_INIT:
//SA51024_Set_State(SA51024_STOP,speaker_ctrl_buf_str.strenght);
PORT_PinWrite(PORT_PIN_PA13,0);/*SHUTDOWN = 1~{o< t~}urn on chip*/
PORT_PinWrite(PORT_PIN_PA13,0);/*SHUTDOWN = 1turn 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;
@ -233,6 +235,7 @@ void speaker_MainTask(void)
speaker_main_state_str = SPEAKER_STOP;
speaker_fault_status = 1;
}
break;
default:
@ -246,8 +249,8 @@ void speaker_MainTask(void)
speaker_cycle_u16 = 0;
/* Disable DAC */
// DAC_REGS->DAC_CTRLA &= ~~DAC_CTRLA_ENABLE_Msk;
PORT_PinGPIOConfig(PORT_PIN_PA02);
// DAC_REGS->DAC_CTRLA &= ~DAC_CTRLA_ENABLE_Msk;
//PORT_PinGPIOConfig(PORT_PIN_PA02);
}
break;
@ -289,9 +292,9 @@ Speaker_main_e_typ Get_Speaker_Main_State(void)
return speaker_main_state_str;
}
uint8_t Get_Speaker_Fault(void)
{
return speaker_fault_status;
}

View File

@ -51,7 +51,7 @@ extern void speaker_Init(void);
extern void speaker_MainTask(void);
extern STATE_UINT8 speeker_Tig_Once(uint16_t cycle_time,FA51024_ctrl_e_typ level);
extern Speaker_main_e_typ Get_Speaker_Main_State(void);
extern uint8_t Get_Speaker_Fault(void);
/***************************extern function end************************************/

View File

@ -28,7 +28,7 @@ static TouchButtons_type key_status[BTN_MAX_CH_NUM - 5U] = {0};
static TouchSurface_type TouchSurface;
static TouchScroller_type TouchScroller;
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
@ -419,7 +419,7 @@ void TouchPanel_init(void)
uint8_t eedata[5];
LIB_Mem_MemSet(&TouchSurface, 0x00U, sizeof(TouchSurface_type));
LIB_Mem_MemSet(&TouchScroller, 0x00U, sizeof(TouchScroller_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)
@ -488,20 +488,12 @@ void GetScroller_Position(uint8 *x, uint8 *y)
TP_SlideDirection_Enum TouchPanel_SlideEventRead(void)
{
TP_SlideDirection_Enum Dir = TP_SlideDirection_NONE;
if (TouchSlideEvent.Event == TRUE)
{
Dir = TouchSlideEvent.Direction;
}
return Dir;
}
TP_SlideLevel_Enum TouchPanel_SlideUpDownLevelRead(void)
{
TP_SlideLevel_Enum SlideLevel = TP_SlideLevel_NONE;
if (TouchSlideEvent.Event == TRUE)
{
SlideLevel = TouchSlideEvent.UpDown_SlideLevel;
}
return SlideLevel;
}
@ -525,7 +517,7 @@ PanelPress_LevelType TouchPanel_PressLevelRead(void)
boolean TouchSurface_is_TouchActive(void)
{
boolean ret = FALSE;
if (TouchPanel_SurfaceStatus & TOUCH_ACTIVE)
if (TouchPanel_SurfaceStatus & TOUCH_ACTIVE && CurrentPosition>0 && CurrentPosition<9)
{
ret = TRUE;
}
@ -558,7 +550,7 @@ boolean TouchScroller_is_TouchActive(void)
Buttons_SignalType TouchSurface_XY_StsRead(void)
{
Buttons_SignalType XY_Sts = BUTTON_RELEASE;
if (TouchPanel_SurfaceStatus & TOUCH_ACTIVE)
if (TouchPanel_SurfaceStatus & TOUCH_ACTIVE && CurrentPosition>0 && CurrentPosition<9)
{
switch (TouchPanel_PressLevel)
@ -581,68 +573,6 @@ Buttons_SignalType TouchSurface_XY_StsRead(void)
return XY_Sts;
}
// kailong
#if 0
uint8 Vibra_PressCheck(void)
{
uint16 RawData = 0;
uint16 temp_RawData = 0;
static uint16 LastRawData = 0;
static PanelPress_LevelType Last_PressLevel = PANEL_PRESS_LEVEL0;
PanelPress_LevelType ret_Press = PANEL_PRESS_LEVEL0;
float32 FilterValue;
float32 PressNValueTable[3][2] = {
{1.5f, 3.0f},
{0.5f, 3.0f},
{1.0f, 1.8f}
};
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())
{
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(FilterValue < PressNValueTable[Last_PressLevel][0]){//< 1N
ret_Press = PANEL_PRESS_LEVEL0;
//Vibra_force_level=PANEL_PRESS_LEVEL0;
}else if(FilterValue >= PressNValueTable[Last_PressLevel][0] &&
FilterValue < PressNValueTable[Last_PressLevel][1]){//1N~3N
ret_Press = PANEL_PRESS_LEVEL1;
//Vibra_force_level=PANEL_PRESS_LEVEL1;
}else{//>=3
ret_Press = PANEL_PRESS_LEVEL2;
//Vibra_force_level=PANEL_PRESS_LEVEL2;
}
LastRawData = RawData;
Last_PressLevel = ret_Press;
return ret_Press;
}
#endif
// kailong
@ -1134,144 +1064,16 @@ static float32 GetSlide_Angle(float32 dx, float32 dy)
/*************************************************************/
static void CheckSlide_Level(TP_SlideDirection_Enum SlideDir, uint8 AbsX, uint8 AbsY)
{
switch (SlideDir)
{
case TP_SlideDirection_ShortUP:
case TP_SlideDirection_LongUP:
TouchSlideEvent.UpDown_SlideDistance = AbsY;
if (TouchSlideEvent.UpDown_SlideDistance > SLIDE_UD_LEVEL1_DISTANCE && TouchSlideEvent.UpDown_SlideDistance <= SLIDE_UD_LEVEL2_DISTANCE)
{
TouchSlideEvent.UpDown_SlideLevel = TP_SlideLevel1_UP;
}
else if (TouchSlideEvent.UpDown_SlideDistance > SLIDE_UD_LEVEL2_DISTANCE && TouchSlideEvent.UpDown_SlideDistance <= SLIDE_UD_LEVEL3_DISTANCE)
{
TouchSlideEvent.UpDown_SlideLevel = TP_SlideLevel2_UP;
}
else if (TouchSlideEvent.UpDown_SlideDistance > SLIDE_UD_LEVEL3_DISTANCE)
{
TouchSlideEvent.UpDown_SlideLevel = TP_SlideLevel3_UP;
}
else
{
TouchSlideEvent.UpDown_SlideLevel = TP_SlideLevel_NONE;
}
break;
case TP_SlideDirection_ShortDOWN:
case TP_SlideDirection_LongDOWN:
TouchSlideEvent.UpDown_SlideDistance = AbsY;
if (TouchSlideEvent.UpDown_SlideDistance > SLIDE_UD_LEVEL1_DISTANCE && TouchSlideEvent.UpDown_SlideDistance <= SLIDE_UD_LEVEL2_DISTANCE)
{
TouchSlideEvent.UpDown_SlideLevel = TP_SlideLevel1_DOWN;
}
else if (TouchSlideEvent.UpDown_SlideDistance > SLIDE_UD_LEVEL2_DISTANCE && TouchSlideEvent.UpDown_SlideDistance <= SLIDE_UD_LEVEL3_DISTANCE)
{
TouchSlideEvent.UpDown_SlideLevel = TP_SlideLevel2_DOWN;
}
else if (TouchSlideEvent.UpDown_SlideDistance > SLIDE_UD_LEVEL3_DISTANCE)
{
TouchSlideEvent.UpDown_SlideLevel = TP_SlideLevel3_DOWN;
}
else
{
TouchSlideEvent.UpDown_SlideLevel = TP_SlideLevel_NONE;
}
break;
default:
TouchSlideEvent.UpDown_SlideDistance = 0x00;
TouchSlideEvent.UpDown_SlideLevel = TP_SlideLevel_NONE;
break;
}
}
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;
}
}
CheckSlide_Level(result, absx, absy);
}
return result;
}
#if 0
uint8 KalmanFilter(uint8 inData, uint8 Dtype)
{
static float32 kalman[2] = {0};
static float32 p[2] = {10, 10};
float32 q = 0.001;
float32 r = 0.001;
float32 kg = 0;
if(Dtype < 2)
{
p[Dtype] += q;
kg = p[Dtype] / ( p[Dtype] + r );
kalman[Dtype] = kalman[Dtype] + (kg * (inData - kalman[Dtype]));
p[Dtype] = (1 - kg) * p[Dtype];
}
return (uint8)kalman[Dtype];
}
#endif
struct Point
{
@ -1351,7 +1153,6 @@ void TouchPanel_MainFunction(void)
{
uint8 index;
uint8 x1, y1, x2, y2, Temp_x, Temp_y;
uint8 touchEnd_flag = 0x00;
uint8 voice_temp, voice_x, voice_y; // by kailong
uint8 pad_trig_x, pad_trig_y;
@ -1526,10 +1327,6 @@ void TouchPanel_MainFunction(void)
TouchPanel_PressLevel = TouchPanel_PressCheck();
// add by kailong
// static uint8 Voice_force_Reach2_flag = 0;
// static uint8 Vol_force_Reach2_flag = 0;
// static uint8 Menu_force_Reach2_flag = 0;
k_voice_touch_Sts = BUTTON_RELEASE;
k_vol_touch_Sts = BUTTON_RELEASE;
k_menu_touch_Sts = BUTTON_RELEASE;
@ -1549,21 +1346,12 @@ void TouchPanel_MainFunction(void)
switch (TouchPanel_PressLevel)
{
case PANEL_PRESS_LEVEL0:
// Voice_force_Reach2_flag = 0;
k_voice_touch_Sts = BUTTON_TOUCH;
break;
case PANEL_PRESS_LEVEL1:
// if(Voice_force_Reach2_flag == 1)
// {
// k_voice_touch_Sts = BUTTON_TOUCH_AND_PRESS;
//}
// else
//{
k_voice_touch_Sts = BUTTON_TOUCH;
//}
break;
case PANEL_PRESS_LEVEL2:
// Voice_force_Reach2_flag = 1;
k_voice_touch_Sts = BUTTON_TOUCH_AND_PRESS;
break;
default:
@ -1576,21 +1364,12 @@ void TouchPanel_MainFunction(void)
switch (TouchPanel_PressLevel)
{
case PANEL_PRESS_LEVEL0:
// Vol_force_Reach2_flag = 0;
k_vol_touch_Sts = BUTTON_TOUCH;
break;
case PANEL_PRESS_LEVEL1:
// if(Vol_force_Reach2_flag == 1)
//{
// k_vol_touch_Sts = BUTTON_TOUCH_AND_PRESS;
// }
// else
//{
k_vol_touch_Sts = BUTTON_TOUCH;
//}
break;
case PANEL_PRESS_LEVEL2:
// Vol_force_Reach2_flag = 1;
k_vol_touch_Sts = BUTTON_TOUCH_AND_PRESS;
break;
default:
@ -1603,21 +1382,12 @@ void TouchPanel_MainFunction(void)
switch (TouchPanel_PressLevel)
{
case PANEL_PRESS_LEVEL0:
// Menu_force_Reach2_flag = 0;
k_menu_touch_Sts = BUTTON_TOUCH;
break;
case PANEL_PRESS_LEVEL1:
// if(Menu_force_Reach2_flag == 1)
// {
// k_menu_touch_Sts = BUTTON_TOUCH_AND_PRESS;
//}
// else
// {
k_menu_touch_Sts = BUTTON_TOUCH;
// }
break;
case PANEL_PRESS_LEVEL2:
// Menu_force_Reach2_flag = 1;
k_menu_touch_Sts = BUTTON_TOUCH_AND_PRESS;
break;
default:
@ -1651,114 +1421,15 @@ void TouchPanel_MainFunction(void)
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;
}
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;
}
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;
}
switch (CurrentPosition)
{
@ -2013,31 +1684,13 @@ void TouchPanel_MainFunction(void)
CurrentPosition = 0xff;
}
if (touchEnd_flag != 0x00)
{
TouchSurface.Event = TOUCH_PANEL_NONE_EVENT;
}
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.UpDown_SlideLevel = TP_SlideLevel_NONE;
TouchSlideEvent.Event = FALSE;
}
}
if (TouchSurface.Event == TOUCH_PANEL_BERR_EVENT)
{
TouchSurface.Event = TOUCH_PANEL_NONE_EVENT;
}
if (Vibra_force_level == 2 && last_Vibra_force_level != 2 &&
Allow_Touch_flag == 1)