C
Qt Quick Ultralite fileloading Example
/****************************************************************************** ** ** Copyright (C) 2023 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Ultralite module. ** ** $QT_BEGIN_LICENSE:COMM$ ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** $QT_END_LICENSE$ ** ******************************************************************************/#include "fatfs/fatfsfilesystem.h" #include "board_config.h" #include "ff.h" #include "ff_gen_drv.h" #include "fsl_sd.h" #include "sdmmc_config.h" #include <platforminterface/log.h> #include <qul/application.h> #include <platform/mem.h> static sd_card_t card; DSTATUS nxp_initialize(BYTE) { return 0; } DSTATUS nxp_status(BYTE) { return 0; } DRESULT nxp_read(BYTE, BYTE *buff, DWORD sector, UINT count) { if (kStatus_Success != SD_ReadBlocks(&card, buff, sector, count)) return RES_ERROR; return RES_OK; } const Diskio_drvTypeDef nxp_driver = {nxp_initialize, nxp_status, nxp_read}; #define BOARD_SDMMC_SD_HOST_IRQ_PRIORITY (5U) void ConfigureBoard() { static FatFsFilesystem filesystem; static FATFS nxpFatFs; static char nxpPath[4]; BOARD_SD_Config(&card, NULL, BOARD_SDMMC_SD_HOST_IRQ_PRIORITY, NULL); if (SD_HostInit(&card) != kStatus_Success) { Qul::PlatformInterface::log("SD host init failed\r\n"); return; } SD_PollingCardInsert(&card, kSD_Inserted); // Power cycle SD_SetCardPower(&card, false); SD_SetCardPower(&card, true); if (SD_CardInit(&card)) { Qul::PlatformInterface::log("SD card init failed\r\n"); return; } if (FATFS_LinkDriver(&nxp_driver, nxpPath) != 0) { Qul::PlatformInterface::log("FATFS_LinkDriver failed\r\n"); return; } if (f_mount(&nxpFatFs, nxpPath, 0) != 0) { Qul::PlatformInterface::log("Mounting filesystem failed!\r\n"); return; } Qul::Application::addFilesystem(&filesystem); } extern "C" { void *ff_memalloc(UINT msize) { return Qul::Platform::qul_malloc(msize); } void ff_memfree(void *ptr) { Qul::Platform::qul_free(ptr); } }