cancel
Showing results for 
Search instead for 
Did you mean: 

fastest method of drawing one pixel

EEuge
Senior

Hello! I have a good 3d library https://github.com/FabioRM/dsp3D 

The author of the library ran it on STM32F746 . The library has the function

void dsp3D_LL_drawPoint(uint32_t x, uint32_t y, color32_t color)
{
	if(x < minX)
		minX = x;
	if(x > maxX)
		maxX = x;
	if(y < minY)
		minY = y;
	if(y > maxY)
		maxY = y;
 
	// YOUR IMPLEMENTATION
	
}

we need to substitute the code of the output pixel

I wrote to it my function TFT_FillRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint32_t color)

oid TFT_FillRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint32_t color)
{
	#define swap(a,b) {int16_t t=a;a=b;b=t;}
 
	if(x1>x2) swap(x1,x2);
	if(y1>y2) swap(y1,y2);
	uint32_t addr=0;
	addr = hltdc.LayerCfg[0].FBStartAdress + 3*(y1*hltdc.LayerCfg[0].ImageWidth+x1);
		
	hdma2d.Init.Mode = DMA2D_R2M;
	
	hdma2d.Init.OutputOffset = hltdc.LayerCfg[0].ImageWidth - (x2-x1);
	if(HAL_DMA2D_Init(&hdma2d) == HAL_OK)
	{
		if(HAL_DMA2D_Start(&hdma2d, color, addr,	x2-x1, y2-y1) == HAL_OK)
		{
			HAL_DMA2D_PollForTransfer(&hdma2d, 10);
		}
	}
}

but drawing is very slowly

https://cloud.mail.ru/public/DGUX/TZoRw7stw

the author of the library does it faster

https://www.youtube.com/watch?v=HqQ-ebsyalM&feature=emb_logo

Please tell me, how can I draw one pixel faster?

5 REPLIES 5
MM..1
Chief III

*(addr) = color;

I wrote

void dsp3D_LL_drawPoint(uint32_t x, uint32_t y, color32_t color)
{
	if(x < minX)
		minX = x;
	if(x > maxX)
		maxX = x;
	if(y < minY)
		minY = y;
	if(y > maxY)
		maxY = y;
 
	// YOUR IMPLEMENTATION
 
	*(__IO uint32_t*)(0xD0000000 + 3*(y * SCREEN_WIDTH + x))=color;
}

Speed isn't increased...

PMath.4
Senior III

If you want it to really go fast everything needs to be simplified and optimised - every function call adds overhead particularly at the pixel level.

Have a look at my example videos. This is all handcrafted code - no DMA, it is too slow

https://www.youtube.com/channel/UCK3btXJrZWnDVVTV7U-qzEw

These are running on an H743 at 800x600 resolution

Good!

Can you give me your library?

PMath.4
Senior III

There is a link to the complete project code on this page. There is no library as such.

https://geoffg.net/maximite.html

One thing to note is that the video memory in internal RAM and then multiple framebuffers are kept in SDRAM. Although pixel level writing can be done to the video memory it is much better to write to a separate framebuffer in non-shared RAM and then bulk copy that to the video memory which is the only bit with shared access.