Transplante TouchGFX en ART-Pi H750 (3) —— Transplante TouchGFX al sistema RT-Thread

Tabla de contenido

Transplante TouchGFX en ART-Pi H750 (1) -Utilice STM32CUBMX para generar un proyecto TouchGFX
Transplante TouchGFX en ART-Pi H750 (2) -Realice el algoritmo de programación QSPI-FLASH externo de MDK
Transplante TouchGFX en ART-Pi H750 ( Tres) -Transplante TouchGFX al sistema RT-Thread Transplante TouchGFX
en ART-Pi H750 (cuatro) -Utilice RT-Thread Studio para trasplantar TouchGFX y trasplante TouchGFX
en ART-Pi H750 (5) -Hacer ST-LINK externo Algoritmo de programación QSPI-FLASH

plataforma de experimentos:

Hardware: RT-Thread versión de desarrollo oficial ART-PI H750, pantalla Punctual Atom de 4.3 pulgadas RGBLCD (800 * 480)
Software: la última versión de la biblioteca de firmware STM32CubeH7, TouchGFXDesigner v4.14 y STM32CubeMX V6.0.1, entorno de desarrollo MDK v5.29
Inserte la descripción de la imagen aquí

Descarga de código:

Que se anunciará

Póngase en contacto con el autor:

Siga la cuenta oficial, véala gratis, responda a "agregar grupo", únase al grupo de intercambio técnico
Inserte la descripción de la imagen aquí

Conociendo RT-Thread

RT-Thread es una plataforma tecnológica que integra el kernel del sistema operativo en tiempo real (RTOS), los componentes de middleware y la comunidad de desarrolladores. Fue desarrollada por el Sr. Xiong Puxiang e integrada con las fuerzas de la comunidad de código abierto. RT-Thread también es un componente completo y rico , Sistema operativo IoT altamente escalable, fácil de desarrollar, ultrabajo consumo de energía y alta seguridad. RT-Thread tiene todos los componentes clave necesarios para una plataforma IoT OS, como GUI, pila de protocolos de red, transmisión segura, componentes de bajo consumo de energía, etc. Después de 11 años de desarrollo acumulativo, RT-Thread ya tiene la comunidad de código abierto integrado más grande de China, y también se usa ampliamente en las industrias de energía, automotriz, médica, electrónica de consumo y otras. La capacidad instalada acumulada supera los 600 millones de unidades, lo que la hace independiente Desarrollado, el RTOS de código abierto más maduro y estable con la mayor capacidad instalada en China.

Desde el lanzamiento del código fuente y el código abierto en 2006, RT-Thread se adhiere al concepto de "código abierto y abierto", cerca de los desarrolladores para satisfacer las necesidades del mercado, e insiste en crear sistemas operativos de IoT pequeños y hermosos, que ahora pueden cubrir perfectamente diferentes escenarios de aplicaciones para IoT integrado y :

  • La MCU en el escenario de recursos pequeños se usa para un control simple de la versión RT-Thread Nano (lanzada en 2006, para Cortex-M, RISC-V, etc.);
  • Los nodos de IoT de mediana escala utilizan la versión RT-Thread IoT OS (lanzada en 2017, para Cortex-M, Loongson, RISC-V, etc.);
  • Los dispositivos inteligentes ricos en funciones utilizan la versión de microkernel inteligente RT-Thread (lanzada en 2020, para procesadores con MMU como Cortex-A, Loongson, RISC-V, etc.).

Cómo obtener el código fuente de RT-Thread

Dirección de github: https://github.com/RT-Thread/rt-thread
Dirección de gitee: https://gitee.com/rtthread/rt-thread

Cómo aprender RT-Thread

  • Documento de aprendizaje oficial del sistema RT-Thread, https://www.rt-thread.org/document/site/
  • Comprenda el núcleo del sistema RT-Thread , descargue e instale la herramienta Env y la herramienta de desarrollo RT-Thread Studio.
  • Aprenda a utilizar los controladores de dispositivo, los componentes y los paquetes de software de RT-Thread.

Cambiar el sistema operativo de TouchGFX

El sistema operativo soportado por STM32CubeMX por defecto es FreeRTOS. TouchGFX puede ejecutarse en aplicaciones con y sin sistemas operativos. Si los usuarios quieren cambiar el sistema operativo, solo necesitan reimplementar la clase OSWrappers para cambiar entre diferentes RTOS.
Inserte la descripción de la imagen aquí

Migrar TouchGFX a RT-Thread

1. Vuelva a implementar la clase OSWrappers:

/**
  ******************************************************************************
  * File Name          : OSWrappers.cpp
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under Ultimate Liberty license
  * SLA0044, the "License"; You may not use this file except in compliance with
  * the License. You may obtain a copy of the License at:
  *                             www.st.com/SLA0044
  *
  ******************************************************************************
  */
#include <touchgfx/hal/OSWrappers.hpp>
#include <stm32h7xx_hal.h>
#include <touchgfx/hal/GPIO.hpp>
#include <touchgfx/hal/HAL.hpp>
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <rthw.h>
static rt_sem_t frame_buffer_sem;
static rt_mq_t vsync_q = 0;
using namespace touchgfx;

// Just a dummy value to insert in the VSYNC queue.
static uint8_t dummy = 0x5a;

/*
 * Initialize frame buffer semaphore and queue/mutex for VSYNC signal.
 */
void OSWrappers::initialize()
{
    
    

	frame_buffer_sem = rt_sem_create("gfx_sem", 1, RT_IPC_FLAG_PRIO);
    // Create a queue of length 1
    vsync_q = rt_mq_create("gfx_mq", 1, 1, RT_IPC_FLAG_PRIO);

}

/*
 * Take the frame buffer semaphore. Blocks until semaphore is available.
 */
void OSWrappers::takeFrameBufferSemaphore()
{
    
    
     rt_sem_take(frame_buffer_sem, RT_WAITING_FOREVER);
}

/*
 * Release the frame buffer semaphore.
 */
void OSWrappers::giveFrameBufferSemaphore()
{
    
    
    rt_sem_release(frame_buffer_sem);
}

/*
 * Attempt to obtain the frame buffer semaphore. If semaphore is not available, do
 * nothing.
 *
 * Note must return immediately! This function does not care who has the taken the semaphore,
 * it only serves to make sure that the semaphore is taken by someone.
 */
void OSWrappers::tryTakeFrameBufferSemaphore()
{
    
    
    rt_sem_trytake(frame_buffer_sem);
}

/*
 * Release the frame buffer semaphore in a way that is safe in interrupt context. Called
 * from ISR.
 *
 * Release the frame buffer semaphore in a way that is safe in interrupt context.
 * Called from ISR.
 */
void OSWrappers::giveFrameBufferSemaphoreFromISR()
{
    
    
    // Since this is called from an interrupt, FreeRTOS requires special handling to trigger a
    // re-scheduling. May be applicable for other OSes as well.
		rt_sem_release(frame_buffer_sem);
}

/*
 * Signal that a VSYNC has occurred. Should make the vsync queue/mutex available.
 *
 * Note This function is called from an ISR, and should (depending on OS) trigger a
 * scheduling.
 */
void OSWrappers::signalVSync()
{
    
    
    if (vsync_q)
    {
    
    
        rt_mq_send(vsync_q, &dummy, 1);
    }
}

/*
 * This function blocks until a VSYNC occurs.
 *
 * Note This function must first clear the mutex/queue and then wait for the next one to
 * occur.
 */
void OSWrappers::waitForVSync()
{
    
    
    // First make sure the queue is empty, by trying to remove an element with 0 timeout.
    rt_mq_recv(vsync_q, &dummy, 1, 0);

    // Then, wait for next VSYNC to occur.
    rt_mq_recv(vsync_q, &dummy, 1, RT_WAITING_FOREVER);
}

/*
 * A function that causes executing task to sleep for a number of milliseconds.
 *
 * A function that causes executing task to sleep for a number of milliseconds.
 * This function is OPTIONAL. It is only used by the TouchGFX in the case of
 * a specific frame refresh strategy (REFRESH_STRATEGY_OPTIM_SINGLE_BUFFER_TFT_CTRL).
 * Due to backwards compatibility, in order for this function to be useable by the HAL
 * the function must be explicitly registered:
 * hal.registerTaskDelayFunction(&OSWrappers::taskDelay)
 *
 * see HAL::setFrameRefreshStrategy(FrameRefreshStrategy s)
 * see HAL::registerTaskDelayFunction(void (*delayF)(uint16_t))
 */
void OSWrappers::taskDelay(uint16_t ms)
{
    
    
     rt_thread_mdelay(ms);
}

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

2. Agregue los periféricos que necesita touchgfx a rtthread.
Ideas de migración: revise los componentes requeridos por touchgfx, simplemente agréguelos según sea necesario en rtthread. Para conocer los pasos detallados, consulte este tutorial: Use RTThread y TouchGFX para implementar medidores digitales de bricolaje (dos ) -Porting TouchGFX al sistema RTThread
Inserte la descripción de la imagen aquí

Demostración de combate real de ART-PI

1. Abra el proyecto de la sección anterior e importe una rutina de juego.
Inserte la descripción de la imagen aquí
Debido a que este proyecto es relativamente grande, a excepción de imágenes y fuentes, la cantidad de código ha excedido los 128k, por lo que no puede descargar el código directamente como el proyecto anterior. En este caso, puede consultar la placa de desarrollo oficial de ST para poner todo el código en el espacio flash externo, y el espacio interno de 128k se usa para hacer el cargador de arranque. Después de que el cargador de arranque se enciende, asigna la dirección qspi y luego salta al flash qspi Ejecute el programa en la dirección.

2.Hacer cargador de arranque

#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <drv_common.h>
#include "w25qxx.h"

#define DBG_TAG "main"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>

/* defined the LED0 pin: PB1 */
#define LED0_PIN    GET_PIN(I, 8)

#define VECT_TAB_OFFSET      0x00000000UL
#define APPLICATION_ADDRESS  (uint32_t)0x90000000

typedef void (*pFunction)(void);
pFunction JumpToApplication;

int main(void)
{
    
    
    /* set LED0 pin mode to output */
    rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT);

    W25QXX_Init();

    W25Q_Memory_Mapped_Enable();//地址映射

    SCB_DisableICache();
    SCB_DisableDCache();

    SysTick->CTRL = 0;

    JumpToApplication = (pFunction)(*(__IO uint32_t *)(APPLICATION_ADDRESS + 4));
    __set_MSP(*(__IO uint32_t *)APPLICATION_ADDRESS);

    JumpToApplication();//跳转

    return RT_EOK;
}

3.Haga una aplicación para
modificar el archivo de carga dispersa, coloque todo el código en el flash externo,
Inserte la descripción de la imagen aquí
agregue la reasignación de interrupciones

static int vtor_config(void)
{
    
    
    /* Vector Table Relocation in Internal QSPI_FLASH */
    SCB->VTOR = QSPI_BASE;
    return 0;
}
INIT_BOARD_EXPORT(vtor_config);

4. Agregue el paquete de software touch gt9147
Inserte la descripción de la imagen aquí
y asigne coordenadas xy a touchgfx en STM32TouchController.cpp

bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y)
{
    
    
    /**
     * By default sampleTouch returns false,
     * return true if a touch has been detected, otherwise false.
     *
     * Coordinates are passed to the caller by reference by x and y.
     *
     * This function is called by the TouchGFX framework.
     * By default sampleTouch is called every tick, this can be adjusted by HAL::setTouchSampleRate(int8_t);
     *
     */
	struct  rt_touch_data *read_data;
	read_data = read_coordinate();

	if (read_data->event == RT_TOUCH_EVENT_DOWN || read_data->event == RT_TOUCH_EVENT_MOVE)
	{
    
    
		x = read_data->x_coordinate;
	    y = read_data->y_coordinate;
		return true;
	}
	else
	{
    
    
		return false;
	}
}

Demo de grabación

Inserte la descripción de la imagen aquí

Supongo que te gusta

Origin blog.csdn.net/sinat_31039061/article/details/108638097
Recomendado
Clasificación