Index: ModuleDemo/TOUCH/Touch/user/main.c
===================================================================
--- /YC3121_demo/ModuleDemo/TOUCH/Touch/user/main.c	(revision 804)
+++ /YC3121_demo/ModuleDemo/TOUCH/Touch/user/main.c	(working copy)
@@ -11,12 +11,12 @@
   * COPYRIGHT 2019 Yichip Microelectronics
   *
   * The purpose of this firmware is to provide guidance to customers engaged in
-	* programming work to guide them smoothly to product development,
-	* so as to save their time.
-	*
-	* Therefore, Yichip microelectronics shall not be responsible for any direct,
-	* indirect or consequential damages caused by any content of this gu jiang
-	* and/or contained in this code used by the customer in its products.
+    * programming work to guide them smoothly to product development,
+    * so as to save their time.
+    *
+    * Therefore, Yichip microelectronics shall not be responsible for any direct,
+    * indirect or consequential damages caused by any content of this gu jiang
+    * and/or contained in this code used by the customer in its products.
   *
   ******************************************************************************
   */
@@ -29,56 +29,59 @@
 #include "yc_timer.h"
 #include "yc_touch.h"
 #include "yc_kscan.h"
+#include "board_config.h"
 
 
-#if (BOARD_VER == MPOS_BOARD_V2_1)
-    //临时定义
-    #define KEY_NUM_0   1
-    #define KEY_NUM_1   2
-    #define KEY_NUM_2   3
-    #define KEY_NUM_3   4
-    #define KEY_NUM_4   5
-    #define KEY_NUM_5   6
-    #define KEY_NUM_6   7
-    #define KEY_NUM_7   8
-    #define KEY_NUM_8   9
-    #define KEY_NUM_9   0
-    #define KEY_UP      10
-    #define KEY_DOWN    11
-    #define KEY_CONFIRM 12
-    #define KEY_CANCEL  13
-    #define KEY_CLEAR   14
-    #define KEY_MENU    15
-    #define KEY_F1      16
-    #define KEY_F2      17
-#endif
-
 /* Private typedef -----------------------------------------------------------*/
+typedef enum
+{
+    PAGE0 = 0,
+    PAGE1,
+    PAGE2,
+    PAGE3
+} TP_MENU_TypeDef;
 /* Private define ------------------------------------------------------------*/
+
+#define TP_X_LEFT_BORDER     (14)
+#define TP_X_RIGHT_BORDER    (320 - TP_X_LEFT_BORDER)
+#define TP_Y_HIGT_BORDER     (35)
+#define TP_Y_LOW_BORDER      (240 - 16*3 - 5)
+
+#define TP_CLEAR_X_LEFT      (320/2 - 5*16/2)
+#define TP_CLEAR_Y_LEFT      (240 - 45)
+#define TP_CLEAR_X_RIGHT     (TP_CLEAR_X_LEFT + 16*5)
+#define TP_CLEAR_Y_RIGHT     (240)
+
+#define TP_EXIT_X_LEFT      (13)
+#define TP_EXIT_Y_LEFT      (240 - 45)
+#define TP_EXIT_X_RIGHT     (TP_EXIT_X_LEFT + 16*4)
+#define TP_EXIT_Y_RIGHT     (240)
+
+#define TP_SAVE_X_LEFT      (320 -13-16*4)
+#define TP_SAVE_Y_LEFT      (240 - 45)
+#define TP_SAVE_X_RIGHT     (TP_SAVE_X_LEFT + 16*4)
+#define TP_SAVE_Y_RIGHT     (240)
+
 /* Private macro -------------------------------------------------------------*/
 /* Private variables ---------------------------------------------------------*/
 /* Private function prototypes -----------------------------------------------*/
-void UART_Configuration(void);
-void ADC_Configuration(void);
-void St7789v2Lcd_Configuration(void);
-void  Touch_Test(void);
-uint8_t ADC_Collection(uint8_t Coordinate);
-
-uint8_t keyvalue = 0;
-extern struct TOUCH _touch;
-extern struct TOUCH_PANEl _touchpanel;
+static void UART_Configuration(void);
+static void ADC_Configuration(void);
+static void St7789vlcd_Configuration(void);
+static void Touch_Test(void);
 
-void TFT_Power_scan(void)
+
+static void TFT_Power_scan(void)
 {
     ST7789_TFT_Picture(284, 4, gImage_full_energe);
 }
 
-void TFT_Single_scan(void)
+static void TFT_Single_scan(void)
 {
     ST7789_TFT_Picture(4, 4, gImage_single_l);
 }
 
-void Display_InterfaceWindow(void)
+static void Display_InterfaceWindow(void)
 {
     uint8_t Show_buff1[] = "Touch demo";
     uint8_t Show_buff2[] = "Please press menu key...";
@@ -97,23 +100,16 @@
   * @param  None
   * @retval None
   */
-
-#define GPIO_AD_MAXVALUE 0x7fe
-#define DIFFERENCE_X_MAX 80
-#define DIFFERENCE_Y_MAX 60
 int main(void)
 {
-    GPIO_Config(GPIOA, GPIO_Pin_2, OUTPUT_HIGH);//�ⲿldoʹ��
-
-    uint8_t Difference_x = 0, Difference_y = 0;
-
-    ADC_Configuration();
+    /*enable ldo*/
+    GPIO_Config(GPIOA, GPIO_Pin_2, OUTPUT_HIGH);
 
     UART_Configuration();
 
     MyPrintf("Yichip Yc3121 Touch Demo V1.0.\r\n");
 
-    St7789v2Lcd_Configuration();
+    St7789vlcd_Configuration();
 
     Display_InterfaceWindow();
 
@@ -123,284 +119,190 @@
     }
 }
 
-/**
-  * @brief  Serial port 0 initialization function.
-  * @param  None
-  * @retval None
-  */
-void UART_Configuration(void)
-{
-    UART_InitTypeDef UART_InitStruct;
-
-    /* Configure serial ports RX and TX for IO. */
-    GPIO_Config(UART0_TX_PORT, UART0_TX_PIN, UART0_TXD);
-    GPIO_Config(UART0_RX_PORT, UART0_RX_PIN, UART0_RXD);
 
 
-    /* USARTx configured as follow:
-    - BaudRate = 115200 baud
-    - Word Length = 8 Bits
-    - Stop Bit = 1 Stop Bit
-    - Parity = No Parity
-    - Hardware flow control disabled (RTS and CTS signals)
-    - Receive and transmit enabled
-    */
-    UART_InitStruct.BaudRate = UARTBAUD;			//Configure serial port baud rate, the baud rate defaults to 128000.
-    UART_InitStruct.DataBits = Databits_8b;
-    UART_InitStruct.StopBits = StopBits_2;
-    UART_InitStruct.Parity = Parity_None;
-    UART_InitStruct.FlowCtrl = FlowCtrl_None;
-    UART_InitStruct.Mode = Mode_duplex;
-
-    UART_Init(UART0, &UART_InitStruct);
-}
-/**
-  * @brief  LCD related IO port and SPI related configuration
-  * @param  None
-  * @retval None
-  */
-
-void St7789v2Lcd_Configuration(void)
+static void Tp_menu(TP_MENU_TypeDef type)
 {
-    #if (BOARD_VER == MPOS_BOARD_V2_1)
-    MyPrintf("MPOS_BOARD_V2_1 not support TOUCH demo\r\n");
-    #else
-    St7789TFT_InitTypedef St7789TFT_InitStruct;
-
-    St7789TFT_InitStruct.SPIx = ST7789VTFTSPI;
-    St7789TFT_InitStruct.IO_TFT_SDA_PIN = ST7789_TFT_SDA_PIN;
-    St7789TFT_InitStruct.IO_TFT_SDA_Port = ST7789_TFT_SDA_PORT;
-    St7789TFT_InitStruct.IO_TFT_SCL_PIN = ST7789_TFT_SCL_PIN;
-    St7789TFT_InitStruct.IO_TFT_SCL_Port = ST7789_TFT_SCL_PORT;
-    St7789TFT_InitStruct.IO_TFT_CS_PIN = ST7789_TFT_CS_PIN;
-    St7789TFT_InitStruct.IO_TFT_CS_Port = ST7789_TFT_CS_PORT;
-    St7789TFT_InitStruct.IO_TFT_RES_PIN = ST7789_TFT_RST_PIN;
-    St7789TFT_InitStruct.IO_TFT_RES_Port = ST7789_TFT_RST_PORT;
-    St7789TFT_InitStruct.IO_TFT_BL_PIN = ST7789_TFT_BL_PIN;
-    St7789TFT_InitStruct.IO_TFT_BL_Port = ST7789_TFT_BL_PORT;
-    St7789TFT_InitStruct.IO_TFT_A0_PIN = ST7789_TFT_A0_PIN;
-    St7789TFT_InitStruct.IO_TFT_A0_Port = ST7789_TFT_A0_PORT;
-
-    ST7789_TFT_GpioInit(&St7789TFT_InitStruct);
-
-    /* Initialize the LCD screen */
-    ST7789_TFT_Init();
-    #endif
-}
-/**
-  * @brief  ADC initialization function.
-  * @param  None
-  * @retval None
-  */
-void ADC_Configuration(void)
-{
-    ADC_InitTypeDef ADCInitStruct;
-    ADCInitStruct.ADC_Mode = ADC_GPIO;
-    ADCInitStruct.ADC_Channel = ADC_CHANNEL_6;
-    ADC_Init(&ADCInitStruct);
-}
-static void Display_touch(void)
-{
-    uint8_t cb_flag = 0;
-    uint8_t calibrated = 0;
-    uint8_t changeFlag = 0;
-    uint8_t Difference_x = 0, Difference_y = 0;
-
-    ADC_Configuration();
-    //������������ADֵ
-    _touch.Adc_Max = GPIO_AD_MAXVALUE;
-
-    if (changeFlag == 0)
+    switch (type)
     {
+    case PAGE0 :
         ST7789_TFT_Clear_White(0, 28, TFT_COL, TFT_ROW);
         ST7789_TFT_ShowChinese(56, 36, calibrated_ch, 32, 7, 1, WHITE, RED);
         St7789_tft_DrawRectangle(115, 88, 205, 129, BLACK);
         ST7789_TFT_ShowChinese(136, 89, confirm_ch, 24, 2, 1, WHITE, MAROON);
-        ST7789_TFT_ShowString(132, 113,  56,  8, "CONFIRM", 16, 1, WHITE, MAROON);
+        ST7789_TFT_ShowString(132, 113,  56,  8, (uint8_t *)"CONFIRM", 16, 1, WHITE, MAROON);
         St7789_tft_DrawRectangle(115, 136, 205, 177, BLACK);
         ST7789_TFT_ShowChinese(136, 137, cancel_ch, 24, 2, 1, WHITE, MAROON);
-        ST7789_TFT_ShowString(136, 161,  48,  8, "CANCEL", 16, 1, WHITE, MAROON);
+        ST7789_TFT_ShowString(136, 161,  48,  8, (uint8_t *)"CANCEL", 16, 1, WHITE, MAROON);
         St7789_tft_DrawRectangle(115, 184, 205, 225, BLACK);
         ST7789_TFT_ShowChinese(136, 185, clear_ch, 24, 2, 1, WHITE, MAROON);
-        ST7789_TFT_ShowString(140, 209,  48,  8, "CLEAR", 16, 1, WHITE, MAROON);
-        cb_flag = 1;
-        KEY_Scan_check();
-    }
-
-    while (cb_flag)
-    {
-        switch (KEY_Scan())
+        ST7789_TFT_ShowString(140, 209,  48,  8, (uint8_t *)"CLEAR", 16, 1, WHITE, MAROON);
+        break;
+    case PAGE1 :
+        ST7789_TFT_ShowChinese(136, 89, confirm_ch, 24, 2, 0, YELLOW, MAROON);
+        ST7789_TFT_ShowString(132, 113,  56,  8, (uint8_t *)"CONFIRM", 16, 0, YELLOW, MAROON);
+        delay_ms(500);
+        ST7789_TFT_Clear_White(0, 28, TFT_COL, TFT_ROW);
+        break;
+    case PAGE2 :
+        ST7789_TFT_Clear_White(0, 28, TFT_COL, TFT_ROW);
+        for (uint8_t i = 0; i < 5 ; i++)
         {
-        case KEY_CONFIRM:
-            cb_flag = 0;
-            changeFlag = 1;
-            calibrated = 1;
-            ST7789_TFT_ShowChinese(136, 89, confirm_ch, 24, 2, 0, YELLOW, MAROON);
-            ST7789_TFT_ShowString(132, 113,  56,  8, "CONFIRM", 16, 0, YELLOW, MAROON);
-            KEY_Scan_check();
-            break;
-        case KEY_CANCEL:
-            cb_flag = 0;
-            changeFlag = 1;
-            ST7789_TFT_ShowChinese(136, 137, cancel_ch, 24, 2, 0, YELLOW, MAROON);
-            ST7789_TFT_ShowString(136, 161,  48,  8, "CANCEL", 16, 0, YELLOW, MAROON);
-            ST7789_TFT_Clear_White(0, 28, TFT_COL, TFT_ROW);
-#if 1
-            _touchpanel.xfac = 102;
-            _touchpanel.yfac = 84;
-            _touchpanel.xbase = 30;
-            _touchpanel.ybase = 30;
-            _touchpanel.xlogic = 29;
-            _touchpanel.ylogic = 83;
-#else
-            _touchpanel.xfac = 96;
-            _touchpanel.yfac = 114;
-            _touchpanel.xbase = 30;
-            _touchpanel.ybase = 30;
-            _touchpanel.xlogic = 51;
-            _touchpanel.ylogic = 26;
-#endif
-            St7789_tft_DrawRectangle(5, 60, 315, 180, RED);
-            St7789_tft_DrawRectangle(6, 61, 314, 179, RED);
-            St7789_tft_DrawRectangle(7, 62, 313, 178, RED);
-            St7789_tft_DrawRectangle(10, 240 - 5, 100, 240 - 50, BLACK);
-            St7789_tft_DrawRectangle(320 - 100, 240 - 5, 320 - 10, 240 - 50, BLACK);
-            ST7789_TFT_ShowString(10 + 3, 240 - 45, 80, 16, "Clear", 32, 1, WHITE, PURPLE);
-            ST7789_TFT_ShowString(320 - 95, 240 - 47, 64, 16, "Save", 32, 1, WHITE, PURPLE);
-            KEY_Scan_check();
-            break;
-        case KEY_CLEAR:
-            cb_flag = 0;
-            ST7789_TFT_ShowChinese(136, 185, clear_ch, 24, 2, 0, YELLOW, MAROON);
-            ST7789_TFT_ShowString(140, 209,  48,  8, "CLEAR", 16, 0, YELLOW, MAROON);
-            KEY_Scan_check();
-            break;
-        default:
-            break;
+            St7789_tft_DrawRectangle(1 + i, 29 + i, 318 - i, 240 - 16 * 3 - i, BLACK);
         }
+
+        ST7789_TFT_ShowString(320 - 13 - 16 * 4, 240 - 45, 16 * 4, 16, (uint8_t *)"Save", 32, 1, WHITE, PURPLE);
+        ST7789_TFT_ShowString(13, 240 - 45, 5 * 16, 16, (uint8_t *)"Exit", 32, 1, WHITE, PURPLE);
+        ST7789_TFT_ShowString(320 / 2 - 5 * 16 / 2, 240 - 45, 16 * 5, 16, (uint8_t *)"Clear", 32, 1, WHITE, PURPLE);
+        break;
+    case PAGE3 :
+        ST7789_TFT_ShowString(320 / 2 - 5 * 16 / 2, 240 - 45, 16 * 5, 16, (uint8_t *)"Clear", 32, 1, YELLOW, MAROON);
+        ST7789_TFT_Clear_White(5, 34, 313, 188);
+        ST7789_TFT_ShowString(320 / 2 - 5 * 16 / 2, 240 - 45, 16 * 5, 16, (uint8_t *)"Clear", 32, 1, WHITE, PURPLE);
+        break;
     }
+}
+
 
-    while (calibrated == 1)
+static Boolean Touch_Cali(void)
+{
+    uint8_t cal_cnt = 3;
+    uint8_t Show_buff1[] = "Calibration success";
+    uint8_t Show_buff2[] = "Calibration failure please recalibrate";
+    while (cal_cnt --)
     {
-        ST7789_TFT_Clear_White(0, 0, TFT_COL, TFT_ROW);
-        if (TP_UpdateCoordVal() == 1)
+        if (Tp_Calibrate() == TRUE)
         {
-            calibrated = 0;
-            St7789_tft_DrawRectangle(5, 60, 315, 180, RED);
-            St7789_tft_DrawRectangle(6, 61, 314, 179, RED);
-            St7789_tft_DrawRectangle(7, 62, 313, 178, RED);
-            St7789_tft_DrawRectangle(10, 240 - 5, 100, 240 - 50, BLACK);
-            St7789_tft_DrawRectangle(320 - 100, 240 - 5, 320 - 10, 240 - 50, BLACK);
-            ST7789_TFT_ShowString(10 + 3, 240 - 45, 80, 16, "Clear", 32, 1, WHITE, PURPLE);
-            ST7789_TFT_ShowString(320 - 95, 240 - 47, 64, 16, "Save", 32, 1, WHITE, PURPLE);
-
+            ST7789_TFT_Clear_White(0, 28, TFT_COL, TFT_ROW);
+            ST7789_TFT_ShowString(10, 80, 8 * sizeof(Show_buff1), 8, Show_buff1, 16, 1, WHITE, MAROON);
+            delay_ms(2000);
+            ST7789_TFT_Clear_White(0, 30, TFT_COL, TFT_ROW);
+            return TRUE;
         }
         else
         {
-            ST7789_TFT_ShowString(0, 100,  16 * 20,  16, "Calibration failure", 32, 1, YELLOW, MAROON);
+            ST7789_TFT_Clear_White(0, 28, TFT_COL, TFT_ROW);
+            ST7789_TFT_ShowString(10, 80, 8 * sizeof(Show_buff2), 8, Show_buff2, 16, 1, WHITE, MAROON);
             delay_ms(2000);
-            calibrated = 0;
-            changeFlag = 0;
+            ST7789_TFT_Clear_White(0, 28, TFT_COL, TFT_ROW);
         }
-
     }
-    if (changeFlag == 1)
+}
+
+static void Touch_Drow_Line(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey)
+{
+    St7899_tft_DrawLine(sx, sy, ex, ey, BLACK);
+    St7899_tft_DrawLine(sx - 1, sy, ex - 1, ey, BLACK);
+    St7899_tft_DrawLine(sx, sy + 1, ex, ey + 1, BLACK);
+    St7899_tft_DrawLine(sx + 1, sy, ex + 1, ey, BLACK);
+    St7899_tft_DrawLine(sx, sy - 1, ex, ey - 1, BLACK);
+}
+
+void Touch_Display(void)
+{
+    uint8_t keyCode = 0;
+    Tp_Sign_Para_TypeDef Sign_Para = {0};
+
+    ADC_Configuration();
+
+    /*Select whether to calibrate*/
+
+    Tp_menu(PAGE0);
+    while (1)
     {
-        ST7789_TFT_ShowChinese(100, 1, Yichip_ch, 24, 5, 1, WHITE, OLIVE);
-        ST7789_TFT_Draw_Piece(0, 27, TFT_COL, 28, DGRAY);
-        TFT_Power_scan();
-        TFT_Single_scan();
+        keyCode = KEY_Scan();
+        if (keyCode == KEY_CONFIRM)
+        {
+            Tp_menu(PAGE1);
+            Touch_Cali();
+            break;
+        }
+        else if (keyCode == KEY_CANCEL)
+        {
+            /*Use the default calibration parameters*/
+            Constant.kx = TP_CONSTANT_X;
+            Constant.ky = TP_CONSTANT_Y;
+            fac.kx = TP_FAC_KX;
+            fac.ky = TP_FAC_KY;
+            break;
+        }
+        else if (keyCode == KEY_CLEAR)
+        {
+            return ;
+        }
     }
-    while (changeFlag == 1)
+
+    /*Start the signature*/
+
+    Tp_menu(PAGE2);
+
+    while (1)
     {
-        if (TP_DetectPressing() == 0)
+        if (Tp_DetectPressing() == TRUE)
         {
-            //��ȡ��������ֵ
-            TP_ReadXY();
+            Tp_GetPoint(&Sign_Para.nx, &Sign_Para.ny);
+
+            TP_PRINT("Sign_Para.nx :%d,Sign_Para.ny :%d\n", Sign_Para.nx, Sign_Para.ny);
+            TP_PRINT("Sign_Para.lx :%d,Sign_Para.ly :%d\n", Sign_Para.lx, Sign_Para.ly);
 
-            if (TP_DetectPressing() == 1)
+            if (Tp_DetectPressing() == FALSE)
             {
-                _touch.PressAgainFalg = 0;
+                Sign_Para.pressflag = 0;
             }
-
-            //����Ƿ�Ϊ�������µĶ���
-            if (_touch.PressAgainFalg == 2)
+            /*Continuous press*/
+            if (Sign_Para.pressflag == 2)
             {
-                //������������µĵ㣬�����ϸ����뵱ǰ���ƫ��
-                if (_touchpanel.x > _touchpanel.ltx) Difference_x = _touchpanel.x - _touchpanel.ltx;
-                else Difference_x = _touchpanel.ltx - _touchpanel.x;
-                if (_touchpanel.y > _touchpanel.lty) Difference_y = _touchpanel.y - _touchpanel.lty;
-                else Difference_y = _touchpanel.lty - _touchpanel.y;
-
-                //���ƫ�����ڷ�Χ�ڣ�������õ�����
-                if (Difference_x < DIFFERENCE_X_MAX && Difference_y < DIFFERENCE_Y_MAX && _touchpanel.y > 62 && _touchpanel.y < 178 && _touchpanel.x > 7 && _touchpanel.x < 313)
-                {
-                    St7899_tft_DrawLine(_touchpanel.ltx, _touchpanel.lty, _touchpanel.x, _touchpanel.y, BLACK);
-                    St7899_tft_DrawLine(_touchpanel.ltx - 1, _touchpanel.lty, _touchpanel.x - 1, _touchpanel.y, BLACK);
-                    St7899_tft_DrawLine(_touchpanel.ltx, _touchpanel.lty + 1, _touchpanel.x, _touchpanel.y + 1, BLACK);
-                    St7899_tft_DrawLine(_touchpanel.ltx + 1, _touchpanel.lty, _touchpanel.x + 1, _touchpanel.y, BLACK);
-                    St7899_tft_DrawLine(_touchpanel.ltx, _touchpanel.lty - 1, _touchpanel.x, _touchpanel.y - 1, BLACK);
-                    St7899_tft_DrawLine(_touchpanel.ltx + 2, _touchpanel.lty, _touchpanel.x + 2, _touchpanel.y, BLACK);
-                    St7899_tft_DrawLine(_touchpanel.ltx, _touchpanel.lty - 2, _touchpanel.x, _touchpanel.y - 2, BLACK);
-                    _touchpanel.ltx = _touchpanel.x;
-                    _touchpanel.lty = _touchpanel.y;
-                }
-                //���ƫ����ڷ�Χ�ڣ�����ǰ����ǩ�������ڣ�������ǰ��
-                else if ((_touchpanel.y > 62 && _touchpanel.y < 178 && _touchpanel.x > 7 && _touchpanel.x < 313))
+                if (Sign_Para.nx > TP_X_LEFT_BORDER && Sign_Para.nx < TP_X_RIGHT_BORDER && \
+                        Sign_Para.ny > TP_Y_HIGT_BORDER && Sign_Para.ny < TP_Y_LOW_BORDER)
                 {
-                    _touchpanel.ltx = _touchpanel.x;
-                    _touchpanel.lty = _touchpanel.y;
+                    if (Tp_AbsolouteDifference(Sign_Para.nx, Sign_Para.lx) < 30 && Tp_AbsolouteDifference(Sign_Para.ny, Sign_Para.ly) < 30)
+                    {
+                        Touch_Drow_Line(Sign_Para.nx, Sign_Para.ny, Sign_Para.lx, Sign_Para.ly);
+                    }
+                    Sign_Para.lx = Sign_Para.nx;
+                    Sign_Para.ly = Sign_Para.ny;
                 }
-                // ����
-                else {}
-
             }
-            //����������
-            else if ((_touchpanel.x > 10 && _touchpanel.x < 100) && (_touchpanel.y < 235 && _touchpanel.y > 190))
+            /*first press*/
+
+            else if (Sign_Para.nx > TP_X_LEFT_BORDER && Sign_Para.nx < TP_X_RIGHT_BORDER && \
+                     Sign_Para.ny > TP_Y_HIGT_BORDER && Sign_Para.ny < TP_Y_LOW_BORDER)
             {
-                St7789_tft_RectangleFill(10, 190, 100, 235, OLIVE);
-                ST7789_TFT_ShowString(13, 195, 80, 16, "Clear", 32, 1, WHITE, PURPLE);
-                ST7789_TFT_Clear_White(8, 63, 312, 177);
-                if (TP_DetectPressing() == 1)
-                {
-                    St7789_tft_RectangleFill(10, 190, 100, 235, WHITE);
-                    St7789_tft_DrawRectangle(10, 235, 100, 190, BLACK);
-                    ST7789_TFT_ShowString(13, 195, 80, 16, "Clear", 32, 1, WHITE, PURPLE);
-                }
-                St7789_tft_DrawRectangle(5, 60, 315, 180, RED);
-                St7789_tft_DrawRectangle(6, 61, 314, 179, RED);
-                St7789_tft_DrawRectangle(7, 62, 313, 178, RED);
+                Sign_Para.pressflag ++;
+                Sign_Para.lx = Sign_Para.nx;
+                Sign_Para.ly = Sign_Para.ny;
             }
-            else if ((_touchpanel.x > 220 && _touchpanel.x < 310) && (_touchpanel.y < 235 && _touchpanel.y > 190))
+            /*press clear*/
+
+            else if (Sign_Para.nx > TP_CLEAR_X_LEFT && Sign_Para.nx < TP_CLEAR_X_RIGHT && \
+                     Sign_Para.ny > TP_CLEAR_Y_LEFT && Sign_Para.ny < TP_CLEAR_Y_RIGHT)
             {
-                St7789_tft_RectangleFill(220, 190, 310, 235, OLIVE);
-                ST7789_TFT_ShowString(225, 193, 64, 16, "Save", 32, 1, WHITE, PURPLE);
-                ST7789_TFT_Clear_White(8, 63, 312, 177);
-                if (TP_DetectPressing() == 1)
-                {
-                    St7789_tft_RectangleFill(220, 190, 310, 235, WHITE);
-                    St7789_tft_DrawRectangle(220, 235, 310, 190, BLACK);
-                    ST7789_TFT_ShowString(225, 193, 128, 16, "Save", 32, 1, WHITE, PURPLE);
-                }
-                ST7789_TFT_ShowString(50, 80, 160, 16, "Saveing...", 32, 1, WHITE, OLIVE);
-                delay_ms(1000);
-                changeFlag = 0;
-                break;
+                Tp_menu(PAGE3);
             }
-            //��һ�δ���
-            else if ((_touchpanel.y > 62 && _touchpanel.y < 178 && _touchpanel.x > 7 && _touchpanel.x < 313))
+            /*press exit*/
+
+            else if (Sign_Para.nx > TP_EXIT_X_LEFT && Sign_Para.nx < TP_EXIT_X_RIGHT && \
+                     Sign_Para.ny > TP_EXIT_Y_LEFT && Sign_Para.ny < TP_EXIT_Y_RIGHT)
             {
-                _touch.PressAgainFalg++;
-                _touchpanel.ltx = _touchpanel.x;
-                _touchpanel.lty = _touchpanel.y;
+                return ;
+            }
 
+            /*Save exit*/
+            else if (Sign_Para.nx > TP_SAVE_X_LEFT && Sign_Para.nx < TP_SAVE_X_RIGHT && \
+                     Sign_Para.ny > TP_SAVE_Y_LEFT && Sign_Para.ny < TP_SAVE_Y_RIGHT)
+            {
+                return ;
             }
-            else {}
         }
-        else _touch.PressAgainFalg = 0;
+        else
+        {
+            /*no press*/
+            Sign_Para.pressflag = 0;
+        }
     }
 }
-void Touch_Test(void)
+
+static void Touch_Test(void)
 {
     uint8_t keyCode = 0;
     uint8_t Show_buff2[] = "Whether or not to continue";
@@ -410,28 +312,101 @@
     }
     while (1)
     {
-        Display_touch();
+        Touch_Display();
         ST7789_TFT_Clear_White(0, 0, TFT_COL, TFT_ROW);
         ST7789_TFT_ShowChinese(100, 1, Yichip_ch, 24, 5, 1, WHITE, OLIVE);
         ST7789_TFT_Draw_Piece(0, 27, TFT_COL, 28, DGRAY);
         TFT_Power_scan();
         TFT_Single_scan();
         ST7789_TFT_ShowString(10, 80, 8 * sizeof(Show_buff2), 8, Show_buff2, 16, 1, WHITE, MAROON);
-        ST7789_TFT_ShowString(0, 180, 20 * 16,  16, "CANCEL       CONFIRM", 32, 1, WHITE, OLIVE);
+        ST7789_TFT_ShowString(0, 180, 20 * 16,  16, (uint8_t *)"CANCEL       CONFIRM", 32, 1, WHITE, OLIVE);
         while (1)
         {
             keyCode = KEY_Scan();
             if (keyCode == KEY_CANCEL)
             {
                 Display_InterfaceWindow();
-                return;//�˳�
+                return;
             }
             else if (keyCode == KEY_CONFIRM)
             {
-                break; // ����
+                break;
             }
         }
     }
 }
 
+/**
+  * @brief  Serial port 0 initialization function.
+  * @param  None
+  * @retval None
+  */
+static void UART_Configuration(void)
+{
+    UART_InitTypeDef UART_InitStruct;
+
+    /* Configure serial ports RX and TX for IO. */
+    GPIO_Config(UART0_TX_PORT, UART0_TX_PIN, UART0_TXD);
+    GPIO_Config(UART0_RX_PORT, UART0_RX_PIN, UART0_RXD);
+
+
+    /* USARTx configured as follow:
+    - BaudRate = 115200 baud
+    - Word Length = 8 Bits
+    - Stop Bit = 1 Stop Bit
+    - Parity = No Parity
+    - Hardware flow control disabled (RTS and CTS signals)
+    - Receive and transmit enabled
+    */
+    UART_InitStruct.BaudRate = UARTBAUD;            //Configure serial port baud rate, the baud rate defaults to 128000.
+    UART_InitStruct.DataBits = Databits_8b;
+    UART_InitStruct.StopBits = StopBits_2;
+    UART_InitStruct.Parity = Parity_None;
+    UART_InitStruct.FlowCtrl = FlowCtrl_None;
+    UART_InitStruct.Mode = Mode_duplex;
+
+    UART_Init(UART0, &UART_InitStruct);
+}
+/**
+  * @brief  LCD related IO port and SPI related configuration
+  * @param  None
+  * @retval None
+  */
+
+static void St7789vlcd_Configuration(void)
+{
+    St7789TFT_InitTypedef St7789TFT_InitStruct;
+
+    St7789TFT_InitStruct.SPIx = ST7789VTFTSPI;
+    St7789TFT_InitStruct.IO_TFT_SDA_PIN = ST7789_TFT_SDA_PIN;
+    St7789TFT_InitStruct.IO_TFT_SDA_Port = ST7789_TFT_SDA_PORT;
+    St7789TFT_InitStruct.IO_TFT_SCL_PIN = ST7789_TFT_SCL_PIN;
+    St7789TFT_InitStruct.IO_TFT_SCL_Port = ST7789_TFT_SCL_PORT;
+    St7789TFT_InitStruct.IO_TFT_CS_PIN = ST7789_TFT_CS_PIN;
+    St7789TFT_InitStruct.IO_TFT_CS_Port = ST7789_TFT_CS_PORT;
+    St7789TFT_InitStruct.IO_TFT_RES_PIN = ST7789_TFT_RST_PIN;
+    St7789TFT_InitStruct.IO_TFT_RES_Port = ST7789_TFT_RST_PORT;
+    St7789TFT_InitStruct.IO_TFT_BL_PIN = ST7789_TFT_BL_PIN;
+    St7789TFT_InitStruct.IO_TFT_BL_Port = ST7789_TFT_BL_PORT;
+    St7789TFT_InitStruct.IO_TFT_A0_PIN = ST7789_TFT_A0_PIN;
+    St7789TFT_InitStruct.IO_TFT_A0_Port = ST7789_TFT_A0_PORT;
+
+    ST7789_TFT_GpioInit(&St7789TFT_InitStruct);
+
+    /* Initialize the LCD screen */
+    ST7789_TFT_Init();
+}
+/**
+  * @brief  ADC initialization function.
+  * @param  None
+  * @retval None
+  */
+static void ADC_Configuration(void)
+{
+    ADC_InitTypeDef ADCInitStruct;
+    ADCInitStruct.ADC_Mode = ADC_GPIO;
+    ADCInitStruct.ADC_Channel = ADC_CHANNEL_6;
+    ADC_Init(&ADCInitStruct);
+}
+
 /************************ (C) COPYRIGHT Yichip Microelectronics *****END OF FILE****/

