Loading Custom Backgrounds / Buttons / Images

FTDI/Bridgetek EVE2 & EVE3 & EVE4 SPI TFT Series by Matrix Orbital

Moderator: Mods

Post Reply
amaul
LCD Geek
Posts: 21
Joined: Mon Jun 08, 2020 5:29 pm

Loading Custom Backgrounds / Buttons / Images

Post by amaul »

Hello Support / Rudolph,

I've been using Rudolph's EVE Libraries in our Arduino based application and it's been very helpful demonstrating and handling much of the functionality needed. Our application requires the use of a custom background, buttons, and fonts. My procedure up to this point has been following what Rudolph's demo code shows. I use the EVE Asset builder to convert jpegs to compressed, ARG565 format image. I open that image in a hex editor (HxD) and copy the data as C code and paste into my application as a const uint_8t array. The conversion also spits out a json file the lists the 'total size' I use to dictate where in G RAM I should place the start address of each image in memory. Using EVE_cmd_loadimage(), I decompress the image and place it into memory. Later in the code I use EVE_cmd_setbitmap to display the image.

At this point I've got a handful of backgrounds and buttons that create the user interface, and now I need to create another screen for the user and I'm all out of G RAM space. Knowing this might be the case, I made sure we had access to extra flash memory per the Matrix Orbital design. It's not clear to me how I use this space. I don't seem to be able to point my memory locations for images to 0x800000 and load images as a normally would, which I presume is not the correct way to do this. Can I access this flash memory location as I would the G RAM? Or am I only limited to the actual G RAM for actual images? Our micro has plenty of space to store the image arrays. I went through the Font example in Rudolph's code which demonstrates flash usage, but in the end it looks like image is loaded back into G RAM which doesn't solve my problem. What is the proper way via EVE to do this?

Thanks,

Alex

Rudolph
LCD Guru
Posts: 67
Joined: Wed Feb 28, 2018 11:09 am

Re: Loading Custom Backgrounds / Buttons / Images

Post by Rudolph »

Hello,

first you can only display ASTC compressed images from the flash.
And then the adress you need to use is to be divided by 32.

So this:

EVE_cmd_dl_burst(DL_COLOR_RGB | WHITE);
EVE_cmd_dl_burst(DL_BEGIN | EVE_BITMAPS);
EVE_cmd_setbitmap_burst(0x800000 | 128, EVE_COMPRESSED_RGBA_ASTC_8x8_KHR, 256, 256);
EVE_cmd_dl_burst(VERTEX2F(0, 0));
EVE_cmd_dl_burst(DL_END);

Displays an image from flash address 4096.

amaul
LCD Geek
Posts: 21
Joined: Mon Jun 08, 2020 5:29 pm

Re: Loading Custom Backgrounds / Buttons / Images

Post by amaul »

Thanks Rudolph! I'll give this a shot.

amaul
LCD Geek
Posts: 21
Joined: Mon Jun 08, 2020 5:29 pm

Re: Loading Custom Backgrounds / Buttons / Images

Post by amaul »

Hello Rudolph,

I must be missing something, I think the image is wrapping around on the G RAM. I take it I can't use the normal loadimage to place the ASTC image into flash? Would I follow your same flash routine you use in the font example?

My binary / hex math is a little rusty. What does 0x800000 | 128 do for us? I'm not quite sure how division by 32 factors in, is it something to do with the 256 / 64bit alignment I'm reading in the flash functions?

Thank you for your help,

Alex

amaul
LCD Geek
Posts: 21
Joined: Mon Jun 08, 2020 5:29 pm

Re: Loading Custom Backgrounds / Buttons / Images

Post by amaul »

Hey Rudolph,

Found this written by you on the BRT Community site:

http://www.brtcommunity.com/index.php?t ... 987#msg987

I'll give this a shot.

Thanks,

Alex

amaul
LCD Geek
Posts: 21
Joined: Mon Jun 08, 2020 5:29 pm

Re: Loading Custom Backgrounds / Buttons / Images

Post by amaul »

Hey Rudolph,

Getting closer. I did not know EAB was so powerful, it can actually manage a lot that I was not aware of (flash generation w/ blob, compression, conversion to c array). I made myself familiar with the flashing on the device and the cursed blob. Some useful links I found for others searching this topic:

viewtopic.php?f=45&t=6894
http://www.brtcommunity.com/index.php?topic=200.0
http://www.brtcommunity.com/index.php?t ... 987#msg987
http://www.brtcommunity.com/index.php?topic=57.0
http://www.brtcommunity.com/index.php?t ... 66#msg1066

My first trial of testing the Eve_ini_flash function I found my flash was not initialized (no surprise since it's a raw chip). I found the blob file in the EAB install directory, opened in HxD and copied the data as C into an array in my application. Then I erased the flash (flasherase) then wrote the blob array to flash. Disabled flash in my application and rebooted to find a successful fastflash.

After that, I tried using loadimage to place an ASTC image into G RAM, then using flashupdate to place that G RAM into flash and I think crashed the whole system.

It was about that time if found the combo of posts above that show how to us EAB to do everything you need to get the image on flash and the inflate function to decompress. So I've got your flash example code added:

Code: Select all

#include "EVE.h"
#include "tft_data.h"

/* some pre-definded colors */
#define WHITE	0xffffffUL
#define BLACK	0x000000UL

uint8_t tft_active = 0;
void TFT_init(void)
{
	if(EVE_init() != 0)
	{
		tft_active = 1;
		EVE_memWrite8(REG_PWM_DUTY, 0x40);	/* setup backlight, range is from 0 = off to 0x80 = max */

	#if 1
		/* this is only needed once to transfer the flash-image to the external flash */
		uint32_t datasize;

		EVE_cmd_inflate(0, flash, sizeof(flash)); /* de-compress flash-image to RAM_G */
		datasize = EVE_cmd_getptr(); /* we unpacked to RAM_G address 0x0000, so the first address after the unpacked data also is the size */
		EVE_cmd_flashupdate(0,0,4096); /* write blob first */
		EVE_init_flash();
		EVE_cmd_flashupdate(0,0,(datasize|4095)+1); /* size must be a multiple of 4096, so set the lower 12 bits and add 1 */
	#endif

		EVE_init_flash();
	}
}


/*
	dynamic portion of display-handling, meant to be called every 20ms or more
*/
void TFT_display(void)
{
	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(VERTEX_FORMAT(0)); /* reduce precision for VERTEX2F to 1 pixel instead of 1/16 pixel default */

		EVE_cmd_dl_burst(DL_COLOR_RGB | WHITE);

		EVE_cmd_setbitmap_burst(0x800000 | (4096/32), EVE_COMPRESSED_RGBA_ASTC_8x8_KHR, 344, 48); /* display directly from FLASH */

		EVE_cmd_dl_burst(DL_BEGIN | EVE_BITMAPS);
		EVE_cmd_dl_burst(VERTEX2F(200, 100));
		EVE_cmd_dl_burst(DL_END);

		EVE_cmd_dl_burst(DL_DISPLAY); /* instruct the graphics processor to show the list */
		EVE_cmd_dl_burst(CMD_SWAP); /* make this list active */

		EVE_end_cmd_burst(); /* stop writing to the cmd-fifo, the cmd-FIFO will be executed automatically after this or when DMA is done */
	}
}
Great, so now time to build the 'flash' array. Here is my procedure:
1. Convert the image to EVE_COMPRESSED_RGBA_ASTC_8x8_KHR, default options:
Screen Shot 2021-05-20 at 4.03.32 PM.png
Screen Shot 2021-05-20 at 4.03.32 PM.png (149.96 KiB) Viewed 2897 times
2. Generate flash image with the blob file automatically included and adding my previously converted EVE_COMPRESSED_RGBA_ASTC_8x8_KHR.raw file
Screen Shot 2021-05-20 at 4.05.45 PM.png
Screen Shot 2021-05-20 at 4.05.45 PM.png (148.09 KiB) Viewed 2897 times
3. Compress flash.bin file created, default settings:
Screen Shot 2021-05-20 at 4.10.23 PM.png
Screen Shot 2021-05-20 at 4.10.23 PM.png (117.73 KiB) Viewed 2897 times
4. Convert Binary file into text file with C array:
Screen Shot 2021-05-20 at 4.11.25 PM.png
Screen Shot 2021-05-20 at 4.11.25 PM.png (113.82 KiB) Viewed 2897 times
5. Open the generated .c file in notepad and copy the array into the firmware in place of example array. For the size, I wrote a quick parser that ran through the data as csv formatted and spit out the array size. Not sure if there is a better place to find this.

6. Compile and download, and I get a pinkish purplish box where my image should be.

Where did I go wrong?

EDIT: I will add I have other image loading operations I'm doing in the same code with operations only in G RAM. For instance, after I use the G RAM above to inflate the flash then load to flash, I overwrite the G RAM stuff with new images that I currently use in the application. Those are showing up just fine.

Thanks,

Alex

PS. I'd like to get this on BTCommunity forum but I'm waiting for approval on the account.

Rudolph
LCD Guru
Posts: 67
Joined: Wed Feb 28, 2018 11:09 am

Re: Loading Custom Backgrounds / Buttons / Images

Post by Rudolph »

Getting closer. I did not know EAB was so powerful
And it still is getting better.

Bridgetek posted an inoffcial/beta version here:
http://www.brtcommunity.com/index.php?topic=127.15

What is huge for me about that version is that they switched from ASTCenc 1.x to 2.x.
Converting fonts takes seconds now.
5. Open the generated .c file in notepad and copy the array into the firmware in place of example array. For the size, I wrote a quick parser that ran through the data as csv formatted and spit out the array size. Not sure if there is a better place to find this.
I just use the size of the .zilib file.
6. Compile and download, and I get a pinkish purplish box where my image should be.
Just to be sure, you adjusted the dimensions?
EVE_cmd_setbitmap_burst(0x800000 | (4096/32), EVE_COMPRESSED_RGBA_ASTC_8x8_KHR, 152, 152);

amaul
LCD Geek
Posts: 21
Joined: Mon Jun 08, 2020 5:29 pm

Re: Loading Custom Backgrounds / Buttons / Images

Post by amaul »

Hey Rudolph,

Thanks for the pointers, I got the flash working. I'm thinking in my end of week stress I fat fingered something as I was able to get the same setup working as it should. My luck, I probably forgot to set the enable bit to true :)

My only question now is the proper addressing for the flash address once I get past the first address (0x800000 relative to BT, and 0x000000 relative to flash). My basic map is as follows:
Screen Shot 2021-05-24 at 6.01.49 PM.png
Screen Shot 2021-05-24 at 6.01.49 PM.png (72.2 KiB) Viewed 2855 times
.

What is the address of the third item?

Thanks,

Alex

Rudolph
LCD Guru
Posts: 67
Joined: Wed Feb 28, 2018 11:09 am

Re: Loading Custom Backgrounds / Buttons / Images

Post by Rudolph »

What is the address of the third item?
As the third item also is an image, it's just the same, address in flash divided by 32.

0x800000 to indicate that the address in the external flash
100096/32

-> EVE_cmd_setbitmap_burst(0x800000 + 3128, EVE_COMPRESSED_RGBA_ASTC_8x8_KHR, 152, 152);

amaul
LCD Geek
Posts: 21
Joined: Mon Jun 08, 2020 5:29 pm

Re: Loading Custom Backgrounds / Buttons / Images

Post by amaul »

That was it, I think I tried dividing everything but that by 32.

Thanks!

Kuddos +10

Post Reply