Example programs for GR-MANGO
Dependencies: opencv-lib mbed-http
This is a collection of sample programs that work on RZ/A2M boards. You can try Mbed OS for RZ/A2M with GR-MANGO board.
Overview
Sample program files are located under the sample_programs
folder.
You can try each sample program by changing the following macro in sample_select.h
.
insample_select.h
#define SAMPLE_PROGRAM_NO 0
No. | Program file | Description |
---|---|---|
0 | sample_00_led_rtc_analogin.cpp | DigitalOut, InterruptIn, RTC, Timer and AnalogIn |
1 | sample_01_flash_write.cpp | FlashAPI sample |
2 | sample_02_ssif_loop_back.cpp | SSIF loop back sample |
4 | sample_04_ssif_wav_playback.cpp | SSIF wav playback sample (use USB memory or SD card) |
7 | sample_07_usb_func_serial.cpp | USBSerial (CDC) sample |
8 | sample_08_usb_func_mouse.cpp | USBMouse sample |
9 | sample_09_usb_func_keyboard.cpp | USBKeyboard sample |
10 | sample_10_usb_func_midi.cpp | USBMIDI sample |
11 | sample_11_usb_func_audio_1.cpp | USBAudio sample |
12 | sample_12_usb_func_audio_2.cpp | USBAudio and SSIF sample |
13 | sample_13_ether_http.cpp | Ether HTTP sample |
14 | sample_14_ether_https.cpp | Ether HTTPS sample |
16 | sample_16_usb_func_msd_1.cpp | USBMSD and FlashAPI sample |
17 | sample_17_usb_func_msd_2.cpp | USBMSD and FlashAPI sample advanced version |
18 | sample_18_mipi_drp_lcd.cpp | MIPI, DRP and LCD sample |
19 | sample_19_mipi_drp_diplayapp.cpp | MIPI, DRP and USBSerial (CDC) sample (use "DisplayApp") |
20 | sample_20_drp_dynamic_loading.cpp | DRP Dynamic Loading Sample |
21 | sample_21_deep_standby_alarm.cpp | Deep standby and RTC alarm sample |
22 | sample_22_hdmi_disp_ssif.cpp | HDMI output and SSIF wav playback Sample |
23 | sample_23_mipi_hdmi.cpp | HDMI output and MIPI Sample |
24 | sample_24_facedetection.cpp | HDMI output and face detection using OpenCV |
25 | sample_25_hdmi_mouse.cpp | HDMI output and Mouse Sample |
Notice
sample_24_facedetection.cpp
only can be compiled with GNU Compiler Collection.
About sample_24_facedetection.cpp
, this is a demonstration that can detect the face of a person without a mask. It will surround the face of a person without a mask with a red rectangle and sound alarm at the same time. To use OpenCV for face recognition, you need to prepare the followings:
・USB drive or SD card
・ Raspberry Pi Camera Module V2
・ HDMI monitor
Perform the following steps to complete face recognition sample.
1. Copy the lbpcascade_frontalface.xml to the root folder of USB drive or SD card and save it.
2. Copy the alarm.wav to the root folder of USB drive or SD card and save it.
3. Set "camera-type" value to "CAMERA_RASPBERRY_PI_832X480" in mbed_app.json
About custom boot loaders
This sample uses custom bootloader
revision 5
, and you can drag & drop the "xxxx_application.bin" file to write the program. Please see here for the detail.
How to write program
When using DAPLink
, please use xxxx.bin
as following.
- Connect the
micro USB type B terminal
to the PC using a USB cable. - You can find the
MBED
directory. - Drag & drop
xxxx.bin
to theMBED
directory. - When writing is completed, press the reset button.
When using custom bootloader
, please use xxxx_application.bin
as following.
- Connect the
USB type C terminal
to the PC using a USB cable. - Hold down
USB0
and press the reset button. - You can find the
GR-MANG
directory. - Drag & drop xxxx_application.bin to the GR-MANGO directory.
When writing is completed, press the reset button.
Attention!
For the first time only, you need to write a custom bootloader
using DAPLink
.
Terminal setting
If you want to confirm the serial communication the terminal soft on your PC, please specify the below values.
You can change the baud rate by platform.stio-baud-rate
of mbed_app.json
.
Baud rate | 115,200 |
Data | 8bit |
Parity | none |
Stop | 1bit |
Flow control | none |
sample_programs/sample_17_usb_func_msd_2.cpp@16:f4798796b4a2, 2021-03-04 (annotated)
- Committer:
- luyao@os.mbed.com
- Date:
- Thu Mar 04 18:22:21 2021 +0900
- Revision:
- 16:f4798796b4a2
- Parent:
- 4:2da9e0f275a1
Modified EP952 Parameters.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 1 | /******************************************************************************* |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 2 | * DISCLAIMER |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 3 | * This software is supplied by Renesas Electronics Corporation and is only |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 4 | * intended for use with Renesas products. No other uses are authorized. This |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 5 | * software is owned by Renesas Electronics Corporation and is protected under |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 6 | * all applicable laws, including copyright laws. |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 7 | * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 8 | * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 9 | * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 10 | * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 11 | * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 12 | * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 13 | * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 14 | * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 15 | * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 16 | * Renesas reserves the right, without notice, to make changes to this software |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 17 | * and to discontinue the availability of this software. By using this software, |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 18 | * you agree to the additional terms and conditions found by accessing the |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 19 | * following link: |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 20 | * http://www.renesas.com/disclaimer |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 21 | * |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 22 | * Copyright (C) 2019 Renesas Electronics Corporation. All rights reserved. |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 23 | *******************************************************************************/ |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 24 | #include "sample_select.h" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 25 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 26 | #if (SAMPLE_PROGRAM_NO == 17) |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 27 | // SAMPLE_PROGRAM_NO 17 : USBMSD and FlashAPI sample advanced version |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 28 | // |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 29 | // USBMSD and FlashAPI sample advanced version |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 30 | // It is a sample program that can read and write serial flash from the PC via Filesystem. |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 31 | // By connecting the board and the PC with a USB cable, you can refer inside the device as a mass storage device. |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 32 | // (The format is required when connecting for the first time.) |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 33 | // When you write a JPEG file (.jpg) from the PC to the storage, the image is displayed. |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 34 | // By pressing SW3, change the save destination to heap memory. |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 35 | // [Attention!] Delete the "OVERRIDE_CONSOLE_USBSERIAL" macro in "mbed_app.json" file if it is set. |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 36 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 37 | #include "mbed.h" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 38 | #include "USBMSD.h" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 39 | #include "ObservingBlockDevice.h" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 40 | #include "FlashIAPBlockDevice.h" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 41 | #include "mbed_drv_cfg.h" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 42 | #include "HeapBlockDevice.h" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 43 | #include "dcache-control.h" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 44 | #include "EasyAttach_CameraAndLCD.h" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 45 | #include "FATFileSystem.h" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 46 | #include "JPEG_Converter.h" |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 47 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 48 | #define FILE_NAME_LEN (64) |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 49 | #define FRAME_BUFFER_STRIDE (((LCD_PIXEL_WIDTH * 2) + 31u) & ~31u) |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 50 | #define FRAME_BUFFER_HEIGHT (LCD_PIXEL_HEIGHT) |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 51 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 52 | static uint8_t user_frame_buffer0[FRAME_BUFFER_STRIDE * FRAME_BUFFER_HEIGHT]__attribute((aligned(32))); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 53 | static uint8_t JpegBuffer[1024 * 128]__attribute((aligned(32))); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 54 | DisplayBase Display; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 55 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 56 | typedef enum { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 57 | BD_FLASHIAP, |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 58 | BD_HEAP, |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 59 | BD_NUM |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 60 | } bd_type_t; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 61 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 62 | static FlashIAPBlockDevice flashiap_bd(FLASH_BASE + 0x100000, FLASH_SIZE - 0x100000); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 63 | static HeapBlockDevice heap_bd(0x100000); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 64 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 65 | static BlockDevice * base_bd[BD_NUM] = { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 66 | &flashiap_bd, // BD_FLASHIAP |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 67 | &heap_bd // BD_HEAP |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 68 | }; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 69 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 70 | static const char * base_bd_str[BD_NUM] = { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 71 | "FlashIAP", // BD_FLASHIAP |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 72 | "Heap" // BD_HEAP |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 73 | }; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 74 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 75 | static InterruptIn storage_btn(USER_BUTTON0); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 76 | static int tmp_bd_index = 0; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 77 | static int bd_index = -1; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 78 | static bool storage_change_flg = false; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 79 | static Timer storage_change_timer; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 80 | static FATFileSystem * p_fs = NULL; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 81 | static ObservingBlockDevice * p_observing_bd = NULL; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 82 | static USBMSD * p_usb = NULL; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 83 | static Thread msdTask(osPriorityAboveNormal); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 84 | static Semaphore usb_sem(0); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 85 | static bool heap_bd_format = false; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 86 | static bool image_disp = false; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 87 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 88 | // Function prototypes |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 89 | static void msd_task(void); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 90 | static void storage_change(BlockDevice * p_bd); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 91 | static void chk_storage_change(void); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 92 | static void chk_bd_change(void); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 93 | static void storage_btn_fall(void); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 94 | static void clear_display(void); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 95 | static void Start_LCD_Display(void); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 96 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 97 | static void usb_callback_func(void) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 98 | usb_sem.release(); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 99 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 100 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 101 | static void msd_task(void) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 102 | while (true) { |
RyoheiHagimoto@os.mbed.com | 4:2da9e0f275a1 | 103 | usb_sem.acquire(); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 104 | if (p_usb != NULL) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 105 | p_usb->process(); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 106 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 107 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 108 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 109 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 110 | static void storage_change(BlockDevice * p_bd) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 111 | storage_change_flg = true; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 112 | storage_change_timer.reset(); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 113 | storage_change_timer.start(); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 114 | if (image_disp) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 115 | clear_display(); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 116 | image_disp = false; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 117 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 118 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 119 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 120 | static void chk_storage_change(void) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 121 | if (!storage_change_flg) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 122 | return; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 123 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 124 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 125 | // wait storage change |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 126 | while (storage_change_timer.read_ms() < 1000) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 127 | ThisThread::sleep_for(100); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 128 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 129 | storage_change_timer.stop(); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 130 | storage_change_timer.reset(); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 131 | storage_change_flg = false; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 132 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 133 | p_fs->unmount(); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 134 | chk_bd_change(); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 135 | p_fs->mount(base_bd[bd_index]); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 136 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 137 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 138 | static void chk_bd_change(void) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 139 | if (bd_index == tmp_bd_index) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 140 | return; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 141 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 142 | if (p_usb != NULL) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 143 | USBMSD * wk = p_usb; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 144 | p_usb = NULL; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 145 | delete wk; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 146 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 147 | if (p_observing_bd != NULL) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 148 | delete p_observing_bd; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 149 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 150 | if (p_fs != NULL) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 151 | delete p_fs; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 152 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 153 | bd_index = tmp_bd_index; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 154 | printf("\r\nconnecting %s\r\n", base_bd_str[bd_index]); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 155 | if (bd_index == BD_HEAP) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 156 | if (!heap_bd_format) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 157 | FATFileSystem::format(&heap_bd); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 158 | heap_bd_format = true; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 159 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 160 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 161 | p_fs = new FATFileSystem(base_bd_str[bd_index]); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 162 | p_observing_bd = new ObservingBlockDevice(base_bd[bd_index]); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 163 | p_observing_bd->attach(&storage_change); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 164 | p_usb = new USBMSD(p_observing_bd); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 165 | p_usb->attach(&usb_callback_func); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 166 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 167 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 168 | static void storage_btn_fall(void) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 169 | if ((tmp_bd_index + 1) < BD_NUM) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 170 | tmp_bd_index++; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 171 | } else { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 172 | tmp_bd_index = 0; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 173 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 174 | storage_change(NULL); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 175 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 176 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 177 | static void clear_display(void) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 178 | // Initialize the background to black |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 179 | for (uint32_t i = 0; i < sizeof(user_frame_buffer0); i += 2) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 180 | user_frame_buffer0[i + 0] = 0x00; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 181 | user_frame_buffer0[i + 1] = 0x80; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 182 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 183 | dcache_clean(user_frame_buffer0, sizeof(user_frame_buffer0)); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 184 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 185 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 186 | static void Start_LCD_Display(void) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 187 | DisplayBase::rect_t rect; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 188 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 189 | rect.vs = 0; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 190 | rect.vw = LCD_PIXEL_HEIGHT; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 191 | rect.hs = 0; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 192 | rect.hw = LCD_PIXEL_WIDTH; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 193 | Display.Graphics_Read_Setting( |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 194 | DisplayBase::GRAPHICS_LAYER_0, |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 195 | (void *)user_frame_buffer0, |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 196 | FRAME_BUFFER_STRIDE, |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 197 | DisplayBase::GRAPHICS_FORMAT_YCBCR422, |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 198 | DisplayBase::WR_RD_WRSWA_32_16BIT, |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 199 | &rect |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 200 | ); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 201 | Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 202 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 203 | ThisThread::sleep_for(50); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 204 | EasyAttach_LcdBacklight(true); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 205 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 206 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 207 | int main() { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 208 | FILE * fp; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 209 | DIR * d; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 210 | struct dirent * p; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 211 | char file_path[10 + FILE_NAME_LEN]; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 212 | int file_num; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 213 | JPEG_Converter Jcu; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 214 | long file_size; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 215 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 216 | clear_display(); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 217 | EasyAttach_Init(Display); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 218 | Start_LCD_Display(); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 219 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 220 | // Start usb task |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 221 | msdTask.start(&msd_task); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 222 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 223 | // Set BlockDevice |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 224 | chk_bd_change(); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 225 | p_fs->mount(base_bd[bd_index]); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 226 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 227 | // Button setting |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 228 | storage_btn.fall(&storage_btn_fall); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 229 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 230 | while (true) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 231 | // Confirm storage change |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 232 | chk_storage_change(); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 233 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 234 | // File search |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 235 | file_num = 0; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 236 | sprintf(file_path, "/%s/", base_bd_str[bd_index]); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 237 | d = opendir(file_path); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 238 | if (d != NULL) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 239 | while ((p = readdir(d)) != NULL) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 240 | size_t len = strlen(p->d_name); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 241 | if (len < FILE_NAME_LEN) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 242 | // Make file path |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 243 | sprintf(file_path, "/%s/%s", base_bd_str[bd_index], p->d_name); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 244 | printf("%s\r\n", file_path); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 245 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 246 | char *extension = strstr(file_path, "."); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 247 | if ((extension != NULL) && (memcmp(extension, ".jpg", 4) == 0)) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 248 | fp = fopen(file_path, "rb"); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 249 | if (fp != NULL) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 250 | fseek(fp, 0, SEEK_END); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 251 | file_size = ftell(fp); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 252 | fseek(fp, 0, SEEK_SET); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 253 | if (file_size <= (long)sizeof(JpegBuffer)) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 254 | JPEG_Converter::bitmap_buff_info_t bitmap_buff_info; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 255 | JPEG_Converter::decode_options_t decode_options; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 256 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 257 | bitmap_buff_info.width = LCD_PIXEL_WIDTH; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 258 | bitmap_buff_info.height = LCD_PIXEL_HEIGHT; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 259 | bitmap_buff_info.format = JPEG_Converter::WR_RD_YCbCr422; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 260 | bitmap_buff_info.buffer_address = (void *)user_frame_buffer0; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 261 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 262 | decode_options.output_swapsetting = JPEG_Converter::WR_RD_WRSWA_32_16_8BIT; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 263 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 264 | setvbuf(fp, NULL, _IONBF, 0); // unbuffered |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 265 | fread(JpegBuffer, sizeof(char), file_size, fp); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 266 | dcache_clean(JpegBuffer, file_size); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 267 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 268 | if (Jcu.decode((void *)JpegBuffer, &bitmap_buff_info, &decode_options) == JPEG_Converter::JPEG_CONV_OK) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 269 | image_disp = true; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 270 | file_num++; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 271 | } else { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 272 | printf("Decode error.\r\n"); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 273 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 274 | } else { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 275 | printf("File size over.\r\n"); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 276 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 277 | fclose(fp); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 278 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 279 | for (int i = 0; (i < 50) && (storage_change_flg == false); i++) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 280 | ThisThread::sleep_for(100); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 281 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 282 | } else { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 283 | printf("File open error.\r\n"); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 284 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 285 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 286 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 287 | if (storage_change_flg) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 288 | clear_display(); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 289 | break; |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 290 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 291 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 292 | closedir(d); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 293 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 294 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 295 | // If there is no files, wait until the storage is changed |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 296 | if ((file_num == 0) && (!storage_change_flg)) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 297 | printf("No files\r\n"); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 298 | while (!storage_change_flg) { |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 299 | ThisThread::sleep_for(100); |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 300 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 301 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 302 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 303 | } |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 304 | |
RyoheiHagimoto@os.mbed.com | 1:13d09ce5b51a | 305 | #endif |