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 fileDescription
0sample_00_led_rtc_analogin.cppDigitalOut, InterruptIn, RTC, Timer and AnalogIn
1sample_01_flash_write.cppFlashAPI sample
2sample_02_ssif_loop_back.cppSSIF loop back sample
4sample_04_ssif_wav_playback.cppSSIF wav playback sample (use USB memory or SD card)
7sample_07_usb_func_serial.cppUSBSerial (CDC) sample
8sample_08_usb_func_mouse.cppUSBMouse sample
9sample_09_usb_func_keyboard.cppUSBKeyboard sample
10sample_10_usb_func_midi.cppUSBMIDI sample
11sample_11_usb_func_audio_1.cppUSBAudio sample
12sample_12_usb_func_audio_2.cppUSBAudio and SSIF sample
13sample_13_ether_http.cppEther HTTP sample
14sample_14_ether_https.cppEther HTTPS sample
16sample_16_usb_func_msd_1.cppUSBMSD and FlashAPI sample
17sample_17_usb_func_msd_2.cppUSBMSD and FlashAPI sample advanced version
18sample_18_mipi_drp_lcd.cppMIPI, DRP and LCD sample
19sample_19_mipi_drp_diplayapp.cppMIPI, DRP and USBSerial (CDC) sample (use "DisplayApp")
20sample_20_drp_dynamic_loading.cppDRP Dynamic Loading Sample
21sample_21_deep_standby_alarm.cppDeep standby and RTC alarm sample
22sample_22_hdmi_disp_ssif.cppHDMI output and SSIF wav playback Sample
23sample_23_mipi_hdmi.cppHDMI output and MIPI Sample
24sample_24_facedetection.cppHDMI output and face detection using OpenCV
25sample_25_hdmi_mouse.cppHDMI 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.

  1. Connect the micro USB type B terminal to the PC using a USB cable.
  2. You can find the MBED directory.
  3. Drag & drop xxxx.bin to the MBED directory.
  4. When writing is completed, press the reset button.

When using custom bootloader, please use xxxx_application.bin as following.

  1. Connect the USB type C terminal to the PC using a USB cable.
  2. Hold down USB0 and press the reset button.
  3. You can find the GR-MANG directory.
  4. 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 rate115,200
Data8bit
Paritynone
Stop1bit
Flow controlnone
Committer:
luyao@os.mbed.com
Date:
Thu Mar 04 18:22:21 2021 +0900
Revision:
16:f4798796b4a2
Parent:
1:13d09ce5b51a
Modified EP952 Parameters.

Who changed what in which revision?

UserRevisionLine numberNew 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 == 6)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 27 // SAMPLE_PROGRAM_NO 6 : LCD, Touch panel and JCU sample (use USB memory or SD card)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 28 //
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 29 // Decodes the JPEG file in the USB memory and displays it on the LED.
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 30 // Touch information displays on the JPEG image.
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 31 // Up to 2 touch positions can be recognized at the same time.
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 32
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 33 #if defined(TARGET_SEMB1402) || defined(TARGET_RZ_A2M_SBEV)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 34 #error "LCD is not supported."
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 35 #endif
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 "FATFileSystem.h"
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 39 #include "SdUsbConnect.h"
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 40 #include "dcache-control.h"
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 41 #include "EasyAttach_CameraAndLCD.h"
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 42 #include "JPEG_Converter.h"
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 43
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 44 #define FRAME_BUFFER_STRIDE (((LCD_PIXEL_WIDTH * 2) + 31u) & ~31u)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 45 #define FRAME_BUFFER_HEIGHT (LCD_PIXEL_HEIGHT)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 46
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 47 #define FILE_NAME_LEN (64)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 48 #define MOUNT_NAME "storage"
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 49
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 50 static uint8_t user_frame_buffer0[FRAME_BUFFER_STRIDE * FRAME_BUFFER_HEIGHT]__attribute((aligned(32)));
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 51 static uint8_t JpegBuffer[128 * 1024]__attribute((aligned(32)));
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 52
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 53 DisplayBase Display;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 54
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 55
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 56 #if defined(TouckKey_LCD_shield)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 57
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 58 /* TOUCH BUFFER Parameter GRAPHICS_LAYER_2 */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 59 #define TOUCH_BUFFER_BYTE_PER_PIXEL (2u)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 60 #define TOUCH_BUFFER_STRIDE (((LCD_PIXEL_WIDTH * TOUCH_BUFFER_BYTE_PER_PIXEL) + 31u) & ~31u)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 61
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 62 /* Touch panel parameter */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 63 #define TOUCH_NUM (2u)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 64 #define DRAW_POINT (8)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 65
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 66 static Semaphore sem_touch_int(0);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 67 static uint8_t user_frame_buffer_touch[TOUCH_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32)));
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 68
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 69 static void draw_touch_pos(uint8_t * p_buf, int id, int x, int y) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 70 int idx_base;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 71 int wk_idx;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 72 int i;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 73 int j;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 74 uint8_t coller_pix[TOUCH_BUFFER_BYTE_PER_PIXEL]; /* ARGB4444 */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 75
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 76 /* A coordinate in the upper left is calculated from a central coordinate. */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 77 if ((x - (DRAW_POINT / 2)) >= 0) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 78 x -= (DRAW_POINT / 2);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 79 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 80 if (x > ((int)LCD_PIXEL_WIDTH - DRAW_POINT)) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 81 x = ((int)LCD_PIXEL_WIDTH - DRAW_POINT);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 82 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 83 if ((y - (DRAW_POINT / 2)) >= 0) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 84 y -= (DRAW_POINT / 2);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 85 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 86 if (y > ((int)LCD_PIXEL_HEIGHT - DRAW_POINT)) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 87 y = ((int)LCD_PIXEL_HEIGHT - DRAW_POINT);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 88 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 89 idx_base = (x + ((int)LCD_PIXEL_WIDTH * y)) * TOUCH_BUFFER_BYTE_PER_PIXEL;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 90
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 91 /* Select color */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 92 if (id == 0) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 93 /* Blue */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 94 coller_pix[0] = 0x0F; /* 4:Green 4:Blue */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 95 coller_pix[1] = 0xF0; /* 4:Alpha 4:Red */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 96 } else {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 97 /* Pink */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 98 coller_pix[0] = 0x07; /* 4:Green 4:Blue */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 99 coller_pix[1] = 0xFF; /* 4:Alpha 4:Red */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 100 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 101
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 102 /* Drawing */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 103 for (i = 0; i < DRAW_POINT; i++) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 104 wk_idx = idx_base + ((int)LCD_PIXEL_WIDTH * TOUCH_BUFFER_BYTE_PER_PIXEL * i);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 105 for (j = 0; j < DRAW_POINT; j++) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 106 p_buf[wk_idx++] = coller_pix[0];
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 107 p_buf[wk_idx++] = coller_pix[1];
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 108 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 109 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 110 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 111
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 112 static void touch_int_callback(void) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 113 sem_touch_int.release();
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 114 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 115
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 116 static void touch_task(void) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 117 DisplayBase::rect_t rect;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 118 TouchKey::touch_pos_t touch_pos[TOUCH_NUM];
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 119 int touch_num = 0;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 120 int touch_num_last = 0;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 121 uint32_t i;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 122 #if defined(TARGET_RZ_A1XX)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 123 TouckKey_LCD_shield touch(P4_0, P2_13, I2C_SDA, I2C_SCL);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 124 #elif defined(TARGET_RZ_A2XX)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 125 TouckKey_LCD_shield touch(NC, P5_7, I2C_SDA, I2C_SCL);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 126 #endif
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 127
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 128 /* The layer by which the touch panel location is drawn */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 129 memset(user_frame_buffer_touch, 0, sizeof(user_frame_buffer_touch));
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 130 dcache_clean(user_frame_buffer_touch, sizeof(user_frame_buffer_touch));
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 131 rect.vs = 0;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 132 rect.vw = LCD_PIXEL_HEIGHT;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 133 rect.hs = 0;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 134 rect.hw = LCD_PIXEL_WIDTH;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 135 Display.Graphics_Read_Setting(
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 136 DisplayBase::GRAPHICS_LAYER_2,
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 137 (void *)user_frame_buffer_touch,
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 138 TOUCH_BUFFER_STRIDE,
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 139 DisplayBase::GRAPHICS_FORMAT_ARGB4444,
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 140 DisplayBase::WR_RD_WRSWA_32_16BIT,
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 141 &rect
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 142 );
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 143 Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_2);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 144
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 145 /* Callback setting */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 146 touch.SetCallback(&touch_int_callback);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 147
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 148 /* Reset touch IC */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 149 touch.Reset();
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 150
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 151 while (1) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 152 /* Wait touch event */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 153 sem_touch_int.wait();
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 154
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 155 /* Get touch coordinates */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 156 touch_num = touch.GetCoordinates(TOUCH_NUM, touch_pos);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 157
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 158 /* When it's a new touch, touch frame buffer is initialized */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 159 if ((touch_num != 0) && (touch_num_last == 0)) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 160 memset(user_frame_buffer_touch, 0, sizeof(user_frame_buffer_touch));
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 161 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 162 touch_num_last = touch_num;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 163
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 164 /* Drawing of a touch coordinate */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 165 for (i = 0; i < TOUCH_NUM; i ++) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 166 printf("{valid=%d,x=%lu,y=%lu} ", touch_pos[i].valid, touch_pos[i].x, touch_pos[i].y);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 167 if (touch_pos[i].valid) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 168 draw_touch_pos(user_frame_buffer_touch, i, touch_pos[i].x, touch_pos[i].y);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 169 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 170 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 171 printf("\r\n");
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 172
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 173 /* Data cache clean */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 174 dcache_clean(user_frame_buffer_touch, sizeof(user_frame_buffer_touch));
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 175 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 176 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 177 #endif // TouckKey_LCD_shield
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 178
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 179 static void Start_LCD_Display(void) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 180 DisplayBase::rect_t rect;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 181
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 182 // Initialize the background to black
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 183 for (uint32_t i = 0; i < sizeof(user_frame_buffer0); i += 2) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 184 user_frame_buffer0[i + 0] = 0x00;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 185 user_frame_buffer0[i + 1] = 0x80;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 186 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 187 dcache_clean(user_frame_buffer0, sizeof(user_frame_buffer0));
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[sizeof("/" MOUNT_NAME "/") + FILE_NAME_LEN];
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 212 SdUsbConnect storage(MOUNT_NAME);
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 EasyAttach_Init(Display);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 217 Start_LCD_Display();
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 218
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 219 /* Start touch panel processing */
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 220 #if defined(TouckKey_LCD_shield)
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 221 Thread touchTask;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 222 touchTask.start(callback(touch_task));
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 223 #endif // TouckKey_LCD_shield
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 224
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 225 while (1) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 226 // connect wait
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 227 storage.wait_connect();
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 228
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 229 // file search
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 230 d = opendir("/" MOUNT_NAME "/");
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 231 if (d != NULL) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 232 while ((p = readdir(d)) != NULL) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 233 size_t len = strlen(p->d_name);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 234 if (len < FILE_NAME_LEN) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 235 // make file path
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 236 sprintf(file_path, "/%s/%s", MOUNT_NAME, p->d_name);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 237 printf("%s\r\n", file_path);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 238
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 239 char *extension = strstr(file_path, ".");
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 240 if ((extension != NULL) && (memcmp(extension, ".jpg", 4) == 0)) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 241 fp = fopen(file_path, "rb");
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 242 if (fp != NULL) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 243 fseek(fp, 0, SEEK_END);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 244 file_size = ftell(fp);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 245 fseek(fp, 0, SEEK_SET);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 246 if (file_size <= (long)sizeof(JpegBuffer)) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 247 JPEG_Converter::bitmap_buff_info_t bitmap_buff_info;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 248 JPEG_Converter::decode_options_t decode_options;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 249
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 250 bitmap_buff_info.width = LCD_PIXEL_WIDTH;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 251 bitmap_buff_info.height = LCD_PIXEL_HEIGHT;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 252 bitmap_buff_info.format = JPEG_Converter::WR_RD_YCbCr422;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 253 bitmap_buff_info.buffer_address = (void *)user_frame_buffer0;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 254
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 255 decode_options.output_swapsetting = JPEG_Converter::WR_RD_WRSWA_32_16_8BIT;
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 256
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 257 setvbuf(fp, NULL, _IONBF, 0); // unbuffered
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 258 fread(JpegBuffer, sizeof(char), file_size, fp);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 259 dcache_clean(JpegBuffer, file_size);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 260
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 261 if (Jcu.decode((void *)JpegBuffer, &bitmap_buff_info, &decode_options) == JPEG_Converter::JPEG_CONV_OK) {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 262 printf("Decode ok.\r\n");
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 263 } else {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 264 printf("Decode error.\r\n");
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 265 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 266 } else {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 267 printf("File size over.\r\n");
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 268 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 269 fclose(fp);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 270
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 271 ThisThread::sleep_for(5000);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 272 } else {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 273 printf("File open error.\r\n");
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 274 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 275 } else {
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 276 printf("File skip.\r\n");
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 277 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 278 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 279 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 280 closedir(d);
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 281 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 282 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 283 }
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 284
RyoheiHagimoto@os.mbed.com 1:13d09ce5b51a 285 #endif