For Seminar
Dependencies: GR-PEACH_video GraphicsFramework R_BSP mbed-rtos mbed
Fork of RGA_HelloWorld by
main.cpp@7:b007a4342314, 2016-09-08 (annotated)
- Committer:
- ShinjiYamano
- Date:
- Thu Sep 08 05:23:27 2016 +0000
- Revision:
- 7:b007a4342314
- Parent:
- 4:99ff10b59637
For Seminar (Rev.2)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
1050186 | 0:84e4649e7707 | 1 | /* |
1050186 | 0:84e4649e7707 | 2 | Permission is hereby granted, free of charge, to any person obtaining a copy |
1050186 | 0:84e4649e7707 | 3 | of this software and associated documentation files (the "Software"), to deal |
1050186 | 0:84e4649e7707 | 4 | in the Software without restriction, including without limitation the rights |
1050186 | 0:84e4649e7707 | 5 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
1050186 | 0:84e4649e7707 | 6 | copies of the Software, and to permit persons to whom the Software is |
1050186 | 0:84e4649e7707 | 7 | furnished to do so, subject to the following conditions: |
1050186 | 0:84e4649e7707 | 8 | |
1050186 | 0:84e4649e7707 | 9 | The above copyright notice and this permission notice shall be included in |
1050186 | 0:84e4649e7707 | 10 | all copies or substantial portions of the Software. |
1050186 | 0:84e4649e7707 | 11 | |
1050186 | 0:84e4649e7707 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
1050186 | 0:84e4649e7707 | 13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
1050186 | 0:84e4649e7707 | 14 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
1050186 | 0:84e4649e7707 | 15 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
1050186 | 0:84e4649e7707 | 16 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
1050186 | 0:84e4649e7707 | 17 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
1050186 | 0:84e4649e7707 | 18 | THE SOFTWARE. |
1050186 | 0:84e4649e7707 | 19 | */ |
dkato | 2:c7faef0ef374 | 20 | |
1050186 | 0:84e4649e7707 | 21 | #include "mbed.h" |
1050186 | 0:84e4649e7707 | 22 | #include "rga_func.h" |
1050186 | 0:84e4649e7707 | 23 | #include "DisplayBace.h" |
1050186 | 0:84e4649e7707 | 24 | #include "rtos.h" |
1050186 | 0:84e4649e7707 | 25 | |
1050186 | 0:84e4649e7707 | 26 | |
1050186 | 0:84e4649e7707 | 27 | /* LCD Parameter */ |
dkato | 2:c7faef0ef374 | 28 | #define LCD_INPUT_CLOCK (66.67f) |
dkato | 2:c7faef0ef374 | 29 | #define LCD_OUTPUT_CLOCK (33.26f) |
1050186 | 0:84e4649e7707 | 30 | |
dkato | 2:c7faef0ef374 | 31 | #define LCD_PIXEL_WIDTH (800) |
dkato | 2:c7faef0ef374 | 32 | #define LCD_PIXEL_HEIGHT (480) |
dkato | 2:c7faef0ef374 | 33 | #define LCD_H_BACK_PORCH (128 + 36) |
dkato | 2:c7faef0ef374 | 34 | #define LCD_H_FRONT_PORCH (92) |
dkato | 2:c7faef0ef374 | 35 | #define LCD_V_BACK_PORCH (35 + 5) |
dkato | 2:c7faef0ef374 | 36 | #define LCD_V_FRONT_PORCH (5) |
1050186 | 0:84e4649e7707 | 37 | |
1050186 | 0:84e4649e7707 | 38 | /* FRAME BUFFER Parameter */ |
dkato | 2:c7faef0ef374 | 39 | #define FRAME_BUFFER_BYTE_PER_PIXEL (2) |
1050186 | 0:84e4649e7707 | 40 | #define FRAME_BUFFER_STRIDE (((LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL) + 31u) & ~31u) |
1050186 | 0:84e4649e7707 | 41 | |
dkato | 2:c7faef0ef374 | 42 | #define DRAW_RECTANGLE_CNT_MAX (4) |
dkato | 2:c7faef0ef374 | 43 | |
1050186 | 0:84e4649e7707 | 44 | typedef enum { |
dkato | 2:c7faef0ef374 | 45 | RGA_FUNC_NON, |
dkato | 2:c7faef0ef374 | 46 | RGA_FUNC_DRAW_RECTANGLE, |
1050186 | 0:84e4649e7707 | 47 | RGA_FUNC_DRAW_IMAGE, |
1050186 | 0:84e4649e7707 | 48 | RGA_FUNC_DISSOLVE, |
1050186 | 0:84e4649e7707 | 49 | RGA_FUNC_SCROLL, |
1050186 | 0:84e4649e7707 | 50 | RGA_FUNC_ZOOM, |
1050186 | 0:84e4649e7707 | 51 | RGA_FUNC_ROTATION, |
1050186 | 0:84e4649e7707 | 52 | RGA_FUNC_ACCELERATE, |
dkato | 2:c7faef0ef374 | 53 | RGA_FUNC_ANIME_EASE, |
dkato | 2:c7faef0ef374 | 54 | RGA_FUNC_ANIME_LINEAR, |
dkato | 2:c7faef0ef374 | 55 | RGA_FUNC_ANIME_EASE_IN, |
dkato | 2:c7faef0ef374 | 56 | RGA_FUNC_ANIME_EASE_OUT, |
dkato | 2:c7faef0ef374 | 57 | RGA_FUNC_ANIME_EASE_IN_OUT, |
dkato | 2:c7faef0ef374 | 58 | RGA_FUNC_RETURN, |
dkato | 2:c7faef0ef374 | 59 | RGA_FUNC_END |
1050186 | 0:84e4649e7707 | 60 | }func_code_t; |
1050186 | 0:84e4649e7707 | 61 | |
1050186 | 0:84e4649e7707 | 62 | DigitalOut lcd_pwon(P7_15); |
1050186 | 0:84e4649e7707 | 63 | DigitalOut lcd_blon(P8_1); |
1050186 | 0:84e4649e7707 | 64 | PwmOut lcd_cntrst(P8_15); |
1050186 | 0:84e4649e7707 | 65 | I2C i2c(I2C_SDA, I2C_SCL); |
1050186 | 0:84e4649e7707 | 66 | DisplayBase Display; |
1050186 | 0:84e4649e7707 | 67 | |
1050186 | 0:84e4649e7707 | 68 | typedef struct { |
1050186 | 0:84e4649e7707 | 69 | uint8_t y_h: 3, |
1050186 | 0:84e4649e7707 | 70 | reserved: 1, |
1050186 | 0:84e4649e7707 | 71 | x_h: 3, |
1050186 | 0:84e4649e7707 | 72 | valid: 1; |
1050186 | 0:84e4649e7707 | 73 | uint8_t x_l; |
1050186 | 0:84e4649e7707 | 74 | uint8_t y_l; |
1050186 | 0:84e4649e7707 | 75 | uint8_t z; |
1050186 | 0:84e4649e7707 | 76 | } xyz_data_t; |
1050186 | 0:84e4649e7707 | 77 | |
1050186 | 0:84e4649e7707 | 78 | typedef struct { |
1050186 | 0:84e4649e7707 | 79 | uint8_t fingers: 4, |
1050186 | 0:84e4649e7707 | 80 | reserved: 4; |
1050186 | 0:84e4649e7707 | 81 | uint8_t keys; |
1050186 | 0:84e4649e7707 | 82 | xyz_data_t xyz_data; |
1050186 | 0:84e4649e7707 | 83 | } stx_report_data_t; |
1050186 | 0:84e4649e7707 | 84 | |
1050186 | 0:84e4649e7707 | 85 | typedef struct { |
1050186 | 0:84e4649e7707 | 86 | uint32_t pic_pos_x; /* X position of the key picture. */ |
1050186 | 0:84e4649e7707 | 87 | uint32_t pic_pos_y; /* Y position of the key picture. */ |
1050186 | 0:84e4649e7707 | 88 | uint32_t pic_width; /* Width of the key picture. */ |
1050186 | 0:84e4649e7707 | 89 | uint32_t pic_height; /* Height of the key picture. */ |
1050186 | 0:84e4649e7707 | 90 | func_code_t func_code; /* func code of the key picture. */ |
1050186 | 0:84e4649e7707 | 91 | } key_pic_info_t; |
1050186 | 0:84e4649e7707 | 92 | |
dkato | 2:c7faef0ef374 | 93 | static uint8_t user_frame_buffer[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32))); /* 32 bytes aligned */ |
dkato | 2:c7faef0ef374 | 94 | static uint8_t user_frame_buffer2[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32))); /* 32 bytes aligned */ |
1050186 | 0:84e4649e7707 | 95 | static frame_buffer_t frame_buffer_info; |
1050186 | 0:84e4649e7707 | 96 | static volatile int32_t vsync_count = 0; |
1050186 | 0:84e4649e7707 | 97 | |
dkato | 2:c7faef0ef374 | 98 | static const key_pic_info_t top_screen_key_tbl[] = { |
dkato | 2:c7faef0ef374 | 99 | /* X Y Width Height Func code */ |
dkato | 2:c7faef0ef374 | 100 | { 50, 350, 120, 52, RGA_FUNC_DRAW_RECTANGLE }, /* RGA Func1 */ |
dkato | 2:c7faef0ef374 | 101 | { 230, 350, 120, 52, RGA_FUNC_DRAW_IMAGE }, /* RGA Func2 */ |
dkato | 2:c7faef0ef374 | 102 | { 410, 350, 120, 52, RGA_FUNC_DISSOLVE }, /* RGA Func3 */ |
dkato | 2:c7faef0ef374 | 103 | { 50, 420, 120, 52, RGA_FUNC_SCROLL }, /* RGA Func4 */ |
dkato | 2:c7faef0ef374 | 104 | { 230, 420, 120, 52, RGA_FUNC_ZOOM }, /* RGA Func5 */ |
dkato | 2:c7faef0ef374 | 105 | { 410, 420, 120, 52, RGA_FUNC_ROTATION }, /* RGA Func6 */ |
dkato | 2:c7faef0ef374 | 106 | { 615, 420, 120, 52, RGA_FUNC_ACCELERATE }, /* RGA Func7 */ |
dkato | 2:c7faef0ef374 | 107 | { 0, 0, 0, 0, RGA_FUNC_END } /* table end */ |
dkato | 2:c7faef0ef374 | 108 | }; |
dkato | 2:c7faef0ef374 | 109 | |
dkato | 2:c7faef0ef374 | 110 | static const key_pic_info_t return_key_tbl[] = { |
dkato | 2:c7faef0ef374 | 111 | /* X Y Width Height Func code */ |
dkato | 2:c7faef0ef374 | 112 | { 640, 10, 150, 84, RGA_FUNC_RETURN }, /* Return Top Screen */ |
dkato | 2:c7faef0ef374 | 113 | { 0, 0, 0, 0, RGA_FUNC_END } /* table end */ |
dkato | 2:c7faef0ef374 | 114 | }; |
dkato | 2:c7faef0ef374 | 115 | |
dkato | 2:c7faef0ef374 | 116 | static const key_pic_info_t animetion_timing_key_tbl[] = { |
dkato | 2:c7faef0ef374 | 117 | /* X Y Width Height Func code */ |
dkato | 2:c7faef0ef374 | 118 | { 640, 10, 150, 84, RGA_FUNC_RETURN }, /* Return Top Screen */ |
dkato | 2:c7faef0ef374 | 119 | { 17, 372, 136, 50, RGA_FUNC_ANIME_EASE }, /* ease */ |
dkato | 2:c7faef0ef374 | 120 | { 173, 372, 136, 50, RGA_FUNC_ANIME_LINEAR }, /* linear */ |
dkato | 2:c7faef0ef374 | 121 | { 330, 372, 136, 50, RGA_FUNC_ANIME_EASE_IN }, /* ease-in */ |
dkato | 2:c7faef0ef374 | 122 | { 487, 372, 136, 50, RGA_FUNC_ANIME_EASE_OUT }, /* ease-out */ |
dkato | 2:c7faef0ef374 | 123 | { 644, 372, 136, 50, RGA_FUNC_ANIME_EASE_IN_OUT }, /* ease-in-out */ |
dkato | 2:c7faef0ef374 | 124 | { 0, 0, 0, 0, RGA_FUNC_END } /* table end */ |
1050186 | 0:84e4649e7707 | 125 | }; |
1050186 | 0:84e4649e7707 | 126 | |
1050186 | 0:84e4649e7707 | 127 | static void IntCallbackFunc_Vsync(DisplayBase::int_type_t int_type) { |
1050186 | 0:84e4649e7707 | 128 | /* Interrupt callback function for Vsync interruption */ |
1050186 | 0:84e4649e7707 | 129 | if (vsync_count > 0) { |
1050186 | 0:84e4649e7707 | 130 | vsync_count--; |
1050186 | 0:84e4649e7707 | 131 | } |
1050186 | 0:84e4649e7707 | 132 | } |
1050186 | 0:84e4649e7707 | 133 | |
1050186 | 0:84e4649e7707 | 134 | static void Wait_Vsync(const int32_t wait_count) { |
1050186 | 0:84e4649e7707 | 135 | /* Wait for the specified number of times Vsync occurs */ |
1050186 | 0:84e4649e7707 | 136 | vsync_count = wait_count; |
1050186 | 0:84e4649e7707 | 137 | while (vsync_count > 0) { |
1050186 | 0:84e4649e7707 | 138 | /* Do nothing */ |
1050186 | 0:84e4649e7707 | 139 | } |
1050186 | 0:84e4649e7707 | 140 | } |
1050186 | 0:84e4649e7707 | 141 | |
1050186 | 0:84e4649e7707 | 142 | static void Init_LCD_Display(uint8_t* disp_buf) { |
1050186 | 0:84e4649e7707 | 143 | /* Create DisplayBase object */ |
1050186 | 0:84e4649e7707 | 144 | DisplayBase::graphics_error_t error; |
1050186 | 0:84e4649e7707 | 145 | DisplayBase::rect_t rect; |
1050186 | 0:84e4649e7707 | 146 | DisplayBase::lcd_config_t lcd_config; |
1050186 | 0:84e4649e7707 | 147 | PinName lvds_pin[8] = { |
1050186 | 0:84e4649e7707 | 148 | /* data pin */ |
1050186 | 0:84e4649e7707 | 149 | P5_7, P5_6, P5_5, P5_4, P5_3, P5_2, P5_1, P5_0 |
1050186 | 0:84e4649e7707 | 150 | }; |
1050186 | 0:84e4649e7707 | 151 | |
1050186 | 0:84e4649e7707 | 152 | lcd_pwon = 0; |
1050186 | 0:84e4649e7707 | 153 | lcd_blon = 0; |
1050186 | 0:84e4649e7707 | 154 | Thread::wait(100); |
1050186 | 0:84e4649e7707 | 155 | lcd_pwon = 1; |
1050186 | 0:84e4649e7707 | 156 | lcd_blon = 1; |
1050186 | 0:84e4649e7707 | 157 | Thread::wait(100); |
1050186 | 0:84e4649e7707 | 158 | |
1050186 | 0:84e4649e7707 | 159 | lcd_config.lcd_type = DisplayBase::LCD_TYPE_LVDS; |
1050186 | 0:84e4649e7707 | 160 | lcd_config.intputClock = LCD_INPUT_CLOCK; |
1050186 | 0:84e4649e7707 | 161 | lcd_config.outputClock = LCD_OUTPUT_CLOCK; |
1050186 | 0:84e4649e7707 | 162 | lcd_config.lcd_outformat = DisplayBase::LCD_OUTFORMAT_RGB888; |
1050186 | 0:84e4649e7707 | 163 | lcd_config.lcd_edge = DisplayBase::EDGE_RISING; |
1050186 | 0:84e4649e7707 | 164 | lcd_config.h_toatal_period = (LCD_PIXEL_WIDTH + LCD_H_FRONT_PORCH + LCD_H_BACK_PORCH); |
1050186 | 0:84e4649e7707 | 165 | lcd_config.v_toatal_period = (LCD_PIXEL_HEIGHT + LCD_V_FRONT_PORCH + LCD_V_BACK_PORCH); |
1050186 | 0:84e4649e7707 | 166 | |
1050186 | 0:84e4649e7707 | 167 | lcd_config.h_disp_widht = LCD_PIXEL_WIDTH; |
1050186 | 0:84e4649e7707 | 168 | lcd_config.v_disp_widht = LCD_PIXEL_HEIGHT; |
1050186 | 0:84e4649e7707 | 169 | lcd_config.h_back_porch = LCD_H_BACK_PORCH; |
1050186 | 0:84e4649e7707 | 170 | lcd_config.v_back_porch = LCD_V_BACK_PORCH; |
1050186 | 0:84e4649e7707 | 171 | |
1050186 | 0:84e4649e7707 | 172 | lcd_config.h_sync_port = DisplayBase::LCD_TCON_PIN_NON; |
1050186 | 0:84e4649e7707 | 173 | lcd_config.h_sync_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED; |
1050186 | 0:84e4649e7707 | 174 | lcd_config.h_sync_width = 0; |
1050186 | 0:84e4649e7707 | 175 | |
1050186 | 0:84e4649e7707 | 176 | lcd_config.v_sync_port = DisplayBase::LCD_TCON_PIN_NON; |
1050186 | 0:84e4649e7707 | 177 | lcd_config.v_sync_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED; |
1050186 | 0:84e4649e7707 | 178 | lcd_config.v_sync_width = 0; |
1050186 | 0:84e4649e7707 | 179 | |
1050186 | 0:84e4649e7707 | 180 | lcd_config.de_port = DisplayBase::LCD_TCON_PIN_3; |
1050186 | 0:84e4649e7707 | 181 | lcd_config.de_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED; |
1050186 | 0:84e4649e7707 | 182 | |
1050186 | 0:84e4649e7707 | 183 | /* Graphics initialization process */ |
1050186 | 0:84e4649e7707 | 184 | error = Display.Graphics_init(&lcd_config); |
1050186 | 0:84e4649e7707 | 185 | if (error != DisplayBase::GRAPHICS_OK) { |
1050186 | 0:84e4649e7707 | 186 | printf("Line %d, error %d\n", __LINE__, error); |
1050186 | 0:84e4649e7707 | 187 | while (1); |
1050186 | 0:84e4649e7707 | 188 | } |
1050186 | 0:84e4649e7707 | 189 | |
1050186 | 0:84e4649e7707 | 190 | /* Interrupt callback function setting (Vsync signal output from scaler 0) */ |
1050186 | 0:84e4649e7707 | 191 | error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_LO_VSYNC, 0, IntCallbackFunc_Vsync); |
1050186 | 0:84e4649e7707 | 192 | if (error != DisplayBase::GRAPHICS_OK) { |
1050186 | 0:84e4649e7707 | 193 | printf("Line %d, error %d\n", __LINE__, error); |
1050186 | 0:84e4649e7707 | 194 | while (1); |
1050186 | 0:84e4649e7707 | 195 | } |
1050186 | 0:84e4649e7707 | 196 | |
1050186 | 0:84e4649e7707 | 197 | Display.Graphics_Lvds_Port_Init(lvds_pin, 8); |
1050186 | 0:84e4649e7707 | 198 | rect.vs = 0; |
1050186 | 0:84e4649e7707 | 199 | rect.vw = LCD_PIXEL_HEIGHT; |
1050186 | 0:84e4649e7707 | 200 | rect.hs = 0; |
1050186 | 0:84e4649e7707 | 201 | rect.hw = LCD_PIXEL_WIDTH; |
1050186 | 0:84e4649e7707 | 202 | |
1050186 | 0:84e4649e7707 | 203 | Display.Graphics_Read_Setting( |
1050186 | 0:84e4649e7707 | 204 | DisplayBase::GRAPHICS_LAYER_0, |
1050186 | 0:84e4649e7707 | 205 | (void *)disp_buf, |
1050186 | 0:84e4649e7707 | 206 | FRAME_BUFFER_STRIDE, |
1050186 | 0:84e4649e7707 | 207 | DisplayBase::GRAPHICS_FORMAT_RGB565, |
1050186 | 0:84e4649e7707 | 208 | DisplayBase::WR_RD_WRSWA_32_16BIT, |
1050186 | 0:84e4649e7707 | 209 | &rect |
1050186 | 0:84e4649e7707 | 210 | ); |
1050186 | 0:84e4649e7707 | 211 | } |
1050186 | 0:84e4649e7707 | 212 | |
1050186 | 0:84e4649e7707 | 213 | static void Start_LCD_Display(void) { |
1050186 | 0:84e4649e7707 | 214 | Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0); |
1050186 | 0:84e4649e7707 | 215 | |
1050186 | 0:84e4649e7707 | 216 | lcd_cntrst.write(1.0); |
1050186 | 0:84e4649e7707 | 217 | } |
1050186 | 0:84e4649e7707 | 218 | |
dkato | 2:c7faef0ef374 | 219 | static void Update_LCD_Display(frame_buffer_t * frmbuf_info) { |
dkato | 2:c7faef0ef374 | 220 | Display.Graphics_Read_Change(DisplayBase::GRAPHICS_LAYER_0, |
dkato | 2:c7faef0ef374 | 221 | (void *)frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]); |
1050186 | 0:84e4649e7707 | 222 | Wait_Vsync(1); |
1050186 | 0:84e4649e7707 | 223 | } |
1050186 | 0:84e4649e7707 | 224 | |
1050186 | 0:84e4649e7707 | 225 | static int Get_Coordinates(uint8_t *count, uint32_t *x0, uint32_t *y0) { |
1050186 | 0:84e4649e7707 | 226 | char buf[6]; |
1050186 | 0:84e4649e7707 | 227 | stx_report_data_t *pdata; |
1050186 | 0:84e4649e7707 | 228 | int ret = -1; |
1050186 | 0:84e4649e7707 | 229 | *count = 0; // Set point detected count to 0 |
1050186 | 0:84e4649e7707 | 230 | |
1050186 | 0:84e4649e7707 | 231 | if (i2c.read((0x55 << 1), buf, sizeof(buf)) == 0) { |
1050186 | 0:84e4649e7707 | 232 | pdata = (stx_report_data_t *)buf; |
1050186 | 0:84e4649e7707 | 233 | if (pdata->fingers) { |
1050186 | 0:84e4649e7707 | 234 | if (pdata->xyz_data.valid) { |
1050186 | 0:84e4649e7707 | 235 | *x0 = (pdata->xyz_data.x_h << 8) | pdata->xyz_data.x_l; |
1050186 | 0:84e4649e7707 | 236 | *y0 = (pdata->xyz_data.y_h << 8) | pdata->xyz_data.y_l; |
1050186 | 0:84e4649e7707 | 237 | (*count)++; |
1050186 | 0:84e4649e7707 | 238 | } |
1050186 | 0:84e4649e7707 | 239 | } |
1050186 | 0:84e4649e7707 | 240 | ret = 0; |
1050186 | 0:84e4649e7707 | 241 | } |
1050186 | 0:84e4649e7707 | 242 | |
1050186 | 0:84e4649e7707 | 243 | return ret; |
1050186 | 0:84e4649e7707 | 244 | } |
1050186 | 0:84e4649e7707 | 245 | |
dkato | 2:c7faef0ef374 | 246 | static func_code_t Scan_Key(const key_pic_info_t * key_tbl, const uint32_t pos_x, const uint32_t pos_y) { |
1050186 | 0:84e4649e7707 | 247 | func_code_t ret = RGA_FUNC_NON; |
1050186 | 0:84e4649e7707 | 248 | |
dkato | 2:c7faef0ef374 | 249 | while (ret == RGA_FUNC_NON) { |
dkato | 2:c7faef0ef374 | 250 | if (key_tbl->func_code == RGA_FUNC_END) { |
dkato | 2:c7faef0ef374 | 251 | break; |
dkato | 2:c7faef0ef374 | 252 | } |
1050186 | 0:84e4649e7707 | 253 | /* Check the range of the X position */ |
dkato | 2:c7faef0ef374 | 254 | if ((pos_x >= key_tbl->pic_pos_x) && (pos_x <= (key_tbl->pic_pos_x + key_tbl->pic_width))) { |
1050186 | 0:84e4649e7707 | 255 | /* Check the range of the Y position */ |
dkato | 2:c7faef0ef374 | 256 | if ((pos_y >= key_tbl->pic_pos_y) && (pos_y <= (key_tbl->pic_pos_y + key_tbl->pic_height))) { |
1050186 | 0:84e4649e7707 | 257 | /* Decide the func code. */ |
dkato | 2:c7faef0ef374 | 258 | ret = key_tbl->func_code; |
1050186 | 0:84e4649e7707 | 259 | } |
1050186 | 0:84e4649e7707 | 260 | } |
dkato | 2:c7faef0ef374 | 261 | key_tbl++; |
1050186 | 0:84e4649e7707 | 262 | } |
1050186 | 0:84e4649e7707 | 263 | |
1050186 | 0:84e4649e7707 | 264 | return ret; |
1050186 | 0:84e4649e7707 | 265 | } |
1050186 | 0:84e4649e7707 | 266 | |
1050186 | 0:84e4649e7707 | 267 | static void Swap_FrameBuffer(frame_buffer_t * frmbuf_info) { |
1050186 | 0:84e4649e7707 | 268 | if (frmbuf_info->draw_buffer_index == 1) { |
1050186 | 0:84e4649e7707 | 269 | frmbuf_info->draw_buffer_index = 0; |
1050186 | 0:84e4649e7707 | 270 | } else { |
1050186 | 0:84e4649e7707 | 271 | frmbuf_info->draw_buffer_index = 1; |
1050186 | 0:84e4649e7707 | 272 | } |
1050186 | 0:84e4649e7707 | 273 | } |
1050186 | 0:84e4649e7707 | 274 | |
1050186 | 0:84e4649e7707 | 275 | static void Exe_RGA_Func(int func_name, frame_buffer_t* frmbuf_info) { |
dkato | 2:c7faef0ef374 | 276 | uint8_t touch_num = 0; |
dkato | 2:c7faef0ef374 | 277 | uint32_t pos_x0 = 0; |
dkato | 2:c7faef0ef374 | 278 | uint32_t pos_y0 = 0; |
dkato | 2:c7faef0ef374 | 279 | func_code_t func_code; |
1050186 | 0:84e4649e7707 | 280 | |
1050186 | 0:84e4649e7707 | 281 | switch (func_name) { |
1050186 | 0:84e4649e7707 | 282 | case RGA_FUNC_DRAW_RECTANGLE: |
dkato | 2:c7faef0ef374 | 283 | bool key_on = false; |
dkato | 2:c7faef0ef374 | 284 | int cnt; |
dkato | 2:c7faef0ef374 | 285 | int color_cnt = 0; |
dkato | 2:c7faef0ef374 | 286 | int x_0 = 0; |
dkato | 2:c7faef0ef374 | 287 | int y_0 = 0; |
dkato | 2:c7faef0ef374 | 288 | draw_rectangle_pos_t pos_tbl[DRAW_RECTANGLE_CNT_MAX] = {0}; |
dkato | 2:c7faef0ef374 | 289 | |
dkato | 2:c7faef0ef374 | 290 | pos_tbl[0].style = "#FF0000"; /* red */ |
dkato | 2:c7faef0ef374 | 291 | pos_tbl[1].style = "#00FF00"; /* green */ |
dkato | 2:c7faef0ef374 | 292 | pos_tbl[2].style = "#0000FF"; /* blue */ |
dkato | 2:c7faef0ef374 | 293 | pos_tbl[3].style = "#000000"; /* black */ |
dkato | 2:c7faef0ef374 | 294 | |
dkato | 2:c7faef0ef374 | 295 | while (1) { |
dkato | 2:c7faef0ef374 | 296 | /* Get coordinates */ |
dkato | 2:c7faef0ef374 | 297 | Get_Coordinates(&touch_num, &pos_x0, &pos_y0); |
dkato | 2:c7faef0ef374 | 298 | if (touch_num != 0) { |
dkato | 2:c7faef0ef374 | 299 | if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) { |
dkato | 2:c7faef0ef374 | 300 | break; |
dkato | 2:c7faef0ef374 | 301 | } |
dkato | 2:c7faef0ef374 | 302 | if (key_on == false) { |
dkato | 2:c7faef0ef374 | 303 | key_on = true; |
dkato | 2:c7faef0ef374 | 304 | if (color_cnt == 0) { |
dkato | 2:c7faef0ef374 | 305 | for (cnt = 0; cnt < DRAW_RECTANGLE_CNT_MAX; cnt++) { |
dkato | 2:c7faef0ef374 | 306 | pos_tbl[cnt].x = 0; |
dkato | 2:c7faef0ef374 | 307 | pos_tbl[cnt].y = 0; |
dkato | 2:c7faef0ef374 | 308 | pos_tbl[cnt].w = 0; |
dkato | 2:c7faef0ef374 | 309 | pos_tbl[cnt].h = 0; |
dkato | 2:c7faef0ef374 | 310 | } |
dkato | 2:c7faef0ef374 | 311 | } |
dkato | 2:c7faef0ef374 | 312 | x_0 = pos_x0; |
dkato | 2:c7faef0ef374 | 313 | y_0 = pos_y0; |
dkato | 2:c7faef0ef374 | 314 | } |
dkato | 2:c7faef0ef374 | 315 | if (x_0 < pos_x0) { |
dkato | 2:c7faef0ef374 | 316 | pos_tbl[color_cnt].x = x_0; |
dkato | 2:c7faef0ef374 | 317 | pos_tbl[color_cnt].w = pos_x0 - x_0; |
dkato | 2:c7faef0ef374 | 318 | } else { |
dkato | 2:c7faef0ef374 | 319 | pos_tbl[color_cnt].x = pos_x0; |
dkato | 2:c7faef0ef374 | 320 | pos_tbl[color_cnt].w = x_0 - pos_x0; |
dkato | 2:c7faef0ef374 | 321 | } |
dkato | 2:c7faef0ef374 | 322 | if (y_0 < pos_y0) { |
dkato | 2:c7faef0ef374 | 323 | pos_tbl[color_cnt].y = y_0; |
dkato | 2:c7faef0ef374 | 324 | pos_tbl[color_cnt].h = pos_y0 - y_0; |
dkato | 2:c7faef0ef374 | 325 | } else { |
dkato | 2:c7faef0ef374 | 326 | pos_tbl[color_cnt].y = pos_y0; |
dkato | 2:c7faef0ef374 | 327 | pos_tbl[color_cnt].h = y_0 - pos_y0; |
dkato | 2:c7faef0ef374 | 328 | } |
dkato | 2:c7faef0ef374 | 329 | } else { |
dkato | 2:c7faef0ef374 | 330 | if (key_on != false) { |
dkato | 2:c7faef0ef374 | 331 | color_cnt++; |
dkato | 2:c7faef0ef374 | 332 | if (color_cnt == DRAW_RECTANGLE_CNT_MAX) { |
dkato | 2:c7faef0ef374 | 333 | color_cnt = 0; |
dkato | 2:c7faef0ef374 | 334 | } |
dkato | 2:c7faef0ef374 | 335 | } |
dkato | 2:c7faef0ef374 | 336 | key_on = false; |
dkato | 2:c7faef0ef374 | 337 | } |
dkato | 2:c7faef0ef374 | 338 | /* Draw screen */ |
dkato | 2:c7faef0ef374 | 339 | Swap_FrameBuffer(frmbuf_info); |
dkato | 2:c7faef0ef374 | 340 | RGA_Func_DrawRectangle(frmbuf_info, pos_tbl, DRAW_RECTANGLE_CNT_MAX); |
dkato | 2:c7faef0ef374 | 341 | Update_LCD_Display(frmbuf_info); |
dkato | 2:c7faef0ef374 | 342 | } |
1050186 | 0:84e4649e7707 | 343 | break; |
1050186 | 0:84e4649e7707 | 344 | case RGA_FUNC_DRAW_IMAGE: |
dkato | 2:c7faef0ef374 | 345 | int center_pos_x = 320; |
dkato | 2:c7faef0ef374 | 346 | int center_pos_y = 110; |
dkato | 2:c7faef0ef374 | 347 | while (1) { |
dkato | 2:c7faef0ef374 | 348 | /* Get coordinates */ |
dkato | 2:c7faef0ef374 | 349 | Get_Coordinates(&touch_num, &pos_x0, &pos_y0); |
dkato | 2:c7faef0ef374 | 350 | if (touch_num != 0) { |
dkato | 2:c7faef0ef374 | 351 | if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) { |
dkato | 2:c7faef0ef374 | 352 | break; |
dkato | 2:c7faef0ef374 | 353 | } |
dkato | 2:c7faef0ef374 | 354 | center_pos_x = pos_x0; |
dkato | 2:c7faef0ef374 | 355 | center_pos_y = pos_y0; |
dkato | 2:c7faef0ef374 | 356 | } |
dkato | 2:c7faef0ef374 | 357 | /* Draw screen */ |
dkato | 2:c7faef0ef374 | 358 | Swap_FrameBuffer(frmbuf_info); |
dkato | 2:c7faef0ef374 | 359 | RGA_Func_DrawImage(frmbuf_info, center_pos_x, center_pos_y); |
dkato | 2:c7faef0ef374 | 360 | Update_LCD_Display(frmbuf_info); |
dkato | 2:c7faef0ef374 | 361 | } |
1050186 | 0:84e4649e7707 | 362 | break; |
1050186 | 0:84e4649e7707 | 363 | case RGA_FUNC_DISSOLVE: |
dkato | 2:c7faef0ef374 | 364 | float32_t work_alpha = 0.0f; |
dkato | 2:c7faef0ef374 | 365 | while (1) { |
dkato | 2:c7faef0ef374 | 366 | /* Get coordinates */ |
dkato | 2:c7faef0ef374 | 367 | Get_Coordinates(&touch_num, &pos_x0, &pos_y0); |
dkato | 2:c7faef0ef374 | 368 | if (touch_num != 0) { |
dkato | 2:c7faef0ef374 | 369 | if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) { |
dkato | 2:c7faef0ef374 | 370 | break; |
dkato | 2:c7faef0ef374 | 371 | } |
dkato | 2:c7faef0ef374 | 372 | work_alpha = (float32_t)pos_x0 / (float32_t)(LCD_PIXEL_WIDTH); |
dkato | 2:c7faef0ef374 | 373 | } |
dkato | 2:c7faef0ef374 | 374 | /* Draw screen */ |
1050186 | 0:84e4649e7707 | 375 | Swap_FrameBuffer(frmbuf_info); |
1050186 | 0:84e4649e7707 | 376 | RGA_Func_Dissolve(frmbuf_info, work_alpha); |
dkato | 2:c7faef0ef374 | 377 | Update_LCD_Display(frmbuf_info); |
1050186 | 0:84e4649e7707 | 378 | } |
1050186 | 0:84e4649e7707 | 379 | break; |
1050186 | 0:84e4649e7707 | 380 | case RGA_FUNC_SCROLL: |
dkato | 2:c7faef0ef374 | 381 | int work_width_pos = 0; |
dkato | 2:c7faef0ef374 | 382 | while (1) { |
dkato | 2:c7faef0ef374 | 383 | /* Get coordinates */ |
dkato | 2:c7faef0ef374 | 384 | Get_Coordinates(&touch_num, &pos_x0, &pos_y0); |
dkato | 2:c7faef0ef374 | 385 | if (touch_num != 0) { |
dkato | 2:c7faef0ef374 | 386 | if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) { |
dkato | 2:c7faef0ef374 | 387 | break; |
dkato | 2:c7faef0ef374 | 388 | } |
dkato | 2:c7faef0ef374 | 389 | work_width_pos = SCROLL_MAX_NUM * ((float32_t)pos_x0 / (float32_t)(LCD_PIXEL_WIDTH)); |
dkato | 2:c7faef0ef374 | 390 | } |
dkato | 2:c7faef0ef374 | 391 | /* Draw screen */ |
1050186 | 0:84e4649e7707 | 392 | Swap_FrameBuffer(frmbuf_info); |
1050186 | 0:84e4649e7707 | 393 | RGA_Func_Scroll(frmbuf_info, work_width_pos); |
dkato | 2:c7faef0ef374 | 394 | Update_LCD_Display(frmbuf_info); |
1050186 | 0:84e4649e7707 | 395 | } |
1050186 | 0:84e4649e7707 | 396 | break; |
1050186 | 0:84e4649e7707 | 397 | case RGA_FUNC_ZOOM: |
dkato | 2:c7faef0ef374 | 398 | int work_height_pos = ZOOM_MAX_NUM; |
dkato | 2:c7faef0ef374 | 399 | while (1) { |
dkato | 2:c7faef0ef374 | 400 | /* Get coordinates */ |
dkato | 2:c7faef0ef374 | 401 | Get_Coordinates(&touch_num, &pos_x0, &pos_y0); |
dkato | 2:c7faef0ef374 | 402 | if (touch_num != 0) { |
dkato | 2:c7faef0ef374 | 403 | if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) { |
dkato | 2:c7faef0ef374 | 404 | break; |
dkato | 2:c7faef0ef374 | 405 | } |
dkato | 2:c7faef0ef374 | 406 | work_height_pos = ZOOM_MAX_NUM * ((float32_t)pos_x0 / (float32_t)(LCD_PIXEL_WIDTH)); |
dkato | 2:c7faef0ef374 | 407 | } |
dkato | 2:c7faef0ef374 | 408 | /* Draw screen */ |
1050186 | 0:84e4649e7707 | 409 | Swap_FrameBuffer(frmbuf_info); |
dkato | 2:c7faef0ef374 | 410 | RGA_Func_Zoom(frmbuf_info, work_height_pos); |
dkato | 2:c7faef0ef374 | 411 | Update_LCD_Display(frmbuf_info); |
1050186 | 0:84e4649e7707 | 412 | } |
1050186 | 0:84e4649e7707 | 413 | break; |
1050186 | 0:84e4649e7707 | 414 | case RGA_FUNC_ROTATION: |
dkato | 2:c7faef0ef374 | 415 | graphics_matrix_float_t work_angle = 0; |
dkato | 2:c7faef0ef374 | 416 | while (1) { |
dkato | 2:c7faef0ef374 | 417 | /* Get coordinates */ |
dkato | 2:c7faef0ef374 | 418 | Get_Coordinates(&touch_num, &pos_x0, &pos_y0); |
dkato | 2:c7faef0ef374 | 419 | if (touch_num != 0) { |
dkato | 2:c7faef0ef374 | 420 | if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) { |
dkato | 2:c7faef0ef374 | 421 | break; |
dkato | 2:c7faef0ef374 | 422 | } |
dkato | 2:c7faef0ef374 | 423 | work_angle = ROTATION_MAX_NUM * ((float32_t)pos_x0 / (float32_t)(LCD_PIXEL_WIDTH)); |
dkato | 2:c7faef0ef374 | 424 | } |
dkato | 2:c7faef0ef374 | 425 | /* Draw screen */ |
1050186 | 0:84e4649e7707 | 426 | Swap_FrameBuffer(frmbuf_info); |
1050186 | 0:84e4649e7707 | 427 | RGA_Func_Rotation(frmbuf_info, work_angle); |
dkato | 2:c7faef0ef374 | 428 | Update_LCD_Display(frmbuf_info); |
1050186 | 0:84e4649e7707 | 429 | } |
1050186 | 0:84e4649e7707 | 430 | break; |
1050186 | 0:84e4649e7707 | 431 | case RGA_FUNC_ACCELERATE: |
dkato | 2:c7faef0ef374 | 432 | int acce_frame_num = 0; |
dkato | 2:c7faef0ef374 | 433 | int animation_timing = 0; |
1050186 | 0:84e4649e7707 | 434 | float32_t work_relative_pos; |
dkato | 2:c7faef0ef374 | 435 | while (1) { |
dkato | 2:c7faef0ef374 | 436 | /* Get coordinates */ |
dkato | 2:c7faef0ef374 | 437 | Get_Coordinates(&touch_num, &pos_x0, &pos_y0); |
dkato | 2:c7faef0ef374 | 438 | if (touch_num != 0) { |
dkato | 2:c7faef0ef374 | 439 | func_code_t func_code; |
dkato | 2:c7faef0ef374 | 440 | |
dkato | 2:c7faef0ef374 | 441 | func_code = Scan_Key(animetion_timing_key_tbl, pos_x0, pos_y0); |
dkato | 2:c7faef0ef374 | 442 | if (func_code == RGA_FUNC_RETURN) { |
dkato | 2:c7faef0ef374 | 443 | break; |
dkato | 2:c7faef0ef374 | 444 | } |
dkato | 2:c7faef0ef374 | 445 | switch (func_code) { |
dkato | 2:c7faef0ef374 | 446 | case RGA_FUNC_ANIME_EASE: |
dkato | 2:c7faef0ef374 | 447 | animation_timing = 0; |
dkato | 2:c7faef0ef374 | 448 | acce_frame_num = 0; |
dkato | 2:c7faef0ef374 | 449 | break; |
dkato | 2:c7faef0ef374 | 450 | case RGA_FUNC_ANIME_LINEAR: |
dkato | 2:c7faef0ef374 | 451 | animation_timing = 1; |
dkato | 2:c7faef0ef374 | 452 | acce_frame_num = 0; |
dkato | 2:c7faef0ef374 | 453 | break; |
dkato | 2:c7faef0ef374 | 454 | case RGA_FUNC_ANIME_EASE_IN: |
dkato | 2:c7faef0ef374 | 455 | animation_timing = 2; |
dkato | 2:c7faef0ef374 | 456 | acce_frame_num = 0; |
dkato | 2:c7faef0ef374 | 457 | break; |
dkato | 2:c7faef0ef374 | 458 | case RGA_FUNC_ANIME_EASE_OUT: |
dkato | 2:c7faef0ef374 | 459 | animation_timing = 3; |
dkato | 2:c7faef0ef374 | 460 | acce_frame_num = 0; |
dkato | 2:c7faef0ef374 | 461 | break; |
dkato | 2:c7faef0ef374 | 462 | case RGA_FUNC_ANIME_EASE_IN_OUT: |
dkato | 2:c7faef0ef374 | 463 | animation_timing = 4; |
dkato | 2:c7faef0ef374 | 464 | acce_frame_num = 0; |
dkato | 2:c7faef0ef374 | 465 | break; |
dkato | 2:c7faef0ef374 | 466 | default: |
dkato | 2:c7faef0ef374 | 467 | /* Do Nothing */ |
dkato | 2:c7faef0ef374 | 468 | break; |
dkato | 2:c7faef0ef374 | 469 | } |
dkato | 2:c7faef0ef374 | 470 | } |
dkato | 2:c7faef0ef374 | 471 | work_relative_pos = acce_frame_num / (float32_t)ACCELERATE_MAX_NUM; |
dkato | 2:c7faef0ef374 | 472 | acce_frame_num++; |
dkato | 2:c7faef0ef374 | 473 | if (acce_frame_num > ACCELERATE_MAX_NUM) { |
dkato | 2:c7faef0ef374 | 474 | acce_frame_num = 0; |
dkato | 2:c7faef0ef374 | 475 | } |
ShinjiYamano | 4:99ff10b59637 | 476 | |
dkato | 2:c7faef0ef374 | 477 | /* Draw screen */ |
1050186 | 0:84e4649e7707 | 478 | Swap_FrameBuffer(frmbuf_info); |
ShinjiYamano | 4:99ff10b59637 | 479 | //RGA_Func_Training(frmbuf_info, animation_timing, work_relative_pos); |
dkato | 2:c7faef0ef374 | 480 | RGA_Func_Accelerate(frmbuf_info, animation_timing, work_relative_pos); |
dkato | 2:c7faef0ef374 | 481 | Update_LCD_Display(frmbuf_info); |
1050186 | 0:84e4649e7707 | 482 | } |
1050186 | 0:84e4649e7707 | 483 | break; |
1050186 | 0:84e4649e7707 | 484 | default : |
1050186 | 0:84e4649e7707 | 485 | /* Do nothing */ |
1050186 | 0:84e4649e7707 | 486 | break; |
1050186 | 0:84e4649e7707 | 487 | } |
1050186 | 0:84e4649e7707 | 488 | } |
1050186 | 0:84e4649e7707 | 489 | |
1050186 | 0:84e4649e7707 | 490 | int main(void) { |
1050186 | 0:84e4649e7707 | 491 | func_code_t func_code; |
1050186 | 0:84e4649e7707 | 492 | uint8_t touch_num = 0; |
1050186 | 0:84e4649e7707 | 493 | uint32_t pos_x0 = 0; |
1050186 | 0:84e4649e7707 | 494 | uint32_t pos_y0 = 0; |
1050186 | 0:84e4649e7707 | 495 | |
1050186 | 0:84e4649e7707 | 496 | memset(user_frame_buffer, 0, sizeof(user_frame_buffer)); |
1050186 | 0:84e4649e7707 | 497 | memset(user_frame_buffer2, 0, sizeof(user_frame_buffer2)); |
1050186 | 0:84e4649e7707 | 498 | frame_buffer_info.buffer_address[0] = user_frame_buffer; |
1050186 | 0:84e4649e7707 | 499 | frame_buffer_info.buffer_address[1] = user_frame_buffer2; |
1050186 | 0:84e4649e7707 | 500 | frame_buffer_info.buffer_count = 2; |
1050186 | 0:84e4649e7707 | 501 | frame_buffer_info.show_buffer_index = 0; |
1050186 | 0:84e4649e7707 | 502 | frame_buffer_info.draw_buffer_index = 0; |
1050186 | 0:84e4649e7707 | 503 | frame_buffer_info.width = LCD_PIXEL_WIDTH; |
1050186 | 0:84e4649e7707 | 504 | frame_buffer_info.byte_per_pixel = FRAME_BUFFER_BYTE_PER_PIXEL; |
1050186 | 0:84e4649e7707 | 505 | frame_buffer_info.stride = LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL; |
1050186 | 0:84e4649e7707 | 506 | frame_buffer_info.height = LCD_PIXEL_HEIGHT; |
1050186 | 0:84e4649e7707 | 507 | frame_buffer_info.pixel_format = PIXEL_FORMAT_RGB565; |
dkato | 2:c7faef0ef374 | 508 | Init_LCD_Display(frame_buffer_info.buffer_address[0]); |
1050186 | 0:84e4649e7707 | 509 | |
1050186 | 0:84e4649e7707 | 510 | /* Display Top Screen */ |
dkato | 2:c7faef0ef374 | 511 | Set_RGAObject(&frame_buffer_info); |
dkato | 2:c7faef0ef374 | 512 | RGA_Func_DrawTopScreen(&frame_buffer_info); |
1050186 | 0:84e4649e7707 | 513 | Start_LCD_Display(); |
1050186 | 0:84e4649e7707 | 514 | |
1050186 | 0:84e4649e7707 | 515 | while (1) { |
dkato | 2:c7faef0ef374 | 516 | /* Get Coordinates */ |
1050186 | 0:84e4649e7707 | 517 | Get_Coordinates(&touch_num, &pos_x0, &pos_y0); |
1050186 | 0:84e4649e7707 | 518 | if (touch_num != 0) { |
dkato | 2:c7faef0ef374 | 519 | func_code = Scan_Key(top_screen_key_tbl, pos_x0, pos_y0); |
1050186 | 0:84e4649e7707 | 520 | if (func_code != RGA_FUNC_NON) { |
dkato | 2:c7faef0ef374 | 521 | /* Wait key off */ |
dkato | 2:c7faef0ef374 | 522 | while (1) { |
dkato | 2:c7faef0ef374 | 523 | Get_Coordinates(&touch_num, &pos_x0, &pos_y0); |
dkato | 2:c7faef0ef374 | 524 | if (touch_num == 0) { |
dkato | 2:c7faef0ef374 | 525 | break; |
dkato | 2:c7faef0ef374 | 526 | } |
dkato | 2:c7faef0ef374 | 527 | Thread::wait(50); |
dkato | 2:c7faef0ef374 | 528 | } |
dkato | 2:c7faef0ef374 | 529 | |
1050186 | 0:84e4649e7707 | 530 | /* Execute RGA functions */ |
dkato | 2:c7faef0ef374 | 531 | Exe_RGA_Func(func_code, &frame_buffer_info); |
dkato | 2:c7faef0ef374 | 532 | |
1050186 | 0:84e4649e7707 | 533 | /* Return Top Screen */ |
dkato | 2:c7faef0ef374 | 534 | Swap_FrameBuffer(&frame_buffer_info); |
dkato | 2:c7faef0ef374 | 535 | RGA_Func_DrawTopScreen(&frame_buffer_info); |
dkato | 2:c7faef0ef374 | 536 | Update_LCD_Display(&frame_buffer_info); |
1050186 | 0:84e4649e7707 | 537 | } |
1050186 | 0:84e4649e7707 | 538 | } |
1050186 | 0:84e4649e7707 | 539 | Thread::wait(100); |
1050186 | 0:84e4649e7707 | 540 | } |
1050186 | 0:84e4649e7707 | 541 | } |
ShinjiYamano | 4:99ff10b59637 | 542 | |
ShinjiYamano | 4:99ff10b59637 | 543 | #if 0 |
ShinjiYamano | 4:99ff10b59637 | 544 | errnum_t Sample_Training( void ) |
ShinjiYamano | 4:99ff10b59637 | 545 | { |
ShinjiYamano | 4:99ff10b59637 | 546 | enum { layer_num = 0 }; |
ShinjiYamano | 4:99ff10b59637 | 547 | enum { frame_num_max = 30 }; |
ShinjiYamano | 4:99ff10b59637 | 548 | |
ShinjiYamano | 4:99ff10b59637 | 549 | errnum_t e; /* error code */ |
ShinjiYamano | 4:99ff10b59637 | 550 | int frame_num; /* frame number for transition */ |
ShinjiYamano | 4:99ff10b59637 | 551 | S_AcceleratedMotionWorkClass* work = &g_S_Training; /* struct for window surface */ |
ShinjiYamano | 4:99ff10b59637 | 552 | graphics_t* graphics; /* struct for graphics context */ |
ShinjiYamano | 4:99ff10b59637 | 553 | frame_buffer_t* frame; /* information for frame buffer */ |
ShinjiYamano | 4:99ff10b59637 | 554 | float32_t position; /* x-coordinate for drawing */ |
ShinjiYamano | 4:99ff10b59637 | 555 | |
ShinjiYamano | 4:99ff10b59637 | 556 | |
ShinjiYamano | 4:99ff10b59637 | 557 | /* 変数の初期化 (Section: 6.9.9.2, 6.9.1.2) */ |
ShinjiYamano | 4:99ff10b59637 | 558 | R_WINDOW_SURFACES_InitConst( &work->WindowSurfaces ); |
ShinjiYamano | 4:99ff10b59637 | 559 | R_GRAPHICS_InitConst( &work->Graphics ); |
ShinjiYamano | 4:99ff10b59637 | 560 | |
ShinjiYamano | 4:99ff10b59637 | 561 | /* Set "work->WindowSurfaces" */ |
ShinjiYamano | 4:99ff10b59637 | 562 | { |
ShinjiYamano | 4:99ff10b59637 | 563 | window_surfaces_config_t config; |
ShinjiYamano | 4:99ff10b59637 | 564 | |
ShinjiYamano | 4:99ff10b59637 | 565 | config.flags = F_WINDOW_SURFACES_PIXEL_FORMAT; |
ShinjiYamano | 4:99ff10b59637 | 566 | config.pixel_format = PIXEL_FORMAT_RGB565; |
ShinjiYamano | 4:99ff10b59637 | 567 | |
ShinjiYamano | 4:99ff10b59637 | 568 | /* ウィンドウサーフェスの初期化 (Section: 6.9.9.3) */ |
ShinjiYamano | 4:99ff10b59637 | 569 | e= R_WINDOW_SURFACES_Initialize( &work->WindowSurfaces, &config ); |
ShinjiYamano | 4:99ff10b59637 | 570 | IF(e) |
ShinjiYamano | 4:99ff10b59637 | 571 | { |
ShinjiYamano | 4:99ff10b59637 | 572 | goto fin; |
ShinjiYamano | 4:99ff10b59637 | 573 | } |
ShinjiYamano | 4:99ff10b59637 | 574 | } |
ShinjiYamano | 4:99ff10b59637 | 575 | |
ShinjiYamano | 4:99ff10b59637 | 576 | /* Set "work->FrameBuffer" */ |
ShinjiYamano | 4:99ff10b59637 | 577 | /* 指定したレイヤのフレームバッファのポインタを取得 (Section: 6.9.9.5) */ |
ShinjiYamano | 4:99ff10b59637 | 578 | e= R_WINDOW_SURFACES_GetLayerFrameBuffer( &work->WindowSurfaces, layer_num, &work->FrameBuffer ); |
ShinjiYamano | 4:99ff10b59637 | 579 | IF(e) |
ShinjiYamano | 4:99ff10b59637 | 580 | { |
ShinjiYamano | 4:99ff10b59637 | 581 | goto fin; |
ShinjiYamano | 4:99ff10b59637 | 582 | } |
ShinjiYamano | 4:99ff10b59637 | 583 | |
ShinjiYamano | 4:99ff10b59637 | 584 | /* Set "work->Graphics" */ |
ShinjiYamano | 4:99ff10b59637 | 585 | { |
ShinjiYamano | 4:99ff10b59637 | 586 | graphics_config_t config; |
ShinjiYamano | 4:99ff10b59637 | 587 | |
ShinjiYamano | 4:99ff10b59637 | 588 | config.flags = F_GRAPHICS_FRAME_BUFFER; |
ShinjiYamano | 4:99ff10b59637 | 589 | config.frame_buffer = work->FrameBuffer; |
ShinjiYamano | 4:99ff10b59637 | 590 | |
ShinjiYamano | 4:99ff10b59637 | 591 | /* コンテキストの初期化 (Section: 6.9.1.3) */ |
ShinjiYamano | 4:99ff10b59637 | 592 | e= R_GRAPHICS_Initialize( &work->Graphics, &config ); |
ShinjiYamano | 4:99ff10b59637 | 593 | IF(e) |
ShinjiYamano | 4:99ff10b59637 | 594 | { |
ShinjiYamano | 4:99ff10b59637 | 595 | goto fin; |
ShinjiYamano | 4:99ff10b59637 | 596 | } |
ShinjiYamano | 4:99ff10b59637 | 597 | } |
ShinjiYamano | 4:99ff10b59637 | 598 | |
ShinjiYamano | 4:99ff10b59637 | 599 | |
ShinjiYamano | 4:99ff10b59637 | 600 | /* アニメーションのタイミングを取得 (Section: 6.9.13.2) */ |
ShinjiYamano | 4:99ff10b59637 | 601 | frame = work->FrameBuffer; |
ShinjiYamano | 4:99ff10b59637 | 602 | graphics = &work->Graphics; |
ShinjiYamano | 4:99ff10b59637 | 603 | e= R_Get_AnimationTimingFunction( "ease-out", &work->Accelerator ); |
ShinjiYamano | 4:99ff10b59637 | 604 | IF(e) |
ShinjiYamano | 4:99ff10b59637 | 605 | { |
ShinjiYamano | 4:99ff10b59637 | 606 | goto fin; |
ShinjiYamano | 4:99ff10b59637 | 607 | } |
ShinjiYamano | 4:99ff10b59637 | 608 | |
ShinjiYamano | 4:99ff10b59637 | 609 | Loop: |
ShinjiYamano | 4:99ff10b59637 | 610 | |
ShinjiYamano | 4:99ff10b59637 | 611 | /* Do accelerated motion */ |
ShinjiYamano | 4:99ff10b59637 | 612 | /* 描画処理ループ */ |
ShinjiYamano | 4:99ff10b59637 | 613 | /* 一回のループ処理で一回分のアニメーション処理を実現 */ |
ShinjiYamano | 4:99ff10b59637 | 614 | for ( frame_num = 0; frame_num <= frame_num_max; frame_num += GS_FRAME_STEP ) |
ShinjiYamano | 4:99ff10b59637 | 615 | { |
ShinjiYamano | 4:99ff10b59637 | 616 | const float32_t angle = (float32_t)(( frame_num * 30) % 360); |
ShinjiYamano | 4:99ff10b59637 | 617 | |
ShinjiYamano | 4:99ff10b59637 | 618 | /* フレームバッファのクリア (Section: 6.9.1.28) */ |
ShinjiYamano | 4:99ff10b59637 | 619 | e= R_GRAPHICS_Clear( graphics, 0, 0, frame->width, frame->height ); |
ShinjiYamano | 4:99ff10b59637 | 620 | IF(e) { goto fin; } |
ShinjiYamano | 4:99ff10b59637 | 621 | /*---------------------------------------------------------------------*/ |
ShinjiYamano | 4:99ff10b59637 | 622 | |
ShinjiYamano | 4:99ff10b59637 | 623 | /*---------------------------------------------------------------------*/ |
ShinjiYamano | 4:99ff10b59637 | 624 | /* 画像の描画 (Section: 6.9.1.29) */ |
ShinjiYamano | 4:99ff10b59637 | 625 | e= R_GRAPHICS_DrawImage( graphics, g_JPEG_jpg_File, 0, 0); |
ShinjiYamano | 4:99ff10b59637 | 626 | IF(e) { goto fin; } |
ShinjiYamano | 4:99ff10b59637 | 627 | |
ShinjiYamano | 4:99ff10b59637 | 628 | /* 表示バッファと描画バッファを入れ替え (Section: 6.9.9.7) */ |
ShinjiYamano | 4:99ff10b59637 | 629 | e= R_WINDOW_SURFACES_SwapBuffers( &work->WindowSurfaces, layer_num, graphics ); |
ShinjiYamano | 4:99ff10b59637 | 630 | IF(e) { goto fin; } |
ShinjiYamano | 4:99ff10b59637 | 631 | |
ShinjiYamano | 4:99ff10b59637 | 632 | if ( frame_num == 0 ) |
ShinjiYamano | 4:99ff10b59637 | 633 | { |
ShinjiYamano | 4:99ff10b59637 | 634 | e= R_OSPL_Delay( 1000 ); |
ShinjiYamano | 4:99ff10b59637 | 635 | IF(e) { goto fin; } |
ShinjiYamano | 4:99ff10b59637 | 636 | } |
ShinjiYamano | 4:99ff10b59637 | 637 | } |
ShinjiYamano | 4:99ff10b59637 | 638 | |
ShinjiYamano | 4:99ff10b59637 | 639 | |
ShinjiYamano | 4:99ff10b59637 | 640 | /* Stay */ |
ShinjiYamano | 4:99ff10b59637 | 641 | /* 描画終了待ち (Section: 6.9.9.10) */ |
ShinjiYamano | 4:99ff10b59637 | 642 | e= R_WINDOW_SURFACES_DoMessageLoop( &work->WindowSurfaces ); |
ShinjiYamano | 4:99ff10b59637 | 643 | IF(e) { goto fin; } |
ShinjiYamano | 4:99ff10b59637 | 644 | e=0; |
ShinjiYamano | 4:99ff10b59637 | 645 | |
ShinjiYamano | 4:99ff10b59637 | 646 | goto Loop; |
ShinjiYamano | 4:99ff10b59637 | 647 | |
ShinjiYamano | 4:99ff10b59637 | 648 | fin: |
ShinjiYamano | 4:99ff10b59637 | 649 | /* 終了処理 */ |
ShinjiYamano | 4:99ff10b59637 | 650 | |
ShinjiYamano | 4:99ff10b59637 | 651 | /* コンテキストの破棄 (Section: 6.9.1.4 and 6.9.9.4) */ |
ShinjiYamano | 4:99ff10b59637 | 652 | e= R_GRAPHICS_Finalize( &work->Graphics, e ); |
ShinjiYamano | 4:99ff10b59637 | 653 | e= R_WINDOW_SURFACES_Finalize( &work->WindowSurfaces, e ); |
ShinjiYamano | 4:99ff10b59637 | 654 | R_DEBUG_BREAK_IF_ERROR(); |
ShinjiYamano | 4:99ff10b59637 | 655 | return e; |
ShinjiYamano | 4:99ff10b59637 | 656 | } |
ShinjiYamano | 4:99ff10b59637 | 657 | |
ShinjiYamano | 4:99ff10b59637 | 658 | #ifdef NEVER_COMES_HERE |
ShinjiYamano | 4:99ff10b59637 | 659 | /* animation */ |
ShinjiYamano | 4:99ff10b59637 | 660 | /* アニメーション処理時のX座標を取得 (Section: 6.9.13.3) */ |
ShinjiYamano | 4:99ff10b59637 | 661 | position = R_ANIMATION_TIMING_FUNCTION_GetValue( work->Accelerator, |
ShinjiYamano | 4:99ff10b59637 | 662 | (float32_t) frame_num / frame_num_max, INITIAL_POSITION_Xf, 100.0f); |
ShinjiYamano | 4:99ff10b59637 | 663 | |
ShinjiYamano | 4:99ff10b59637 | 664 | /* 画像の描画 (Section: 6.9.1.29) */ |
ShinjiYamano | 4:99ff10b59637 | 665 | e= R_GRAPHICS_DrawImage( graphics, g_JPEG_jpg_File, (int_fast32_t) position, INITIAL_POSITION_Yi); IF(e) { goto fin; } |
ShinjiYamano | 4:99ff10b59637 | 666 | /* animation */ |
ShinjiYamano | 4:99ff10b59637 | 667 | |
ShinjiYamano | 4:99ff10b59637 | 668 | |
ShinjiYamano | 4:99ff10b59637 | 669 | /* rotate */ |
ShinjiYamano | 4:99ff10b59637 | 670 | /* 原点中心で回転処理 */ |
ShinjiYamano | 4:99ff10b59637 | 671 | e= R_GRAPHICS_RotateMatrixDegree( graphics, angle ); IF(e) { goto fin; } |
ShinjiYamano | 4:99ff10b59637 | 672 | |
ShinjiYamano | 4:99ff10b59637 | 673 | /* 原点が左上の画像に対して、画像の中心が原点となるように平行移動 */ |
ShinjiYamano | 4:99ff10b59637 | 674 | e= R_GRAPHICS_TranslateMatrix( graphics, |
ShinjiYamano | 4:99ff10b59637 | 675 | (graphics_matrix_float_t)(-JPEG_WIDTH / 2), |
ShinjiYamano | 4:99ff10b59637 | 676 | (graphics_matrix_float_t)(-JPEG_HEIGHT / 2) ); IF(e) { goto fin; } |
ShinjiYamano | 4:99ff10b59637 | 677 | |
ShinjiYamano | 4:99ff10b59637 | 678 | /* 希望する位置への移動 */ |
ShinjiYamano | 4:99ff10b59637 | 679 | e= R_GRAPHICS_TranslateMatrix(graphics, position, 100.0f); IF(e) { goto fin; } |
ShinjiYamano | 4:99ff10b59637 | 680 | |
ShinjiYamano | 4:99ff10b59637 | 681 | /* 挿入画像の描画 (Section: 6.9.1.29) */ |
ShinjiYamano | 4:99ff10b59637 | 682 | e= R_GRAPHICS_DrawImage( graphics, g_JPEG_jpg_File, 0, 0 ); IF(e) { goto fin; } |
ShinjiYamano | 4:99ff10b59637 | 683 | /* rotate */ |
ShinjiYamano | 4:99ff10b59637 | 684 | |
ShinjiYamano | 4:99ff10b59637 | 685 | /* clipping */ |
ShinjiYamano | 4:99ff10b59637 | 686 | /* クリッピングされた画像の描画 (Section: 6.9.1.29) */ |
ShinjiYamano | 4:99ff10b59637 | 687 | e= R_GRAPHICS_DrawImageChild( graphics, g_sample00_jpg_file, |
ShinjiYamano | 4:99ff10b59637 | 688 | 0, 0, WVGA_WIDTH - (int_fast32_t)position, WVGA_HEIGHT, |
ShinjiYamano | 4:99ff10b59637 | 689 | (int_fast32_t) position, 0, WVGA_WIDTH - (int_fast32_t)position, WVGA_HEIGHT); IF(e) { goto fin; } |
ShinjiYamano | 4:99ff10b59637 | 690 | /* clipping */ |
ShinjiYamano | 4:99ff10b59637 | 691 | |
ShinjiYamano | 4:99ff10b59637 | 692 | /* alpha blending */ |
ShinjiYamano | 4:99ff10b59637 | 693 | /* アルファ値の設定 */ |
ShinjiYamano | 4:99ff10b59637 | 694 | alpha = (uint8_t) (frame_num * 8) + 15; |
ShinjiYamano | 4:99ff10b59637 | 695 | e= R_GRAPHICS_SetGlobalAlpha(graphics, alpha); IF(e) { goto fin; } |
ShinjiYamano | 4:99ff10b59637 | 696 | /* alpha blending */ |
ShinjiYamano | 4:99ff10b59637 | 697 | |
ShinjiYamano | 4:99ff10b59637 | 698 | #endif |
ShinjiYamano | 4:99ff10b59637 | 699 | #endif |