C

Qt Quick Ultralite freertos_app_switch Example

/******************************************************************************
**
** Copyright (C) 2022 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 "hal_data.h"
#include "bg_image.h"
#include "string.h" //for memcpy and memset

extern bsp_leds_t g_bsp_leds;

#if defined(__ICCARM__)
#pragma location = ".noinit"
#elif defined(__GNUC__)
__attribute__((section(".noinit")))
#endif
int selectedApplication;

#define APP_IMG_WIDTH 480
#define APP_IMG_HEIGHT 272

#define BG_IMG_WIDTH 200
#define BG_IMG_HEIGHT BG_IMG_WIDTH

int readBootValue()
{
    return selectedApplication;
}

void writeBootValue(int app)
{
    selectedApplication = app;
}

void reset(int app)
{
    writeBootValue(app);
    NVIC_SystemReset();
}

void initLED() {}

void toggleLED()
{
    const bsp_io_port_pin_t pin = (bsp_io_port_pin_t) g_bsp_leds.p_leds[BSP_LED_LED1];
    R_BSP_PinAccessEnable();
    const bsp_io_level_t level = (bsp_io_level_t) R_BSP_PinRead(pin);
    R_BSP_PinWrite(pin, level == BSP_IO_LEVEL_LOW ? BSP_IO_LEVEL_HIGH : BSP_IO_LEVEL_LOW);
    R_BSP_PinAccessDisable();
}

void displayApp2Background()
{
    R_GLCDC_Open(g_display0.p_ctrl, g_display0.p_cfg);
    R_GLCDC_Start(g_display0.p_ctrl);

    // Get framebuffer pointer
    unsigned char *fb = fb_background[0];

    //Set white background (memset framebuffer to 255)
    const int width = APP_IMG_WIDTH;
    const int height = APP_IMG_HEIGHT;
    const int bpp = 2;
    memset((void *) fb, 255, width * height * bpp);

    //Copy the content of bg_image to the framebuffer line by line
    const unsigned int h_offset = ((height - BG_IMG_HEIGHT) / 2) * width * bpp;
    const unsigned int w_offset = ((width - BG_IMG_WIDTH) / 2) * bpp;
    for (int i = 0; i < BG_IMG_HEIGHT; ++i) {
        unsigned char *dst = fb + h_offset + w_offset + i * width * bpp;
        unsigned char *src = &bg_image[i * BG_IMG_WIDTH * bpp];
        memcpy((void *) dst, (void *) src, BG_IMG_WIDTH * bpp);
    }

    R_GLCDC_BufferChange(&g_display0.p_ctrl, fb, DISPLAY_FRAME_LAYER_1);
}