Camera in sample for GR-PEACH. This sample works on GR-LYCHEE besides GR-PEACH.

Video Links on how to setup and run Camera_in Application:

Your video will be live at: https://youtu.be/XNH8jLhjeS4 Part1 of 1

Camera in sample for GR-PEACH or GR-LYCHEE. While USER_BUTTON0 is pressed, it will save the camera image(default is jpeg fotmat) to USB memory or SD card.
If both USB and SD are inserted, GR-PEACH or GR-LYCHEE connect to the previously detected device.

The default setting of serial communication (baud rate etc.) in mbed is shown the following link.
Please refer to the link and change the settings of your PC terminal software.
The default value of baud rate in mbed is 9600, and this application uses baud rate 9600.
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication

Please refer to following link about Audio/Camera Shield.
https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield

You can configure this sample application via the following definitions. If you set to 1, it will save the video file as a AVI format:

main.cpp

/**** User Selection *********/
#define SAVE_FILE_TYPE         (0)     /* Select  0(Image(.jpg)) or 1(Movie(.avi)) */
/*****************************/


  • USB channel available in this sample program
    By default, the GR-PEACH's USB connector (USB0) is configured to be used. When using USB0, please close GR-PEACH's JP3.
    /media/uploads/RyoheiHagimoto/usb.jpg


    Or, you can use the Audio/Camera Shield's USB connector (USB1). When using USB1, you need to close JP1 of Audio/Camera Shield.
    /media/uploads/dkato/audiocamerashield_jp1.jpg


  • Specify each configuration
    To specify camera and LCD, add camera-type and lcd-type to mbed_app.json.
    For details, please refer to mbed-gr-libs / README.md.

mbed_app.json

{
    "config": {
        "camera":{
            "help": "0:disable 1:enable",
            "value": "1"
        },
        "camera-type":{
            "help": "Please see mbed-gr-libs/README.md",
            "value": "CAMERA_CVBS"
        },
        "lcd":{
            "help": "0:disable 1:enable",
            "value": "0"
        },
        "lcd-type":{
            "help": "Please see mbed-gr-libs/README.md",
            "value": "GR_PEACH_4_3INCH_SHIELD"
        },
        "usb-host-ch":{
            "help": "(for GR-PEACH) 0:ch0 1:ch1",
            "value": "1"
        },
        "audio-camera-shield":{
            "help": "(for GR-PEACH) 0:not use 1:use",
            "value": "1"
        }
    }
}
Committer:
Osamu Nakamura
Date:
Tue Mar 21 12:06:48 2017 +0900
Revision:
2:9d98159fa9c9
Parent:
0:2f1caf4ce924
Introduced mbed OS 5 instead of mbed OS 2 (classic)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:2f1caf4ce924 1 /** @file bitmap.h */
dkato 0:2f1caf4ce924 2 #include "mbed.h"
dkato 0:2f1caf4ce924 3
dkato 0:2f1caf4ce924 4 /** A class to communicate a bitmap
dkato 0:2f1caf4ce924 5 *
dkato 0:2f1caf4ce924 6 */
dkato 0:2f1caf4ce924 7 class bitmap {
dkato 0:2f1caf4ce924 8 public:
dkato 0:2f1caf4ce924 9
dkato 0:2f1caf4ce924 10 /** convert RGB888 to bitmap
dkato 0:2f1caf4ce924 11 *
dkato 0:2f1caf4ce924 12 * @param file_name save file name
dkato 0:2f1caf4ce924 13 * @param buf data buffer address
dkato 0:2f1caf4ce924 14 * @param pic_width picture width
dkato 0:2f1caf4ce924 15 * @param pic_height picture height
dkato 0:2f1caf4ce924 16 * @return save data size
dkato 0:2f1caf4ce924 17 */
dkato 0:2f1caf4ce924 18 int Rgb888ToBmp(char * file_name, uint8_t * buf, unsigned long pic_width, unsigned long pic_height) {
dkato 0:2f1caf4ce924 19 unsigned long offset_size = 54;
dkato 0:2f1caf4ce924 20 unsigned long buf_stride = (((pic_width * 4u) + 31u) & ~31u);
dkato 0:2f1caf4ce924 21 unsigned long pic_size = buf_stride * pic_height;
dkato 0:2f1caf4ce924 22 unsigned long file_size = 0;
dkato 0:2f1caf4ce924 23 int save_file_size = 0;
dkato 0:2f1caf4ce924 24 int write_index = (buf_stride * pic_height) - buf_stride;
dkato 0:2f1caf4ce924 25 unsigned long cnt;
dkato 0:2f1caf4ce924 26 uint8_t wk_bitmap_buf[16];
dkato 0:2f1caf4ce924 27 FILE * fp = fopen(file_name, "w");
dkato 0:2f1caf4ce924 28
dkato 0:2f1caf4ce924 29 if (fp != NULL) {
dkato 0:2f1caf4ce924 30 file_size = pic_size + offset_size;
dkato 0:2f1caf4ce924 31
dkato 0:2f1caf4ce924 32 /* BITMAPFILEHEADER */
dkato 0:2f1caf4ce924 33 wk_bitmap_buf[0] = 'B';
dkato 0:2f1caf4ce924 34 wk_bitmap_buf[1] = 'M';
dkato 0:2f1caf4ce924 35 wk_bitmap_buf[2] = (unsigned char)(file_size >> 0); /* bfSize */
dkato 0:2f1caf4ce924 36 wk_bitmap_buf[3] = (unsigned char)(file_size >> 8); /* bfSize */
dkato 0:2f1caf4ce924 37 wk_bitmap_buf[4] = (unsigned char)(file_size >> 16); /* bfSize */
dkato 0:2f1caf4ce924 38 wk_bitmap_buf[5] = (unsigned char)(file_size >> 24); /* bfSize */
dkato 0:2f1caf4ce924 39 wk_bitmap_buf[6] = 0; /* bfReserved1 */
dkato 0:2f1caf4ce924 40 wk_bitmap_buf[7] = 0; /* bfReserved1 */
dkato 0:2f1caf4ce924 41 wk_bitmap_buf[8] = 0; /* bfReserved2 */
dkato 0:2f1caf4ce924 42 wk_bitmap_buf[9] = 0; /* bfReserved2 */
dkato 0:2f1caf4ce924 43 wk_bitmap_buf[10] = (unsigned char)(offset_size >> 0); /* bfOffBits */
dkato 0:2f1caf4ce924 44 wk_bitmap_buf[11] = (unsigned char)(offset_size >> 8); /* bfOffBits */
dkato 0:2f1caf4ce924 45 wk_bitmap_buf[12] = (unsigned char)(offset_size >> 16); /* bfOffBits */
dkato 0:2f1caf4ce924 46 wk_bitmap_buf[13] = (unsigned char)(offset_size >> 24); /* bfOffBits */
dkato 0:2f1caf4ce924 47 fwrite(wk_bitmap_buf, sizeof(char), 14, fp);
dkato 0:2f1caf4ce924 48
dkato 0:2f1caf4ce924 49 /* BITMAPINFOHEADER */
dkato 0:2f1caf4ce924 50 wk_bitmap_buf[0] = 40; /* biSize */
dkato 0:2f1caf4ce924 51 wk_bitmap_buf[1] = 0; /* biSize */
dkato 0:2f1caf4ce924 52 wk_bitmap_buf[2] = 0; /* biSize */
dkato 0:2f1caf4ce924 53 wk_bitmap_buf[3] = 0; /* biSize */
dkato 0:2f1caf4ce924 54 wk_bitmap_buf[4] = (unsigned char)(pic_width >> 0); /* biWidth */
dkato 0:2f1caf4ce924 55 wk_bitmap_buf[5] = (unsigned char)(pic_width >> 8); /* biWidth */
dkato 0:2f1caf4ce924 56 wk_bitmap_buf[6] = (unsigned char)(pic_width >> 16); /* biWidth */
dkato 0:2f1caf4ce924 57 wk_bitmap_buf[7] = (unsigned char)(pic_width >> 24); /* biWidth */
dkato 0:2f1caf4ce924 58 wk_bitmap_buf[8] = (unsigned char)(pic_height >> 0); /* biHeight */
dkato 0:2f1caf4ce924 59 wk_bitmap_buf[9] = (unsigned char)(pic_height >> 8); /* biHeight */
dkato 0:2f1caf4ce924 60 wk_bitmap_buf[10] = (unsigned char)(pic_height >> 16); /* biHeight */
dkato 0:2f1caf4ce924 61 wk_bitmap_buf[11] = (unsigned char)(pic_height >> 24); /* biHeight */
dkato 0:2f1caf4ce924 62 wk_bitmap_buf[12] = 1; /* biPlanes */
dkato 0:2f1caf4ce924 63 wk_bitmap_buf[13] = 0; /* biPlanes */
dkato 0:2f1caf4ce924 64 wk_bitmap_buf[14] = 32; /* biBitCount */
dkato 0:2f1caf4ce924 65 wk_bitmap_buf[15] = 0; /* biBitCount */
dkato 0:2f1caf4ce924 66 fwrite(wk_bitmap_buf, sizeof(char), 16, fp);
dkato 0:2f1caf4ce924 67
dkato 0:2f1caf4ce924 68 wk_bitmap_buf[0] = 0; /* biCopmression */
dkato 0:2f1caf4ce924 69 wk_bitmap_buf[1] = 0; /* biCopmression */
dkato 0:2f1caf4ce924 70 wk_bitmap_buf[2] = 0; /* biCopmression */
dkato 0:2f1caf4ce924 71 wk_bitmap_buf[3] = 0; /* biCopmression */
dkato 0:2f1caf4ce924 72 wk_bitmap_buf[4] = (unsigned char)(pic_size >> 0); /* biSizeImage */
dkato 0:2f1caf4ce924 73 wk_bitmap_buf[5] = (unsigned char)(pic_size >> 8); /* biSizeImage */
dkato 0:2f1caf4ce924 74 wk_bitmap_buf[6] = (unsigned char)(pic_size >> 16); /* biSizeImage */
dkato 0:2f1caf4ce924 75 wk_bitmap_buf[7] = (unsigned char)(pic_size >> 24); /* biSizeImage */
dkato 0:2f1caf4ce924 76 wk_bitmap_buf[8] = 0; /* biXPixPerMeter */
dkato 0:2f1caf4ce924 77 wk_bitmap_buf[9] = 0; /* biXPixPerMeter */
dkato 0:2f1caf4ce924 78 wk_bitmap_buf[10] = 0; /* biXPixPerMeter */
dkato 0:2f1caf4ce924 79 wk_bitmap_buf[11] = 0; /* biXPixPerMeter */
dkato 0:2f1caf4ce924 80 wk_bitmap_buf[12] = 0; /* biYPixPerMeter */
dkato 0:2f1caf4ce924 81 wk_bitmap_buf[13] = 0; /* biYPixPerMeter */
dkato 0:2f1caf4ce924 82 wk_bitmap_buf[14] = 0; /* biYPixPerMeter */
dkato 0:2f1caf4ce924 83 wk_bitmap_buf[15] = 0; /* biYPixPerMeter */
dkato 0:2f1caf4ce924 84 fwrite(wk_bitmap_buf, sizeof(char), 16, fp);
dkato 0:2f1caf4ce924 85
dkato 0:2f1caf4ce924 86 wk_bitmap_buf[0] = 0; /* biClrUsed */
dkato 0:2f1caf4ce924 87 wk_bitmap_buf[1] = 0; /* biClrUsed */
dkato 0:2f1caf4ce924 88 wk_bitmap_buf[2] = 0; /* biClrUsed */
dkato 0:2f1caf4ce924 89 wk_bitmap_buf[3] = 0; /* biClrUsed */
dkato 0:2f1caf4ce924 90 wk_bitmap_buf[4] = 0; /* biCirImportant */
dkato 0:2f1caf4ce924 91 wk_bitmap_buf[5] = 0; /* biCirImportant */
dkato 0:2f1caf4ce924 92 wk_bitmap_buf[6] = 0; /* biCirImportant */
dkato 0:2f1caf4ce924 93 wk_bitmap_buf[7] = 0; /* biCirImportant */
dkato 0:2f1caf4ce924 94 fwrite(wk_bitmap_buf, sizeof(char), 8, fp);
dkato 0:2f1caf4ce924 95
dkato 0:2f1caf4ce924 96 save_file_size = 54;
dkato 0:2f1caf4ce924 97 for (cnt = 0; cnt < pic_height; cnt ++) {
dkato 0:2f1caf4ce924 98 save_file_size += fwrite(&buf[write_index], sizeof(char), buf_stride, fp);
dkato 0:2f1caf4ce924 99 write_index -= buf_stride;
dkato 0:2f1caf4ce924 100 }
dkato 0:2f1caf4ce924 101 fclose(fp);
dkato 0:2f1caf4ce924 102 }
dkato 0:2f1caf4ce924 103
dkato 0:2f1caf4ce924 104 return (int)save_file_size;
dkato 0:2f1caf4ce924 105 };
dkato 0:2f1caf4ce924 106 };