Просмотр исходного кода

1.编写软件IIC
2.编写GT1151Q触摸驱动

zhanghongyi 3 месяцев назад
Родитель
Сommit
9a9e602593

+ 166 - 9
App/Src/App_freertosTask.c

@@ -3,6 +3,9 @@
 
 #include "lvgl.h"
 #include "lv_port_disp.h"
+#include "lv_port_indev.h"
+#include "Int_gt1151.h"
+#include "Int_lcd.h"
 
 #define TASK_CPLD_PRIORITY          4
 #define TASK_CPLD_STACK_SIZE        512
@@ -16,16 +19,19 @@
 /* 测试1(顺序测试)条件编译开关:1=运行;0=静态红底+文字页 */
 #define ENABLE_TEST1                1
 
+/* 触摸验证(可点击按钮)条件编译开关:1=运行触摸验证界面;0=不运行 */
+#define ENABLE_TOUCH_TEST           1
+
 #if ENABLE_TEST1
 
 /**
  * @brief 测试1 状态机
  *
- * 顺序:10→1 倒数(局部文字刷新)→ 背景三原色切换(各 1s)→ 3x3 九宫格 9 色
+ * 顺序:10s 倒数(局部文字刷新)→ 背景三原色切换(1s)→ 3x3 九宫格
  */
 typedef enum
 {
-    TEST1_PHASE_COUNTDOWN,   /* 10→1 倒数 */
+    TEST1_PHASE_COUNTDOWN,   /* 10s 倒数 */
     TEST1_PHASE_BG,          /* 三原色背景切换 */
     TEST1_PHASE_GRID         /* 三原色九宫格 */
 } test1_phase_t;
@@ -34,7 +40,7 @@ typedef struct
 {
     test1_phase_t phase;
     uint32_t      last_ms;
-    int32_t       count;     /* 倒数值 10..1 */
+    int32_t       count;     /* 倒数 10..1 */
     uint32_t      bg_idx;    /* 当前背景色索引 */
     lv_obj_t    * scr;
     lv_obj_t    * lbl;
@@ -52,10 +58,10 @@ static const uint32_t test1_grid_hex[9] = {
     0x0000FF,   /* 蓝 */
     0xFFFF00,   /* 黄 */
     0x00FFFF,   /* 青 */
-    0xFF00FF,   /* 紫 */
+    0xFF00FF,   /* 品红 */
     0xFF8000,   /* 橙 */
     0x80FF00,   /* 草绿 */
-    0x8000FF    /* 品红 */
+    0x8000FF    /* 品蓝 */
 };
 
 /* 九宫格列宽:800 = 266 + 267 + 267;行高:480 = 160 * 3 */
@@ -143,6 +149,139 @@ static void Test1_Tick(test1_state_t * st)
 
 #endif /* ENABLE_TEST1 */
 
+#if ENABLE_TOUCH_TEST
+
+/**
+ * @brief 触摸画板: 配合电容触摸, 在屏幕上用手指绘制线条
+ *
+ * 实现方式:
+ *  - 全屏 lv_canvas (RGB565), 白底黑笔。
+ *  - 画布数据缓冲放在 SDRAM 第三块 (非缓存区, 无缓存一致性问题)。
+ *  - 主循环每帧轮询按压状态: 按下则用 Bresenham 从上一触点连线到当前触点;
+ *    松开则重置上一触点, 下次按下从新起点开始 (不连线)。
+ *  - 右上角提供 "CLEAR" 清屏按钮。
+ */
+
+/* 画板常量 */
+#define PAD_BUF_ADDR    (INT_LCD_FRAME_BUF_ADDR + 2 * INT_LCD_FRAME_BUF_SIZE)  /* SDRAM 3rd block */
+#define PAD_WIDTH       INT_LCD_WIDTH
+#define PAD_HEIGHT      INT_LCD_HEIGHT
+
+/* 画板句柄 */
+static lv_obj_t * s_pad_canvas   = NULL;
+static lv_coord_t s_pad_last_x;
+static lv_coord_t s_pad_last_y;
+static uint8_t    s_pad_drawing;   /* 是否正在连线中 */
+
+/**
+ * @brief Bresenham 画线: 在 canvas 上从 (x0,y0) 到 (x1,y1) 逐点涂色
+ */
+static void Pad_DrawLine(lv_coord_t x0, lv_coord_t y0, lv_coord_t x1, lv_coord_t y1)
+{
+    int dx = (x1 > x0) ? (x1 - x0) : (x0 - x1);
+    int dy = (y1 > y0) ? (y1 - y0) : (y0 - y1);
+    int sx = (x1 > x0) ? 1 : -1;
+    int sy = (y1 > y0) ? 1 : -1;
+    int err = dx - dy;
+    lv_color_t c = lv_color_black();
+
+    while (1)
+    {
+        if (x0 >= 0 && x0 < PAD_WIDTH && y0 >= 0 && y0 < PAD_HEIGHT)
+        {
+            lv_canvas_set_px(s_pad_canvas, x0, y0, c);
+        }
+        if (x0 == x1 && y0 == y1) break;
+        int e2 = 2 * err;
+        if (e2 > -dy) { err -= dy; x0 += sx; }
+        if (e2 <  dx) { err += dx; y0 += sy; }
+    }
+}
+
+/**
+ * @brief 清屏按钮事件回调
+ */
+static void Pad_ClearCb(lv_event_t * e)
+{
+    if (lv_event_get_code(e) == LV_EVENT_CLICKED && s_pad_canvas != NULL)
+    {
+        lv_canvas_fill_bg(s_pad_canvas, lv_color_white(), LV_OPA_COVER);
+        lv_obj_invalidate(s_pad_canvas);
+        s_pad_drawing = 0;
+    }
+}
+
+/**
+ * @brief 画板主循环动作: 每帧调用, 根据按压状态绘制
+ */
+static void TouchTest_Tick(void)
+{
+    uint16_t px = 0;
+    uint16_t py = 0;
+
+    if (s_pad_canvas == NULL) return;
+
+    if (Int_gt1151_pressed())
+    {
+        Int_gt1151_get_point(&px, &py);
+
+        if (s_pad_drawing)
+        {
+            /* 上一触点 -> 当前触点连线 */
+            Pad_DrawLine(s_pad_last_x, s_pad_last_y, (lv_coord_t)px, (lv_coord_t)py);
+        }
+        else
+        {
+            /* 刚按下: 画一个起始点 */
+            if (px < PAD_WIDTH && py < PAD_HEIGHT)
+            {
+                lv_canvas_set_px(s_pad_canvas, (lv_coord_t)px, (lv_coord_t)py, lv_color_black());
+            }
+            s_pad_drawing = 1;
+        }
+        s_pad_last_x = (lv_coord_t)px;
+        s_pad_last_y = (lv_coord_t)py;
+
+        /* 通知 LVGL 重绘画布, 将新画笔迹刷到显示 */
+        lv_obj_invalidate(s_pad_canvas);
+    }
+    else
+    {
+        s_pad_drawing = 0;   /* 松开, 下次按下重新起笔 */
+    }
+}
+
+/**
+ * @brief 初始化触摸画板
+ */
+static void TouchTest_Init(lv_obj_t * scr)
+{
+    lv_obj_set_style_bg_color(scr, lv_color_hex(0x000000), LV_STATE_DEFAULT);
+
+    /* 创建全屏画布 */
+    s_pad_canvas = lv_canvas_create(scr);
+    /* 画布缓冲使用 SDRAM 固定地址 */
+    lv_canvas_set_buffer(s_pad_canvas, (void *)PAD_BUF_ADDR, PAD_WIDTH, PAD_HEIGHT, LV_IMG_CF_TRUE_COLOR);
+    lv_obj_center(s_pad_canvas);
+    lv_canvas_fill_bg(s_pad_canvas, lv_color_white(), LV_OPA_COVER);
+
+    s_pad_drawing = 0;
+    s_pad_last_x  = 0;
+    s_pad_last_y  = 0;
+
+    /* 右上角清屏按钮 */
+    lv_obj_t * btn = lv_btn_create(scr);
+    lv_obj_set_size(btn, 96, 40);
+    lv_obj_align(btn, LV_ALIGN_TOP_RIGHT, -10, 10);
+    lv_obj_add_event_cb(btn, Pad_ClearCb, LV_EVENT_CLICKED, NULL);
+
+    lv_obj_t * lbl = lv_label_create(btn);
+    lv_label_set_text(lbl, "CLEAR");
+    lv_obj_center(lbl);
+}
+
+#endif /* ENABLE_TOUCH_TEST */
+
 TaskHandle_t xCPLDProcessTaskHandle = NULL;
 TaskHandle_t xLVGLDisplayTaskHandle = NULL;
 TaskHandle_t xTestTaskHandle = NULL;
@@ -185,7 +324,6 @@ void Task_CPLD_Process(void *argument)
     printf("CPLD process task running...\r\n");
     while (1)
     {
-        printf("CPLD\r\n");
         /* TODO: CPLD 通信处理 */
         vTaskDelay(pdMS_TO_TICKS(1000));
     }
@@ -207,7 +345,25 @@ void Task_LVGL_Display(void *argument)
     /* 注册显示驱动:LTDC + SDRAM 静态显存 + 双全屏缓冲 */
     lv_port_disp_init();
 
-#if ENABLE_TEST1
+    /* 初始化 GT1151Q 电容触摸芯片 */
+    if (Int_gt1151_init() == 0)
+    {
+        printf("GT1151 Init OK\r\n");
+        /* 注册触摸输入设备 (注意: 需在 lv_init 之后、主循环 lv_timer_handler 之前) */
+        lv_port_indev_init();
+    }
+    else
+    {
+        printf("[ERR] GT1151 Init failed\r\n");
+    }
+
+#if ENABLE_TOUCH_TEST
+    /* 触摸验证界面:可点击按钮 + 实时坐标显示 */
+    {
+        lv_obj_t *scr = lv_scr_act();
+        TouchTest_Init(scr);
+    }
+#elif ENABLE_TEST1
     test1_state_t test1;
     Test1_Init(&test1);
 #else
@@ -224,7 +380,9 @@ void Task_LVGL_Display(void *argument)
     {
         /* 周期驱动 LVGL(渲染/动画/输入),配合 LV_DISP_DEF_REFR_PERIOD 30ms */
         lv_timer_handler();
-#if ENABLE_TEST1
+#if ENABLE_TOUCH_TEST
+        TouchTest_Tick();
+#elif ENABLE_TEST1
         Test1_Tick(&test1);
 #endif
         vTaskDelay(pdMS_TO_TICKS(5));
@@ -242,7 +400,6 @@ void Task_Test(void *argument)
     printf("Test task running...\r\n");
     while (1)
     {
-        printf("TEST\r\n");
         /* TODO: 测试 */
         vTaskDelay(pdMS_TO_TICKS(5000));
     }

+ 76 - 0
Core/Inc/Core_i2c_sw.h

@@ -0,0 +1,76 @@
+/* USER CODE BEGIN Header */
+/**
+  ******************************************************************************
+  * @file    Core_i2c_sw.h
+  * @brief   软件模拟 I2C (Software I2C) 驱动头文件 - 用于 GT1151Q 电容触摸屏
+  *
+  *          GT1151QC 触摸芯片通过两根普通 GPIO 引脚以软件 I2C 时序通信:
+  *            - SCL: PD12 (GPIO 推挽输出, 上拉)
+  *            - SDA: PD13 (GPIO 开漏输出, 上拉, 支持双向读写)
+  *
+  *          引脚已在 CubeMX 工程 (Core/Src/gpio.c 的 MX_GPIO_Init) 中初始化完成,
+  *          此处不再重复配置 IO, 仅提供 I2C 总线时序操作的函数。
+  *
+  ******************************************************************************
+  */
+/* USER CODE END Header */
+#ifndef __CORE_I2C_SW_H
+#define __CORE_I2C_SW_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+#include "main.h"
+
+/* USER CODE BEGIN Includes */
+
+/* USER CODE END Includes */
+
+/* USER CODE BEGIN Private defines */
+
+/*----------------------- 软件 I2C 引脚定义 ------------------------*/
+#define CORE_I2C_SW_SCL_GPIO_PORT            GPIOD
+#define CORE_I2C_SW_SCL_GPIO_PIN             GPIO_PIN_12   /* SCL: PD12 */
+#define CORE_I2C_SW_SDA_GPIO_PORT            GPIOD
+#define CORE_I2C_SW_SDA_GPIO_PIN             GPIO_PIN_13   /* SDA: PD13 */
+
+/* IO 操作宏: 设置/读取 SCL、SDA */
+#define CORE_I2C_SW_SCL(x)  do{ HAL_GPIO_WritePin(CORE_I2C_SW_SCL_GPIO_PORT, CORE_I2C_SW_SCL_GPIO_PIN, ((x)?GPIO_PIN_SET:GPIO_PIN_RESET)); }while(0)
+#define CORE_I2C_SW_SDA(x)  do{ HAL_GPIO_WritePin(CORE_I2C_SW_SDA_GPIO_PORT, CORE_I2C_SW_SDA_GPIO_PIN, ((x)?GPIO_PIN_SET:GPIO_PIN_RESET)); }while(0)
+#define CORE_I2C_SW_READ_SDA  HAL_GPIO_ReadPin(CORE_I2C_SW_SDA_GPIO_PORT, CORE_I2C_SW_SDA_GPIO_PIN)
+
+/* USER CODE END Private defines */
+
+/* USER CODE BEGIN Private prototypes */
+
+/* USER CODE END Private prototypes */
+
+/* USER CODE BEGIN Private function prototypes */
+
+/* USER CODE END Private function prototypes */
+
+/* USER CODE BEGIN Exported functions */
+
+/* USER CODE END Exported functions */
+
+/* USER CODE BEGIN Exported function prototypes */
+
+/* 软件 I2C 总线操作函数 */
+void      Core_i2c_sw_init(void);                        /* 初始化软件 I2C (释放总线) */
+void      Core_i2c_sw_start(void);                       /* 产生起始信号 */
+void      Core_i2c_sw_stop(void);                        /* 产生停止信号 */
+void      Core_i2c_sw_ack(void);                         /* 主机发送 ACK 应答 */
+void      Core_i2c_sw_nack(void);                        /* 主机发送 NACK 应答 */
+uint8_t   Core_i2c_sw_wait_ack(void);                    /* 等待从机 ACK, 返回0=成功,1=超时 */
+void      Core_i2c_sw_send_byte(uint8_t txd);            /* 发送一个字节 (高位在前) */
+uint8_t   Core_i2c_sw_read_byte(uint8_t ack);            /* 读取一个字节, ack=1发ACK, ack=0发NACK */
+
+/* USER CODE END Exported function prototypes */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CORE_I2C_SW_H */

+ 230 - 0
Core/Src/Core_i2c_sw.c

@@ -0,0 +1,230 @@
+/* USER CODE BEGIN Header */
+/**
+  ******************************************************************************
+  * @file    Core_i2c_sw.c
+  * @brief   软件模拟 I2C (Software I2C) 驱动源文件 - 用于 GT1151Q 电容触摸屏
+  *
+  *
+  *          硬件连接 (引脚已在 Core/Src/gpio.c 的 MX_GPIO_Init 中初始化):
+  *            - SCL: PD12 (GPIO 推挽输出, 上拉)
+  *            - SDA: PD13 (GPIO 开漏输出, 上拉, 支持双向读写)
+  *
+  *          说明:
+  *            - SDA 配置为开漏 (OD), 当输出高/释放时由外部上拉电阻拉高,
+  *              同时可以用 GPIO 读回从机返回的电平, 实现双向半双工通信。
+  *            - 使用 DWT.CYCCNT 实现微秒级延时 (相继基于 SystemCoreClock 换算)。
+  ******************************************************************************
+  */
+/* USER CODE END Header */
+
+/* Private includes ----------------------------------------------------------*/
+/* USER CODE BEGIN Includes */
+#include "Core_i2c_sw.h"
+/* USER CODE END Includes */
+
+/* USER CODE BEGIN 0 */
+
+/**
+  * @brief  微秒级延时 (基于 DWT 数据观察点周期计数器)
+  * @note   320MHz 以上可用 DWT->CYCCNT 计数 CPU 周期, 据此实现高精度 us 延时。
+  *         SystemCoreClock 为当前 CPU 主频 (本项目为 480MHz)。
+  * @param  us: 延时微秒数
+  * @retval 无
+  */
+static void Core_i2c_sw_delay_us(uint32_t us)
+{
+    if (us == 0) return;
+
+    volatile uint32_t *dwt_ctrl  = (volatile uint32_t *)0xE0001000UL;  /* DWT->CTRL   */
+    volatile uint32_t *dwt_cyccnt = (volatile uint32_t *)0xE0001004UL; /* DWT->CYCCNT */
+    volatile uint32_t *core_debug = (volatile uint32_t *)0xE000EDFCUL; /* CoreDebug->DEMCR */
+
+    /* 首次使用时使能 DWT 周期计数器 */
+    if ((*core_debug & (1UL << 24)) == 0)   /* DEMCR.TRCENA */
+    {
+        *core_debug |= (1UL << 24);
+        *dwt_cyccnt = 0;
+        *dwt_ctrl  |= 1UL;                  /* DWT_CTRL_CYCCNTENA */
+    }
+
+    uint32_t start   = *dwt_cyccnt;
+    uint32_t ticks   = (uint32_t)(SystemCoreClock / 1000000UL * us);
+    uint32_t current;
+
+    do
+    {
+        current = *dwt_cyccnt;
+    }
+    while ((current - start) < ticks);
+}
+
+/**
+  * @brief  软件 I2C 引脚初始化
+  * @note   引脚 GPIO 模式已由 CubeMX 的 MX_GPIO_Init 配置 (SCL=PP输出, SDA=OD输出)。
+  *         此处仅发送一个停止信号以复位总线, 释放挂起的从机。
+  * @param  无
+  * @retval 无
+  */
+void Core_i2c_sw_init(void)
+{
+    Core_i2c_sw_stop();
+}
+
+/**
+  * @brief  产生 I2C 起始信号
+  * @note   SCL 为高电平时, SDA 由高变低 -> 起始信号
+  * @param  无
+  * @retval 无
+  */
+void Core_i2c_sw_start(void)
+{
+    CORE_I2C_SW_SDA(1);
+    CORE_I2C_SW_SCL(1);
+    Core_i2c_sw_delay_us(2);
+    CORE_I2C_SW_SDA(0);
+    Core_i2c_sw_delay_us(2);
+    CORE_I2C_SW_SCL(0);
+    Core_i2c_sw_delay_us(2);
+}
+
+/**
+  * @brief  产生 I2C 停止信号
+  * @note   SCL 为高电平时, SDA 由低变高 -> 停止信号
+  * @param  无
+  * @retval 无
+  */
+void Core_i2c_sw_stop(void)
+{
+    CORE_I2C_SW_SDA(0);
+    Core_i2c_sw_delay_us(2);
+    CORE_I2C_SW_SCL(1);
+    Core_i2c_sw_delay_us(2);
+    CORE_I2C_SW_SDA(1);
+    Core_i2c_sw_delay_us(2);
+}
+
+/**
+  * @brief  等待从机返回 ACK 应答
+  * @note   释放 SDA, 拉高 SCL, 在 SCL 高电平期间从机可将 SDA 拉低表示 ACK (0)。
+  * @param  无
+  * @retval 0, 收到 ACK (成功); 1, 超时 (失败)
+  */
+uint8_t Core_i2c_sw_wait_ack(void)
+{
+    uint8_t waittime = 0;
+    uint8_t rack = 0;
+
+    CORE_I2C_SW_SDA(1);   /* 释放 SDA */
+    Core_i2c_sw_delay_us(2);
+    CORE_I2C_SW_SCL(1);   /* SCL 拉高, 从机在此期间拉低 SDA 表示 ACK */
+    Core_i2c_sw_delay_us(2);
+
+    while (CORE_I2C_SW_READ_SDA) /* 等待 SDA 被拉低 (ACK) */
+    {
+        waittime++;
+        if (waittime > 250)
+        {
+            Core_i2c_sw_stop();
+            rack = 1;
+            break;
+        }
+        Core_i2c_sw_delay_us(2);
+    }
+
+    CORE_I2C_SW_SCL(0);   /* 拉低 SCL 完成 ACK 时钟 */
+    Core_i2c_sw_delay_us(2);
+
+    return rack;
+}
+
+/**
+  * @brief  主机发送 ACK 应答 
+  * @param  无
+  * @retval 无
+  */
+void Core_i2c_sw_ack(void)
+{
+    CORE_I2C_SW_SDA(0);
+    Core_i2c_sw_delay_us(2);
+    CORE_I2C_SW_SCL(1);
+    Core_i2c_sw_delay_us(2);
+    CORE_I2C_SW_SCL(0);
+    Core_i2c_sw_delay_us(2);
+    CORE_I2C_SW_SDA(1);   /* 释放 SDA */
+    Core_i2c_sw_delay_us(2);
+}
+
+/**
+  * @brief  主机发送 NACK 应答 
+  * @param  无
+  * @retval 无
+  */
+void Core_i2c_sw_nack(void)
+{
+    CORE_I2C_SW_SDA(1);
+    Core_i2c_sw_delay_us(2);
+    CORE_I2C_SW_SCL(1);
+    Core_i2c_sw_delay_us(2);
+    CORE_I2C_SW_SCL(0);
+    Core_i2c_sw_delay_us(2);
+}
+
+/**
+  * @brief  发送一个字节 (高位在前)
+  * @param  txd: 要发送的字节
+  * @retval 无
+  */
+void Core_i2c_sw_send_byte(uint8_t txd)
+{
+    uint8_t t;
+
+    for (t = 0; t < 8; t++)
+    {
+        CORE_I2C_SW_SDA((txd & 0x80) >> 7); /* 高位先发 */
+        Core_i2c_sw_delay_us(2);
+        CORE_I2C_SW_SCL(1);
+        Core_i2c_sw_delay_us(2);
+        CORE_I2C_SW_SCL(0);
+        txd <<= 1;
+    }
+
+    CORE_I2C_SW_SDA(1);   /* 发送完毕, 释放 SDA, 等待从机 ACK */
+}
+
+/**
+  * @brief  读取一个字节 (高位在前)
+  * @param  ack: 1=读完本字节再发 ACK (继续读); 0=读完本字节发 NACK (结束)
+  * @retval 收到的字节
+  */
+uint8_t Core_i2c_sw_read_byte(uint8_t ack)
+{
+    uint8_t i, receive = 0;
+
+    for (i = 0; i < 8; i++)
+    {
+        receive <<= 1;
+        CORE_I2C_SW_SCL(1);
+        Core_i2c_sw_delay_us(2);
+
+        if (CORE_I2C_SW_READ_SDA)
+        {
+            receive++;
+        }
+
+        CORE_I2C_SW_SCL(0);
+        Core_i2c_sw_delay_us(2);
+    }
+
+    if (!ack)
+    {
+        Core_i2c_sw_nack();   /* 最后一个字节 -> NACK */
+    }
+    else
+    {
+        Core_i2c_sw_ack();    /* 非最后一个字节 -> ACK */
+    }
+
+    return receive;
+}
+
+/* USER CODE END 0 */

+ 51 - 0
Int/Inc/Int_gt1151.h

@@ -0,0 +1,51 @@
+#ifndef __INT_GT1151_H
+#define __INT_GT1151_H
+
+#include "main.h"
+
+/*----------------------- GT1151 复位/中断引脚定义 ------------------------*/
+#define INT_GT1151_RST_GPIO_PORT     GPIOB
+#define INT_GT1151_RST_GPIO_PIN      GPIO_PIN_12   /* RST: PB12 */
+#define INT_GT1151_INT_GPIO_PORT     GPIOH
+#define INT_GT1151_INT_GPIO_PIN      GPIO_PIN_7    /* INT: PH7 */
+
+#define INT_GT1151_RST(x)  do{ HAL_GPIO_WritePin(INT_GT1151_RST_GPIO_PORT, INT_GT1151_RST_GPIO_PIN, ((x)?GPIO_PIN_SET:GPIO_PIN_RESET)); }while(0)
+#define INT_GT1151_INT     HAL_GPIO_ReadPin(INT_GT1151_INT_GPIO_PORT, INT_GT1151_INT_GPIO_PIN)
+
+/*----------------------- GT1151 I2C 器件命令 ------------------------*/
+#define INT_GT1151_CMD_WR         0X28        /* 写命令 (器件地址<<1 | 0) */
+#define INT_GT1151_CMD_RD         0X29        /* 读命令 (器件地址<<1 | 1) */
+
+/*----------------------- GT1151 关键寄存器地址 ------------------------*/
+#define INT_GT1151_CTRL_REG       0X8040      /* 控制寄存器 */
+#define INT_GT1151_CFGS_REG       0X8047      /* 配置数据起始地址寄存器 */
+#define INT_GT1151_CHECK_REG      0X80FF      /* 配置校验和寄存器 */
+#define INT_GT1151_PID_REG        0X8140      /* 产品 ID 寄存器 (4字节, 本板为 "1151") */
+#define INT_GT1151_GSTID_REG      0X814E      /* 触摸点数/状态寄存器 */
+#define INT_GT1151_TP1_REG        0X8150      /* 第一触点数据地址 */
+#define INT_GT1151_TP2_REG        0X8158
+#define INT_GT1151_TP3_REG        0X8160
+#define INT_GT1151_TP4_REG        0X8168
+#define INT_GT1151_TP5_REG        0X8170
+
+/*----------------------- 屏幕分辨率 (与 LCD 一致) ------------------------*/
+#define INT_GT1151_WIDTH          800
+#define INT_GT1151_HEIGHT         480
+#define INT_GT1151_TOUCH_NUM      5           /* GT1151 支持 5 点触摸 */
+
+/*----------------------- 坐标方向调整宏 ------------------------
+ * 触点原始坐标方向可能与 LCD 逻辑坐标不一致, 提供以下开关便于实测调整:
+ *   SWAP : 交换 X/Y 轴; FLIPX: X 轴镜像; FLIPY: Y 轴镜像
+ */
+#define INT_GT1151_SWAP_X_Y       1
+#define INT_GT1151_FLIP_X         0
+#define INT_GT1151_FLIP_Y         0
+
+uint8_t   Int_gt1151_wr_reg(uint16_t reg, uint8_t *buf, uint8_t len);  /* 向 GT1151 写寄存器 */
+void      Int_gt1151_rd_reg(uint16_t reg, uint8_t *buf, uint8_t len);  /* 从 GT1151 读寄存器 */
+uint8_t   Int_gt1151_init(void);                                       /* 初始化 GT1151, 返回0=成功 */
+uint8_t   Int_gt1151_scan(uint8_t mode);                               /* 扫描触摸, 返回1=有触点 */
+void      Int_gt1151_get_point(uint16_t *x, uint16_t *y);              /* 获取当前触点坐标 (LCD逻辑坐标) */
+uint8_t   Int_gt1151_pressed(void);                                    /* 查询当前是否处于按下状态 */
+
+#endif

+ 220 - 0
Int/Src/Int_gt1151.c

@@ -0,0 +1,220 @@
+#include <stdio.h>
+#include "Int_gt1151.h"
+#include "Core_i2c_sw.h"
+
+/* 当前触点状态缓存: x[0]/y[0] 为当前有效触点 */
+static uint16_t g_int_gt_x    = 0;
+static uint16_t g_int_gt_y    = 0;
+static uint16_t g_int_gt_sta  = 0;   /* bit15=按下 */
+
+/**
+  * @brief  向 GT1151 写入一段寄存器数据
+  * @param  reg : 起始寄存器地址 (16位)
+  * @param  buf : 数据缓冲区
+  * @param  len : 要写入的字节数
+  * @retval 0, 成功; 1, 失败 (从机无 ACK)
+  */
+uint8_t Int_gt1151_wr_reg(uint16_t reg, uint8_t *buf, uint8_t len)
+{
+    uint8_t i;
+    uint8_t ret = 0;
+
+    Core_i2c_sw_start();
+    Core_i2c_sw_send_byte(INT_GT1151_CMD_WR);   /* 发送写命令 */
+    Core_i2c_sw_wait_ack();
+    Core_i2c_sw_send_byte(reg >> 8);            /* 寄存器高 8 位地址 */
+    Core_i2c_sw_wait_ack();
+    Core_i2c_sw_send_byte(reg & 0XFF);          /* 寄存器低 8 位地址 */
+    Core_i2c_sw_wait_ack();
+
+    for (i = 0; i < len; i++)
+    {
+        Core_i2c_sw_send_byte(buf[i]);          /* 写数据 */
+        ret = Core_i2c_sw_wait_ack();
+        if (ret) break;
+    }
+
+    Core_i2c_sw_stop();                         /* 发送停止信号 */
+    return ret;
+}
+
+/**
+  * @brief  从 GT1151 读取一段寄存器数据
+  * @param  reg : 起始寄存器地址 (16位)
+  * @param  buf : 数据缓冲区
+  * @param  len : 要读取的字节数
+  * @retval 无
+  */
+void Int_gt1151_rd_reg(uint16_t reg, uint8_t *buf, uint8_t len)
+{
+    uint8_t i;
+
+    Core_i2c_sw_start();
+    Core_i2c_sw_send_byte(INT_GT1151_CMD_WR);   /* 发送写命令 (指向寄存器地址) */
+    Core_i2c_sw_wait_ack();
+    Core_i2c_sw_send_byte(reg >> 8);
+    Core_i2c_sw_wait_ack();
+    Core_i2c_sw_send_byte(reg & 0XFF);
+    Core_i2c_sw_wait_ack();
+
+    Core_i2c_sw_start();                         /* 重复起始信号, 转为读 */
+    Core_i2c_sw_send_byte(INT_GT1151_CMD_RD);   /* 发送读命令 */
+    Core_i2c_sw_wait_ack();
+
+    for (i = 0; i < len; i++)
+    {
+        buf[i] = Core_i2c_sw_read_byte(i == (len - 1) ? 0 : 1);   /* 最后一个字节发 NACK */
+    }
+
+    Core_i2c_sw_stop();
+}
+
+/**
+  * @brief  初始化 GT1151 触摸芯片
+  * @note   复位流程: RST拉低 -> 延时 -> RST拉高 -> INT 改为无上拉输入 -> 延时 -> 读产品ID
+  * @param  无
+  * @retval 0, 初始化成功; 1, 初始化失败 (未识别到 GT1151)
+  */
+uint8_t Int_gt1151_init(void)
+{
+    GPIO_InitTypeDef gpio_init_struct;
+    uint8_t temp[5];
+
+    /* RST/INT 引脚时钟使能 */
+    __HAL_RCC_GPIOB_CLK_ENABLE();
+    __HAL_RCC_GPIOH_CLK_ENABLE();
+
+    /* 配置 RST 引脚为推挽输出 (默认上拉) */
+    gpio_init_struct.Pin    = INT_GT1151_RST_GPIO_PIN;
+    gpio_init_struct.Mode   = GPIO_MODE_OUTPUT_PP;
+    gpio_init_struct.Pull   = GPIO_PULLUP;
+    gpio_init_struct.Speed  = GPIO_SPEED_FREQ_MEDIUM;
+    HAL_GPIO_Init(INT_GT1151_RST_GPIO_PORT, &gpio_init_struct);
+
+    /* 配置 INT 引脚为输入 (默认上拉) */
+    gpio_init_struct.Pin    = INT_GT1151_INT_GPIO_PIN;
+    gpio_init_struct.Mode   = GPIO_MODE_INPUT;
+    gpio_init_struct.Pull   = GPIO_PULLUP;
+    gpio_init_struct.Speed  = GPIO_SPEED_FREQ_MEDIUM;
+    HAL_GPIO_Init(INT_GT1151_INT_GPIO_PORT, &gpio_init_struct);
+
+    /* 初始化软件 I2C 总线 */
+    Core_i2c_sw_init();
+
+    /* 硬件复位: RST 拉低 30ms, 再拉高 30ms */
+    INT_GT1151_RST(0);
+    HAL_Delay(30);
+    INT_GT1151_RST(1);
+    HAL_Delay(30);
+
+    /* 复位完成后, INT 引脚改为无上下拉输入 (进入普通输入模式) */
+    gpio_init_struct.Pin    = INT_GT1151_INT_GPIO_PIN;
+    gpio_init_struct.Mode   = GPIO_MODE_INPUT;
+    gpio_init_struct.Pull   = GPIO_NOPULL;
+    gpio_init_struct.Speed  = GPIO_SPEED_FREQ_MEDIUM;
+    HAL_GPIO_Init(INT_GT1151_INT_GPIO_PORT, &gpio_init_struct);
+
+    HAL_Delay(100);
+
+    /* 读取并打印产品 ID (仅作调试参考, 不同屏幕批次 ID 可能不同) */
+    temp[4] = 0;
+    Int_gt1151_rd_reg(INT_GT1151_PID_REG, temp, 4);
+    printf("CTP ID:%s\r\n", temp);
+
+    /* 软复位并进入正常工作状态 */
+    temp[0] = 0X02;
+    Int_gt1151_wr_reg(INT_GT1151_CTRL_REG, temp, 1);
+    HAL_Delay(10);
+
+    temp[0] = 0X00;
+    Int_gt1151_wr_reg(INT_GT1151_CTRL_REG, temp, 1);
+
+    return 0;
+}
+
+/* GT1151 各触摸点寄存器地址表 */
+static const uint16_t s_int_gt_tp_tbl[INT_GT1151_TOUCH_NUM] =
+{
+    INT_GT1151_TP1_REG, INT_GT1151_TP2_REG, INT_GT1151_TP3_REG,
+    INT_GT1151_TP4_REG, INT_GT1151_TP5_REG,
+};
+
+/**
+  * @brief  扫描触摸屏 (查询方式)
+  * @note   把原始触点坐标经方向变换后, 保存在内部 g_int_gt_x/g_int_gt_y (LCD 逻辑坐标)。
+  * @param  mode : 0 = 屏幕扫描 (正常使用); 1 = 预留 (校准等场景, 本驱动未用)
+  * @retval 1, 有触点按下; 0, 无触点
+  */
+uint8_t Int_gt1151_scan(uint8_t mode)
+{
+    uint8_t buf[4];
+    uint8_t num = 0;
+    uint8_t res = 0;
+    uint16_t raw_x, raw_y;
+
+    (void)mode;
+
+    uint8_t gstid = 0;
+    Int_gt1151_rd_reg(INT_GT1151_GSTID_REG, &gstid, 1);
+
+    if ((gstid & 0X80) && ((gstid & 0X0F) <= INT_GT1151_TOUCH_NUM))
+    {
+        num = 0;
+        Int_gt1151_wr_reg(INT_GT1151_GSTID_REG, &num, 1);  /* 清标志 */
+    }
+
+    if ((gstid & 0X0F) && ((gstid & 0X0F) <= INT_GT1151_TOUCH_NUM))
+    {
+        /* 读取第一个触点坐标 (LVGL 单点即可) */
+        Int_gt1151_rd_reg(INT_GT1151_TP1_REG, buf, 4);
+        raw_x = ((uint16_t)buf[3] << 8) + buf[2];
+        raw_y = ((uint16_t)buf[1] << 8) + buf[0];
+
+        /* 方向变换: 通过宏调节镜像/交换, 得到 LCD 逻辑坐标 */
+        if (INT_GT1151_SWAP_X_Y)
+        {
+            uint16_t tmp = raw_x; raw_x = raw_y; raw_y = tmp;
+        }
+        g_int_gt_x = (INT_GT1151_FLIP_X) ? (INT_GT1151_WIDTH  - 1 - raw_x) : raw_x;
+        g_int_gt_y = (INT_GT1151_FLIP_Y) ? (INT_GT1151_HEIGHT - 1 - raw_y) : raw_y;
+
+        /* 越界保护 */
+        if (g_int_gt_x >= INT_GT1151_WIDTH)  g_int_gt_x = INT_GT1151_WIDTH  - 1;
+        if (g_int_gt_y >= INT_GT1151_HEIGHT) g_int_gt_y = INT_GT1151_HEIGHT - 1;
+
+        g_int_gt_sta = 0X8000;   /* 标记按下 */
+        res = 1;
+    }
+    else
+    {
+        /* 无触点: 统一复位坐标/状态/返回值 */
+        g_int_gt_sta &= ~0X8000;
+        g_int_gt_x = 0xFFFF;
+        g_int_gt_y = 0xFFFF;
+        res = 0;
+    }
+
+    return res;
+}
+
+/**
+  * @brief  获取当前触点坐标 (LCD 逻辑坐标)
+  * @param  x, y : 输出坐标指针
+  * @retval 无
+  */
+void Int_gt1151_get_point(uint16_t *x, uint16_t *y)
+{
+    if (x) *x = g_int_gt_x;
+    if (y) *y = g_int_gt_y;
+}
+
+/**
+  * @brief  查询当前是否处于按下状态
+  * @note   供画板/上层轮询使用 (由 Int_gt1151_scan 更新按下状态, 本函数只读)。
+  * @param  无
+  * @retval 1, 按下; 0, 松开
+  */
+uint8_t Int_gt1151_pressed(void)
+{
+    return (g_int_gt_sta & 0X8000) ? 1 : 0;
+}

+ 36 - 357
LVGL8v3/examples/porting/lv_port_indev.c

@@ -1,410 +1,89 @@
 /**
- * @file lv_port_indev_templ.c
+ * @file lv_port_indev.c
  *
+ * @brief LVGL 输入设备 (触摸) 移植实现。
+ *  输入设备: 板载 GT1151Q 电容触摸屏 (软件 I2C on PD12/PD13)。
+ *  将触摸扫描结果接入 LVGL 指点设备 (LV_INDEV_TYPE_POINTER)。
  */
 
-/*Copy this file as "lv_port_indev.c" and set this value to "1" to enable content*/
-#if 0
+#if 1
+
 
-/*********************
- *      INCLUDES
- *********************/
 #include "lv_port_indev.h"
 #include "../../lvgl.h"
-
-/*********************
- *      DEFINES
- *********************/
-
-/**********************
- *      TYPEDEFS
- **********************/
-
-/**********************
- *  STATIC PROTOTYPES
- **********************/
+#include "Int_gt1151.h"
 
 static void touchpad_init(void);
 static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
 static bool touchpad_is_pressed(void);
 static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y);
 
-static void mouse_init(void);
-static void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
-static bool mouse_is_pressed(void);
-static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y);
-
-static void keypad_init(void);
-static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
-static uint32_t keypad_get_key(void);
-
-static void encoder_init(void);
-static void encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
-static void encoder_handler(void);
-
-static void button_init(void);
-static void button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
-static int8_t button_get_pressed_id(void);
-static bool button_is_pressed(uint8_t id);
-
-/**********************
- *  STATIC VARIABLES
- **********************/
 lv_indev_t * indev_touchpad;
-lv_indev_t * indev_mouse;
-lv_indev_t * indev_keypad;
-lv_indev_t * indev_encoder;
-lv_indev_t * indev_button;
 
-static int32_t encoder_diff;
-static lv_indev_state_t encoder_state;
-
-/**********************
- *      MACROS
- **********************/
-
-/**********************
- *   GLOBAL FUNCTIONS
- **********************/
 
+/**
+ * @brief  注册 LVGL 触摸输入设备
+ * @note   触摸芯片 Int_gt1151_init() 需在此之前调用 (见 App_freertosTask.c)
+ * @param  无
+ * @retval 无
+ */
 void lv_port_indev_init(void)
 {
-    /**
-     * Here you will find example implementation of input devices supported by LittelvGL:
-     *  - Touchpad
-     *  - Mouse (with cursor support)
-     *  - Keypad (supports GUI usage only with key)
-     *  - Encoder (supports GUI usage only with: left, right, push)
-     *  - Button (external buttons to press points on the screen)
-     *
-     *  The `..._read()` function are only examples.
-     *  You should shape them according to your hardware
-     */
-
     static lv_indev_drv_t indev_drv;
 
-    /*------------------
-     * Touchpad
-     * -----------------*/
-
-    /*Initialize your touchpad if you have*/
+    /* 初始化触摸板 */
     touchpad_init();
 
-    /*Register a touchpad input device*/
-    lv_indev_drv_init(&indev_drv);
-    indev_drv.type = LV_INDEV_TYPE_POINTER;
-    indev_drv.read_cb = touchpad_read;
-    indev_touchpad = lv_indev_drv_register(&indev_drv);
-
-    /*------------------
-     * Mouse
-     * -----------------*/
-
-    /*Initialize your mouse if you have*/
-    mouse_init();
-
-    /*Register a mouse input device*/
-    lv_indev_drv_init(&indev_drv);
-    indev_drv.type = LV_INDEV_TYPE_POINTER;
-    indev_drv.read_cb = mouse_read;
-    indev_mouse = lv_indev_drv_register(&indev_drv);
-
-    /*Set cursor. For simplicity set a HOME symbol now.*/
-    lv_obj_t * mouse_cursor = lv_img_create(lv_scr_act());
-    lv_img_set_src(mouse_cursor, LV_SYMBOL_HOME);
-    lv_indev_set_cursor(indev_mouse, mouse_cursor);
-
-    /*------------------
-     * Keypad
-     * -----------------*/
-
-    /*Initialize your keypad or keyboard if you have*/
-    keypad_init();
-
-    /*Register a keypad input device*/
+    /* 注册触摸板输入设备 */
     lv_indev_drv_init(&indev_drv);
-    indev_drv.type = LV_INDEV_TYPE_KEYPAD;
-    indev_drv.read_cb = keypad_read;
-    indev_keypad = lv_indev_drv_register(&indev_drv);
-
-    /*Later you should create group(s) with `lv_group_t * group = lv_group_create()`,
-     *add objects to the group with `lv_group_add_obj(group, obj)`
-     *and assign this input device to group to navigate in it:
-     *`lv_indev_set_group(indev_keypad, group);`*/
-
-    /*------------------
-     * Encoder
-     * -----------------*/
-
-    /*Initialize your encoder if you have*/
-    encoder_init();
-
-    /*Register a encoder input device*/
-    lv_indev_drv_init(&indev_drv);
-    indev_drv.type = LV_INDEV_TYPE_ENCODER;
-    indev_drv.read_cb = encoder_read;
-    indev_encoder = lv_indev_drv_register(&indev_drv);
-
-    /*Later you should create group(s) with `lv_group_t * group = lv_group_create()`,
-     *add objects to the group with `lv_group_add_obj(group, obj)`
-     *and assign this input device to group to navigate in it:
-     *`lv_indev_set_group(indev_encoder, group);`*/
-
-    /*------------------
-     * Button
-     * -----------------*/
-
-    /*Initialize your button if you have*/
-    button_init();
-
-    /*Register a button input device*/
-    lv_indev_drv_init(&indev_drv);
-    indev_drv.type = LV_INDEV_TYPE_BUTTON;
-    indev_drv.read_cb = button_read;
-    indev_button = lv_indev_drv_register(&indev_drv);
-
-    /*Assign buttons to points on the screen*/
-    static const lv_point_t btn_points[2] = {
-        {10, 10},   /*Button 0 -> x:10; y:10*/
-        {40, 100},  /*Button 1 -> x:40; y:100*/
-    };
-    lv_indev_set_button_points(indev_button, btn_points);
+    indev_drv.type     = LV_INDEV_TYPE_POINTER;
+    indev_drv.read_cb  = touchpad_read;
+    indev_touchpad     = lv_indev_drv_register(&indev_drv);
 }
 
-/**********************
- *   STATIC FUNCTIONS
- **********************/
-
-/*------------------
- * Touchpad
- * -----------------*/
-
-/*Initialize your touchpad*/
+/* 初始化触摸板 */
 static void touchpad_init(void)
 {
-    /*Your code comes here*/
+    /* 触摸芯片初始化已在 App_freertosTask.c 中通过 Int_gt1151_init() 完成 */
 }
 
-/*Will be called by the library to read the touchpad*/
+/* 由 LVGL 周期调用, 读取触摸状态与坐标 */
 static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
 {
     static lv_coord_t last_x = 0;
     static lv_coord_t last_y = 0;
 
-    /*Save the pressed coordinates and the state*/
-    if(touchpad_is_pressed()) {
+    (void)indev_drv;
+
+    if (touchpad_is_pressed())
+    {
         touchpad_get_xy(&last_x, &last_y);
         data->state = LV_INDEV_STATE_PR;
     }
-    else {
+    else
+    {
         data->state = LV_INDEV_STATE_REL;
     }
 
-    /*Set the last pressed coordinates*/
+    /* 记录最近一次触点坐标 (松开时仍返回最后一次位置) */
     data->point.x = last_x;
     data->point.y = last_y;
 }
 
-/*Return true is the touchpad is pressed*/
+/* 返回触摸屏当前是否有触点按下 */
 static bool touchpad_is_pressed(void)
 {
-    /*Your code comes here*/
-
-    return false;
+    return (Int_gt1151_scan(0) == 1) ? true : false;
 }
 
-/*Get the x and y coordinates if the touchpad is pressed*/
+/* 获取当前触点坐标 (LCD 逻辑坐标) */
 static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y)
 {
-    /*Your code comes here*/
-
-    (*x) = 0;
-    (*y) = 0;
-}
-
-/*------------------
- * Mouse
- * -----------------*/
-
-/*Initialize your mouse*/
-static void mouse_init(void)
-{
-    /*Your code comes here*/
-}
-
-/*Will be called by the library to read the mouse*/
-static void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
-{
-    /*Get the current x and y coordinates*/
-    mouse_get_xy(&data->point.x, &data->point.y);
-
-    /*Get whether the mouse button is pressed or released*/
-    if(mouse_is_pressed()) {
-        data->state = LV_INDEV_STATE_PR;
-    }
-    else {
-        data->state = LV_INDEV_STATE_REL;
-    }
-}
-
-/*Return true is the mouse button is pressed*/
-static bool mouse_is_pressed(void)
-{
-    /*Your code comes here*/
-
-    return false;
-}
-
-/*Get the x and y coordinates if the mouse is pressed*/
-static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y)
-{
-    /*Your code comes here*/
-
-    (*x) = 0;
-    (*y) = 0;
-}
-
-/*------------------
- * Keypad
- * -----------------*/
-
-/*Initialize your keypad*/
-static void keypad_init(void)
-{
-    /*Your code comes here*/
-}
-
-/*Will be called by the library to read the mouse*/
-static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
-{
-    static uint32_t last_key = 0;
-
-    /*Get the current x and y coordinates*/
-    mouse_get_xy(&data->point.x, &data->point.y);
-
-    /*Get whether the a key is pressed and save the pressed key*/
-    uint32_t act_key = keypad_get_key();
-    if(act_key != 0) {
-        data->state = LV_INDEV_STATE_PR;
-
-        /*Translate the keys to LVGL control characters according to your key definitions*/
-        switch(act_key) {
-            case 1:
-                act_key = LV_KEY_NEXT;
-                break;
-            case 2:
-                act_key = LV_KEY_PREV;
-                break;
-            case 3:
-                act_key = LV_KEY_LEFT;
-                break;
-            case 4:
-                act_key = LV_KEY_RIGHT;
-                break;
-            case 5:
-                act_key = LV_KEY_ENTER;
-                break;
-        }
-
-        last_key = act_key;
-    }
-    else {
-        data->state = LV_INDEV_STATE_REL;
-    }
-
-    data->key = last_key;
-}
-
-/*Get the currently being pressed key.  0 if no key is pressed*/
-static uint32_t keypad_get_key(void)
-{
-    /*Your code comes here*/
-
-    return 0;
-}
-
-/*------------------
- * Encoder
- * -----------------*/
-
-/*Initialize your keypad*/
-static void encoder_init(void)
-{
-    /*Your code comes here*/
-}
-
-/*Will be called by the library to read the encoder*/
-static void encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
-{
-
-    data->enc_diff = encoder_diff;
-    data->state = encoder_state;
-}
-
-/*Call this function in an interrupt to process encoder events (turn, press)*/
-static void encoder_handler(void)
-{
-    /*Your code comes here*/
-
-    encoder_diff += 0;
-    encoder_state = LV_INDEV_STATE_REL;
-}
-
-/*------------------
- * Button
- * -----------------*/
-
-/*Initialize your buttons*/
-static void button_init(void)
-{
-    /*Your code comes here*/
-}
-
-/*Will be called by the library to read the button*/
-static void button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
-{
-
-    static uint8_t last_btn = 0;
-
-    /*Get the pressed button's ID*/
-    int8_t btn_act = button_get_pressed_id();
-
-    if(btn_act >= 0) {
-        data->state = LV_INDEV_STATE_PR;
-        last_btn = btn_act;
-    }
-    else {
-        data->state = LV_INDEV_STATE_REL;
-    }
-
-    /*Save the last pressed button's ID*/
-    data->btn_id = last_btn;
-}
-
-/*Get ID  (0, 1, 2 ..) of the pressed button*/
-static int8_t button_get_pressed_id(void)
-{
-    uint8_t i;
-
-    /*Check to buttons see which is being pressed (assume there are 2 buttons)*/
-    for(i = 0; i < 2; i++) {
-        /*Return the pressed button's ID*/
-        if(button_is_pressed(i)) {
-            return i;
-        }
-    }
-
-    /*No button pressed*/
-    return -1;
-}
-
-/*Test if `id` button is pressed or not*/
-static bool button_is_pressed(uint8_t id)
-{
-
-    /*Your code comes here*/
-
-    return false;
+    uint16_t px = 0;
+    uint16_t py = 0;
+    Int_gt1151_get_point(&px, &py);
+    (*x) = (lv_coord_t)px;
+    (*y) = (lv_coord_t)py;
 }
 
 #else /*Enable this file at the top*/

+ 12 - 23
LVGL8v3/examples/porting/lv_port_indev.h

@@ -1,45 +1,34 @@
-
 /**
- * @file lv_port_indev_templ.h
+ * @file lv_port_indev.h
  *
+ * @brief LVGL 输入设备 (触摸屏) 移植头文件。
  */
 
-/*Copy this file as "lv_port_indev.h" and set this value to "1" to enable content*/
-#if 0
+#if 1
 
-#ifndef LV_PORT_INDEV_TEMPL_H
-#define LV_PORT_INDEV_TEMPL_H
+#ifndef LV_PORT_INDEV_H
+#define LV_PORT_INDEV_H
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-/*********************
- *      INCLUDES
- *********************/
-#include "lvgl/lvgl.h"
 
-/*********************
- *      DEFINES
- *********************/
+#if defined(LV_LVGL_H_INCLUDE_SIMPLE)
+#include "lvgl.h"
+#else
+#include "lvgl/lvgl.h"
+#endif
 
-/**********************
- *      TYPEDEFS
- **********************/
 
-/**********************
- * GLOBAL PROTOTYPES
- **********************/
 void lv_port_indev_init(void);
 
-/**********************
- *      MACROS
- **********************/
+
 
 #ifdef __cplusplus
 } /*extern "C"*/
 #endif
 
-#endif /*LV_PORT_INDEV_TEMPL_H*/
+#endif /*LV_PORT_INDEV_H*/
 
 #endif /*Disable/Enable content*/

+ 10 - 0
MDK-ARM/STMH7_temperature_control_board.uvprojx

@@ -552,6 +552,11 @@
                 </FileArmAds>
               </FileOption>
             </File>
+            <File>
+              <FileName>Core_i2c_sw.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>../Core/Src/Core_i2c_sw.c</FilePath>
+            </File>
           </Files>
         </Group>
         <Group>
@@ -873,6 +878,11 @@
               <FileType>1</FileType>
               <FilePath>../Int/Src/Int_eeprom.c</FilePath>
             </File>
+            <File>
+              <FileName>Int_gt1151.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>../Int/Src/Int_gt1151.c</FilePath>
+            </File>
           </Files>
         </Group>
         <Group>