mirror of
https://github.com/opentx/opentx.git
synced 2025-07-15 04:15:26 +03:00
[Horus] Use of SD buffers in RAM instead of CCM for loading bitmaps (they may only be loaded from the main thread now)
This commit is contained in:
parent
b5f6618238
commit
3e1d87d5b3
3 changed files with 31 additions and 34 deletions
|
@ -455,7 +455,7 @@ int cliDisplay(const char ** argv)
|
|||
|
||||
int cliDebugVars(const char ** argv)
|
||||
{
|
||||
#if defined(PCBHORUS) && !defined(SIMU)
|
||||
#if defined(PCBHORUS)
|
||||
extern uint32_t ioMutexReq, ioMutexRel;
|
||||
extern uint32_t sdReadRetries;
|
||||
|
||||
|
|
|
@ -397,32 +397,33 @@ BitmapBuffer * BitmapBuffer::load(const char * filename)
|
|||
return load_stb(filename);
|
||||
}
|
||||
|
||||
FIL imgFile __DMA;
|
||||
|
||||
BitmapBuffer * BitmapBuffer::load_bmp(const char * filename)
|
||||
{
|
||||
FIL bmpFile;
|
||||
UINT read;
|
||||
uint8_t palette[16];
|
||||
uint8_t bmpBuf[LCD_W]; /* maximum with LCD_W */
|
||||
uint8_t * buf = &bmpBuf[0];
|
||||
|
||||
FRESULT result = f_open(&bmpFile, filename, FA_OPEN_EXISTING | FA_READ);
|
||||
FRESULT result = f_open(&imgFile, filename, FA_OPEN_EXISTING | FA_READ);
|
||||
if (result != FR_OK) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (f_size(&bmpFile) < 14) {
|
||||
f_close(&bmpFile);
|
||||
if (f_size(&imgFile) < 14) {
|
||||
f_close(&imgFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = f_read(&bmpFile, buf, 14, &read);
|
||||
result = f_read(&imgFile, buf, 14, &read);
|
||||
if (result != FR_OK || read != 14) {
|
||||
f_close(&bmpFile);
|
||||
f_close(&imgFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (buf[0] != 'B' || buf[1] != 'M') {
|
||||
f_close(&bmpFile);
|
||||
f_close(&imgFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -430,9 +431,9 @@ BitmapBuffer * BitmapBuffer::load_bmp(const char * filename)
|
|||
uint32_t hsize = *((uint32_t *)&buf[10]); /* header size */
|
||||
|
||||
uint32_t len = limit((uint32_t)4, (uint32_t)(hsize-14), (uint32_t)32);
|
||||
result = f_read(&bmpFile, buf, len, &read);
|
||||
result = f_read(&imgFile, buf, len, &read);
|
||||
if (result != FR_OK || read != len) {
|
||||
f_close(&bmpFile);
|
||||
f_close(&imgFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -440,17 +441,17 @@ BitmapBuffer * BitmapBuffer::load_bmp(const char * filename)
|
|||
|
||||
/* invalid header size */
|
||||
if (ihsize + 14 > hsize) {
|
||||
f_close(&bmpFile);
|
||||
f_close(&imgFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* sometimes file size is set to some headers size, set a real size in that case */
|
||||
if (fsize == 14 || fsize == ihsize + 14)
|
||||
fsize = f_size(&bmpFile) - 2;
|
||||
fsize = f_size(&imgFile) - 2;
|
||||
|
||||
/* declared file size less than header size */
|
||||
if (fsize <= hsize) {
|
||||
f_close(&bmpFile);
|
||||
f_close(&imgFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -472,12 +473,12 @@ BitmapBuffer * BitmapBuffer::load_bmp(const char * filename)
|
|||
buf += 8;
|
||||
break;
|
||||
default:
|
||||
f_close(&bmpFile);
|
||||
f_close(&imgFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (*((uint16_t *)&buf[0]) != 1) { /* planes */
|
||||
f_close(&bmpFile);
|
||||
f_close(&imgFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -486,8 +487,8 @@ BitmapBuffer * BitmapBuffer::load_bmp(const char * filename)
|
|||
buf = &bmpBuf[0];
|
||||
|
||||
if (depth == 4) {
|
||||
if (f_lseek(&bmpFile, hsize-64) != FR_OK || f_read(&bmpFile, buf, 64, &read) != FR_OK || read != 64) {
|
||||
f_close(&bmpFile);
|
||||
if (f_lseek(&imgFile, hsize-64) != FR_OK || f_read(&imgFile, buf, 64, &read) != FR_OK || read != 64) {
|
||||
f_close(&imgFile);
|
||||
return NULL;
|
||||
}
|
||||
for (uint8_t i=0; i<16; i++) {
|
||||
|
@ -495,15 +496,15 @@ BitmapBuffer * BitmapBuffer::load_bmp(const char * filename)
|
|||
}
|
||||
}
|
||||
else {
|
||||
if (f_lseek(&bmpFile, hsize) != FR_OK) {
|
||||
f_close(&bmpFile);
|
||||
if (f_lseek(&imgFile, hsize) != FR_OK) {
|
||||
f_close(&imgFile);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
BitmapBuffer * bmp = new BitmapBuffer(BMP_RGB565, w, h);
|
||||
if (bmp == NULL) {
|
||||
f_close(&bmpFile);
|
||||
f_close(&imgFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -517,9 +518,9 @@ BitmapBuffer * BitmapBuffer::load_bmp(const char * filename)
|
|||
uint8_t * dst = ((uint8_t *)dest) + i*w*2;
|
||||
for (unsigned int j=0; j<w; j++) {
|
||||
uint32_t pixel;
|
||||
result = f_read(&bmpFile, (uint8_t *)&pixel, 4, &read);
|
||||
result = f_read(&imgFile, (uint8_t *)&pixel, 4, &read);
|
||||
if (result != FR_OK || read != 4) {
|
||||
f_close(&bmpFile);
|
||||
f_close(&imgFile);
|
||||
delete bmp;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -551,9 +552,9 @@ BitmapBuffer * BitmapBuffer::load_bmp(const char * filename)
|
|||
case 4:
|
||||
rowSize = ((4*w+31)/32)*4;
|
||||
for (int32_t i=h-1; i>=0; i--) {
|
||||
result = f_read(&bmpFile, buf, rowSize, &read);
|
||||
result = f_read(&imgFile, buf, rowSize, &read);
|
||||
if (result != FR_OK || read != rowSize) {
|
||||
f_close(&bmpFile);
|
||||
f_close(&imgFile);
|
||||
delete bmp;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -568,12 +569,12 @@ BitmapBuffer * BitmapBuffer::load_bmp(const char * filename)
|
|||
break;
|
||||
|
||||
default:
|
||||
f_close(&bmpFile);
|
||||
f_close(&imgFile);
|
||||
delete bmp;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
f_close(&bmpFile);
|
||||
f_close(&imgFile);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
|
@ -651,8 +652,6 @@ const stbi_io_callbacks stbCallbacks = {
|
|||
|
||||
BitmapBuffer * BitmapBuffer::load_stb(const char * filename)
|
||||
{
|
||||
FIL imgFile;
|
||||
|
||||
FRESULT result = f_open(&imgFile, filename, FA_OPEN_EXISTING | FA_READ);
|
||||
if (result != FR_OK) {
|
||||
return NULL;
|
||||
|
|
|
@ -2553,10 +2553,6 @@ void opentxInit(OPENTX_INIT_ARGS)
|
|||
|
||||
storageReadAll();
|
||||
|
||||
#if defined(COLORLCD)
|
||||
loadTheme();
|
||||
#endif
|
||||
|
||||
#if defined(CPUARM)
|
||||
if (UNEXPECTED_SHUTDOWN()) {
|
||||
unexpectedShutdown = 1;
|
||||
|
@ -2596,6 +2592,10 @@ void opentxInit(OPENTX_INIT_ARGS)
|
|||
rtcInit();
|
||||
#endif
|
||||
|
||||
#if defined(COLORLCD)
|
||||
loadTheme();
|
||||
#endif
|
||||
|
||||
if (g_eeGeneral.backlightMode != e_backlight_mode_off) backlightOn(); // on Tx start turn the light on
|
||||
|
||||
if (UNEXPECTED_SHUTDOWN()) {
|
||||
|
@ -2635,8 +2635,6 @@ void opentxInit(OPENTX_INIT_ARGS)
|
|||
startPulses();
|
||||
|
||||
wdt_enable(WDTO_500MS);
|
||||
|
||||
|
||||
}
|
||||
|
||||
#if !defined(SIMU)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue