最近看到有网友用NAND flash刷屏,刷到20fps。我想起来原来测试STM32 SDIO读写速度时,有10MB/s的速度。用这个速度放未压缩的视频,可以超过60fps。于是我写个代码试试看效果。
经过测试,不限制速度的话,可以达到72fps。320 x 240 x 2byte/pixel x 72fps = 11,059,200 byte/second。
我用Yadif+Bob产生60fps的视频,转成一张张BMP,然后写程序转成RGB565的,写到SD卡里,最后STM32直接从指定扇区开始读数据到LCD。全程用DMA操作,CPU使用率<1%
拍了一段视频,声音是后来加上去的。拍的视频是30fps的,显得不那么流畅了。实际是非常流畅的。
http://v.youku.com/v_show/id_XNzg3OTQwNDk2.html
代码:
STM32F103_SD2LCD.rar
(195.7 KB, 下载次数: 900)
2014-9-22 12:17 上传
点击文件名下载附件
有兴趣的网友可以试试,Keil 和 IAR的工程都有。不过需要根据自己的板子改一下GPIO配置、FSMC地址等。硬件需要用4bit的SDIO模式。还有SD卡要能有10MB/s的读速度,不过一般的卡都有这个速度了。
- // RGB24toRGB565.cpp
- //
- #include "stdafx.h"
- #include "windows.h"
- unsigned char SrcBMP[320 * 240 * 3];
- unsigned char DstBMP[240 * 320 * 2];
- #define RGB565(r, g, b)
- ((((r) & 0x1f) << 11) |
- (((g) & 0x3f) << 5) |
- (((b) & 0x1f) ))
- int _tmain(int argc, _TCHAR* argv[])
- {
- HANDLE hSrcFile;
- HANDLE hDstFile;
- DWORD r,g,b;
- unsigned char * SrcPixel;
- DWORD dwBytesRead, dwBytesWritten, dwPos;
- unsigned short * DstPixel;
- TCHAR SrcFileName[MAX_PATH];
- hDstFile = CreateFile(TEXT("J:\grab_bmp\!output.img"), // open DST file
- GENERIC_WRITE, // open for writing
- 0, // do not share
- NULL, // no security
- OPEN_ALWAYS, // open or create
- FILE_ATTRIBUTE_NORMAL, // normal file
- NULL); // no attr. template
- for (int FileIndex = 484; FileIndex <= 6951; FileIndex++)
- {
- _stprintf (SrcFileName, TEXT("J:\grab_bmp\grab%05d.bmp"), FileIndex);
- hSrcFile = CreateFile(SrcFileName, // open SRC file
- GENERIC_READ, // open for reading
- 0, // do not share
- NULL, // no security
- OPEN_EXISTING, // existing file only
- FILE_ATTRIBUTE_NORMAL, // normal file
- NULL); // no attr. template
- if (hSrcFile == INVALID_HANDLE_VALUE)
- {
- printf("Could not open source file.");
- return 0;
- }
- SetFilePointer(hSrcFile, 0x1A, NULL, FILE_BEGIN);
- ReadFile(hSrcFile, SrcBMP, sizeof(SrcBMP), &dwBytesRead, NULL);
- if (dwBytesRead != sizeof(SrcBMP))
- {
- printf("Read file error.");
- return 0;
- }
- CloseHandle(hSrcFile);
- for( int x = 0; x < 240; x++)
- {
- for( int y = 0; y < 320; y++)
- {
- SrcPixel = SrcBMP + ((319 - y) * 3) + ((239 - x) * 320 * 3);
- b = SrcPixel[0];
- g = SrcPixel[1];
- r = SrcPixel[2];
- DstPixel = (unsigned short *)(DstBMP + x * 2 + y * 240 * 2);
- *DstPixel = RGB565(r >> 3, g >> 2, b >> 3);
- }
- }
- WriteFile(hDstFile, DstBMP, sizeof(DstBMP), &dwBytesWritten, NULL);
- }
- CloseHandle(hDstFile);
- return 0;
- }
复制代码一周热门 更多>