GR-MANGO sample using mbed-os library from my repository.

Dependencies:   mbed-http

Committer:
RyoheiHagimoto
Date:
Mon Oct 12 02:25:49 2020 +0000
Revision:
0:b4c1e32627f2
replaced mbed-os library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RyoheiHagimoto 0:b4c1e32627f2 1 /*******************************************************************************
RyoheiHagimoto 0:b4c1e32627f2 2 * DISCLAIMER
RyoheiHagimoto 0:b4c1e32627f2 3 * This software is supplied by Renesas Electronics Corporation and is only
RyoheiHagimoto 0:b4c1e32627f2 4 * intended for use with Renesas products. No other uses are authorized. This
RyoheiHagimoto 0:b4c1e32627f2 5 * software is owned by Renesas Electronics Corporation and is protected under
RyoheiHagimoto 0:b4c1e32627f2 6 * all applicable laws, including copyright laws.
RyoheiHagimoto 0:b4c1e32627f2 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
RyoheiHagimoto 0:b4c1e32627f2 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
RyoheiHagimoto 0:b4c1e32627f2 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
RyoheiHagimoto 0:b4c1e32627f2 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
RyoheiHagimoto 0:b4c1e32627f2 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
RyoheiHagimoto 0:b4c1e32627f2 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
RyoheiHagimoto 0:b4c1e32627f2 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
RyoheiHagimoto 0:b4c1e32627f2 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
RyoheiHagimoto 0:b4c1e32627f2 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
RyoheiHagimoto 0:b4c1e32627f2 16 * Renesas reserves the right, without notice, to make changes to this software
RyoheiHagimoto 0:b4c1e32627f2 17 * and to discontinue the availability of this software. By using this software,
RyoheiHagimoto 0:b4c1e32627f2 18 * you agree to the additional terms and conditions found by accessing the
RyoheiHagimoto 0:b4c1e32627f2 19 * following link:
RyoheiHagimoto 0:b4c1e32627f2 20 * http://www.renesas.com/disclaimer
RyoheiHagimoto 0:b4c1e32627f2 21 *
RyoheiHagimoto 0:b4c1e32627f2 22 * Copyright (C) 2019 Renesas Electronics Corporation. All rights reserved.
RyoheiHagimoto 0:b4c1e32627f2 23 *******************************************************************************/
RyoheiHagimoto 0:b4c1e32627f2 24 #include "sample_select.h"
RyoheiHagimoto 0:b4c1e32627f2 25
RyoheiHagimoto 0:b4c1e32627f2 26 #if (SAMPLE_PROGRAM_NO == 17)
RyoheiHagimoto 0:b4c1e32627f2 27 // SAMPLE_PROGRAM_NO 17 : USBMSD and FlashAPI sample advanced version
RyoheiHagimoto 0:b4c1e32627f2 28 //
RyoheiHagimoto 0:b4c1e32627f2 29 // USBMSD and FlashAPI sample advanced version
RyoheiHagimoto 0:b4c1e32627f2 30 // It is a sample program that can read and write serial flash from the PC via Filesystem.
RyoheiHagimoto 0:b4c1e32627f2 31 // By connecting the board and the PC with a USB cable, you can refer inside the device as a mass storage device.
RyoheiHagimoto 0:b4c1e32627f2 32 // (The format is required when connecting for the first time.)
RyoheiHagimoto 0:b4c1e32627f2 33 // When you write a JPEG file (.jpg) from the PC to the storage, the image is displayed.
RyoheiHagimoto 0:b4c1e32627f2 34 // By pressing SW3, change the save destination to heap memory.
RyoheiHagimoto 0:b4c1e32627f2 35 // [Attention!] Delete the "OVERRIDE_CONSOLE_USBSERIAL" macro in "mbed_app.json" file if it is set.
RyoheiHagimoto 0:b4c1e32627f2 36
RyoheiHagimoto 0:b4c1e32627f2 37 #include "mbed.h"
RyoheiHagimoto 0:b4c1e32627f2 38 #include "USBMSD.h"
RyoheiHagimoto 0:b4c1e32627f2 39 #include "ObservingBlockDevice.h"
RyoheiHagimoto 0:b4c1e32627f2 40 #include "FlashIAPBlockDevice.h"
RyoheiHagimoto 0:b4c1e32627f2 41 #include "mbed_drv_cfg.h"
RyoheiHagimoto 0:b4c1e32627f2 42 #include "HeapBlockDevice.h"
RyoheiHagimoto 0:b4c1e32627f2 43 #include "dcache-control.h"
RyoheiHagimoto 0:b4c1e32627f2 44 #include "EasyAttach_CameraAndLCD.h"
RyoheiHagimoto 0:b4c1e32627f2 45 #include "FATFileSystem.h"
RyoheiHagimoto 0:b4c1e32627f2 46 #include "JPEG_Converter.h"
RyoheiHagimoto 0:b4c1e32627f2 47
RyoheiHagimoto 0:b4c1e32627f2 48 #define FILE_NAME_LEN (64)
RyoheiHagimoto 0:b4c1e32627f2 49 #define FRAME_BUFFER_STRIDE (((LCD_PIXEL_WIDTH * 2) + 31u) & ~31u)
RyoheiHagimoto 0:b4c1e32627f2 50 #define FRAME_BUFFER_HEIGHT (LCD_PIXEL_HEIGHT)
RyoheiHagimoto 0:b4c1e32627f2 51
RyoheiHagimoto 0:b4c1e32627f2 52 static uint8_t user_frame_buffer0[FRAME_BUFFER_STRIDE * FRAME_BUFFER_HEIGHT]__attribute((aligned(32)));
RyoheiHagimoto 0:b4c1e32627f2 53 static uint8_t JpegBuffer[1024 * 128]__attribute((aligned(32)));
RyoheiHagimoto 0:b4c1e32627f2 54 DisplayBase Display;
RyoheiHagimoto 0:b4c1e32627f2 55
RyoheiHagimoto 0:b4c1e32627f2 56 typedef enum {
RyoheiHagimoto 0:b4c1e32627f2 57 BD_FLASHIAP,
RyoheiHagimoto 0:b4c1e32627f2 58 BD_HEAP,
RyoheiHagimoto 0:b4c1e32627f2 59 BD_NUM
RyoheiHagimoto 0:b4c1e32627f2 60 } bd_type_t;
RyoheiHagimoto 0:b4c1e32627f2 61
RyoheiHagimoto 0:b4c1e32627f2 62 static FlashIAPBlockDevice flashiap_bd(FLASH_BASE + 0x100000, FLASH_SIZE - 0x100000);
RyoheiHagimoto 0:b4c1e32627f2 63 static HeapBlockDevice heap_bd(0x100000);
RyoheiHagimoto 0:b4c1e32627f2 64
RyoheiHagimoto 0:b4c1e32627f2 65 static BlockDevice * base_bd[BD_NUM] = {
RyoheiHagimoto 0:b4c1e32627f2 66 &flashiap_bd, // BD_FLASHIAP
RyoheiHagimoto 0:b4c1e32627f2 67 &heap_bd // BD_HEAP
RyoheiHagimoto 0:b4c1e32627f2 68 };
RyoheiHagimoto 0:b4c1e32627f2 69
RyoheiHagimoto 0:b4c1e32627f2 70 static const char * base_bd_str[BD_NUM] = {
RyoheiHagimoto 0:b4c1e32627f2 71 "FlashIAP", // BD_FLASHIAP
RyoheiHagimoto 0:b4c1e32627f2 72 "Heap" // BD_HEAP
RyoheiHagimoto 0:b4c1e32627f2 73 };
RyoheiHagimoto 0:b4c1e32627f2 74
RyoheiHagimoto 0:b4c1e32627f2 75 static InterruptIn storage_btn(USER_BUTTON0);
RyoheiHagimoto 0:b4c1e32627f2 76 static int tmp_bd_index = 0;
RyoheiHagimoto 0:b4c1e32627f2 77 static int bd_index = -1;
RyoheiHagimoto 0:b4c1e32627f2 78 static bool storage_change_flg = false;
RyoheiHagimoto 0:b4c1e32627f2 79 static Timer storage_change_timer;
RyoheiHagimoto 0:b4c1e32627f2 80 static FATFileSystem * p_fs = NULL;
RyoheiHagimoto 0:b4c1e32627f2 81 static ObservingBlockDevice * p_observing_bd = NULL;
RyoheiHagimoto 0:b4c1e32627f2 82 static USBMSD * p_usb = NULL;
RyoheiHagimoto 0:b4c1e32627f2 83 static Thread msdTask(osPriorityAboveNormal);
RyoheiHagimoto 0:b4c1e32627f2 84 static Semaphore usb_sem(0);
RyoheiHagimoto 0:b4c1e32627f2 85 static bool heap_bd_format = false;
RyoheiHagimoto 0:b4c1e32627f2 86 static bool image_disp = false;
RyoheiHagimoto 0:b4c1e32627f2 87
RyoheiHagimoto 0:b4c1e32627f2 88 // Function prototypes
RyoheiHagimoto 0:b4c1e32627f2 89 static void msd_task(void);
RyoheiHagimoto 0:b4c1e32627f2 90 static void storage_change(BlockDevice * p_bd);
RyoheiHagimoto 0:b4c1e32627f2 91 static void chk_storage_change(void);
RyoheiHagimoto 0:b4c1e32627f2 92 static void chk_bd_change(void);
RyoheiHagimoto 0:b4c1e32627f2 93 static void storage_btn_fall(void);
RyoheiHagimoto 0:b4c1e32627f2 94 static void clear_display(void);
RyoheiHagimoto 0:b4c1e32627f2 95 static void Start_LCD_Display(void);
RyoheiHagimoto 0:b4c1e32627f2 96
RyoheiHagimoto 0:b4c1e32627f2 97 static void usb_callback_func(void) {
RyoheiHagimoto 0:b4c1e32627f2 98 usb_sem.release();
RyoheiHagimoto 0:b4c1e32627f2 99 }
RyoheiHagimoto 0:b4c1e32627f2 100
RyoheiHagimoto 0:b4c1e32627f2 101 static void msd_task(void) {
RyoheiHagimoto 0:b4c1e32627f2 102 while (true) {
RyoheiHagimoto 0:b4c1e32627f2 103 usb_sem.acquire();
RyoheiHagimoto 0:b4c1e32627f2 104 if (p_usb != NULL) {
RyoheiHagimoto 0:b4c1e32627f2 105 p_usb->process();
RyoheiHagimoto 0:b4c1e32627f2 106 }
RyoheiHagimoto 0:b4c1e32627f2 107 }
RyoheiHagimoto 0:b4c1e32627f2 108 }
RyoheiHagimoto 0:b4c1e32627f2 109
RyoheiHagimoto 0:b4c1e32627f2 110 static void storage_change(BlockDevice * p_bd) {
RyoheiHagimoto 0:b4c1e32627f2 111 storage_change_flg = true;
RyoheiHagimoto 0:b4c1e32627f2 112 storage_change_timer.reset();
RyoheiHagimoto 0:b4c1e32627f2 113 storage_change_timer.start();
RyoheiHagimoto 0:b4c1e32627f2 114 if (image_disp) {
RyoheiHagimoto 0:b4c1e32627f2 115 clear_display();
RyoheiHagimoto 0:b4c1e32627f2 116 image_disp = false;
RyoheiHagimoto 0:b4c1e32627f2 117 }
RyoheiHagimoto 0:b4c1e32627f2 118 }
RyoheiHagimoto 0:b4c1e32627f2 119
RyoheiHagimoto 0:b4c1e32627f2 120 static void chk_storage_change(void) {
RyoheiHagimoto 0:b4c1e32627f2 121 if (!storage_change_flg) {
RyoheiHagimoto 0:b4c1e32627f2 122 return;
RyoheiHagimoto 0:b4c1e32627f2 123 }
RyoheiHagimoto 0:b4c1e32627f2 124
RyoheiHagimoto 0:b4c1e32627f2 125 // wait storage change
RyoheiHagimoto 0:b4c1e32627f2 126 while (storage_change_timer.read_ms() < 1000) {
RyoheiHagimoto 0:b4c1e32627f2 127 ThisThread::sleep_for(100);
RyoheiHagimoto 0:b4c1e32627f2 128 }
RyoheiHagimoto 0:b4c1e32627f2 129 storage_change_timer.stop();
RyoheiHagimoto 0:b4c1e32627f2 130 storage_change_timer.reset();
RyoheiHagimoto 0:b4c1e32627f2 131 storage_change_flg = false;
RyoheiHagimoto 0:b4c1e32627f2 132
RyoheiHagimoto 0:b4c1e32627f2 133 p_fs->unmount();
RyoheiHagimoto 0:b4c1e32627f2 134 chk_bd_change();
RyoheiHagimoto 0:b4c1e32627f2 135 p_fs->mount(base_bd[bd_index]);
RyoheiHagimoto 0:b4c1e32627f2 136 }
RyoheiHagimoto 0:b4c1e32627f2 137
RyoheiHagimoto 0:b4c1e32627f2 138 static void chk_bd_change(void) {
RyoheiHagimoto 0:b4c1e32627f2 139 if (bd_index == tmp_bd_index) {
RyoheiHagimoto 0:b4c1e32627f2 140 return;
RyoheiHagimoto 0:b4c1e32627f2 141 }
RyoheiHagimoto 0:b4c1e32627f2 142 if (p_usb != NULL) {
RyoheiHagimoto 0:b4c1e32627f2 143 USBMSD * wk = p_usb;
RyoheiHagimoto 0:b4c1e32627f2 144 p_usb = NULL;
RyoheiHagimoto 0:b4c1e32627f2 145 delete wk;
RyoheiHagimoto 0:b4c1e32627f2 146 }
RyoheiHagimoto 0:b4c1e32627f2 147 if (p_observing_bd != NULL) {
RyoheiHagimoto 0:b4c1e32627f2 148 delete p_observing_bd;
RyoheiHagimoto 0:b4c1e32627f2 149 }
RyoheiHagimoto 0:b4c1e32627f2 150 if (p_fs != NULL) {
RyoheiHagimoto 0:b4c1e32627f2 151 delete p_fs;
RyoheiHagimoto 0:b4c1e32627f2 152 }
RyoheiHagimoto 0:b4c1e32627f2 153 bd_index = tmp_bd_index;
RyoheiHagimoto 0:b4c1e32627f2 154 printf("\r\nconnecting %s\r\n", base_bd_str[bd_index]);
RyoheiHagimoto 0:b4c1e32627f2 155 if (bd_index == BD_HEAP) {
RyoheiHagimoto 0:b4c1e32627f2 156 if (!heap_bd_format) {
RyoheiHagimoto 0:b4c1e32627f2 157 FATFileSystem::format(&heap_bd);
RyoheiHagimoto 0:b4c1e32627f2 158 heap_bd_format = true;
RyoheiHagimoto 0:b4c1e32627f2 159 }
RyoheiHagimoto 0:b4c1e32627f2 160 }
RyoheiHagimoto 0:b4c1e32627f2 161 p_fs = new FATFileSystem(base_bd_str[bd_index]);
RyoheiHagimoto 0:b4c1e32627f2 162 p_observing_bd = new ObservingBlockDevice(base_bd[bd_index]);
RyoheiHagimoto 0:b4c1e32627f2 163 p_observing_bd->attach(&storage_change);
RyoheiHagimoto 0:b4c1e32627f2 164 p_usb = new USBMSD(p_observing_bd);
RyoheiHagimoto 0:b4c1e32627f2 165 p_usb->attach(&usb_callback_func);
RyoheiHagimoto 0:b4c1e32627f2 166 }
RyoheiHagimoto 0:b4c1e32627f2 167
RyoheiHagimoto 0:b4c1e32627f2 168 static void storage_btn_fall(void) {
RyoheiHagimoto 0:b4c1e32627f2 169 if ((tmp_bd_index + 1) < BD_NUM) {
RyoheiHagimoto 0:b4c1e32627f2 170 tmp_bd_index++;
RyoheiHagimoto 0:b4c1e32627f2 171 } else {
RyoheiHagimoto 0:b4c1e32627f2 172 tmp_bd_index = 0;
RyoheiHagimoto 0:b4c1e32627f2 173 }
RyoheiHagimoto 0:b4c1e32627f2 174 storage_change(NULL);
RyoheiHagimoto 0:b4c1e32627f2 175 }
RyoheiHagimoto 0:b4c1e32627f2 176
RyoheiHagimoto 0:b4c1e32627f2 177 static void clear_display(void) {
RyoheiHagimoto 0:b4c1e32627f2 178 // Initialize the background to black
RyoheiHagimoto 0:b4c1e32627f2 179 for (uint32_t i = 0; i < sizeof(user_frame_buffer0); i += 2) {
RyoheiHagimoto 0:b4c1e32627f2 180 user_frame_buffer0[i + 0] = 0x00;
RyoheiHagimoto 0:b4c1e32627f2 181 user_frame_buffer0[i + 1] = 0x80;
RyoheiHagimoto 0:b4c1e32627f2 182 }
RyoheiHagimoto 0:b4c1e32627f2 183 dcache_clean(user_frame_buffer0, sizeof(user_frame_buffer0));
RyoheiHagimoto 0:b4c1e32627f2 184 }
RyoheiHagimoto 0:b4c1e32627f2 185
RyoheiHagimoto 0:b4c1e32627f2 186 static void Start_LCD_Display(void) {
RyoheiHagimoto 0:b4c1e32627f2 187 DisplayBase::rect_t rect;
RyoheiHagimoto 0:b4c1e32627f2 188
RyoheiHagimoto 0:b4c1e32627f2 189 rect.vs = 0;
RyoheiHagimoto 0:b4c1e32627f2 190 rect.vw = LCD_PIXEL_HEIGHT;
RyoheiHagimoto 0:b4c1e32627f2 191 rect.hs = 0;
RyoheiHagimoto 0:b4c1e32627f2 192 rect.hw = LCD_PIXEL_WIDTH;
RyoheiHagimoto 0:b4c1e32627f2 193 Display.Graphics_Read_Setting(
RyoheiHagimoto 0:b4c1e32627f2 194 DisplayBase::GRAPHICS_LAYER_0,
RyoheiHagimoto 0:b4c1e32627f2 195 (void *)user_frame_buffer0,
RyoheiHagimoto 0:b4c1e32627f2 196 FRAME_BUFFER_STRIDE,
RyoheiHagimoto 0:b4c1e32627f2 197 DisplayBase::GRAPHICS_FORMAT_YCBCR422,
RyoheiHagimoto 0:b4c1e32627f2 198 DisplayBase::WR_RD_WRSWA_32_16BIT,
RyoheiHagimoto 0:b4c1e32627f2 199 &rect
RyoheiHagimoto 0:b4c1e32627f2 200 );
RyoheiHagimoto 0:b4c1e32627f2 201 Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0);
RyoheiHagimoto 0:b4c1e32627f2 202
RyoheiHagimoto 0:b4c1e32627f2 203 ThisThread::sleep_for(50);
RyoheiHagimoto 0:b4c1e32627f2 204 EasyAttach_LcdBacklight(true);
RyoheiHagimoto 0:b4c1e32627f2 205 }
RyoheiHagimoto 0:b4c1e32627f2 206
RyoheiHagimoto 0:b4c1e32627f2 207 int main() {
RyoheiHagimoto 0:b4c1e32627f2 208 FILE * fp;
RyoheiHagimoto 0:b4c1e32627f2 209 DIR * d;
RyoheiHagimoto 0:b4c1e32627f2 210 struct dirent * p;
RyoheiHagimoto 0:b4c1e32627f2 211 char file_path[10 + FILE_NAME_LEN];
RyoheiHagimoto 0:b4c1e32627f2 212 int file_num;
RyoheiHagimoto 0:b4c1e32627f2 213 JPEG_Converter Jcu;
RyoheiHagimoto 0:b4c1e32627f2 214 long file_size;
RyoheiHagimoto 0:b4c1e32627f2 215
RyoheiHagimoto 0:b4c1e32627f2 216 clear_display();
RyoheiHagimoto 0:b4c1e32627f2 217 EasyAttach_Init(Display);
RyoheiHagimoto 0:b4c1e32627f2 218 Start_LCD_Display();
RyoheiHagimoto 0:b4c1e32627f2 219
RyoheiHagimoto 0:b4c1e32627f2 220 // Start usb task
RyoheiHagimoto 0:b4c1e32627f2 221 msdTask.start(&msd_task);
RyoheiHagimoto 0:b4c1e32627f2 222
RyoheiHagimoto 0:b4c1e32627f2 223 // Set BlockDevice
RyoheiHagimoto 0:b4c1e32627f2 224 chk_bd_change();
RyoheiHagimoto 0:b4c1e32627f2 225 p_fs->mount(base_bd[bd_index]);
RyoheiHagimoto 0:b4c1e32627f2 226
RyoheiHagimoto 0:b4c1e32627f2 227 // Button setting
RyoheiHagimoto 0:b4c1e32627f2 228 storage_btn.fall(&storage_btn_fall);
RyoheiHagimoto 0:b4c1e32627f2 229
RyoheiHagimoto 0:b4c1e32627f2 230 while (true) {
RyoheiHagimoto 0:b4c1e32627f2 231 // Confirm storage change
RyoheiHagimoto 0:b4c1e32627f2 232 chk_storage_change();
RyoheiHagimoto 0:b4c1e32627f2 233
RyoheiHagimoto 0:b4c1e32627f2 234 // File search
RyoheiHagimoto 0:b4c1e32627f2 235 file_num = 0;
RyoheiHagimoto 0:b4c1e32627f2 236 sprintf(file_path, "/%s/", base_bd_str[bd_index]);
RyoheiHagimoto 0:b4c1e32627f2 237 d = opendir(file_path);
RyoheiHagimoto 0:b4c1e32627f2 238 if (d != NULL) {
RyoheiHagimoto 0:b4c1e32627f2 239 while ((p = readdir(d)) != NULL) {
RyoheiHagimoto 0:b4c1e32627f2 240 size_t len = strlen(p->d_name);
RyoheiHagimoto 0:b4c1e32627f2 241 if (len < FILE_NAME_LEN) {
RyoheiHagimoto 0:b4c1e32627f2 242 // Make file path
RyoheiHagimoto 0:b4c1e32627f2 243 sprintf(file_path, "/%s/%s", base_bd_str[bd_index], p->d_name);
RyoheiHagimoto 0:b4c1e32627f2 244 printf("%s\r\n", file_path);
RyoheiHagimoto 0:b4c1e32627f2 245
RyoheiHagimoto 0:b4c1e32627f2 246 char *extension = strstr(file_path, ".");
RyoheiHagimoto 0:b4c1e32627f2 247 if ((extension != NULL) && (memcmp(extension, ".jpg", 4) == 0)) {
RyoheiHagimoto 0:b4c1e32627f2 248 fp = fopen(file_path, "rb");
RyoheiHagimoto 0:b4c1e32627f2 249 if (fp != NULL) {
RyoheiHagimoto 0:b4c1e32627f2 250 fseek(fp, 0, SEEK_END);
RyoheiHagimoto 0:b4c1e32627f2 251 file_size = ftell(fp);
RyoheiHagimoto 0:b4c1e32627f2 252 fseek(fp, 0, SEEK_SET);
RyoheiHagimoto 0:b4c1e32627f2 253 if (file_size <= (long)sizeof(JpegBuffer)) {
RyoheiHagimoto 0:b4c1e32627f2 254 JPEG_Converter::bitmap_buff_info_t bitmap_buff_info;
RyoheiHagimoto 0:b4c1e32627f2 255 JPEG_Converter::decode_options_t decode_options;
RyoheiHagimoto 0:b4c1e32627f2 256
RyoheiHagimoto 0:b4c1e32627f2 257 bitmap_buff_info.width = LCD_PIXEL_WIDTH;
RyoheiHagimoto 0:b4c1e32627f2 258 bitmap_buff_info.height = LCD_PIXEL_HEIGHT;
RyoheiHagimoto 0:b4c1e32627f2 259 bitmap_buff_info.format = JPEG_Converter::WR_RD_YCbCr422;
RyoheiHagimoto 0:b4c1e32627f2 260 bitmap_buff_info.buffer_address = (void *)user_frame_buffer0;
RyoheiHagimoto 0:b4c1e32627f2 261
RyoheiHagimoto 0:b4c1e32627f2 262 decode_options.output_swapsetting = JPEG_Converter::WR_RD_WRSWA_32_16_8BIT;
RyoheiHagimoto 0:b4c1e32627f2 263
RyoheiHagimoto 0:b4c1e32627f2 264 setvbuf(fp, NULL, _IONBF, 0); // unbuffered
RyoheiHagimoto 0:b4c1e32627f2 265 fread(JpegBuffer, sizeof(char), file_size, fp);
RyoheiHagimoto 0:b4c1e32627f2 266 dcache_clean(JpegBuffer, file_size);
RyoheiHagimoto 0:b4c1e32627f2 267
RyoheiHagimoto 0:b4c1e32627f2 268 if (Jcu.decode((void *)JpegBuffer, &bitmap_buff_info, &decode_options) == JPEG_Converter::JPEG_CONV_OK) {
RyoheiHagimoto 0:b4c1e32627f2 269 image_disp = true;
RyoheiHagimoto 0:b4c1e32627f2 270 file_num++;
RyoheiHagimoto 0:b4c1e32627f2 271 } else {
RyoheiHagimoto 0:b4c1e32627f2 272 printf("Decode error.\r\n");
RyoheiHagimoto 0:b4c1e32627f2 273 }
RyoheiHagimoto 0:b4c1e32627f2 274 } else {
RyoheiHagimoto 0:b4c1e32627f2 275 printf("File size over.\r\n");
RyoheiHagimoto 0:b4c1e32627f2 276 }
RyoheiHagimoto 0:b4c1e32627f2 277 fclose(fp);
RyoheiHagimoto 0:b4c1e32627f2 278
RyoheiHagimoto 0:b4c1e32627f2 279 for (int i = 0; (i < 50) && (storage_change_flg == false); i++) {
RyoheiHagimoto 0:b4c1e32627f2 280 ThisThread::sleep_for(100);
RyoheiHagimoto 0:b4c1e32627f2 281 }
RyoheiHagimoto 0:b4c1e32627f2 282 } else {
RyoheiHagimoto 0:b4c1e32627f2 283 printf("File open error.\r\n");
RyoheiHagimoto 0:b4c1e32627f2 284 }
RyoheiHagimoto 0:b4c1e32627f2 285 }
RyoheiHagimoto 0:b4c1e32627f2 286 }
RyoheiHagimoto 0:b4c1e32627f2 287 if (storage_change_flg) {
RyoheiHagimoto 0:b4c1e32627f2 288 clear_display();
RyoheiHagimoto 0:b4c1e32627f2 289 break;
RyoheiHagimoto 0:b4c1e32627f2 290 }
RyoheiHagimoto 0:b4c1e32627f2 291 }
RyoheiHagimoto 0:b4c1e32627f2 292 closedir(d);
RyoheiHagimoto 0:b4c1e32627f2 293 }
RyoheiHagimoto 0:b4c1e32627f2 294
RyoheiHagimoto 0:b4c1e32627f2 295 // If there is no files, wait until the storage is changed
RyoheiHagimoto 0:b4c1e32627f2 296 if ((file_num == 0) && (!storage_change_flg)) {
RyoheiHagimoto 0:b4c1e32627f2 297 printf("No files\r\n");
RyoheiHagimoto 0:b4c1e32627f2 298 while (!storage_change_flg) {
RyoheiHagimoto 0:b4c1e32627f2 299 ThisThread::sleep_for(100);
RyoheiHagimoto 0:b4c1e32627f2 300 }
RyoheiHagimoto 0:b4c1e32627f2 301 }
RyoheiHagimoto 0:b4c1e32627f2 302 }
RyoheiHagimoto 0:b4c1e32627f2 303 }
RyoheiHagimoto 0:b4c1e32627f2 304
RyoheiHagimoto 0:b4c1e32627f2 305 #endif