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 == 19)
RyoheiHagimoto 0:b4c1e32627f2 27 // SAMPLE_PROGRAM_NO 19 : MIPI, DRP and USBSerial (CDC) sample (use "DisplayApp")
RyoheiHagimoto 0:b4c1e32627f2 28 // If you want to know more about SimpleIsp, please refer to: https://github.com/d-kato/RZ_A2M_WebCamera_MIPI
RyoheiHagimoto 0:b4c1e32627f2 29 //
RyoheiHagimoto 0:b4c1e32627f2 30 // Converts the input image from MIPI camera to YUV image using DRP and outputs to PC display using DisplayApp.
RyoheiHagimoto 0:b4c1e32627f2 31 // DisplayApp (Image display on PC display with USB connection)
RyoheiHagimoto 0:b4c1e32627f2 32 // https://github.com/d-kato/mbed-gr-libs#displayapp-image-display-on-pc-display-with-usb-connection
RyoheiHagimoto 0:b4c1e32627f2 33 // Please refer to the document for details. (RZ_A2M_Mbed\drp-for-mbed\r_drp\doc),
RyoheiHagimoto 0:b4c1e32627f2 34 //
RyoheiHagimoto 0:b4c1e32627f2 35 // Please set the value of "camera-type" in "mbed_app.json" to "CAMERA_RASPBERRY_PI".
RyoheiHagimoto 0:b4c1e32627f2 36 //
RyoheiHagimoto 0:b4c1e32627f2 37 // "camera-type":{
RyoheiHagimoto 0:b4c1e32627f2 38 // "help": "Please see EasyAttach_CameraAndLCD/README.md",
RyoheiHagimoto 0:b4c1e32627f2 39 // "value": "CAMERA_RASPBERRY_PI"
RyoheiHagimoto 0:b4c1e32627f2 40 // },
RyoheiHagimoto 0:b4c1e32627f2 41 // [Attention!] Delete the "OVERRIDE_CONSOLE_USBSERIAL" macro in "mbed_app.json" file if it is set.
RyoheiHagimoto 0:b4c1e32627f2 42
RyoheiHagimoto 0:b4c1e32627f2 43 #if !defined(TARGET_RZ_A2XX)
RyoheiHagimoto 0:b4c1e32627f2 44 #error "DRP and MIPI are not supported."
RyoheiHagimoto 0:b4c1e32627f2 45 #endif
RyoheiHagimoto 0:b4c1e32627f2 46 #if MBED_CONF_APP_CAMERA_TYPE != CAMERA_RASPBERRY_PI
RyoheiHagimoto 0:b4c1e32627f2 47 #error Please set the value of "camera-type" in "mbed_app.json" to "CAMERA_RASPBERRY_PI" and build.
RyoheiHagimoto 0:b4c1e32627f2 48 #endif
RyoheiHagimoto 0:b4c1e32627f2 49
RyoheiHagimoto 0:b4c1e32627f2 50 #include "mbed.h"
RyoheiHagimoto 0:b4c1e32627f2 51 #include "EasyAttach_CameraAndLCD.h"
RyoheiHagimoto 0:b4c1e32627f2 52 #include "AsciiFont.h"
RyoheiHagimoto 0:b4c1e32627f2 53 #include "r_dk2_if.h"
RyoheiHagimoto 0:b4c1e32627f2 54 #include "r_drp_simple_isp.h"
RyoheiHagimoto 0:b4c1e32627f2 55 #include "JPEG_Converter.h"
RyoheiHagimoto 0:b4c1e32627f2 56 #include "DisplayApp.h"
RyoheiHagimoto 0:b4c1e32627f2 57 #include "dcache-control.h"
RyoheiHagimoto 0:b4c1e32627f2 58
RyoheiHagimoto 0:b4c1e32627f2 59 /*! Frame buffer stride: Frame buffer stride should be set to a multiple of 32 or 128
RyoheiHagimoto 0:b4c1e32627f2 60 in accordance with the frame buffer burst transfer mode. */
RyoheiHagimoto 0:b4c1e32627f2 61 #define VIDEO_PIXEL_HW (640)
RyoheiHagimoto 0:b4c1e32627f2 62 #define VIDEO_PIXEL_VW (480)
RyoheiHagimoto 0:b4c1e32627f2 63
RyoheiHagimoto 0:b4c1e32627f2 64 #define FRAME_BUFFER_STRIDE (((VIDEO_PIXEL_HW * 1) + 31u) & ~31u)
RyoheiHagimoto 0:b4c1e32627f2 65 #define FRAME_BUFFER_STRIDE_2 (((VIDEO_PIXEL_HW * 2) + 31u) & ~31u)
RyoheiHagimoto 0:b4c1e32627f2 66 #define FRAME_BUFFER_HEIGHT (VIDEO_PIXEL_VW)
RyoheiHagimoto 0:b4c1e32627f2 67
RyoheiHagimoto 0:b4c1e32627f2 68 #define DRP_FLG_TILE_ALL (R_DK2_TILE_0 | R_DK2_TILE_1 | R_DK2_TILE_2 | R_DK2_TILE_3 | R_DK2_TILE_4 | R_DK2_TILE_5)
RyoheiHagimoto 0:b4c1e32627f2 69 #define DRP_FLG_CAMER_IN (0x00000100)
RyoheiHagimoto 0:b4c1e32627f2 70
RyoheiHagimoto 0:b4c1e32627f2 71 #define WB_DAYLIGHT (0)
RyoheiHagimoto 0:b4c1e32627f2 72 #define WB_CLOUDY (1)
RyoheiHagimoto 0:b4c1e32627f2 73 #define WB_FLUORESCENT (2)
RyoheiHagimoto 0:b4c1e32627f2 74 #define WB_TUNGSTEN (3)
RyoheiHagimoto 0:b4c1e32627f2 75
RyoheiHagimoto 0:b4c1e32627f2 76 static DisplayBase Display;
RyoheiHagimoto 0:b4c1e32627f2 77 static uint8_t fbuf_bayer[FRAME_BUFFER_STRIDE * FRAME_BUFFER_HEIGHT]__attribute((aligned(128)));
RyoheiHagimoto 0:b4c1e32627f2 78 static uint8_t fbuf_yuv[FRAME_BUFFER_STRIDE_2 * FRAME_BUFFER_HEIGHT]__attribute((aligned(32)));
RyoheiHagimoto 0:b4c1e32627f2 79 static uint8_t JpegBuffer[1024 * 64]__attribute((aligned(32)));
RyoheiHagimoto 0:b4c1e32627f2 80 static DisplayApp display_app;
RyoheiHagimoto 0:b4c1e32627f2 81
RyoheiHagimoto 0:b4c1e32627f2 82 static r_drp_simple_isp_t param_isp __attribute((section("NC_BSS")));
RyoheiHagimoto 0:b4c1e32627f2 83 static uint8_t drp_lib_id[R_DK2_TILE_NUM] = {0};
RyoheiHagimoto 0:b4c1e32627f2 84 static Thread drpTask(osPriorityHigh);
RyoheiHagimoto 0:b4c1e32627f2 85 static uint32_t isp_wb_mode_req;
RyoheiHagimoto 0:b4c1e32627f2 86 static uint32_t isp_wb_mode;
RyoheiHagimoto 0:b4c1e32627f2 87
RyoheiHagimoto 0:b4c1e32627f2 88 static const uint32_t clut_data_resut[] = {0x00000000, 0xff00ff00}; // ARGB8888
RyoheiHagimoto 0:b4c1e32627f2 89
RyoheiHagimoto 0:b4c1e32627f2 90 static void IntCallbackFunc_Vfield(DisplayBase::int_type_t int_type) {
RyoheiHagimoto 0:b4c1e32627f2 91 drpTask.flags_set(DRP_FLG_CAMER_IN);
RyoheiHagimoto 0:b4c1e32627f2 92 }
RyoheiHagimoto 0:b4c1e32627f2 93
RyoheiHagimoto 0:b4c1e32627f2 94 static void cb_drp_finish(uint8_t id) {
RyoheiHagimoto 0:b4c1e32627f2 95 uint32_t tile_no;
RyoheiHagimoto 0:b4c1e32627f2 96 uint32_t set_flgs = 0;
RyoheiHagimoto 0:b4c1e32627f2 97
RyoheiHagimoto 0:b4c1e32627f2 98 // Change the operation state of the DRP library notified by the argument to finish
RyoheiHagimoto 0:b4c1e32627f2 99 for (tile_no = 0; tile_no < R_DK2_TILE_NUM; tile_no++) {
RyoheiHagimoto 0:b4c1e32627f2 100 if (drp_lib_id[tile_no] == id) {
RyoheiHagimoto 0:b4c1e32627f2 101 set_flgs |= (1 << tile_no);
RyoheiHagimoto 0:b4c1e32627f2 102 }
RyoheiHagimoto 0:b4c1e32627f2 103 }
RyoheiHagimoto 0:b4c1e32627f2 104 drpTask.flags_set(set_flgs);
RyoheiHagimoto 0:b4c1e32627f2 105 }
RyoheiHagimoto 0:b4c1e32627f2 106
RyoheiHagimoto 0:b4c1e32627f2 107 static void Start_Video_Camera(void) {
RyoheiHagimoto 0:b4c1e32627f2 108 // Video capture setting (progressive form fixed)
RyoheiHagimoto 0:b4c1e32627f2 109 Display.Video_Write_Setting(
RyoheiHagimoto 0:b4c1e32627f2 110 DisplayBase::VIDEO_INPUT_CHANNEL_0,
RyoheiHagimoto 0:b4c1e32627f2 111 DisplayBase::COL_SYS_NTSC_358,
RyoheiHagimoto 0:b4c1e32627f2 112 (void *)fbuf_bayer,
RyoheiHagimoto 0:b4c1e32627f2 113 FRAME_BUFFER_STRIDE,
RyoheiHagimoto 0:b4c1e32627f2 114 DisplayBase::VIDEO_FORMAT_RAW8,
RyoheiHagimoto 0:b4c1e32627f2 115 DisplayBase::WR_RD_WRSWA_NON,
RyoheiHagimoto 0:b4c1e32627f2 116 VIDEO_PIXEL_VW,
RyoheiHagimoto 0:b4c1e32627f2 117 VIDEO_PIXEL_HW
RyoheiHagimoto 0:b4c1e32627f2 118 );
RyoheiHagimoto 0:b4c1e32627f2 119 EasyAttach_CameraStart(Display, DisplayBase::VIDEO_INPUT_CHANNEL_0);
RyoheiHagimoto 0:b4c1e32627f2 120 }
RyoheiHagimoto 0:b4c1e32627f2 121
RyoheiHagimoto 0:b4c1e32627f2 122 static void button_fall(void) {
RyoheiHagimoto 0:b4c1e32627f2 123 if (isp_wb_mode_req < WB_TUNGSTEN) {
RyoheiHagimoto 0:b4c1e32627f2 124 isp_wb_mode_req++;
RyoheiHagimoto 0:b4c1e32627f2 125 } else {
RyoheiHagimoto 0:b4c1e32627f2 126 isp_wb_mode_req = WB_DAYLIGHT;
RyoheiHagimoto 0:b4c1e32627f2 127 }
RyoheiHagimoto 0:b4c1e32627f2 128 }
RyoheiHagimoto 0:b4c1e32627f2 129
RyoheiHagimoto 0:b4c1e32627f2 130 static void drp_task(void) {
RyoheiHagimoto 0:b4c1e32627f2 131 JPEG_Converter Jcu;
RyoheiHagimoto 0:b4c1e32627f2 132 JPEG_Converter::bitmap_buff_info_t bitmap_buff_info;
RyoheiHagimoto 0:b4c1e32627f2 133 JPEG_Converter::encode_options_t encode_options;
RyoheiHagimoto 0:b4c1e32627f2 134 size_t encode_size;
RyoheiHagimoto 0:b4c1e32627f2 135
RyoheiHagimoto 0:b4c1e32627f2 136 EasyAttach_Init(Display);
RyoheiHagimoto 0:b4c1e32627f2 137 // Interrupt callback function setting (Field end signal for recording function in scaler 0)
RyoheiHagimoto 0:b4c1e32627f2 138 Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_VFIELD, 0, IntCallbackFunc_Vfield);
RyoheiHagimoto 0:b4c1e32627f2 139 Start_Video_Camera();
RyoheiHagimoto 0:b4c1e32627f2 140
RyoheiHagimoto 0:b4c1e32627f2 141 R_DK2_Initialize();
RyoheiHagimoto 0:b4c1e32627f2 142
RyoheiHagimoto 0:b4c1e32627f2 143 /* Load DRP Library */
RyoheiHagimoto 0:b4c1e32627f2 144 /* +-----------------------+ */
RyoheiHagimoto 0:b4c1e32627f2 145 /* tile 0 | | */
RyoheiHagimoto 0:b4c1e32627f2 146 /* + + */
RyoheiHagimoto 0:b4c1e32627f2 147 /* tile 1 | | */
RyoheiHagimoto 0:b4c1e32627f2 148 /* + + */
RyoheiHagimoto 0:b4c1e32627f2 149 /* tile 2 | | */
RyoheiHagimoto 0:b4c1e32627f2 150 /* + SimpleIsp bayer2yuv_6 + */
RyoheiHagimoto 0:b4c1e32627f2 151 /* tile 3 | | */
RyoheiHagimoto 0:b4c1e32627f2 152 /* + + */
RyoheiHagimoto 0:b4c1e32627f2 153 /* tile 4 | | */
RyoheiHagimoto 0:b4c1e32627f2 154 /* + + */
RyoheiHagimoto 0:b4c1e32627f2 155 /* tile 5 | | */
RyoheiHagimoto 0:b4c1e32627f2 156 /* +-----------------------+ */
RyoheiHagimoto 0:b4c1e32627f2 157 R_DK2_Load(g_drp_lib_simple_isp_bayer2yuv_6,
RyoheiHagimoto 0:b4c1e32627f2 158 R_DK2_TILE_0,
RyoheiHagimoto 0:b4c1e32627f2 159 R_DK2_TILE_PATTERN_6, NULL, &cb_drp_finish, drp_lib_id);
RyoheiHagimoto 0:b4c1e32627f2 160 R_DK2_Activate(0, 0);
RyoheiHagimoto 0:b4c1e32627f2 161
RyoheiHagimoto 0:b4c1e32627f2 162 memset(&param_isp, 0, sizeof(param_isp));
RyoheiHagimoto 0:b4c1e32627f2 163 param_isp.src = (uint32_t)fbuf_bayer;
RyoheiHagimoto 0:b4c1e32627f2 164 param_isp.dst = (uint32_t)fbuf_yuv;
RyoheiHagimoto 0:b4c1e32627f2 165 param_isp.width = VIDEO_PIXEL_HW;
RyoheiHagimoto 0:b4c1e32627f2 166 param_isp.height = VIDEO_PIXEL_VW;
RyoheiHagimoto 0:b4c1e32627f2 167 param_isp.gain_r = 0x1266;
RyoheiHagimoto 0:b4c1e32627f2 168 param_isp.gain_g = 0x0CB0;
RyoheiHagimoto 0:b4c1e32627f2 169 param_isp.gain_b = 0x1359;
RyoheiHagimoto 0:b4c1e32627f2 170
RyoheiHagimoto 0:b4c1e32627f2 171 isp_wb_mode_req = WB_DAYLIGHT;
RyoheiHagimoto 0:b4c1e32627f2 172 isp_wb_mode = WB_DAYLIGHT;
RyoheiHagimoto 0:b4c1e32627f2 173
RyoheiHagimoto 0:b4c1e32627f2 174 InterruptIn button(USER_BUTTON0);
RyoheiHagimoto 0:b4c1e32627f2 175 button.fall(&button_fall);
RyoheiHagimoto 0:b4c1e32627f2 176
RyoheiHagimoto 0:b4c1e32627f2 177 bitmap_buff_info.width = VIDEO_PIXEL_HW;
RyoheiHagimoto 0:b4c1e32627f2 178 bitmap_buff_info.height = VIDEO_PIXEL_VW;
RyoheiHagimoto 0:b4c1e32627f2 179 bitmap_buff_info.format = JPEG_Converter::WR_RD_YCbCr422;
RyoheiHagimoto 0:b4c1e32627f2 180 bitmap_buff_info.buffer_address = (void *)fbuf_yuv;
RyoheiHagimoto 0:b4c1e32627f2 181 encode_options.encode_buff_size = sizeof(JpegBuffer);
RyoheiHagimoto 0:b4c1e32627f2 182 encode_options.input_swapsetting = JPEG_Converter::WR_RD_WRSWA_32_16BIT;
RyoheiHagimoto 0:b4c1e32627f2 183
RyoheiHagimoto 0:b4c1e32627f2 184 while (true) {
RyoheiHagimoto 0:b4c1e32627f2 185 ThisThread::flags_wait_all(DRP_FLG_CAMER_IN);
RyoheiHagimoto 0:b4c1e32627f2 186 if (isp_wb_mode_req != isp_wb_mode) {
RyoheiHagimoto 0:b4c1e32627f2 187 isp_wb_mode = isp_wb_mode_req;
RyoheiHagimoto 0:b4c1e32627f2 188 switch (isp_wb_mode) {
RyoheiHagimoto 0:b4c1e32627f2 189 case WB_DAYLIGHT:
RyoheiHagimoto 0:b4c1e32627f2 190 param_isp.gain_r = 0x1266;
RyoheiHagimoto 0:b4c1e32627f2 191 param_isp.gain_g = 0x0CB0;
RyoheiHagimoto 0:b4c1e32627f2 192 param_isp.gain_b = 0x1359;
RyoheiHagimoto 0:b4c1e32627f2 193 break;
RyoheiHagimoto 0:b4c1e32627f2 194 case WB_CLOUDY:
RyoheiHagimoto 0:b4c1e32627f2 195 param_isp.gain_r = 0x1400;
RyoheiHagimoto 0:b4c1e32627f2 196 param_isp.gain_g = 0x0CB0;
RyoheiHagimoto 0:b4c1e32627f2 197 param_isp.gain_b = 0x11CA;
RyoheiHagimoto 0:b4c1e32627f2 198 break;
RyoheiHagimoto 0:b4c1e32627f2 199 case WB_FLUORESCENT:
RyoheiHagimoto 0:b4c1e32627f2 200 param_isp.gain_r = 0x1000;
RyoheiHagimoto 0:b4c1e32627f2 201 param_isp.gain_g = 0x0CB0;
RyoheiHagimoto 0:b4c1e32627f2 202 param_isp.gain_b = 0x163D;
RyoheiHagimoto 0:b4c1e32627f2 203 break;
RyoheiHagimoto 0:b4c1e32627f2 204 case WB_TUNGSTEN:
RyoheiHagimoto 0:b4c1e32627f2 205 param_isp.gain_r = 0x0E66;
RyoheiHagimoto 0:b4c1e32627f2 206 param_isp.gain_g = 0x0CB0;
RyoheiHagimoto 0:b4c1e32627f2 207 param_isp.gain_b = 0x1876;
RyoheiHagimoto 0:b4c1e32627f2 208 break;
RyoheiHagimoto 0:b4c1e32627f2 209 }
RyoheiHagimoto 0:b4c1e32627f2 210 }
RyoheiHagimoto 0:b4c1e32627f2 211 R_DK2_Start(drp_lib_id[0], (void *)&param_isp, sizeof(r_drp_simple_isp_t));
RyoheiHagimoto 0:b4c1e32627f2 212
RyoheiHagimoto 0:b4c1e32627f2 213 ThisThread::flags_wait_all(DRP_FLG_TILE_ALL);
RyoheiHagimoto 0:b4c1e32627f2 214 dcache_invalid(JpegBuffer, sizeof(JpegBuffer));
RyoheiHagimoto 0:b4c1e32627f2 215 if (Jcu.encode(&bitmap_buff_info, JpegBuffer, &encode_size, &encode_options) == JPEG_Converter::JPEG_CONV_OK) {
RyoheiHagimoto 0:b4c1e32627f2 216 display_app.SendJpeg(JpegBuffer, (int)encode_size);
RyoheiHagimoto 0:b4c1e32627f2 217 }
RyoheiHagimoto 0:b4c1e32627f2 218 }
RyoheiHagimoto 0:b4c1e32627f2 219 }
RyoheiHagimoto 0:b4c1e32627f2 220
RyoheiHagimoto 0:b4c1e32627f2 221 int main(void) {
RyoheiHagimoto 0:b4c1e32627f2 222 // Start DRP task
RyoheiHagimoto 0:b4c1e32627f2 223 drpTask.start(callback(drp_task));
RyoheiHagimoto 0:b4c1e32627f2 224
RyoheiHagimoto 0:b4c1e32627f2 225 ThisThread::sleep_for(osWaitForever);
RyoheiHagimoto 0:b4c1e32627f2 226 }
RyoheiHagimoto 0:b4c1e32627f2 227
RyoheiHagimoto 0:b4c1e32627f2 228 #endif