硬件:野火挑战者STM32F429 V1开发版,5寸屏
软件:最新版本的STM32CubeF4固件库,TouchGFXDesigner v4.13和 STM32CubeMX v5.6.1,开发环境MDK v5.29
1.准备一套STM32F429开发版,和下载工具
2.下载 TouchGFXDesigner v4.13
压缩包下载完后,解压如下:
Projects目录下有STM32H7B3I-DK的工程,可以用来参考。touchGFX Designer的PC端安装包在Utilities目录下,找到后并安装。
3.下载 STM32CubeMX v5.6.1
安装完STM32CubeMX v5.6.1版本后,还需要安装X_CUBE_TOUCHGFX软件包,安装路径如下:
4.下载 MDK v5.27以上版本
效果演示:
代码持续更新中:
github代码下载地址 https://gitee.com/Aladdin-Wang/hellotouchGFX.git
觉得有用的话,欢迎给个小星星
通读RT-Thread系统官方学习文档,https://www.rt-thread.org/document/site/
快速了解RT-Thread系统的内核,设备、组件和软件包的使用方法,下载并安装Env开发工工具
参考官方使用 Env 创建 RT-Thread 项目工程的教程
选择 BSP
获取 RT-Thread 源代码后需要根据自己手上的开发板型号找到对应的 BSP,我实验所使用的是野火的STM32F29 V1开发板,所以可以选择stm32f29-fire-challenger的BSP,在此BSP的基础上移植touchgfx,首先找到如下目录:…\rt-thread\bsp\stm32\stm32f429-fire-challenger。
搭建项目框架
打开 Env 工具进入 stm32f429-fire-challenger 目录,运行scons --dist 命令。使用此命令会在 stm32f429-fire-challenger目录下生成 dist 目录,这便是开发项目的目录结构,RT-Thread 源码位于项目文件夹内,仅包含stm32f429-fire-challenger 的 BSP,可以随意拷贝此 BSP 到任何目录下使用。
进入dist目录下,把工程里面的 stm32f429-fire-challenger压缩包拷贝到你的项目目录下待使用。
制作BSP
也可以自己重新制作对应自己板子的BSP,可以参考官方教程
打开…\board\CubeMX_Config\CubeMX_Config.ioc,由于bsp已经配置了很多外设,所以只需要修改部分配置就可以了
打开CRC
重新配置LTCD
打开freertos
打开Touchgfx
配置Touchgfx
配置SPI_FLASH管脚
生成工程
通过TouchGFX 4.13.0 Designer打开ApplicationTemplate.touchgfx.part
配置TouchGFX UI,创建三个页面
拷贝OSWrappers.cpp,重命名为OSWrappers_RTT.cpp文件
更改代码
1/**
2 ******************************************************************************
3 * File Name : OSWrappers.cpp
4 ******************************************************************************
5 * @attention
6 *
7 * © Copyright (c) 2020 STMicroelectronics.
8 * All rights reserved.
9 *
10 * This software component is licensed by ST under Ultimate Liberty license
11 * SLA0044, the "License"; You may not use this file except in compliance with
12 * the License. You may obtain a copy of the License at:
13 * www.st.com/SLA0044
14 *
15 ******************************************************************************
16 */
17#include
18#include
19#include
20#include
21#include
22#include
23#include
24
25static rt_sem_t frame_buffer_sem;
26static rt_mq_t vsync_q = 0;
27using namespace touchgfx;
28
29// Just a dummy value to insert in the VSYNC queue.
30static uint8_t dummy = 0x5a;
31
32/*
33 * Initialize frame buffer semaphore and queue/mutex for VSYNC signal.
34 */
35void OSWrappers::initialize()
36{
37
38 frame_buffer_sem = rt_sem_create("gfx_sem", 1, RT_IPC_FLAG_PRIO);
39 // Create a queue of length 1
40 vsync_q = rt_mq_create("gfx_mq", 1, 1, RT_IPC_FLAG_PRIO);
41
42}
43
44/*
45 * Take the frame buffer semaphore. Blocks until semaphore is available.
46 */
47void OSWrappers::takeFrameBufferSemaphore()
48{
49 rt_sem_take(frame_buffer_sem, RT_WAITING_FOREVER);
50}
51
52/*
53 * Release the frame buffer semaphore.
54 */
55void OSWrappers::giveFrameBufferSemaphore()
56{
57 rt_sem_release(frame_buffer_sem);
58}
59
60/*
61 * Attempt to obtain the frame buffer semaphore. If semaphore is not available, do
62 * nothing.
63 *
64 * Note must return immediately! This function does not care who has the taken the semaphore,
65 * it only serves to make sure that the semaphore is taken by someone.
66 */
67void OSWrappers::tryTakeFrameBufferSemaphore()
68{
69 rt_sem_trytake(frame_buffer_sem);
70}
71
72/*
73 * Release the frame buffer semaphore in a way that is safe in interrupt context. Called
74 * from ISR.
75 *
76 * Release the frame buffer semaphore in a way that is safe in interrupt context.
77 * Called from ISR.
78 */
79void OSWrappers::giveFrameBufferSemaphoreFromISR()
80{
81 // Since this is called from an interrupt, FreeRTOS requires special handling to trigger a
82 // re-scheduling. May be applicable for other OSes as well.
83 rt_sem_release(frame_buffer_sem);
84}
85
86/*
87 * Signal that a VSYNC has occurred. Should make the vsync queue/mutex available.
88 *
89 * Note This function is called from an ISR, and should (depending on OS) trigger a
90 * scheduling.
91 */
92void OSWrappers::signalVSync()
93{
94 if (vsync_q)
95 {
96 rt_mq_send(vsync_q, &dummy, 1);
97 }
98}
99
100/*
101 * This function blocks until a VSYNC occurs.
102 *
103 * Note This function must first clear the mutex/queue and then wait for the next one to
104 * occur.
105 */
106void OSWrappers::waitForVSync()
107{
108 // First make sure the queue is empty, by trying to remove an element with 0 timeout.
109 rt_mq_recv(vsync_q, &dummy, 1, 0);
110
111 // Then, wait for next VSYNC to occur.
112 rt_mq_recv(vsync_q, &dummy, 1, RT_WAITING_FOREVER);
113}
114
115/*
116 * A function that causes executing task to sleep for a number of milliseconds.
117 *
118 * A function that causes executing task to sleep for a number of milliseconds.
119 * This function is OPTIONAL. It is only used by the TouchGFX in the case of
120 * a specific frame refresh strategy (REFRESH_STRATEGY_OPTIM_SINGLE_BUFFER_TFT_CTRL).
121 * Due to backwards compatibility, in order for this function to be useable by the HAL
122 * the function must be explicitly registered:
123 * hal.registerTaskDelayFunction(&OSWrappers::taskDelay)
124 *
125 * see HAL::setFrameRefreshStrategy(FrameRefreshStrategy s)
126 * see HAL::registerTaskDelayFunction(void (*delayF)(uint16_t))
127 */
128void OSWrappers::taskDelay(uint16_t ms)
129{
130 rt_thread_mdelay(ms);
131}
132static rt_base_t IdleTaskHook(void* p)
133{
134 if ((int)p) //idle task sched out
135 {
136 touchgfx::HAL::getInstance()->setMCUActive(true);
137 }
138 else //idle task sched in
139 {
140 touchgfx::HAL::getInstance()->setMCUActive(false);
141 }
142 return RT_TRUE;
143}
144
145// FreeRTOS specific handlers
146extern "C"
147{
148 void vApplicationStackOverflowHook(rt_thread_t xTask,
149 signed char* pcTaskName)
150 {
151 while (1);
152 }
153
154 void vApplicationMallocFailedHook(rt_thread_t xTask,
155 signed char* pcTaskName)
156 {
157 while (1);
158 }
159
160 void vApplicationIdleHook(void)
161 {
162 // Set task tag in order to have the "IdleTaskHook" function called when the idle task is
163 // switched in/out. Used solely for measuring MCU load, and can be removed if MCU load
164 // readout is not needed.
165 //vTaskSetApplicationTaskTag(NULL, IdleTaskHook);
166 }
167}
168/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
拷贝main.c的部分外设初始化代码到sample_touchgfx.c,示例代码如下:
1#include
2#include
3#include
4#include "app_touchgfx.h"
5
6CRC_HandleTypeDef hcrc;
7
8DMA2D_HandleTypeDef hdma2d;
9
10LTDC_HandleTypeDef hltdc;
11
12static void MX_CRC_Init(void);
13static void MX_DMA2D_Init(void);
14static void MX_LTDC_Init(void);
15
16#define DISP_Pin GET_PIN(D, 4)
17#define CTDL_BL_Pin GET_PIN(D, 7)
18#define WIFI_Pin GET_PIN(G, 9)//野火开发板使用LCD需要关闭WIFI电源
19
20/**
21 * @brief This function handles LTDC global interrupt.
22 */
23void LTDC_IRQHandler(void)
24{
25 /* USER CODE BEGIN LTDC_IRQn 0 */
26
27 /* USER CODE END LTDC_IRQn 0 */
28 HAL_LTDC_IRQHandler(&hltdc);
29 /* USER CODE BEGIN LTDC_IRQn 1 */
30
31 /* USER CODE END LTDC_IRQn 1 */
32}
33
34/**
35 * @brief This function handles DMA2D global interrupt.
36 */
37void DMA2D_IRQHandler(void)
38{
39 /* USER CODE BEGIN DMA2D_IRQn 0 */
40
41 /* USER CODE END DMA2D_IRQn 0 */
42 HAL_DMA2D_IRQHandler(&hdma2d);
43 /* USER CODE BEGIN DMA2D_IRQn 1 */
44
45 /* USER CODE END DMA2D_IRQn 1 */
46}
47/**
48 * @brief CRC Initialization Function
49 * @param None
50 * @retval None
51 */
52static void MX_CRC_Init(void)
53{
54
55 /* USER CODE BEGIN CRC_Init 0 */
56
57 /* USER CODE END CRC_Init 0 */
58
59 /* USER CODE BEGIN CRC_Init 1 */
60
61 /* USER CODE END CRC_Init 1 */
62 hcrc.Instance = CRC;
63 if (HAL_CRC_Init(&hcrc) != HAL_OK)
64 {
65 Error_Handler();
66 }
67 /* USER CODE BEGIN CRC_Init 2 */
68
69 /* USER CODE END CRC_Init 2 */
70
71}
72
73/**
74 * @brief DMA2D Initialization Function
75 * @param None
76 * @retval None
77 */
78static void MX_DMA2D_Init(void)
79{
80
81 /* USER CODE BEGIN DMA2D_Init 0 */
82
83 /* USER CODE END DMA2D_Init 0 */
84
85 /* USER CODE BEGIN DMA2D_Init 1 */
86
87 /* USER CODE END DMA2D_Init 1 */
88 hdma2d.Instance = DMA2D;
89 hdma2d.Init.Mode = DMA2D_M2M;
90 hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
91 hdma2d.Init.OutputOffset = 0;
92 hdma2d.LayerCfg[1].InputOffset = 0;
93 hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
94 hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
95 hdma2d.LayerCfg[1].InputAlpha = 0;
96 if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
97 {
98 Error_Handler();
99 }
100 if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
101 {
102 Error_Handler();
103 }
104 /* USER CODE BEGIN DMA2D_Init 2 */
105
106 /* USER CODE END DMA2D_Init 2 */
107
108}
109
110/**
111 * @brief LTDC Initialization Function
112 * @param None
113 * @retval None
114 */
115static void MX_LTDC_Init(void)
116{
117
118 /* USER CODE BEGIN LTDC_Init 0 */
119
120 /* USER CODE END LTDC_Init 0 */
121
122 LTDC_LayerCfgTypeDef pLayerCfg = {0};
123
124 /* USER CODE BEGIN LTDC_Init 1 */
125
126 /* USER CODE END LTDC_Init 1 */
127 hltdc.Instance = LTDC;
128 hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
129 hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
130 hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
131 hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
132 hltdc.Init.HorizontalSync = 0;
133 hltdc.Init.VerticalSync = 0;
134 hltdc.Init.AccumulatedHBP = 46;
135 hltdc.Init.AccumulatedVBP = 23;
136 hltdc.Init.AccumulatedActiveW = 846;
137 hltdc.Init.AccumulatedActiveH = 503;
138 hltdc.Init.TotalWidth = 866;
139 hltdc.Init.TotalHeigh = 525;
140 hltdc.Init.Backcolor.Blue = 0;
141 hltdc.Init.Backcolor.Green = 0;
142 hltdc.Init.Backcolor.Red = 0;
143 if (HAL_LTDC_Init(&hltdc) != HAL_OK)
144 {
145 Error_Handler();
146 }
147 pLayerCfg.WindowX0 = 0;
148 pLayerCfg.WindowX1 = 800;
149 pLayerCfg.WindowY0 = 0;
150 pLayerCfg.WindowY1 = 480;
151 pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
152 pLayerCfg.Alpha = 255;
153 pLayerCfg.Alpha0 = 0;
154 pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA;
155 pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA;
156 pLayerCfg.FBStartAdress = 0xd0000000;
157 pLayerCfg.ImageWidth = 800;
158 pLayerCfg.ImageHeight = 480;
159 pLayerCfg.Backcolor.Blue = 255;
160 pLayerCfg.Backcolor.Green = 255;
161 pLayerCfg.Backcolor.Red = 255;
162 if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
163 {
164 Error_Handler();
165 }
166 /* USER CODE BEGIN LTDC_Init 2 */
167 rt_pin_mode(DISP_Pin, PIN_MODE_OUTPUT);
168 rt_pin_mode(CTDL_BL_Pin, PIN_MODE_OUTPUT);
169 rt_pin_mode(WIFI_Pin, PIN_MODE_OUTPUT);
170 rt_pin_write(DISP_Pin, 1);
171 rt_pin_write(CTDL_BL_Pin, 1);
172 rt_pin_write(WIFI_Pin, 0);
173 /* USER CODE END LTDC_Init 2 */
174
175}
176void touchgfx_thread_entry(void *parameter)
177{
178 MX_CRC_Init();
179 MX_DMA2D_Init();
180 MX_LTDC_Init();
181 MX_TouchGFX_Init();
182 MX_TouchGFX_Process();
183 for(;;)
184 {
185 rt_thread_mdelay(100);
186 }
187}
188int TouchGFXTask(void)
189{
190 rt_thread_t tid = NULL;
191 tid = rt_thread_create("TouchGFX",
192 touchgfx_thread_entry, RT_NULL,
193 4096, 15, 20);
194
195 if (tid != RT_NULL)
196 rt_thread_startup(tid);
197 else
198 return -1;
199
200 return RT_EOK;
201}
202INIT_APP_EXPORT(TouchGFXTask);
1import os
2import rtconfig
3from building import *
4
5cwd = GetCurrentDir()
6
7# add general drivers
8src = Split('''
9Src/sample_touchgfx.c
10Src/OSWrappers_RTT.cpp
11Src/STM32DMA.cpp
12Src/STM32TouchController.cpp
13Src/TouchGFXGPIO.cpp
14Src/TouchGFXConfiguration.cpp
15Src/TouchGFXGeneratedHAL.cpp
16Src/TouchGFXHAL.cpp
17Src/app_touchgfx.c
18''')
19
20path = [cwd + '/Src']
21path += [cwd + '/Middlewares/ST/touchgfx/framework/include']
22
23
24if rtconfig.CROSS_TOOL == 'gcc':
25 src += [cwd + '/Middlewares/ST/touchgfx/lib/core/cortex_m4f/gcc/libtouchgfx.a']
26elif rtconfig.CROSS_TOOL == 'keil':
27 src += [cwd + '/Middlewares/ST/touchgfx/lib/core/cortex_m4f/Keil/touchgfx_core.lib']
28elif rtconfig.CROSS_TOOL == 'iar':
29 src += [cwd + '/Middlewares/ST/touchgfx/lib/core/cortex_m4f/IAR8.x/touchgfx_core.a']
30
31group = DefineGroup('TouchGFX_app', src, depend = [''], CPPPATH = path)
32
33# add TouchGFX generated
34genSrc = Glob('./Src/generated/fonts/src/*.cpp')
35genSrc += Glob('./Src/generated/gui_generated/src/*/*.cpp')
36genSrc += Glob('./Src/generated/images/src/*.cpp')
37genSrc += Glob('./Src/generated/texts/src/*.cpp')
38
39genPath = [cwd + '/Src/generated/fonts/include']
40genPath += [cwd + '/Src/generated/gui_generated/include']
41genPath += [cwd + '/Src/generated/images/include']
42genPath += [cwd + '/Src/generated/texts/include']
43
44group = group + DefineGroup('TouchGFX_generated', genSrc, depend = [''], CPPPATH = genPath)
45
46# add TouchGFX resource
47resSrc = Glob('./Src/generated/images/src/*/*.cpp')
48
49group = group + DefineGroup('TouchGFX_resource', resSrc, depend = [''])
50
51# add TouchGFX gui
52guiSrc = Glob('./Src/gui/src/*/*.cpp')
53guiPath = [cwd + '/Src/gui/include']
54
55group = group + DefineGroup('TouchGFX_gui', guiSrc, depend = [''], CPPPATH = guiPath)
56
57Return('group')
添加如下代码:
1if GetDepend(['BSP_USING_TouchGFX']):
2 src += ['STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_ltdc.c']
3 src += ['STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_ltdc_ex.c']
4 src += ['STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma2d.c']
5 src += ['STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_dma2d.c']
6 src += ['STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dsi.c']
使用scons --target=mdk5 命令生成 MDK工程。此时还不能编译下载,因为图片资源太大,会超过内部flash的存储空间,还需要把图片下载到外部flash,上电初始化通过spi把图片资源加载到SDRAM。
配置fal_cfg.h,
tgfx分区用于touchgfx的资源存储,其他分区用于OTA、文件系统和系统参数配置。
1/*
2 * Copyright (c) 2006-2018, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2018-05-17 armink the first version
9 */
10
11#ifndef _FAL_CFG_H_
12#define _FAL_CFG_H_
13
14#include
15#include
16
17#define FLASH_SIZE_GRANULARITY_16K (4 * 16 * 1024)
18#define FLASH_SIZE_GRANULARITY_64K (64 * 1024)
19#define FLASH_SIZE_GRANULARITY_128K (7 * 128 * 1024)
20
21#define STM32_FLASH_START_ADRESS_16K STM32_FLASH_START_ADRESS
22#define STM32_FLASH_START_ADRESS_64K (STM32_FLASH_START_ADRESS_16K + FLASH_SIZE_GRANULARITY_16K)
23#define STM32_FLASH_START_ADRESS_128K (STM32_FLASH_START_ADRESS_64K + FLASH_SIZE_GRANULARITY_64K)
24
25
26
27/* ===================== Flash device Configuration ========================= */
28extern const struct fal_flash_dev stm32_onchip_flash_16k;
29extern const struct fal_flash_dev stm32_onchip_flash_64k;
30extern const struct fal_flash_dev stm32_onchip_flash_128k;
31extern struct fal_flash_dev nor_flash0;
32
33/* flash device table */
34#define FAL_FLASH_DEV_TABLE \
35{ \
36 &stm32_onchip_flash_16k, \
37 &stm32_onchip_flash_64k, \
38 &stm32_onchip_flash_128k, \
39 &nor_flash0, \
40}
41/* ====================== Partition Configuration ========================== */
42#ifdef FAL_PART_HAS_TABLE_CFG
43/* partition table */
44#define FAL_PART_TABLE \
45{ \
46 {FAL_PART_MAGIC_WROD, "bootloader", "onchip_flash_16k", 0 , FLASH_SIZE_GRANULARITY_16K , 0}, \
47 {FAL_PART_MAGIC_WROD, "ef", "onchip_flash_64k", 0 , FLASH_SIZE_GRANULARITY_64K , 0}, \
48 {FAL_PART_MAGIC_WROD, "app", "onchip_flash_128k", 0 , FLASH_SIZE_GRANULARITY_128K, 0}, \
49 {FAL_PART_MAGIC_WROD, "tgfx", "W25Q128", 0 , 4 * 1024 * 1024, 0}, \
50 {FAL_PART_MAGIC_WROD, "download", "W25Q128", 4 * 1024 * 1024 , 1024 * 1024, 0}, \
51 {FAL_PART_MAGIC_WROD, "factory", "W25Q128", (4 * 1024 + 1024) * 1024 , 1024 * 1024, 0}, \
52 {FAL_PART_MAGIC_WROD, "filesystem", "W25Q128", (4 * 1024 + 1024 + 1024) * 1024 , 2 * 1024 * 1024, 0}, \
53}
54#endif /* FAL_PART_HAS_TABLE_CFG */
55
56#endif /* _FAL_CFG_H_ */
初始化fal
1int fs_init(void)
2{
3 /* partition initialized */
4 fal_init();
5 return 0;
6}
7INIT_COMPONENT_EXPORT(fs_init);
制作STM32F429的SPI FLASH下载算法(看附文)
修改工程模版template.uvprojx
编辑链接文件
将位图数据从外部flash复制到缓存
此时重新生成 MDK工程,便可以下载到板子上运行。
参考资料:https://support.touchgfx.com/docs/development/ui-development/scenarios/using-non-memory-mapped-flash
配置模拟I2C
在applications文件夹下新建gtxx_ccollect.c文件,添加一下内容
1/*
2 * Copyright (c) 2006-2018, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2019-06-01 tyustli the first version
9 */
10
11#include
12#include "gt9147.h"
13#define DBG_TAG "gt9147"
14#define DBG_LVL DBG_LOG
15#include
16#define THREAD_PRIORITY 5
17#define THREAD_STACK_SIZE 1024
18#define THREAD_TIMESLICE 5
19
20#define GT9147_RST_PIN 59
21#define GT9147_IRQ_PIN 61
22
23static rt_thread_t gt9147_thread = RT_NULL;
24static rt_sem_t gt9147_sem = RT_NULL;
25static rt_device_t dev = RT_NULL;
26static struct rt_touch_data *read_data;
27static struct rt_touch_info info;
28
29struct rt_touch_data *read_coordinate(void)
30{
31 return &read_data[0];
32}
33static void gt9147_entry(void *parameter)
34{
35 rt_device_control(dev, RT_TOUCH_CTRL_GET_INFO, &info);
36
37 read_data = (struct rt_touch_data *)rt_malloc(sizeof(struct rt_touch_data) * info.point_num);
38
39 while (1)
40 {
41 rt_sem_take(gt9147_sem, RT_WAITING_FOREVER);
42
43 if (rt_device_read(dev, 0, read_data, info.point_num) == info.point_num)
44 {
45 for (rt_uint8_t i = 0; i < info.point_num; i++)
46 {
47 if (read_data[i].event == RT_TOUCH_EVENT_DOWN || read_data[i].event == RT_TOUCH_EVENT_MOVE)
48 {
49 LOG_D("%d %d %d %d %d\n", read_data[i].track_id,
50 read_data[i].x_coordinate,
51 read_data[i].y_coordinate,
52 read_data[i].timestamp,
53 read_data[i].width);
54 }
55
56 }
57 }
58 rt_device_control(dev, RT_TOUCH_CTRL_ENABLE_INT, RT_NULL);
59 }
60}
61
62static rt_err_t rx_callback(rt_device_t dev, rt_size_t size)
63{
64 rt_sem_release(gt9147_sem);
65 rt_device_control(dev, RT_TOUCH_CTRL_DISABLE_INT, RT_NULL);
66 return 0;
67}
68
69static int rt_hw_gt9147_port(void)
70{
71 struct rt_touch_config config;
72 rt_uint8_t rst;
73 rst = GT9147_RST_PIN;
74 config.dev_name = "i2c1";
75 config.irq_pin.pin = GT9147_IRQ_PIN;
76 config.irq_pin.mode = PIN_MODE_INPUT_PULLDOWN;
77 config.user_data = &rst;
78 rt_hw_gt9147_init("gt", &config);
79 return 0;
80}
81/* Test function */
82int gt9147_init(void)
83{
84 void *id;
85 rt_hw_gt9147_port();
86 dev = rt_device_find("gt");
87 if (dev == RT_NULL)
88 {
89 rt_kprintf("can't find device gt\n");
90 return -1;
91 }
92
93 if (rt_device_open(dev, RT_DEVICE_FLAG_INT_RX) != RT_EOK)
94 {
95 rt_kprintf("open device failed!");
96 return -1;
97 }
98
99 id = rt_malloc(sizeof(rt_uint8_t) * 8);
100 rt_device_control(dev, RT_TOUCH_CTRL_GET_ID, id);
101 rt_uint8_t * read_id = (rt_uint8_t *)id;
102 rt_kprintf("id = %c %c %c %c \n", read_id[0], read_id[1], read_id[2], read_id[3]);
103
104 rt_device_control(dev, RT_TOUCH_CTRL_GET_INFO, id);
105 rt_kprintf("range_x = %d \n", (*(struct rt_touch_info*)id).range_x);
106 rt_kprintf("range_y = %d \n", (*(struct rt_touch_info*)id).range_y);
107 rt_kprintf("point_num = %d \n", (*(struct rt_touch_info*)id).point_num);
108 rt_free(id);
109 rt_device_set_rx_indicate(dev, rx_callback);
110 gt9147_sem = rt_sem_create("dsem", 0, RT_IPC_FLAG_FIFO);
111
112 if (gt9147_sem == RT_NULL)
113 {
114 rt_kprintf("create dynamic semaphore failed.\n");
115 return -1;
116 }
117
118 gt9147_thread = rt_thread_create("gt9147",
119 gt9147_entry,
120 RT_NULL,
121 THREAD_STACK_SIZE,
122 THREAD_PRIORITY,
123 THREAD_TIMESLICE);
124
125 if (gt9147_thread != RT_NULL)
126 rt_thread_startup(gt9147_thread);
127
128 return 0;
129}
130INIT_APP_EXPORT(gt9147_init);
修改STM32TouchController.cpp
1/**
2 ******************************************************************************
3 * File Name : STM32TouchController.cpp
4 ******************************************************************************
5 * @attention
6 *
7 * © Copyright (c) 2020 STMicroelectronics.
8 * All rights reserved.
9 *
10 * This software component is licensed by ST under Ultimate Liberty license
11 * SLA0044, the "License"; You may not use this file except in compliance with
12 * the License. You may obtain a copy of the License at:
13 * www.st.com/SLA0044
14 *
15 ******************************************************************************
16 */
17
18/* USER CODE BEGIN STM32TouchController */
19
20#include
21#include "gt9147.h"
22extern "C"
23{
24 struct rt_touch_data *read_coordinate(void);
25}
26void STM32TouchController::init()
27{
28 /**
29 * Initialize touch controller and driver
30 *
31 */
32}
33
34bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y)
35{
36 /**
37 * By default sampleTouch returns false,
38 * return true if a touch has been detected, otherwise false.
39 *
40 * Coordinates are passed to the caller by reference by x and y.
41 *
42 * This function is called by the TouchGFX framework.
43 * By default sampleTouch is called every tick, this can be adjusted by HAL::setTouchSampleRate(int8_t);
44 *
45 */
46 struct rt_touch_data *read_data;
47 read_data = read_coordinate();
48
49 if (read_data->event == RT_TOUCH_EVENT_DOWN || read_data->event == RT_TOUCH_EVENT_MOVE)
50 {
51 x = read_data->x_coordinate;
52 y = read_data->y_coordinate;
53 return true;
54 }
55 else
56 {
57 return false;
58 }
59
60}
61
62/* USER CODE END STM32TouchController */
63
64/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
打开rtc实时时钟
添加以下代码
配置此缓存可以让screen切换具有滑动效果
你可以添加微信17775982065为好友,注明:公司+姓名,拉进 RT-Thread 官方微信交流群!
RT-Thread
让物联网终端的开发变得简单、快速,芯片的价值得到最大化发挥。Apache2.0协议,可免费在商业产品中使用,不需要公布源码,无潜在商业风险。
长按二维码,关注我们
转一转
赞一赞
看一看
???? 点击阅读原文进入RT-Thread新版社区
“在看”的小可爱永远十八岁!