2024-01-13 04:21 AM - edited 2024-01-13 04:55 AM
Hello
I'm trying to implement simple drawing app with TouchGFX (v. 4.23), 24bpp LTDC display
My screen should have pointer (just small square for set location) moved by 4 screen buttons to different directions. Another button will set mode - move pointer or draw. After user set start location, he could draw just single point or line, rectangle, circle, etc, of course set for these end location, radius, depends of figure.
Now I'm try to realise best solution to achive such requirements and have some questions
1. implementing drawing pane (area) - could it be Drawable class ? it is better to draw each figure by pixel or use standard Touchgfx shape widgets and then somehow save it to bitmap or framebuffer
2. implementing cursor - I think use Box with border widget, but unfortunately there no transparency for internal area.
I have tried to implement framebuffer like here, but seems it not working for me, may be because TouchGFX (RTOS mode) overlap my changes.
My code for direct access to framebuffer is following
main.c
/* USER CODE BEGIN PV */
uint16_t framebuffer[200*120*3];
...
/* USER CODE BEGIN 2 */
HAL_LTDC_SetAddress(&hltdc, (uint32_t)framebuffer, LTDC_LAYER_1);
...
/* USER CODE BEGIN WHILE */
uint8_t *fb = framebuffer;
while(fb < (uint8_t*)(framebuffer + (200*120*3)))
{
*fb++ = 0x00; // Write blue color and increment pointer by one byte
*fb++ = 0x00; // Write green color
*fb++ = 0xFF; // Write red color
}
...
Also when I try to implement LTDC IRQ in `mainc.c` (in `/* USER CODE BEGIN 4 */`) using
`void HAL_LTDC_LineEventCallback(LTDC_HandleTypeDef* hltdc)`
I got following error:
multiple definition of `HAL_LTDC_LineEventCallback'; ./Core/Src/main.o:C:/mcu/MYPRJ/Debug/../Core/Src/main.c:843: first defined here
because `HAL_LTDC_LineEventCallback` already defined in `TouchGFXGeneratedHAL.cpp`
So next question is how properly work with framebuffer in TouchGFX (RTOS mode).
Also I have looked at this post and provided example (`STM32H7B3dk_drawing_curves.7z`) and found drawing shapes (line) implementation with Snapshot widget. May be using Drawable class will be better and more flexible than Snapshot ?
Will be appreciate to any suggestions and examples for my project, thank you !
2024-01-25 07:50 AM
Hello @rBlr ,
I will answer your questions in the order you've asked:
1) Drawable is an abstract class used to define objects that can be drawn on the display in TouchGFX, so if your goal is to only draw elements on the board, I suggest using the available widgets instead of defining a class inheriting from Drawable.
2) For creating a cursor, you can either use an image, or create a custom container which you have 4 boxes shaped like a rectangle with empty body:Cursor made out of 4 boxes
3) The article that you pointed out is meant for checking the functionality of your MCU's internal memory. If you already have setup TouchGFX, then you don't need to worry about handling the framebuffer because it is handled by TouchGFX and LTDC. That's why you cannot redefine HAL_LTDC_LineEventCallback
4) The demo you are referring to is for showing how you can have a drawing board and uses Snapshot to react quickly to the drawing of the next line. So, there is no need to use the Drawable class in this case.
I hope this helps you