I have a C Function which tries to copy a framebuffer to FSMC RAM.
The functions eats the frame rate of the game loop to 10FPS. I would like to know how to analyze
Just to purely reduce the number of looped operations, you could do something like so. I did make some assumptions which may not be accurate: You had a loop that went from i=0:239
, and I am assuming that fbWidth
is the same as 240
. If this isn't true then the loop would have to be more complicated.
void LCD_Flip()
{
u16 i,limit = fbHeight+fbWidth;
// We will use a precalculated limit and one single loop
LCD_SetCursor(0x00, 0x0000);
LCD_WriteRegister(0x0050,0x00);//GRAM horizontal start position
LCD_WriteRegister(0x0051,239);//GRAM horizontal end position
LCD_WriteRegister(0x0052,0);//Vertical GRAM Start position
LCD_WriteRegister(0x0053,319);//Vertical GRAM end position
LCD_WriteIndex(0x0022);
// Single loop from 0:limit-1 takes care of having to do an
// x,y conversion each iteration.
for(i=0;i
This strips out the two loops in favor of a single for loop with only one conditional test per iteration. On top of that, the indexing into frameBuffer
is now linear, so we don't need to multiply out the width to go from x,y to linear storage. Your loop iterations won't have been reduced (i.e. it is still O(N)
with N = height*width
), but the number of instructions should have been reduced.
As @Joe Hass noted in his answer, this may not actually help at all if you are really limited by the LCD interface. Depending on which STM32 you're using, the FSMC may not be particularly fast, and I can't imagine the LCD controller would be very fast either.