Plays MJPEG Video using the RGA. THe RGA allows resize of the JPEG file.

Dependencies:   GR-PEACH_video GraphicsFramework LCD_shield_config R_BSP SDBlockDevice_GR_PEACH TLV320_RBSP USBHost_custom

Fork of RGA_HelloWorld by Renesas

Overview

This demo shows how play a MJPEG and WAV file video using the RZA1 hardware RGA, JCU and SSIF. The JCU decodes each MJPEG frame. The SSIF plays the raw WAV file, and the RGA supplies the GUI and resize of the JPEG image.

MJPEG Creation

Requirements

Python Script

SD Card

  • Rename the jpg file to Renesas.jpg and audio file Renesas.wav
  • Download this image file and rename is Background.jpg /media/uploads/zkimike/background.jpg
Revision:
4:ce438477eddb
Parent:
2:c7faef0ef374
Child:
6:6a8ce6f7767b
--- a/main.cpp	Thu Jan 21 10:21:28 2016 +0000
+++ b/main.cpp	Mon Aug 08 02:11:23 2016 +0000
@@ -22,18 +22,11 @@
 #include "rga_func.h"
 #include "DisplayBace.h"
 #include "rtos.h"
-
-
-/* LCD Parameter */
-#define LCD_INPUT_CLOCK                     (66.67f)
-#define LCD_OUTPUT_CLOCK                    (33.26f)
+#include "LCD_shield_config_7_1inch.h"
 
-#define LCD_PIXEL_WIDTH                     (800)
-#define LCD_PIXEL_HEIGHT                    (480)
-#define LCD_H_BACK_PORCH                    (128 + 36)
-#define LCD_H_FRONT_PORCH                   (92)
-#define LCD_V_BACK_PORCH                    (35 + 5)
-#define LCD_V_FRONT_PORCH                   (5)
+#define GRAPHICS_FORMAT                     (DisplayBase::GRAPHICS_FORMAT_RGB565)
+#define WR_RD_WRSWA                         (DisplayBase::WR_RD_WRSWA_32_16BIT)
+#define TOUCH_NUM                           (1u)
 
 /* FRAME BUFFER Parameter */
 #define FRAME_BUFFER_BYTE_PER_PIXEL         (2)
@@ -57,32 +50,14 @@
     RGA_FUNC_ANIME_EASE_IN_OUT,
     RGA_FUNC_RETURN,
     RGA_FUNC_END
-}func_code_t;
+} func_code_t;
 
 DigitalOut  lcd_pwon(P7_15);
 DigitalOut  lcd_blon(P8_1);
 PwmOut      lcd_cntrst(P8_15);
-I2C         i2c(I2C_SDA, I2C_SCL);
 DisplayBase Display;
 
 typedef struct {
-    uint8_t y_h: 3,
-    reserved: 1,
-    x_h: 3,
-    valid: 1;
-    uint8_t x_l;
-    uint8_t y_l;
-    uint8_t z;
-} xyz_data_t;
- 
-typedef struct {
-    uint8_t fingers: 4,
-    reserved: 4;
-    uint8_t keys;
-    xyz_data_t xyz_data;
-} stx_report_data_t;
-
-typedef struct {
     uint32_t pic_pos_x;             /* X position of the key picture. */
     uint32_t pic_pos_y;             /* Y position of the key picture. */
     uint32_t pic_width;             /* Width of the key picture. */
@@ -90,8 +65,15 @@
     func_code_t func_code;          /* func code of the key picture. */
 } key_pic_info_t;
 
-static uint8_t user_frame_buffer[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32)));  /* 32 bytes aligned */
+#if defined(__ICCARM__)
+#pragma data_alignment=32
+static uint8_t user_frame_buffer1[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT];
+static uint8_t user_frame_buffer2[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT];
+#pragma data_alignment=4
+#else
+static uint8_t user_frame_buffer1[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32))); /* 32 bytes aligned */
 static uint8_t user_frame_buffer2[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32))); /* 32 bytes aligned */
+#endif
 static frame_buffer_t frame_buffer_info;
 static volatile int32_t vsync_count = 0;
 
@@ -124,7 +106,8 @@
     {     0,      0,      0,      0,    RGA_FUNC_END               }   /* table end */
 };
 
-static void IntCallbackFunc_Vsync(DisplayBase::int_type_t int_type) {
+/****** LCD ******/
+static void IntCallbackFunc_LoVsync(DisplayBase::int_type_t int_type) {
     /* Interrupt callback function for Vsync interruption */
     if (vsync_count > 0) {
         vsync_count--;
@@ -139,10 +122,8 @@
     }
 }
 
-static void Init_LCD_Display(uint8_t* disp_buf) {
-    /* Create DisplayBase object */
+static void Init_LCD_Display(void) {
     DisplayBase::graphics_error_t error;
-    DisplayBase::rect_t rect;
     DisplayBase::lcd_config_t lcd_config;
     PinName lvds_pin[8] = {
         /* data pin */
@@ -154,66 +135,41 @@
     Thread::wait(100);
     lcd_pwon = 1;
     lcd_blon = 1;
-    Thread::wait(100);
 
-    lcd_config.lcd_type             = DisplayBase::LCD_TYPE_LVDS;
-    lcd_config.intputClock          = LCD_INPUT_CLOCK;
-    lcd_config.outputClock          = LCD_OUTPUT_CLOCK;
-    lcd_config.lcd_outformat        = DisplayBase::LCD_OUTFORMAT_RGB888;
-    lcd_config.lcd_edge             = DisplayBase::EDGE_RISING;
-    lcd_config.h_toatal_period      = (LCD_PIXEL_WIDTH  + LCD_H_FRONT_PORCH + LCD_H_BACK_PORCH);
-    lcd_config.v_toatal_period      = (LCD_PIXEL_HEIGHT + LCD_V_FRONT_PORCH + LCD_V_BACK_PORCH);
-
-    lcd_config.h_disp_widht         = LCD_PIXEL_WIDTH;
-    lcd_config.v_disp_widht         = LCD_PIXEL_HEIGHT;
-    lcd_config.h_back_porch         = LCD_H_BACK_PORCH;
-    lcd_config.v_back_porch         = LCD_V_BACK_PORCH;
-
-    lcd_config.h_sync_port          = DisplayBase::LCD_TCON_PIN_NON;
-    lcd_config.h_sync_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED;
-    lcd_config.h_sync_width         = 0;
-
-    lcd_config.v_sync_port          = DisplayBase::LCD_TCON_PIN_NON;
-    lcd_config.v_sync_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED;
-    lcd_config.v_sync_width         = 0;
-
-    lcd_config.de_port              = DisplayBase::LCD_TCON_PIN_3;
-    lcd_config.de_port_polarity     = DisplayBase::SIG_POL_NOT_INVERTED;
+    Display.Graphics_Lvds_Port_Init(lvds_pin, 8);
 
     /* Graphics initialization process */
+    lcd_config = LcdCfgTbl_LCD_shield;
     error = Display.Graphics_init(&lcd_config);
     if (error != DisplayBase::GRAPHICS_OK) {
         printf("Line %d, error %d\n", __LINE__, error);
-        while (1);
+        mbed_die();
     }
 
     /* Interrupt callback function setting (Vsync signal output from scaler 0) */
-    error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_LO_VSYNC, 0, IntCallbackFunc_Vsync);
+    error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_LO_VSYNC, 0, IntCallbackFunc_LoVsync);
     if (error != DisplayBase::GRAPHICS_OK) {
         printf("Line %d, error %d\n", __LINE__, error);
-        while (1);
+        mbed_die();
     }
+}
 
-    Display.Graphics_Lvds_Port_Init(lvds_pin, 8);
+static void Start_LCD_Display(uint8_t * p_buf) {
+    DisplayBase::rect_t rect;
+
     rect.vs = 0;
     rect.vw = LCD_PIXEL_HEIGHT;
     rect.hs = 0;
     rect.hw = LCD_PIXEL_WIDTH;
-
     Display.Graphics_Read_Setting(
         DisplayBase::GRAPHICS_LAYER_0,
-        (void *)disp_buf,
+        (void *)p_buf,
         FRAME_BUFFER_STRIDE,
-        DisplayBase::GRAPHICS_FORMAT_RGB565,
-        DisplayBase::WR_RD_WRSWA_32_16BIT,
+        GRAPHICS_FORMAT,
+        WR_RD_WRSWA,
         &rect
     );
-}
-
-static void Start_LCD_Display(void) {
     Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0);
-
-    lcd_cntrst.write(1.0);
 }
 
 static void Update_LCD_Display(frame_buffer_t * frmbuf_info) {
@@ -222,27 +178,15 @@
     Wait_Vsync(1);
 }
 
-static int Get_Coordinates(uint8_t *count, uint32_t *x0, uint32_t *y0) {
-    char buf[6];
-    stx_report_data_t *pdata;
-    int ret = -1;
-    *count = 0;                     // Set point detected count to 0
-
-    if (i2c.read((0x55 << 1), buf, sizeof(buf)) == 0) {
-        pdata = (stx_report_data_t *)buf;
-        if (pdata->fingers) {
-            if (pdata->xyz_data.valid) {
-                *x0 = (pdata->xyz_data.x_h << 8) | pdata->xyz_data.x_l;
-                *y0 = (pdata->xyz_data.y_h << 8) | pdata->xyz_data.y_l;
-                (*count)++;
-            }
-        }
-        ret = 0;
+static void Swap_FrameBuffer(frame_buffer_t * frmbuf_info) {
+    if (frmbuf_info->draw_buffer_index == 1) {
+        frmbuf_info->draw_buffer_index = 0;
+    } else {
+        frmbuf_info->draw_buffer_index = 1;
     }
-
-    return ret;
 }
 
+/****** Touch ******/
 static func_code_t Scan_Key(const key_pic_info_t * key_tbl, const uint32_t pos_x, const uint32_t pos_y) {
     func_code_t ret = RGA_FUNC_NON;
 
@@ -264,19 +208,10 @@
     return ret;
 }
 
-static void Swap_FrameBuffer(frame_buffer_t * frmbuf_info) {
-    if (frmbuf_info->draw_buffer_index == 1) {
-        frmbuf_info->draw_buffer_index = 0;
-    } else {
-        frmbuf_info->draw_buffer_index = 1;
-    }
-}
-
-static void Exe_RGA_Func(int func_name, frame_buffer_t* frmbuf_info) {
+/****** Efect ******/
+static void Exe_RGA_Func(func_code_t func_name, frame_buffer_t* frmbuf_info, TouckKey_LCD_shield * p_touch) {
     uint8_t touch_num = 0;
-    uint32_t pos_x0 = 0;
-    uint32_t pos_y0 = 0;
-    func_code_t func_code;
+    TouchKey::touch_pos_t touch_pos[TOUCH_NUM];
 
     switch (func_name) {
         case RGA_FUNC_DRAW_RECTANGLE:
@@ -294,9 +229,9 @@
 
             while (1) {
                 /* Get coordinates */
-                Get_Coordinates(&touch_num, &pos_x0, &pos_y0);
+                touch_num = p_touch->GetCoordinates(TOUCH_NUM, touch_pos);
                 if (touch_num != 0) {
-                    if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) {
+                    if (Scan_Key(return_key_tbl, touch_pos[0].x, touch_pos[0].y) == RGA_FUNC_RETURN) {
                         break;
                     }
                     if (key_on == false) {
@@ -309,22 +244,22 @@
                                 pos_tbl[cnt].h = 0;
                             }
                         }
-                        x_0 = pos_x0;
-                        y_0 = pos_y0;
+                        x_0 = touch_pos[0].x;
+                        y_0 = touch_pos[0].y;
                     }
-                    if (x_0 < pos_x0) {
+                    if (x_0 < touch_pos[0].x) {
                         pos_tbl[color_cnt].x = x_0;
-                        pos_tbl[color_cnt].w = pos_x0 - x_0;
+                        pos_tbl[color_cnt].w = touch_pos[0].x - x_0;
                     } else {
-                        pos_tbl[color_cnt].x = pos_x0;
-                        pos_tbl[color_cnt].w = x_0 - pos_x0;
+                        pos_tbl[color_cnt].x = touch_pos[0].x;
+                        pos_tbl[color_cnt].w = x_0 - touch_pos[0].x;
                     }
-                    if (y_0 < pos_y0) {
+                    if (y_0 < touch_pos[0].y) {
                         pos_tbl[color_cnt].y = y_0;
-                        pos_tbl[color_cnt].h = pos_y0 - y_0;
+                        pos_tbl[color_cnt].h = touch_pos[0].y - y_0;
                     } else {
-                        pos_tbl[color_cnt].y = pos_y0;
-                        pos_tbl[color_cnt].h = y_0 - pos_y0;
+                        pos_tbl[color_cnt].y = touch_pos[0].y;
+                        pos_tbl[color_cnt].h = y_0 - touch_pos[0].y;
                     }
                 } else {
                     if (key_on != false) {
@@ -346,13 +281,13 @@
             int center_pos_y = 110;
             while (1) {
                 /* Get coordinates */
-                Get_Coordinates(&touch_num, &pos_x0, &pos_y0);
+                touch_num = p_touch->GetCoordinates(TOUCH_NUM, touch_pos);
                 if (touch_num != 0) {
-                    if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) {
+                    if (Scan_Key(return_key_tbl, touch_pos[0].x, touch_pos[0].y) == RGA_FUNC_RETURN) {
                         break;
                     }
-                    center_pos_x = pos_x0;
-                    center_pos_y = pos_y0;
+                    center_pos_x = touch_pos[0].x;
+                    center_pos_y = touch_pos[0].y;
                 }
                 /* Draw screen */
                 Swap_FrameBuffer(frmbuf_info);
@@ -364,12 +299,12 @@
             float32_t work_alpha = 0.0f;
             while (1) {
                 /* Get coordinates */
-                Get_Coordinates(&touch_num, &pos_x0, &pos_y0);
+                touch_num = p_touch->GetCoordinates(TOUCH_NUM, touch_pos);
                 if (touch_num != 0) {
-                    if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) {
+                    if (Scan_Key(return_key_tbl, touch_pos[0].x, touch_pos[0].y) == RGA_FUNC_RETURN) {
                         break;
                     }
-                    work_alpha = (float32_t)pos_x0 / (float32_t)(LCD_PIXEL_WIDTH);
+                    work_alpha = (float32_t)touch_pos[0].x / (float32_t)(LCD_PIXEL_WIDTH);
                 }
                 /* Draw screen */
                 Swap_FrameBuffer(frmbuf_info);
@@ -381,12 +316,12 @@
             int work_width_pos = 0;
             while (1) {
                 /* Get coordinates */
-                Get_Coordinates(&touch_num, &pos_x0, &pos_y0);
+                touch_num = p_touch->GetCoordinates(TOUCH_NUM, touch_pos);
                 if (touch_num != 0) {
-                    if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) {
+                    if (Scan_Key(return_key_tbl, touch_pos[0].x, touch_pos[0].y) == RGA_FUNC_RETURN) {
                         break;
                     }
-                    work_width_pos = SCROLL_MAX_NUM * ((float32_t)pos_x0 / (float32_t)(LCD_PIXEL_WIDTH));
+                    work_width_pos = SCROLL_MAX_NUM * ((float32_t)touch_pos[0].x / (float32_t)(LCD_PIXEL_WIDTH));
                 }
                 /* Draw screen */
                 Swap_FrameBuffer(frmbuf_info);
@@ -398,12 +333,12 @@
             int work_height_pos = ZOOM_MAX_NUM;
             while (1) {
                 /* Get coordinates */
-                Get_Coordinates(&touch_num, &pos_x0, &pos_y0);
+                touch_num = p_touch->GetCoordinates(TOUCH_NUM, touch_pos);
                 if (touch_num != 0) {
-                    if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) {
+                    if (Scan_Key(return_key_tbl, touch_pos[0].x, touch_pos[0].y) == RGA_FUNC_RETURN) {
                         break;
                     }
-                    work_height_pos = ZOOM_MAX_NUM * ((float32_t)pos_x0 / (float32_t)(LCD_PIXEL_WIDTH));
+                    work_height_pos = ZOOM_MAX_NUM * ((float32_t)touch_pos[0].x / (float32_t)(LCD_PIXEL_WIDTH));
                 }
                 /* Draw screen */
                 Swap_FrameBuffer(frmbuf_info);
@@ -415,12 +350,12 @@
             graphics_matrix_float_t work_angle = 0;
             while (1) {
                 /* Get coordinates */
-                Get_Coordinates(&touch_num, &pos_x0, &pos_y0);
+                touch_num = p_touch->GetCoordinates(TOUCH_NUM, touch_pos);
                 if (touch_num != 0) {
-                    if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) {
+                    if (Scan_Key(return_key_tbl, touch_pos[0].x, touch_pos[0].y) == RGA_FUNC_RETURN) {
                         break;
                     }
-                    work_angle = ROTATION_MAX_NUM * ((float32_t)pos_x0 / (float32_t)(LCD_PIXEL_WIDTH));
+                    work_angle = ROTATION_MAX_NUM * ((float32_t)touch_pos[0].x / (float32_t)(LCD_PIXEL_WIDTH));
                 }
                 /* Draw screen */
                 Swap_FrameBuffer(frmbuf_info);
@@ -434,11 +369,11 @@
             float32_t work_relative_pos;
             while (1) {
                 /* Get coordinates */
-                Get_Coordinates(&touch_num, &pos_x0, &pos_y0);
+                touch_num = p_touch->GetCoordinates(TOUCH_NUM, touch_pos);
                 if (touch_num != 0) {
                     func_code_t func_code;
 
-                    func_code = Scan_Key(animetion_timing_key_tbl, pos_x0, pos_y0);
+                    func_code = Scan_Key(animetion_timing_key_tbl, touch_pos[0].x, touch_pos[0].y);
                     if (func_code == RGA_FUNC_RETURN) {
                         break;
                     }
@@ -488,12 +423,14 @@
 int main(void) {
     func_code_t func_code;
     uint8_t touch_num = 0;
-    uint32_t pos_x0 = 0;
-    uint32_t pos_y0 = 0;
+    TouchKey::touch_pos_t touch_pos[TOUCH_NUM];
 
-    memset(user_frame_buffer, 0, sizeof(user_frame_buffer));
+    /* Initialization of LCD */
+    Init_LCD_Display();    /* When using LCD, please call before than Init_Video(). */
+
+    memset(user_frame_buffer1, 0, sizeof(user_frame_buffer1));
     memset(user_frame_buffer2, 0, sizeof(user_frame_buffer2));
-    frame_buffer_info.buffer_address[0] = user_frame_buffer;
+    frame_buffer_info.buffer_address[0] = user_frame_buffer1;
     frame_buffer_info.buffer_address[1] = user_frame_buffer2;
     frame_buffer_info.buffer_count      = 2;
     frame_buffer_info.show_buffer_index = 0;
@@ -503,30 +440,39 @@
     frame_buffer_info.stride            = LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL;
     frame_buffer_info.height            = LCD_PIXEL_HEIGHT;
     frame_buffer_info.pixel_format      = PIXEL_FORMAT_RGB565;
-    Init_LCD_Display(frame_buffer_info.buffer_address[0]);
 
     /* Display Top Screen */
     Set_RGAObject(&frame_buffer_info);
     RGA_Func_DrawTopScreen(&frame_buffer_info);
-    Start_LCD_Display();
+
+    /* Start of LCD */
+    Start_LCD_Display(frame_buffer_info.buffer_address[0]);
+
+    /* Backlight on */
+    Thread::wait(200);
+    lcd_cntrst.write(1.0);
+
+    /* Reset touch IC */
+    TouckKey_LCD_shield touch(P4_0, P2_13, I2C_SDA, I2C_SCL);
+    touch.Reset();
 
     while (1) {
         /* Get Coordinates */
-        Get_Coordinates(&touch_num, &pos_x0, &pos_y0);
+        touch_num = touch.GetCoordinates(TOUCH_NUM, touch_pos);
         if (touch_num != 0) {
-            func_code = Scan_Key(top_screen_key_tbl, pos_x0, pos_y0);
+            func_code = Scan_Key(top_screen_key_tbl, touch_pos[0].x, touch_pos[0].y);
             if (func_code != RGA_FUNC_NON) {
                 /* Wait key off */
                 while (1) {
-                    Get_Coordinates(&touch_num, &pos_x0, &pos_y0);
+                    touch_num = touch.GetCoordinates(TOUCH_NUM, touch_pos);
                     if (touch_num == 0) {
                         break;
                     }
-                    Thread::wait(50);
+                    Thread::wait(20);
                 }
 
                 /* Execute RGA functions */
-                Exe_RGA_Func(func_code, &frame_buffer_info);
+                Exe_RGA_Func(func_code, &frame_buffer_info, &touch);
 
                 /* Return Top Screen */
                 Swap_FrameBuffer(&frame_buffer_info);
@@ -534,6 +480,6 @@
                 Update_LCD_Display(&frame_buffer_info);
             }
         }
-        Thread::wait(100);
+        Thread::wait(20);
     }
 }