Transplante TouchGFX em ART-Pi H750 (3) -Transplante TouchGFX para sistema RT-Thread

índice

Transplant TouchGFX em ART-Pi H750 (1) -Use STM32CUBMX para gerar projeto TouchGFX
Transplant TouchGFX em ART-Pi H750 (2) -Faça o algoritmo de programação QSPI-FLASH externo de MDK
Transplant TouchGFX em ART-Pi H750 ( Três) - Transplante TouchGFX para sistema RT-Thread Transplante TouchGFX
em ART-Pi H750 (quatro) - Use RT-Thread Studio para transplantar TouchGFX e transplante TouchGFX
em ART-Pi H750 (5) - Faça ST-LINK externo Algoritmo de programação QSPI-FLASH

plataforma de experimento:

Hardware: versão de desenvolvimento oficial RT-Thread ART-PI H750, tela Punctual Atom 4.3 polegadas RGBLCD (800 * 480)
Software: a versão mais recente da biblioteca de firmware STM32CubeH7, TouchGFXDesigner v4.14 e STM32CubeMX V6.0.1, ambiente de desenvolvimento MDK v5.29
Insira a descrição da imagem aqui

Download do código:

A ser anunciado

Contate o autor:

Siga a conta oficial, veja-a gratuitamente, responda a "adicionar grupo", junte-se ao grupo de intercâmbio técnico
Insira a descrição da imagem aqui

Conhecendo o RT-Thread

RT-Thread é uma plataforma de tecnologia que integra kernel do sistema operacional em tempo real (RTOS), componentes de middleware e comunidade de desenvolvedores. Foi desenvolvida pelo Sr. Xiong Puxiang e integrada com as forças da comunidade de código aberto. RT-Thread também é um componente completo e rico , Sistema operacional IoT altamente escalável, fácil de desenvolver, consumo de energia ultrabaixo e alta segurança. RT-Thread tem todos os principais componentes necessários para uma plataforma IoT OS, como GUI, pilha de protocolo de rede, transmissão segura, componentes de baixo consumo de energia, etc. Após 11 anos de desenvolvimento cumulativo, a RT-Thread já possui a maior comunidade de código aberto incorporada na China e também é amplamente utilizada nas indústrias de energia, automotiva, médica, eletrônica de consumo e outras. A capacidade instalada cumulativa ultrapassa 600 milhões de unidades, tornando-a independente Desenvolvido, o RTOS open source mais maduro e estável com a maior capacidade instalada na China.

Desde o lançamento do código-fonte e do código-fonte aberto em 2006, RT-Thread adere ao conceito de "código-fonte aberto e aberto", próximo aos desenvolvedores para atender às necessidades do mercado, e insiste em fazer sistemas operacionais de IoT pequenos e bonitos, que agora podem cobrir perfeitamente diferentes cenários de aplicativos para IoT incorporados e :

  • O MCU na cena de pequenos recursos é usado para controle simples da versão RT-Thread Nano (lançado em 2006, para Cortex-M, RISC-V, etc.);
  • Os nós de IoT de média escala usam a versão do sistema operacional RT-Thread IoT (lançado em 2017, para Cortex-M, Loongson, RISC-V, etc.);
  • Dispositivos inteligentes ricos em recursos usam a versão RT-Thread Smart microkernel (lançada em 2020, para processadores com MMU, como Cortex-A, Loongson, RISC-V, etc.).

Como obter o código-fonte RT-Thread

endereço do github: https://github.com/RT-Thread/rt-thread
endereço do gitee: https://gitee.com/rtthread/rt-thread

Como aprender RT-Thread

Alterar o sistema operacional do TouchGFX

O sistema operacional compatível com STM32CubeMX por padrão é FreeRTOS. TouchGFX pode ser executado em aplicativos com e sem sistemas operacionais. Se os usuários quiserem alterar o sistema operacional, eles só precisam reimplementar a classe OSWrappers para alternar entre diferentes RTOSs.
Insira a descrição da imagem aqui

Migrar TouchGFX para RT-Thread

1. Reimplemente a classe 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. Adicione periféricos necessários ao touchgfx ao rtthread.
Ideias de migração: analise os componentes exigidos pelo touchgfx, basta adicioná-los conforme necessário em rtthread. Para obter etapas detalhadas, consulte este tutorial: Use RTThread e TouchGFX para implementar medidores digitais DIY (dois ) -Portando TouchGFX para sistema RTThread
Insira a descrição da imagem aqui

Demonstração de combate real do ART-PI

1. Abra o projeto da seção anterior e importe uma rotina de
Insira a descrição da imagem aqui
jogo.Porque este projeto é relativamente grande, exceto para imagens e fontes, a quantidade de código ultrapassou 128k, então você não pode baixar o código diretamente como o projeto anterior. Nesse caso, você pode consultar a placa de desenvolvimento oficial do ST para colocar todo o código no espaço flash externo, e o espaço interno de 128k é usado para fazer o carregador de inicialização. Depois que o carregador de inicialização é ligado, ele mapeia o endereço qspi e então pula para o flash qspi Execute o programa no endereço.

2. Faça bootloader

#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. Faça o APP para
modificar o arquivo de carregamento disperso, coloque todo o código no flash externo,
Insira a descrição da imagem aqui
adicione remapeamento de interrupção

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

4. Adicione o pacote de software touch gt9147
Insira a descrição da imagem aqui
e atribua coordenadas xy para touchgfx em 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 gravação

Insira a descrição da imagem aqui

Acho que você gosta

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