Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: GR-PEACH_video GraphicsFramework R_BSP SDFileSystem_tmp mbed-rtos mbed
main.cpp@6:e7bafd9bba1a, 2016-05-27 (annotated)
- Committer:
- dkato
- Date:
- Fri May 27 04:57:05 2016 +0000
- Revision:
- 6:e7bafd9bba1a
- Parent:
- 5:a429cac419e9
- Child:
- 7:ed885a78b17f
Fix the HD_720p output settings.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dkato | 0:8970afa15acc | 1 | /* |
dkato | 0:8970afa15acc | 2 | Permission is hereby granted, free of charge, to any person obtaining a copy |
dkato | 0:8970afa15acc | 3 | of this software and associated documentation files (the "Software"), to deal |
dkato | 0:8970afa15acc | 4 | in the Software without restriction, including without limitation the rights |
dkato | 0:8970afa15acc | 5 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
dkato | 0:8970afa15acc | 6 | copies of the Software, and to permit persons to whom the Software is |
dkato | 0:8970afa15acc | 7 | furnished to do so, subject to the following conditions: |
dkato | 0:8970afa15acc | 8 | |
dkato | 0:8970afa15acc | 9 | The above copyright notice and this permission notice shall be included in |
dkato | 0:8970afa15acc | 10 | all copies or substantial portions of the Software. |
dkato | 0:8970afa15acc | 11 | |
dkato | 0:8970afa15acc | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
dkato | 0:8970afa15acc | 13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
dkato | 0:8970afa15acc | 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
dkato | 0:8970afa15acc | 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
dkato | 0:8970afa15acc | 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
dkato | 0:8970afa15acc | 17 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
dkato | 0:8970afa15acc | 18 | THE SOFTWARE. |
dkato | 0:8970afa15acc | 19 | */ |
dkato | 0:8970afa15acc | 20 | |
dkato | 0:8970afa15acc | 21 | #include "mbed.h" |
dkato | 0:8970afa15acc | 22 | #include "DisplayBace.h" |
dkato | 0:8970afa15acc | 23 | #include "RGA.h" |
dkato | 0:8970afa15acc | 24 | #include "rtos.h" |
dkato | 0:8970afa15acc | 25 | #include "SDFileSystem.h" |
dkato | 0:8970afa15acc | 26 | |
dkato | 0:8970afa15acc | 27 | #define SVGA (0u) /* 800 x 600 */ |
dkato | 0:8970afa15acc | 28 | #define XGA (1u) /* 1024 x 768 */ |
dkato | 1:2f9f102b2b4c | 29 | #define HD_720p (2u) /* 1280 x 720 */ |
dkato | 1:2f9f102b2b4c | 30 | #define WXGA (3u) /* 1280 x 800 */ |
dkato | 0:8970afa15acc | 31 | |
dkato | 0:8970afa15acc | 32 | /**** User Selection *********/ |
dkato | 3:8489fb71f53d | 33 | #define WAIT_TIME (10000) /* wait time (ms) */ |
dkato | 0:8970afa15acc | 34 | #define DISSOLVE_STEP_NUM (16) /* minimum 1 */ |
dkato | 0:8970afa15acc | 35 | #define SCROLL_STEP_NUM (8) /* minimum 1 */ |
dkato | 0:8970afa15acc | 36 | #define SCROLL_DIRECTION (-1) /* Select 1(left to right) or -1(right to left) */ |
dkato | 5:a429cac419e9 | 37 | #define LCD_SIZE HD_720p /* Select SVGA, XGA, HD_720p or WXGA */ |
dkato | 0:8970afa15acc | 38 | /*****************************/ |
dkato | 0:8970afa15acc | 39 | |
dkato | 0:8970afa15acc | 40 | #define FILE_NAME_LEN (64) |
dkato | 0:8970afa15acc | 41 | #define TEXT_SIZE (64 + 1) //null-terminated |
dkato | 0:8970afa15acc | 42 | #define FLD_PATH "/sd/" |
dkato | 4:1a08ad86d9af | 43 | #define MAX_JPEG_SIZE (1024 * 450) |
dkato | 0:8970afa15acc | 44 | |
dkato | 0:8970afa15acc | 45 | /* LCD Parameter */ |
dkato | 0:8970afa15acc | 46 | #define LCD_INPUT_CLOCK (66.67f) |
dkato | 0:8970afa15acc | 47 | #if ( LCD_SIZE == SVGA ) |
dkato | 1:2f9f102b2b4c | 48 | #define LCD_OUTPUT_CLOCK (40.000f) |
dkato | 0:8970afa15acc | 49 | #define LCD_PIXEL_WIDTH (800u) |
dkato | 0:8970afa15acc | 50 | #define LCD_PIXEL_HEIGHT (600u) |
dkato | 0:8970afa15acc | 51 | #define LCD_H_BACK_PORCH (88u) |
dkato | 0:8970afa15acc | 52 | #define LCD_H_FRONT_PORCH (40u) |
dkato | 0:8970afa15acc | 53 | #define LCD_H_SYNC_WIDTH (128u) |
dkato | 0:8970afa15acc | 54 | #define LCD_V_BACK_PORCH (23u) |
dkato | 0:8970afa15acc | 55 | #define LCD_V_FRONT_PORCH (1u) |
dkato | 0:8970afa15acc | 56 | #define LCD_V_SYNC_WIDTH (4u) |
dkato | 0:8970afa15acc | 57 | #elif ( LCD_SIZE == XGA ) |
dkato | 1:2f9f102b2b4c | 58 | #define LCD_OUTPUT_CLOCK (65.000f) |
dkato | 0:8970afa15acc | 59 | #define LCD_PIXEL_WIDTH (1024u) |
dkato | 0:8970afa15acc | 60 | #define LCD_PIXEL_HEIGHT (768u) |
dkato | 0:8970afa15acc | 61 | #define LCD_H_BACK_PORCH (160u) |
dkato | 0:8970afa15acc | 62 | #define LCD_H_FRONT_PORCH (24u) |
dkato | 0:8970afa15acc | 63 | #define LCD_H_SYNC_WIDTH (136u) |
dkato | 0:8970afa15acc | 64 | #define LCD_V_BACK_PORCH (29u) |
dkato | 0:8970afa15acc | 65 | #define LCD_V_FRONT_PORCH (3u) |
dkato | 0:8970afa15acc | 66 | #define LCD_V_SYNC_WIDTH (6u) |
dkato | 1:2f9f102b2b4c | 67 | #elif ( LCD_SIZE == HD_720p ) |
dkato | 1:2f9f102b2b4c | 68 | #define LCD_OUTPUT_CLOCK (74.1800f) |
dkato | 1:2f9f102b2b4c | 69 | #define LCD_PIXEL_WIDTH (1280u) |
dkato | 6:e7bafd9bba1a | 70 | #define LCD_PIXEL_HEIGHT (720u) |
dkato | 1:2f9f102b2b4c | 71 | #define LCD_H_BACK_PORCH (220u) |
dkato | 1:2f9f102b2b4c | 72 | #define LCD_H_FRONT_PORCH (70u) |
dkato | 1:2f9f102b2b4c | 73 | #define LCD_H_SYNC_WIDTH (80u) |
dkato | 1:2f9f102b2b4c | 74 | #define LCD_V_BACK_PORCH (20u) |
dkato | 1:2f9f102b2b4c | 75 | #define LCD_V_FRONT_PORCH (5u) |
dkato | 1:2f9f102b2b4c | 76 | #define LCD_V_SYNC_WIDTH (5u) |
dkato | 0:8970afa15acc | 77 | #elif ( LCD_SIZE == WXGA ) |
dkato | 1:2f9f102b2b4c | 78 | #define LCD_OUTPUT_CLOCK (85.4000f) |
dkato | 0:8970afa15acc | 79 | #define LCD_PIXEL_WIDTH (1280u) |
dkato | 0:8970afa15acc | 80 | #define LCD_PIXEL_HEIGHT (800u) |
dkato | 0:8970afa15acc | 81 | #define LCD_H_BACK_PORCH (200u) |
dkato | 0:8970afa15acc | 82 | #define LCD_H_FRONT_PORCH (64u) |
dkato | 0:8970afa15acc | 83 | #define LCD_H_SYNC_WIDTH (136u) |
dkato | 0:8970afa15acc | 84 | #define LCD_V_BACK_PORCH (24u) |
dkato | 0:8970afa15acc | 85 | #define LCD_V_FRONT_PORCH (1u) |
dkato | 0:8970afa15acc | 86 | #define LCD_V_SYNC_WIDTH (3u) |
dkato | 0:8970afa15acc | 87 | #endif |
dkato | 0:8970afa15acc | 88 | |
dkato | 0:8970afa15acc | 89 | /* FRAME BUFFER Parameter */ |
dkato | 0:8970afa15acc | 90 | #define FRAME_BUFFER_BYTE_PER_PIXEL (2) |
dkato | 0:8970afa15acc | 91 | #define FRAME_BUFFER_STRIDE (((LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL) + 31u) & ~31u) |
dkato | 0:8970afa15acc | 92 | |
dkato | 0:8970afa15acc | 93 | DigitalIn button(USER_BUTTON0); |
dkato | 0:8970afa15acc | 94 | I2C i2c(I2C_SDA, I2C_SCL); |
dkato | 0:8970afa15acc | 95 | DisplayBase Display; |
dkato | 0:8970afa15acc | 96 | Canvas2D_ContextClass canvas2d; |
dkato | 0:8970afa15acc | 97 | |
dkato | 2:e79ddc136968 | 98 | #if defined(__ICCARM__) |
dkato | 3:8489fb71f53d | 99 | #pragma data_alignment=32 |
dkato | 3:8489fb71f53d | 100 | static uint8_t user_frame_buffer[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]; |
dkato | 3:8489fb71f53d | 101 | static uint8_t user_frame_buffer2[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]; |
dkato | 3:8489fb71f53d | 102 | #pragma data_alignment=8 |
dkato | 4:1a08ad86d9af | 103 | static uint8_t JpegBuffer[MAX_JPEG_SIZE]@ ".mirrorram"; //8 bytes aligned!; |
dkato | 3:8489fb71f53d | 104 | #pragma data_alignment=4 |
dkato | 2:e79ddc136968 | 105 | #else |
dkato | 3:8489fb71f53d | 106 | static uint8_t user_frame_buffer[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32))); /* 32 bytes aligned */ |
dkato | 3:8489fb71f53d | 107 | static uint8_t user_frame_buffer2[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32))); /* 32 bytes aligned */ |
dkato | 4:1a08ad86d9af | 108 | static uint8_t JpegBuffer[MAX_JPEG_SIZE]__attribute((section("NC_BSS"),aligned(8))); //8 bytes aligned!; |
dkato | 2:e79ddc136968 | 109 | #endif |
dkato | 0:8970afa15acc | 110 | static frame_buffer_t frame_buffer_info; |
dkato | 0:8970afa15acc | 111 | static volatile int32_t vsync_count = 0; |
dkato | 0:8970afa15acc | 112 | |
dkato | 0:8970afa15acc | 113 | static void IntCallbackFunc_Vsync(DisplayBase::int_type_t int_type) { |
dkato | 0:8970afa15acc | 114 | /* Interrupt callback function for Vsync interruption */ |
dkato | 0:8970afa15acc | 115 | if (vsync_count > 0) { |
dkato | 0:8970afa15acc | 116 | vsync_count--; |
dkato | 0:8970afa15acc | 117 | } |
dkato | 0:8970afa15acc | 118 | } |
dkato | 0:8970afa15acc | 119 | |
dkato | 0:8970afa15acc | 120 | static void Wait_Vsync(const int32_t wait_count) { |
dkato | 0:8970afa15acc | 121 | /* Wait for the specified number of times Vsync occurs */ |
dkato | 0:8970afa15acc | 122 | vsync_count = wait_count; |
dkato | 0:8970afa15acc | 123 | while (vsync_count > 0) { |
dkato | 0:8970afa15acc | 124 | /* Do nothing */ |
dkato | 0:8970afa15acc | 125 | } |
dkato | 0:8970afa15acc | 126 | } |
dkato | 0:8970afa15acc | 127 | |
dkato | 0:8970afa15acc | 128 | static void Init_LCD_Display(uint8_t* disp_buf) { |
dkato | 0:8970afa15acc | 129 | /* Create DisplayBase object */ |
dkato | 0:8970afa15acc | 130 | DisplayBase::graphics_error_t error; |
dkato | 0:8970afa15acc | 131 | DisplayBase::rect_t rect; |
dkato | 0:8970afa15acc | 132 | DisplayBase::lcd_config_t lcd_config; |
dkato | 0:8970afa15acc | 133 | PinName lcd_pin[28] = { |
dkato | 0:8970afa15acc | 134 | /* data pin */ |
dkato | 0:8970afa15acc | 135 | P11_15, P11_14, P11_13, P11_12, P5_7, P5_6, P5_5, P5_4, P5_3, P5_2, P5_1, P5_0, |
dkato | 0:8970afa15acc | 136 | P4_7, P4_6, P4_5, P4_4, P10_12, P10_13, P10_14, P10_15, P3_15, P3_14, P3_13, |
dkato | 0:8970afa15acc | 137 | P3_12, P3_11, P3_10, P3_9, P3_8 |
dkato | 0:8970afa15acc | 138 | }; |
dkato | 0:8970afa15acc | 139 | |
dkato | 0:8970afa15acc | 140 | Thread::wait(100); |
dkato | 0:8970afa15acc | 141 | |
dkato | 0:8970afa15acc | 142 | lcd_config.lcd_type = DisplayBase::LCD_TYPE_PARALLEL_RGB; |
dkato | 0:8970afa15acc | 143 | lcd_config.intputClock = LCD_INPUT_CLOCK; |
dkato | 0:8970afa15acc | 144 | lcd_config.outputClock = LCD_OUTPUT_CLOCK; |
dkato | 0:8970afa15acc | 145 | lcd_config.lcd_outformat = DisplayBase::LCD_OUTFORMAT_RGB888; |
dkato | 0:8970afa15acc | 146 | lcd_config.lcd_edge = DisplayBase::EDGE_RISING; |
dkato | 0:8970afa15acc | 147 | lcd_config.h_toatal_period = (LCD_PIXEL_WIDTH + LCD_H_FRONT_PORCH + LCD_H_BACK_PORCH); |
dkato | 0:8970afa15acc | 148 | lcd_config.v_toatal_period = (LCD_PIXEL_HEIGHT + LCD_V_FRONT_PORCH + LCD_V_BACK_PORCH); |
dkato | 0:8970afa15acc | 149 | |
dkato | 0:8970afa15acc | 150 | lcd_config.h_disp_widht = LCD_PIXEL_WIDTH; |
dkato | 0:8970afa15acc | 151 | lcd_config.v_disp_widht = LCD_PIXEL_HEIGHT; |
dkato | 0:8970afa15acc | 152 | lcd_config.h_back_porch = LCD_H_BACK_PORCH; |
dkato | 0:8970afa15acc | 153 | lcd_config.v_back_porch = LCD_V_BACK_PORCH; |
dkato | 0:8970afa15acc | 154 | |
dkato | 0:8970afa15acc | 155 | lcd_config.h_sync_port = DisplayBase::LCD_TCON_PIN_1; |
dkato | 0:8970afa15acc | 156 | lcd_config.h_sync_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED; |
dkato | 0:8970afa15acc | 157 | lcd_config.h_sync_width = LCD_H_SYNC_WIDTH; |
dkato | 0:8970afa15acc | 158 | |
dkato | 0:8970afa15acc | 159 | lcd_config.v_sync_port = DisplayBase::LCD_TCON_PIN_2; |
dkato | 0:8970afa15acc | 160 | lcd_config.v_sync_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED; |
dkato | 0:8970afa15acc | 161 | lcd_config.v_sync_width = LCD_V_SYNC_WIDTH; |
dkato | 0:8970afa15acc | 162 | |
dkato | 0:8970afa15acc | 163 | lcd_config.de_port = DisplayBase::LCD_TCON_PIN_0; |
dkato | 0:8970afa15acc | 164 | lcd_config.de_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED; |
dkato | 0:8970afa15acc | 165 | |
dkato | 0:8970afa15acc | 166 | /* Graphics initialization process */ |
dkato | 0:8970afa15acc | 167 | error = Display.Graphics_init(&lcd_config); |
dkato | 0:8970afa15acc | 168 | if (error != DisplayBase::GRAPHICS_OK) { |
dkato | 0:8970afa15acc | 169 | printf("Line %d, error %d\n", __LINE__, error); |
dkato | 0:8970afa15acc | 170 | while (1); |
dkato | 0:8970afa15acc | 171 | } |
dkato | 0:8970afa15acc | 172 | |
dkato | 0:8970afa15acc | 173 | /* Interrupt callback function setting (Vsync signal output from scaler 0) */ |
dkato | 0:8970afa15acc | 174 | error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_LO_VSYNC, 0, IntCallbackFunc_Vsync); |
dkato | 0:8970afa15acc | 175 | if (error != DisplayBase::GRAPHICS_OK) { |
dkato | 0:8970afa15acc | 176 | printf("Line %d, error %d\n", __LINE__, error); |
dkato | 0:8970afa15acc | 177 | while (1); |
dkato | 0:8970afa15acc | 178 | } |
dkato | 0:8970afa15acc | 179 | |
dkato | 0:8970afa15acc | 180 | Display.Graphics_Lcd_Port_Init(lcd_pin, 28); |
dkato | 0:8970afa15acc | 181 | rect.vs = 0; |
dkato | 0:8970afa15acc | 182 | rect.vw = LCD_PIXEL_HEIGHT; |
dkato | 0:8970afa15acc | 183 | rect.hs = 0; |
dkato | 0:8970afa15acc | 184 | rect.hw = LCD_PIXEL_WIDTH; |
dkato | 0:8970afa15acc | 185 | |
dkato | 0:8970afa15acc | 186 | Display.Graphics_Read_Setting( |
dkato | 0:8970afa15acc | 187 | DisplayBase::GRAPHICS_LAYER_0, |
dkato | 0:8970afa15acc | 188 | (void *)disp_buf, |
dkato | 0:8970afa15acc | 189 | FRAME_BUFFER_STRIDE, |
dkato | 0:8970afa15acc | 190 | DisplayBase::GRAPHICS_FORMAT_RGB565, |
dkato | 0:8970afa15acc | 191 | DisplayBase::WR_RD_WRSWA_32_16BIT, |
dkato | 0:8970afa15acc | 192 | &rect |
dkato | 0:8970afa15acc | 193 | ); |
dkato | 0:8970afa15acc | 194 | } |
dkato | 0:8970afa15acc | 195 | |
dkato | 0:8970afa15acc | 196 | static void Start_LCD_Display(void) { |
dkato | 0:8970afa15acc | 197 | Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0); |
dkato | 0:8970afa15acc | 198 | } |
dkato | 0:8970afa15acc | 199 | |
dkato | 0:8970afa15acc | 200 | static void Update_LCD_Display(frame_buffer_t * frmbuf_info) { |
dkato | 0:8970afa15acc | 201 | Display.Graphics_Read_Change(DisplayBase::GRAPHICS_LAYER_0, |
dkato | 0:8970afa15acc | 202 | (void *)frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]); |
dkato | 0:8970afa15acc | 203 | Wait_Vsync(1); |
dkato | 0:8970afa15acc | 204 | } |
dkato | 0:8970afa15acc | 205 | |
dkato | 0:8970afa15acc | 206 | static void Swap_FrameBuffer(frame_buffer_t * frmbuf_info) { |
dkato | 0:8970afa15acc | 207 | if (frmbuf_info->draw_buffer_index == 1) { |
dkato | 0:8970afa15acc | 208 | frmbuf_info->draw_buffer_index = 0; |
dkato | 0:8970afa15acc | 209 | } else { |
dkato | 0:8970afa15acc | 210 | frmbuf_info->draw_buffer_index = 1; |
dkato | 0:8970afa15acc | 211 | } |
dkato | 0:8970afa15acc | 212 | } |
dkato | 0:8970afa15acc | 213 | |
dkato | 0:8970afa15acc | 214 | static void draw_image(frame_buffer_t* frmbuf_info, const graphics_image_t* image_new) { |
dkato | 0:8970afa15acc | 215 | Swap_FrameBuffer(frmbuf_info); |
dkato | 0:8970afa15acc | 216 | /* Clear */ |
dkato | 0:8970afa15acc | 217 | canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height); |
dkato | 0:8970afa15acc | 218 | /* Draw a image */ |
dkato | 0:8970afa15acc | 219 | canvas2d.globalAlpha = 1.0f; |
dkato | 0:8970afa15acc | 220 | canvas2d.drawImage((const graphics_image_t*)image_new, 0, 0, frmbuf_info->width, frmbuf_info->height); |
dkato | 0:8970afa15acc | 221 | R_OSPL_CLEAR_ERROR(); |
dkato | 0:8970afa15acc | 222 | /* Complete drawing */ |
dkato | 0:8970afa15acc | 223 | R_GRAPHICS_Finish(canvas2d.c_LanguageContext); |
dkato | 0:8970afa15acc | 224 | Update_LCD_Display(frmbuf_info); |
dkato | 0:8970afa15acc | 225 | } |
dkato | 0:8970afa15acc | 226 | |
dkato | 0:8970afa15acc | 227 | static void draw_image_scroll(frame_buffer_t* frmbuf_info, const graphics_image_t* image_last, |
dkato | 0:8970afa15acc | 228 | const graphics_image_t* image_new, float32_t scroll) { |
dkato | 0:8970afa15acc | 229 | Swap_FrameBuffer(frmbuf_info); |
dkato | 0:8970afa15acc | 230 | /* Clear */ |
dkato | 0:8970afa15acc | 231 | canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height); |
dkato | 0:8970afa15acc | 232 | /* Draw a image */ |
dkato | 0:8970afa15acc | 233 | canvas2d.globalAlpha = 1.0f; |
dkato | 0:8970afa15acc | 234 | canvas2d.drawImage((const graphics_image_t*)image_last, |
dkato | 0:8970afa15acc | 235 | (int_t)(frmbuf_info->width * scroll) * SCROLL_DIRECTION, 0, |
dkato | 0:8970afa15acc | 236 | frmbuf_info->width, frmbuf_info->height); |
dkato | 0:8970afa15acc | 237 | R_OSPL_CLEAR_ERROR(); |
dkato | 0:8970afa15acc | 238 | canvas2d.globalAlpha = 1.0f; |
dkato | 0:8970afa15acc | 239 | canvas2d.drawImage((const graphics_image_t*)image_new, |
dkato | 0:8970afa15acc | 240 | ((int_t)(frmbuf_info->width * scroll) - frmbuf_info->width) * SCROLL_DIRECTION, 0, |
dkato | 0:8970afa15acc | 241 | frmbuf_info->width, frmbuf_info->height); |
dkato | 0:8970afa15acc | 242 | R_OSPL_CLEAR_ERROR(); |
dkato | 0:8970afa15acc | 243 | /* Complete drawing */ |
dkato | 0:8970afa15acc | 244 | R_GRAPHICS_Finish(canvas2d.c_LanguageContext); |
dkato | 0:8970afa15acc | 245 | Update_LCD_Display(frmbuf_info); |
dkato | 0:8970afa15acc | 246 | } |
dkato | 0:8970afa15acc | 247 | |
dkato | 0:8970afa15acc | 248 | static void draw_image_dissolve(frame_buffer_t* frmbuf_info, const graphics_image_t* image_last, |
dkato | 0:8970afa15acc | 249 | const graphics_image_t* image_new, float32_t alpha) { |
dkato | 0:8970afa15acc | 250 | Swap_FrameBuffer(frmbuf_info); |
dkato | 0:8970afa15acc | 251 | /* Clear */ |
dkato | 0:8970afa15acc | 252 | canvas2d.clearRect(0, 0, frmbuf_info->width, frmbuf_info->height); |
dkato | 0:8970afa15acc | 253 | /* Draw a image */ |
dkato | 0:8970afa15acc | 254 | canvas2d.globalAlpha = 1.0f - alpha; |
dkato | 0:8970afa15acc | 255 | canvas2d.drawImage((const graphics_image_t*)image_last, 0, 0, frmbuf_info->width, frmbuf_info->height); |
dkato | 0:8970afa15acc | 256 | R_OSPL_CLEAR_ERROR(); |
dkato | 0:8970afa15acc | 257 | canvas2d.globalAlpha = alpha; |
dkato | 0:8970afa15acc | 258 | canvas2d.drawImage((const graphics_image_t*)image_new, 0, 0, frmbuf_info->width, frmbuf_info->height); |
dkato | 0:8970afa15acc | 259 | R_OSPL_CLEAR_ERROR(); |
dkato | 0:8970afa15acc | 260 | /* Complete drawing */ |
dkato | 0:8970afa15acc | 261 | R_GRAPHICS_Finish(canvas2d.c_LanguageContext); |
dkato | 0:8970afa15acc | 262 | Update_LCD_Display(frmbuf_info); |
dkato | 0:8970afa15acc | 263 | } |
dkato | 0:8970afa15acc | 264 | |
dkato | 0:8970afa15acc | 265 | int main(void) { |
dkato | 0:8970afa15acc | 266 | errnum_t err; |
dkato | 0:8970afa15acc | 267 | Canvas2D_ContextConfigClass config; |
dkato | 0:8970afa15acc | 268 | |
dkato | 0:8970afa15acc | 269 | memset(user_frame_buffer, 0, sizeof(user_frame_buffer)); |
dkato | 0:8970afa15acc | 270 | memset(user_frame_buffer2, 0, sizeof(user_frame_buffer2)); |
dkato | 0:8970afa15acc | 271 | frame_buffer_info.buffer_address[0] = user_frame_buffer; |
dkato | 0:8970afa15acc | 272 | frame_buffer_info.buffer_address[1] = user_frame_buffer2; |
dkato | 0:8970afa15acc | 273 | frame_buffer_info.buffer_count = 2; |
dkato | 0:8970afa15acc | 274 | frame_buffer_info.show_buffer_index = 0; |
dkato | 0:8970afa15acc | 275 | frame_buffer_info.draw_buffer_index = 0; |
dkato | 0:8970afa15acc | 276 | frame_buffer_info.width = LCD_PIXEL_WIDTH; |
dkato | 0:8970afa15acc | 277 | frame_buffer_info.byte_per_pixel = FRAME_BUFFER_BYTE_PER_PIXEL; |
dkato | 0:8970afa15acc | 278 | frame_buffer_info.stride = LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL; |
dkato | 0:8970afa15acc | 279 | frame_buffer_info.height = LCD_PIXEL_HEIGHT; |
dkato | 0:8970afa15acc | 280 | frame_buffer_info.pixel_format = PIXEL_FORMAT_RGB565; |
dkato | 0:8970afa15acc | 281 | Init_LCD_Display(frame_buffer_info.buffer_address[0]); |
dkato | 0:8970afa15acc | 282 | |
dkato | 0:8970afa15acc | 283 | config.frame_buffer = &frame_buffer_info; |
dkato | 0:8970afa15acc | 284 | canvas2d = R_RGA_New_Canvas2D_ContextClass(config); |
dkato | 0:8970afa15acc | 285 | err = R_OSPL_GetErrNum(); |
dkato | 0:8970afa15acc | 286 | if (err != 0) { |
dkato | 0:8970afa15acc | 287 | printf("Line %d, error %d\n", __LINE__, err); |
dkato | 0:8970afa15acc | 288 | while (1); |
dkato | 0:8970afa15acc | 289 | } |
dkato | 0:8970afa15acc | 290 | Start_LCD_Display(); |
dkato | 0:8970afa15acc | 291 | |
dkato | 0:8970afa15acc | 292 | SDFileSystem sd(P8_5, P8_6, P8_3, P8_4, "sd"); |
dkato | 0:8970afa15acc | 293 | FILE * fp = NULL; |
dkato | 0:8970afa15acc | 294 | DIR * d = NULL; |
dkato | 0:8970afa15acc | 295 | char file_path[sizeof(FLD_PATH) + FILE_NAME_LEN]; |
dkato | 0:8970afa15acc | 296 | int jpeg_toggle = 0; |
dkato | 0:8970afa15acc | 297 | bool first_view = true; |
dkato | 0:8970afa15acc | 298 | size_t ret; |
dkato | 3:8489fb71f53d | 299 | Timer t; |
dkato | 4:1a08ad86d9af | 300 | uint8_t * p_JpegBuffer[2]; |
dkato | 4:1a08ad86d9af | 301 | |
dkato | 4:1a08ad86d9af | 302 | p_JpegBuffer[0] = JpegBuffer; |
dkato | 4:1a08ad86d9af | 303 | p_JpegBuffer[1] = new uint8_t[MAX_JPEG_SIZE]; |
dkato | 0:8970afa15acc | 304 | |
dkato | 0:8970afa15acc | 305 | while (1) { |
dkato | 0:8970afa15acc | 306 | // file search |
dkato | 0:8970afa15acc | 307 | if (d == NULL) { |
dkato | 0:8970afa15acc | 308 | d = opendir(FLD_PATH); |
dkato | 0:8970afa15acc | 309 | } |
dkato | 0:8970afa15acc | 310 | struct dirent * p; |
dkato | 0:8970afa15acc | 311 | while ((p = readdir(d)) != NULL) { |
dkato | 0:8970afa15acc | 312 | size_t len = strlen(p->d_name); |
dkato | 0:8970afa15acc | 313 | if ((len > 4) && (len < FILE_NAME_LEN) |
dkato | 0:8970afa15acc | 314 | && (strncasecmp(&p->d_name[len - 4], ".jpg", 4) == 0)) { |
dkato | 0:8970afa15acc | 315 | strcpy(file_path, FLD_PATH); |
dkato | 0:8970afa15acc | 316 | strcat(file_path, p->d_name); |
dkato | 0:8970afa15acc | 317 | fp = fopen(file_path, "r"); |
dkato | 4:1a08ad86d9af | 318 | ret = fread(p_JpegBuffer[jpeg_toggle], sizeof(char), MAX_JPEG_SIZE, fp); |
dkato | 0:8970afa15acc | 319 | fclose(fp); |
dkato | 0:8970afa15acc | 320 | if (ret < MAX_JPEG_SIZE) { |
dkato | 0:8970afa15acc | 321 | if (first_view != false) { |
dkato | 3:8489fb71f53d | 322 | t.reset(); |
dkato | 3:8489fb71f53d | 323 | t.start(); |
dkato | 0:8970afa15acc | 324 | // Effect NONE |
dkato | 0:8970afa15acc | 325 | first_view = false; |
dkato | 4:1a08ad86d9af | 326 | draw_image(&frame_buffer_info, (const graphics_image_t*)p_JpegBuffer[jpeg_toggle]); |
dkato | 0:8970afa15acc | 327 | } else { |
dkato | 0:8970afa15acc | 328 | bool key_press = false; |
dkato | 3:8489fb71f53d | 329 | t.stop(); |
dkato | 0:8970afa15acc | 330 | // Wait timeout or key press |
dkato | 3:8489fb71f53d | 331 | for (int i = t.read_ms(); i < WAIT_TIME; i += 100) { |
dkato | 0:8970afa15acc | 332 | if (button == 0) { |
dkato | 0:8970afa15acc | 333 | key_press = true; |
dkato | 0:8970afa15acc | 334 | break; |
dkato | 0:8970afa15acc | 335 | } |
dkato | 0:8970afa15acc | 336 | Thread::wait(100); |
dkato | 0:8970afa15acc | 337 | } |
dkato | 3:8489fb71f53d | 338 | t.reset(); |
dkato | 3:8489fb71f53d | 339 | t.start(); |
dkato | 0:8970afa15acc | 340 | if (key_press == false) { |
dkato | 0:8970afa15acc | 341 | // Effect DISSOLVE |
dkato | 0:8970afa15acc | 342 | for (int i = 1; i <= DISSOLVE_STEP_NUM; i++) { |
dkato | 0:8970afa15acc | 343 | draw_image_dissolve(&frame_buffer_info, |
dkato | 4:1a08ad86d9af | 344 | (const graphics_image_t*)p_JpegBuffer[!jpeg_toggle], |
dkato | 4:1a08ad86d9af | 345 | (const graphics_image_t*)p_JpegBuffer[jpeg_toggle], |
dkato | 0:8970afa15acc | 346 | (float32_t)i / (float32_t)DISSOLVE_STEP_NUM); |
dkato | 0:8970afa15acc | 347 | } |
dkato | 0:8970afa15acc | 348 | } else { |
dkato | 0:8970afa15acc | 349 | // Effect SCROLL |
dkato | 0:8970afa15acc | 350 | for (int i = 1; i <= SCROLL_STEP_NUM; i++) { |
dkato | 0:8970afa15acc | 351 | draw_image_scroll(&frame_buffer_info, |
dkato | 4:1a08ad86d9af | 352 | (const graphics_image_t*)p_JpegBuffer[!jpeg_toggle], |
dkato | 4:1a08ad86d9af | 353 | (const graphics_image_t*)p_JpegBuffer[jpeg_toggle], |
dkato | 0:8970afa15acc | 354 | (float32_t)i / (float32_t)SCROLL_STEP_NUM); |
dkato | 0:8970afa15acc | 355 | } |
dkato | 0:8970afa15acc | 356 | } |
dkato | 0:8970afa15acc | 357 | } |
dkato | 0:8970afa15acc | 358 | jpeg_toggle = !jpeg_toggle; |
dkato | 0:8970afa15acc | 359 | } |
dkato | 0:8970afa15acc | 360 | break; |
dkato | 0:8970afa15acc | 361 | } |
dkato | 0:8970afa15acc | 362 | } |
dkato | 0:8970afa15acc | 363 | if (p == NULL) { |
dkato | 0:8970afa15acc | 364 | closedir(d); |
dkato | 0:8970afa15acc | 365 | d = NULL; |
dkato | 0:8970afa15acc | 366 | } |
dkato | 0:8970afa15acc | 367 | } |
dkato | 0:8970afa15acc | 368 | } |