RudolphRiedel / FT800-FT813

Multi-Platform C code Library for EVE graphics controllers from FTDI / Bridgetek (FT810, FT811, FT812, FT813, BT815, BT816, BT817, BT818)
MIT License
121 stars 56 forks source link

Unable to trigger buttons when I remove my finger from the screen : EVE2 - FT813 - STM32 - PlatformIO #58

Open lotfibk opened 1 year ago

lotfibk commented 1 year ago

Hello,

I am using a FT813 Development Module with 5.0 inch WVGA TFT LCD (800x480p Capacitive) and I am developing a GUI on that screen. The problem is that I am trying to trigger the buttons on the screen only when I remove my finger from the screen (on a rising edge). But, so far, I am not able to do so, as they only trigger when I press.

Although I spotted that in the "Calibration" demo, all 3 buttons that appear on the screen (one after the other) are only triggered once my finger has been removed from the screen. And even after having a look at the code that runs the Calibration demo, I can't figure out how to do so.

Thank you in advance.

Here is some of the code that I am using (in case it could help) : in void TFT_display(void):

    /* display "Home" button */
    EVE_cmd_dl_burst(DL_COLOR_RGB | BLACK);
    EVE_cmd_fgcolor_burst(0x00f7f7f7);         
    EVE_cmd_dl_burst(TAG(5));         //assign tag-value '5' to the button that follows
    EVE_cmd_button_burst(0,0, 224, 80, 29, toggle_home, "Main");
    EVE_cmd_dl_burst(TAG(0)); /* no touch * `

in void TFT_touch(void):

        case 5: /* use "Home" button to come back to the home menu

        message = "Home Menu";
        TFT_display_main();

        if (toggle_lock == 0)
        {

            toggle_lock = 42;
            if (toggle_home == EVE_OPT_FLAT)
            {
                //message = "Home Menu";
                //toggle_home = 0;

            }
            else
            {       
                //toggle_home = EVE_OPT_FLAT;

            }
        }

        break;
RudolphRiedel commented 1 year ago

How is this an issue? :-) Sure, this is worthy to be discussed and the place to discuss this would have been two over in "Discussions". :-)

Now doing stuff on release of buttons just requires to shuffle things around in the state machine. Like this for example:

void TFT_touch(void)
{
    uint8_t tag;
    static uint8_t toggle_lock = 0;
    static uint8_t tag_pressed_10 = 0;

    if(tft_active != 0)
    {
        if(EVE_IS_BUSY == EVE_busy()) /* is EVE still processing the last display list? */
        {
            return;
        }

        display_list_size = EVE_memRead16(REG_CMD_DL); /* debug-information, get the size of the last generated display-list */

        uint32_t touchtest = EVE_memRead32(REG_TOUCH_RAW_XY); /* to check if the display is touched at all */
        tag = EVE_memRead8(REG_TOUCH_TAG); /* read the value for the first touch point */

        switch(tag)
        {
            case 0:
                if(0xffffffff == touchtest) /* no touching registered */
                {
                    toggle_lock = 0;

                    if(tag_pressed_10) /* use button on top as on/off toggle-switch */
                    {
                        tag_pressed_10 = 0;
                        if(0 == toggle_state)
                        {
                            toggle_state = EVE_OPT_FLAT;
                        }
                        else
                        {
                            toggle_state = 0;
                        }
                    }
                }
                break;

            case 10:
                if(0 == toggle_lock) /* lock out other events */
                {
                    tag_pressed_10 = 42;
                }
                break;
        }
    }
}

As there are no extra events for "touch up" and the tag-value just falls back to zero, I added the extra variable to store events with tag 10: tag_pressed_10 What the toggle_lock is now supposed to do is to prevent additional events, from a second button for example.

When the tag-value returns to zero the toggle_lock is cleared and if the button had been touched before it is toggled between on and off.

And I threw in something new, reading REG_TOUCH_RAW_XY. With this we can differentiate between continued sliding around on the display and that the finger is actually lifted. When you slide off a button the tag value reported falls back to zero.

RudolphRrr commented 1 year ago

And I just noticed that I forgot to set toggle_lock in "case 10". This would make more sense in a scenario with more than one button but I just slightly modified my basic example.

lotfibk commented 1 year ago

Hello,

You are right it is not an issue, I am new to GitHub and I posted this topic in the wrong "folder", my bad.

Thank you very much for your fast and useful answer!

Though I have two other questions, as I am developing a GUI, I am wondering if it is possible for the buttons to flatten (256 => EVE_OPT_FLAT) while they get pressed, and to return to 0 (3D mode) when the finger is removed from the button?

My other question is about pictures/icons, I managed to display icons on my screen by converting them to .hex and adding them to my tft_data.c, and I gave them the correct address (btw, I'm not sure what is the "limit address" when it comes to writing pictures into the memory, but I assume the limit is 0x000F FFFF. Let me know if the final address is wrong)

I have several TFT_display() functions, and when I try to display the icons on several of those functions, only the first-called function displays the icons correctly. All the other ones display a black square.

Display_main Display_protocol


#define MEM_PIC1 0x000fa000 /* start of 48x48 pixel test image, ARGB565, needs 2*48*48 = 4608 bytes of memory */ //icon_home_white
#define MEM_PIC2 0x000fb000 /* start of 48x48 pixel test image, ARGB565, needs 2*48*48 = 4068 bytes of memory */ //icon_home_blue
...

void TFT_init(void)

{
...
EVE_cmd_loadimage(MEM_PIC1, EVE_OPT_NODL, icon_home_white, sizeof(icon_home_white));
EVE_cmd_loadimage(MEM_PIC2, EVE_OPT_NODL, icon_home_blue, sizeof(icon_home_blue));`
}

void TFT_display_main(void) //First "display function" to be called
{
    initStaticBackground();

    if (tft_active != 0)
    {

        EVE_start_cmd_burst(); /* start writing to the cmd-fifo as one stream of bytes, only sending the address once */

        EVE_cmd_dl_burst(CMD_DLSTART);                            /* start the display list */
        EVE_cmd_dl_burst(DL_CLEAR_RGB | BLACK);                   /* set the default clear color to white */
        EVE_cmd_dl_burst(DL_CLEAR | CLR_COL | CLR_STN | CLR_TAG); /* clear the screen - this and the previous prevent artifacts between lists, Attributes are the color, stencil and tag buffers */
        EVE_cmd_dl_burst(TAG(0));

        EVE_cmd_append_burst(MEM_DL_STATIC, num_dl_static); /* insert static part of display-list from copy in gfx-mem */

        /* display "Fond" button */
        EVE_cmd_dl_burst(DL_COLOR_RGB | 0x00eeeeee);
        EVE_cmd_fgcolor_burst(0x0FF7F7F7); /* some grey */
        EVE_cmd_dl_burst(TAG(0));         
        EVE_cmd_button_burst(0, 0, 224, 400, 28, EVE_OPT_FLAT, "");
        EVE_cmd_dl_burst(TAG(0)); /* no touch */

        /* display "Home" button */
        EVE_cmd_dl_burst(DL_COLOR_RGB | WHITE);
        EVE_cmd_fgcolor_burst(0x00318ce7); //some grey
        EVE_cmd_dl_burst(TAG(5));         //assign tag-value '10' to the button that follows
        EVE_cmd_button_burst(0,0, 224, 80, 29, toggle_home, "Main");
        EVE_cmd_dl_burst(TAG(0)); /* no touch */

        /* display "Home" icon*/
        EVE_cmd_setbitmap_burst(MEM_PIC2, EVE_RGB565, 48, 48);
        EVE_cmd_dl_burst(DL_BEGIN | EVE_BITMAPS);
        EVE_cmd_dl_burst(VERTEX2F(15,16));  //position x and y
        EVE_cmd_dl_burst(DL_END);

         /* display "Home" icon*/
        EVE_cmd_setbitmap_burst(MEM_PIC1, EVE_RGB565, 48, 48);
        EVE_cmd_dl_burst(DL_BEGIN | EVE_BITMAPS);
        EVE_cmd_dl_burst(VERTEX2F(168,16));  //position x and y
        EVE_cmd_dl_burst(DL_END);
...
}

void TFT_display_protocol(void)
{
    initStaticBackground();

    if (tft_active != 0)
    {

        EVE_start_cmd_burst(); /* start writing to the cmd-fifo as one stream of bytes, only sending the address once */

        EVE_cmd_dl_burst(CMD_DLSTART);                            /* start the display list */
        EVE_cmd_dl_burst(DL_CLEAR_RGB | BLACK);                   /* set the default clear color to white */
        EVE_cmd_dl_burst(DL_CLEAR | CLR_COL | CLR_STN | CLR_TAG); /* clear the screen - this and the previous prevent artifacts between lists, Attributes are the color, stencil and tag buffers */
        EVE_cmd_dl_burst(TAG(0));

        EVE_cmd_append_burst(MEM_DL_STATIC, num_dl_static); /* insert static part of display-list from copy in gfx-mem */

          /* display "Home" button */
        EVE_cmd_dl_burst(DL_COLOR_RGB | BLACK);
        EVE_cmd_fgcolor_burst(0x00eeeeee); //some grey
        EVE_cmd_dl_burst(TAG(5));         //assign tag-value '10' to the button that follows
        EVE_cmd_button_burst(0,0, 224, 80, 29, toggle_home, "Main");
        EVE_cmd_dl_burst(TAG(0)); /* no touch * 

        /* display "Home" icon*/
        EVE_cmd_setbitmap_burst(MEM_PIC2, EVE_RGB565, 48, 48);
        EVE_cmd_dl_burst(DL_BEGIN | EVE_BITMAPS);
        EVE_cmd_dl_burst(VERTEX2F(15,16));  //position x and y
        EVE_cmd_dl_burst(DL_END);

         /* display "Home" icon*/
        EVE_cmd_setbitmap_burst(MEM_PIC1, EVE_RGB565, 48, 48);
        EVE_cmd_dl_burst(DL_BEGIN | EVE_BITMAPS);
        EVE_cmd_dl_burst(VERTEX2F(168,16));  //position x and y
        EVE_cmd_dl_burst(DL_END);

...
}

``
RudolphRrr commented 1 year ago

You are right it is not an issue, I am new to GitHub and I posted this topic in the wrong "folder", my bad.

No worries, the "Discussions" feature still is fairly new and it's not like I am drowning in issues. :-)

I am wondering if it is possible for the buttons to flatten (256 => EVE_OPT_FLAT) while they get pressed, and to return to 0 >(3D mode) when the finger is removed from the button?

Sure, just set a flag when the button is detected as touched and reset it with release of the button. Or do I misinterpret the question?

(btw, I'm not sure what is the "limit address" when it comes to writing pictures into the memory, but I assume the limit is >0x000F FFFF. Let me know if the final address is wrong)

This is RAM_G so the range is 0x00000 to 0xFFFFF. There is one restriction, decompressing PNG images uses some portion from the top of RAM_G.

EVE_cmd_loadimage(

So you are using image files instead of already converted data, if these are PNG, well. :-)

define MEM_PIC1 0x000fa000 / start of 48x48 pixel test image, ARGB565, needs 24848 = 4608 bytes of memory /

define MEM_PIC2 0x000fb000 / start of 48x48 pixel test image, ARGB565, needs 24848 = 4068 bytes of memory /

That is not quite correct as 4608 bytes is 0x1200 so your memory overlaps.

lotfibk commented 1 year ago

You were right, I did manage to flatten the button while it is pressed with a flag depending on the "touchtest"'s value.

About the images, I simply convert .jpg to hexadecimal values, and I create a constant in tft_data.c to which I give the hex matrix. But am I wrong using "EVE_cmd_loadimage" ?

I corrected the memory overlap between the two images, but it still displays black images when I call another display function :/

RudolphRrr commented 1 year ago

About the images, I simply convert .jpg to hexadecimal values, and I create a constant in tft_data.c to which I give the hex matrix. But am I wrong using "EVE_cmd_loadimage" ?

No, this is fine, there would be an issue with PNG images. Regardless you could check out EVE Asset Builder, converting the images first gives better control over the resulting format. You could for example use ARGB1555 as well. And EAB has an asset compressor as well as a C file converter, the result can be loaded with EVE_cmd_inflate().

I corrected the memory overlap between the two images, but it still displays black images when I call another display function :/

Try to put these somewhere else, like 0x0000 and 0x2000.

lotfibk commented 1 year ago

Yes you are right, I have used that EVE Asset Builder and it does convert the images in hex quite well.

Regarding the images, I changed their addresses, but it is still the same. Even when I am only trying to display one image, everything is fine when calling the first "display function" (TFT_Display_Main), but when I call any other display function, I get that black square.

RudolphRrr commented 1 year ago

Please reduce the code to a bare minimum that shows the issue and then attach the tft and tft_data files.

I noticed something else though:

void TFT_display_main(void) //First "display function" to be called { initStaticBackground();

void TFT_display_protocol(void) { initStaticBackground();

Why are you running initStaticBackground() with your display functions? The idea with initStaticBackground() is that it only needs to be run once in TFT_init(), it reduces the necessary SPI traffic per display update. So for several different screens the program would need maybe one function for common elements, like the bar on top in my "Design" and the logo. Plus one function per screen for the things on that screen like text that is static for that screen: "Measurement Foobar:".

Or well, remove that entirely when SPI traffic is not an issue and send everything every time.

lotfibk commented 1 year ago

Hello, I finally found the issue with the pictures turning black! It happens whenever the function "EVE_cmd_dl_burst(DL_COLOR_RGB | BLACK);" is called before the image.

I used to call this function to change the color of my font, as you can see, the word "Main" was white at first, and then black, and the picture was affected by this change as well.

And to solve the issue, we simply need to write the same function right before calling the image, but we need to change the parameter from "BLACK" to "WHITE"

RudolphRrr commented 1 year ago

Oh, yes indeed, COLOR_RGB is used to modify images.