Piu' sotto, al termine della lingua inglese trovi il testo in italiano. Below English text you'll find the Italian version
Now that you have created a new CubeIDE project as per these instructions:
Now that you have chosen the backlight handling mode and set it as per these instructions:
You are ready to go integrating TouchGFX!
Follow the below instructions if you like handling the display through this GUI systems using only buttons as input widgets, having a minor impact on the overall performances.
Otherwise:
- if you want to directly draw on the display through the library functions, do not proceed here and go to (Direct handling) "How to" add this library to the created project
- if you want/need to use all TouchGFX widgets (with the limitations imposed by these displays) go to (TouchGFX full mode) "How to" add this library to the created project
you must "tune" the software parameters in two files:
- z_displ_ILI9XXX.h
- z_touch_XPT2046.h
into "z_displ_ILI9XXX.h" file you have to setup this configuration:
- step 1 - TouchGFX parameter: ok, if you are here reading, it means you have to remove the comment sign to parameter in section 0, enabling TouchGFX handling
- step 2 - define the display you are using (ILI9346 or ILI9488 V1.0 or V2.0) uncommenting the related #define
- step 3 - Port Parameters: here you have to set two macro constant with the SPI port name connecting display (see below "z_touch_XPT2046.h" also)
- step 4 - Port Speed: here you must assign bitrate SPI prescaler when transferring data to display or to/from touch sensor. Consider that touch uses baudrates below 2MBps
- step 5 - SPI communication mode: uncomment the macro definition related to enabled communication mode (Polling mode, Interrupt mode or DMA mode). You must uncomment no less and no more than ONE definition here
- step 6 - Backlight Mode: see BACKLIGHT page
- step 7 - TouchGFX Time base timer: unused in "button mode", be sure that these parameters refer to an unused timer
- step 8 - Buffer size: Used converting from RGB565 to RGB666 with ILI9488 V1.0 displays. Follow instructions into .h file
into "z_touch_XPT2046.h" file you have to setup this configuration:
- step 1 - Port Parameters: here you have to set two macro constant with the SPI port name connecting touch sensor
- step 2 - Delay to Key Repeat: touching a TouchGFX button for a time longer then what indicated here (ms) a key repeat feature starts. Set this value to 0 disabling the feature. Do not set negative values: it will enable library handling TouchGFX in "full mode" (see related info page)
- enter in uC configuration (CubeMX) doubleclicking the ".ioc" file
- goto "Software Packs", then to "Select components" and install "TouchGFX" if not yet done in your CubeIDE
- after installation click on TouchGFX details and select it
- close the Software packs component selector
- goto Computing->CRC and activate it
- goto Software Packs->TouchGFX and activate it
now in TouchGFX generator, set these parameters:
Parameter | Value |
---|---|
Framebuffer PixelFormat | RGB565 (*) |
Width | |
Height | |
Framebuffer Strategy | Partial Buffer |
all other parameters as per default |
Save and generate (or update) software.
(*)
even if you are using a display needing RGB666 (e.g. ILI9488 board V1.0), set TouchGFX to RGB565.
TouchGFX doesn't work with RGB666 and will send frames in RGB565: library will make convertion from RBG565 to RGB666 needed by the display.
Open TouchGFX->target folder in your project.
Open STM32TouchController.cpp inside this folder.
add the include:
(STM32TouchController.cpp)
...
#include "main.h"
...
In the same file change sampleTouch() as shown here:
(STM32TouchController.cpp)
...
bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y)
{
return ((bool) Touch_TouchGFXSampleTouch(&x, &y));
}
...
<br
in main.c you now need to initialize display before entering in the main loop, this way:
(main.c)
...
/* USER CODE BEGIN 2 */ // "USER CODE BEGIN 2" is after all system initializations and before entering the main loop. Good place to initialize display
Displ_Init(Displ_Orientat_0); // initialize the display and set the initial display orientation (here is orientaton: 0°) - THIS FUNCTION MUST PRECEED ANY OTHER DISPLAY FUNCTION CALL.
touchgfxSignalVSync(); // asks TouchGFX to start initial display drawing
Displ_BackLight('I'); // initialize backlight and turn it on at init level
/* USER CODE END 2 */
...
PLEASE NOTE:
set parameter in Displ_Init() function as per orientation of your display graphics.
Then, in the main loop, add the cycling activation of TouchGFX.
You may ask a continuous TouchGFX refresh as here below:
...
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) // into the main loop you can add the test functions
{
touchgfxSignalVSync(); // asks TouchGFX to get events and redraw screen
/* USER CODE END WHILE */
MX_TouchGFX_Process();
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
...
but it is beter to submit TouchGFX activation only to the events requiring it, see below:
...
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) // into the main loop you can add the test functions
{
if ("event occourred needing a display update")
touchgfxSignalVSync(); // asks TouchGFX to get events and redraw screen
/* USER CODE END WHILE */
MX_TouchGFX_Process();
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
...
... and the typical case of an event requiring TouchGFX update is a touch on the display.
Library provides a function for fast display polling: Touch_GotATouch(param).
It returns the status of a flag set by interrupt activated by a display touch.
It accepts a parameter (see function code for details) that can be set to "2" specifically for the touchgfxSignalVSync() call.
So main loop can (should) be set this way:
...
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) // into the main loop you can add the test functions
{
...
if (Touch_GotATouch(2))
touchgfxSignalVSync(); // asks TouchGFX to handle touch and redraw screen
if ("other events needing a display update")
touchgfxSignalVSync(); // asks TouchGFX to get events and redraw screen
...
/* USER CODE END WHILE */
MX_TouchGFX_Process();
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
...
That's all, start using TouchGFX designer to setup your GUI!
When you first compile your project, it may stop on these two errors:
...
#error "A user must call touchgfx::startNewTransfer(); once touchgfxDisplayDriverTransmitBlock() has succesfully sent a block."
#error "A user must implement C-methods touchgfxDisplayDriverTransmitActive() and touchgfxDisplayDriverTransmitBlock() used by the Partial Framebuffer Strategy."
...
It is just a reminder for you to develop the interface routines to Touch GFX.
They are already available in the library.
So, just delete the two "#error" lines, the two warnings, and re-compile the project.
They will not appear anymore.
if you see that TouchGFX graphics works fine over the display but there is no reply touching sensor there could be a problem of calibration. Check that here: "How to" calibrate touch sensor
Ora che hai creato un nuovo progetto con CubeIDE project seguendo queste istruzioni:
Ora che hai scelto la gestione della retroilluminazione, seguendo queste istruzioni:
You are ready to go integrating TouchGFX!
Follow the below instructions if you like handling the display through this GUI systems using only buttons as input widgets, having a minor impact on the overall performances.
Otherwise:
- if you want to directly draw on the display through the library functions, do not proceed here and go to (Direct handling) "How to" add this library to the created project
- if you want/need to use all TouchGFX widgets (with the limitations imposed by these displays) go to (TouchGFX full mode) "How to" add this library to the created project
Sei pronto a configurare gli ultimi parametri ed eseguire il programma!
Segui le istruzioni sotto se vuoi gestire il display attraverso TouchGFX utilizzando solo bottoni come widget di ingresso, con un impatto ridotto sulle prestazioni complessive.
Altrimenti:
- se vuoi gestire il display direttamente attraverso le funzioni grafiche della libreria, non proseguire e passa a: (Direct handling) "How to" add this library to the created project
- se invece vuoi/devi utilizzare tutti i widget di input TouchGFX (con le limitazioni introdotte da questi display) passa a (TouchGFX full mode) "How to" add this library to the created project
Il progetto è quasi pronto. Devi mettere a punti i parametri nel file "z_displ_ST7735.h":
- step 1 - TouchGFX: se stai leggendo qui devi togliere il commento alla la macro nella sezione 0, abilitando la gestione TouchGFX
- step 2 - Definisci il display che stai usando (ILI9346 or ILI9488 V1.0 or V2.0) togliendo ail commento al #define relativo
- step 3 - Port Parameters: qui devi impostare due costanti macro con il nome della porta SPI a cui è connesso il display (vedi anche "z_touch_XPT2046.h", sotto)
- step 4 - Port Speed: qui devi assegnare il valore al bitrate SPI prescaler quando trasferisce dati al display o al/dal sensore touch. Considera che il sensore touch comunica sotto i 2MBps
- step 5 - SPI communication mode: togli il commento alla definizione definition relativa al tipo di comunicazione attivato (Polling mode, Interrupt mode o DMA mode). Devi togliere il commento ad una riga (NON di più e NON di meno)
- step 6 - Backlight Mode: vedi la pagina BACKLIGHT
- step 7 - TouchGFX Time base timer: non usato in "button mode", assicurati che questi parametri facciano riferimento ad un timer non utilizzato
- step 8 - Dimensione Buffer: Usati per convertire dal protocollo RGB565 ad RGB666 con ILI9488 V1.0: segui istruzioni nel file .ho
in "z_touch_XPT2046.h" devi impostare i seguenti parametri:
- step 1 - Port Parameters: qui devi impostare due costanti macro con il nome della porta SPI a cui è connesso il sensore touch
- step 2 - Delay to Key Repeat: toccando un bottone per un tempo superiore a quanto indicato qui (ms) attiverai la ripetizione automatica del tasto dopo. Metti 0 per disabilitare la ripetizione del tasto. Non mettere valori degativi: mettendo un valore negativo attivi la gestione TouchGFX "full mode" (vedi pagina di configurazione relativa)
- entra nella configurazione del uC (CubeMX) con un doppio click sul file ".ioc"
- vai in "Software Packs", poi in "Select components" e installa "TouchGFX" se non lo hai ancora fatto sul tuo CubeIDE
- dopo l'installazione clicca sulla tendina TouchGFX e selezionalo
- chiudi il Software packs component selector
- vai in Computing->CRC e attivalo
- vai in Software Packs->TouchGFX e attivalo
ora, in TouchGFX generator, imposta questi parametri:
Parametro | Valore |
---|---|
Framebuffer PixelFormat | RGB565 (*) |
Width | |
Height | |
Framebuffer Strategy | Partial Buffer |
tutti gli altri parametri come default |
Salva e genera (o aggiorna) il software.
(*)
anche se stai usando un display che richiede RGB666 (e.g. ILI9488 board V1.0), imposta TouchGFX per RGB565.
TouchGFX non lavora in RGB666 e manderà i frame in RGB565: la libreria convertirà da RBG565 al formato RGB666 richiesto dal display.
Apri la cartella TouchGFX->target nel tuo progetto.
Apri STM32TouchController.cpp all'interno di questa cartella.
aggiungi l'include include:
(STM32TouchController.cpp)
...
#include "main.h"
...
Nello stesso file modifica sampleTouch() come sotto:
(STM32TouchController.cpp)
...
bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y)
{
return ((bool) Touch_TouchGFXSampleTouch(&x, &y));
}
...
<br
in main.c ora devi inizializzare il display prima di entrare nel main loop, in questo modo:
(main.c)
...
/* USER CODE BEGIN 2 */ // "USER CODE BEGIN 2" is after all system initializations and before entering the main loop. Good place to initialize display
Displ_Init(Displ_Orientat_0); // initialize the display and set the initial display orientation (here is orientaton: 0°) - THIS FUNCTION MUST PRECEED ANY OTHER DISPLAY FUNCTION CALL.
touchgfxSignalVSync(); // asks TouchGFX to start initial display drawing
Displ_BackLight('I'); // initialize backlight and turn it on at init level
/* USER CODE END 2 */
...
NOTA BENE: il parametro della funzione Displ_Init() deve corrispondere all'orientamento assegnato della grafica del display.
Poi, nel loop principale, aggiungi l'attivazione ciclica di TouchGFX.
Puoi chiedere un aggiornamento continuo di TouchGFX come qui sotto:
...
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) // into the main loop you can add the test functions
{
touchgfxSignalVSync(); // asks TouchGFX to get events and redraw screen
/* USER CODE END WHILE */
MX_TouchGFX_Process();
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
...
è però meglio attivare TouchGFX solo a fronte di eventi che ne richiedano l'intervento, vedi qui:
...
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) // into the main loop you can add the test functions
{
if ("e' accaduto un evento che richiede l'aggiornamento del display")
touchgfxSignalVSync(); // asks TouchGFX to get events and redraw screen
/* USER CODE END WHILE */
MX_TouchGFX_Process();
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
...
... e il tipico caso di un evento che richiede l'aggiornamento di TouchGFX è il tocco del display.
La libreria fornisce una funzione per una veloce interrogazione del display: Touch_GotATouch(param).
La funzione restituisce lo stato di un flag settato dall'interrupt attivato dal sensore touch.
La funzione accetta un parametro (vedi il codice per i dettagli) che puo' essere definito a "2" specificatamente per la chimata a touchgfxSignalVSync().
Quindi il main loop potrebbe (dovrebbe) essere scritto così:
...
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) // into the main loop you can add the test functions
{
...
if (Touch_GotATouch(2))
touchgfxSignalVSync(); // asks TouchGFX to handle touch and redraw screen
if ("other events needing a display update")
touchgfxSignalVSync(); // asks TouchGFX to get events and redraw screen
...
/* USER CODE END WHILE */
MX_TouchGFX_Process();
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
...
E' tutto. Inizia ad usare TouchGFX designer per impostare la tua GUI!
Quando compili il progetto per la prima volta, potrebbe fermarsi su questi due errori:
...
#error "A user must call touchgfx::startNewTransfer(); once touchgfxDisplayDriverTransmitBlock() has succesfully sent a block."
#error "A user must implement C-methods touchgfxDisplayDriverTransmitActive() and touchgfxDisplayDriverTransmitBlock() used by the Partial Framebuffer Strategy."
...
Si tratta semplicemente di un avviso per ricordarti di sviluppare le routine di interfaccia a TouchGFX.
Queste sono già disponibili nella libreria.
Quindi, semplicemente cancella le due righe "#error", i due avvisi, e ricompila il progetto.
Non appariranno più.
Se verifichi the la parte grafica del progetto funziona correttamente ma non ottieni risposta dal sensore touchm ci potrebbe essere la necessità di calibrarlo. Puoi seguire queste indicazioni: Guida per la calibrazione del sensore touch