C
Qt Quick Ultralite imagedecoder Example
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial
#include "board_config.h"
#include "stmimagedecoder.h"
#include "stm32_mcu_specific.h"
#include <qul/application.h>
#if defined(SUPPORT_FILESYSTEM)
#include "fatfs/fatfsfilesystem.h"
#include "ff.h"
#include "ff_gen_drv.h"
#include "stm32u5_emmc.h"
FIL JPEG_File; /* File object */
static DSTATUS u5_initialize(BYTE)
{
return RES_OK;
}
static DSTATUS u5_status(BYTE)
{
return RES_OK;
}
static DRESULT u5_read(BYTE, BYTE *buff, DWORD sector, UINT count)
{
if (!Qul::Platform::Private::readBlockFromDevice(0 /*blockDeviceIndex*/, sector, count, buff))
return RES_ERROR;
return RES_OK;
}
const Diskio_drvTypeDef u5_driver = {u5_initialize, u5_status, u5_read};
extern "C" {
void *ff_memalloc(UINT msize)
{
return Qul::Platform::qul_malloc(msize);
}
void ff_memfree(void *ptr)
{
Qul::Platform::qul_free(ptr);
}
}
#endif
JPEG_HandleTypeDef JPEG_Handle;
#ifdef USE_DMA_BASED_JPEG_DECODING
DMA_HandleTypeDef handle_GPDMA1_Channel0;
DMA_HandleTypeDef handle_GPDMA1_Channel1;
#endif
extern "C" {
void JPEG_InitColorTables();
}
void ConfigureBoard()
{
#ifdef USE_DMA_BASED_JPEG_DECODING
__HAL_RCC_GPDMA1_CLK_ENABLE();
HAL_NVIC_SetPriority(GPDMA1_Channel0_IRQn, 6, 0);
HAL_NVIC_EnableIRQ(GPDMA1_Channel0_IRQn);
HAL_NVIC_SetPriority(GPDMA1_Channel1_IRQn, 7, 0);
HAL_NVIC_EnableIRQ(GPDMA1_Channel1_IRQn);
#endif
/* Init The JPEG Look Up Tables used for YCbCr to RGB conversion*/
JPEG_InitColorTables();
/* Init the HAL JPEG driver */
JPEG_Handle.Instance = JPEG;
if (HAL_JPEG_Init(&JPEG_Handle) != HAL_OK)
Qul::PlatformInterface::log("HAL_JPEG_Init failed\n");
#if defined(SUPPORT_FILESYSTEM)
// eMMC_init is supposed to be called from the platform init already.
static FatFsFilesystem filesystem;
static FATFS sdFatFs;
static char sdPath[4];
if (FATFS_LinkDriver(&u5_driver, sdPath) != 0) {
Qul::PlatformInterface::log("FATFS_LinkDriver failed\r\n");
return;
}
if (f_mount(&sdFatFs, sdPath, 0) != 0) {
Qul::PlatformInterface::log("Mounting filesystem failed!\r\n");
return;
}
Qul::Application::addFilesystem(&filesystem);
#endif
static StmImageDecoder imagedecoder;
Qul::Application::addImageDecoder(&imagedecoder);
}