2019-05-06 06:18 AM
Hello,
I have gone through the KB articles of TouchGFX. But I think they are very shallow. Not able to found how memory management is done. I know a good graphical system needs lots of RAM so touch gfx needs external SDRAM. Ok I have got SDRAM. But how it uses the SD RAM? Normally software uses dynamic memory allocation for such purpose (example when it allocates memory for screen buffers or caching(loading) bitmaps). But in embedded system we cant easily use dynamic memory so some kind of tricks are implemented.
I am not able to find out how TouchGFX uses dynamic memory? Where we define the area which is used for caching bitmaps.
Solved! Go to Solution.
2019-05-13 06:48 AM
You tell the Bitmap class the start of your cache. e.g. It's up to you if you want to place these in internal or external. Example for internal:
static uint32_t bitmapCache[2048 * 1024];
Bitmap::setCache((uint16_t*)bitmapCache, sizeof(bitmapCache), 128);
Here's the declaration + doc:
/**
* @fn static void Bitmap::setCache(uint16_t* cachep, uint32_t csize, uint32_t numberOfDynamicBitmaps = 0);
*
* @brief Register a memory region in which bitmap data can be cached.
*
* Register a memory region in which bitmap data can be cached.
*
* @param [in,out] cachep Pointer to memory region in which bitmap data can be cached.
* @param csize Size of cache memory region in bytes.
* @param numberOfDynamicBitmaps Number of dynamic bitmaps to be allowed in the cache.
*/
static void setCache(uint16_t* cachep, uint32_t csize, uint32_t numberOfDynamicBitmaps = 0);
You can then create a dynamic bitmap using:
BitmapId id = Bitmap::dynamicBitmapCreate(100, 100, Bitmap::RGB565);
and get a pointer to it's data which you can then populate with pixel data read from your non-mapped memory.
uint16_t* data = (uint16_t*)Bitmap::dynamicBitmapGetAddress(id);
You can now use this BitmapID as you would a regular BitmapID and display the pixel data.
/Martin
2019-05-07 12:00 AM
Hi @avinash_elec,
You're right, the article on this is in the making to better explain what goes on under the hood in TouchhGFX.
TouchGFX does not use dynamic memory allocation. It uses primarily static allocation with one exception - TouchGFX determines the size of the largest View/Presenter pair that you have and uses placement new to construct a new active screen into previously allocated memory (only one can be active at a time).
TouchGFX just requires a pointer to the addressable and writeable memory that you want to use for the framebuffer. It can be internal SRAM og external SDRAM - doesn't matter which. It's all up to you to determine whether or not you can fit your framebuffer(s) and what kind of speed you want.
Hope that helps a bit, let me know.
Best regards,
Martin
2019-05-07 06:51 AM
Thanks Mr. Martin for your answer.
I have seen that if we use bitmaps from memories that does NOT support memory mapped interface then we have to cache the bitmap in RAM. So in which area these get cached? Where is this region and its size defined?
2019-05-13 06:48 AM
You tell the Bitmap class the start of your cache. e.g. It's up to you if you want to place these in internal or external. Example for internal:
static uint32_t bitmapCache[2048 * 1024];
Bitmap::setCache((uint16_t*)bitmapCache, sizeof(bitmapCache), 128);
Here's the declaration + doc:
/**
* @fn static void Bitmap::setCache(uint16_t* cachep, uint32_t csize, uint32_t numberOfDynamicBitmaps = 0);
*
* @brief Register a memory region in which bitmap data can be cached.
*
* Register a memory region in which bitmap data can be cached.
*
* @param [in,out] cachep Pointer to memory region in which bitmap data can be cached.
* @param csize Size of cache memory region in bytes.
* @param numberOfDynamicBitmaps Number of dynamic bitmaps to be allowed in the cache.
*/
static void setCache(uint16_t* cachep, uint32_t csize, uint32_t numberOfDynamicBitmaps = 0);
You can then create a dynamic bitmap using:
BitmapId id = Bitmap::dynamicBitmapCreate(100, 100, Bitmap::RGB565);
and get a pointer to it's data which you can then populate with pixel data read from your non-mapped memory.
uint16_t* data = (uint16_t*)Bitmap::dynamicBitmapGetAddress(id);
You can now use this BitmapID as you would a regular BitmapID and display the pixel data.
/Martin
2019-05-20 12:54 AM
Wow! Nice information! Thank you.
2019-05-20 01:01 AM
You're welcome! :)