Image Zoom In/out Sample. This program uses GraphicsFramework library and GP2Y0A21YK sensor. Please use distance sensor in the range of 10-30cm.
Dependencies: GR-PEACH_video GraphicsFramework R_BSP mbed-rtos mbed
Fork of RGA_HelloWorld by
About GP2Y0A21YK
GP2Y0A21YK is a distance sensor and can be controlled by using the AnalogIn.
The range of this sensor is 10-80cm.
- Datasheet of GP2Y0A21YK
https://www.sparkfun.com/datasheets/Components/GP2Y0A21YK.pdf
About wiring
Sensor | GR-PEACH |
White wire | A0 |
Orange wire | GND |
Black wire | 5.0V |
main.cpp@0:84e4649e7707, 2016-01-20 (annotated)
- Committer:
- 1050186
- Date:
- Wed Jan 20 02:35:42 2016 +0000
- Revision:
- 0:84e4649e7707
- Child:
- 2:c7faef0ef374
First commit
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 | */ |
1050186 | 0:84e4649e7707 | 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 */ |
1050186 | 0:84e4649e7707 | 28 | #define LCD_INPUT_CLOCK 66.67f |
1050186 | 0:84e4649e7707 | 29 | #define LCD_OUTPUT_CLOCK 33.26f |
1050186 | 0:84e4649e7707 | 30 | |
1050186 | 0:84e4649e7707 | 31 | #define LCD_PIXEL_WIDTH 800 |
1050186 | 0:84e4649e7707 | 32 | #define LCD_PIXEL_HEIGHT 480 |
1050186 | 0:84e4649e7707 | 33 | #define LCD_H_BACK_PORCH (128 + 36) |
1050186 | 0:84e4649e7707 | 34 | #define LCD_H_FRONT_PORCH 92 |
1050186 | 0:84e4649e7707 | 35 | #define LCD_V_BACK_PORCH (35 + 5) |
1050186 | 0:84e4649e7707 | 36 | #define LCD_V_FRONT_PORCH 5 |
1050186 | 0:84e4649e7707 | 37 | |
1050186 | 0:84e4649e7707 | 38 | /* Func Button Image */ |
1050186 | 0:84e4649e7707 | 39 | #define XPOS_BUTTON1 50 |
1050186 | 0:84e4649e7707 | 40 | #define YPOS_BUTTON1 350 |
1050186 | 0:84e4649e7707 | 41 | #define XPOS_BUTTON2 230 |
1050186 | 0:84e4649e7707 | 42 | #define YPOS_BUTTON2 YPOS_BUTTON1 |
1050186 | 0:84e4649e7707 | 43 | #define XPOS_BUTTON3 410 |
1050186 | 0:84e4649e7707 | 44 | #define YPOS_BUTTON3 YPOS_BUTTON1 |
1050186 | 0:84e4649e7707 | 45 | #define XPOS_BUTTON4 XPOS_BUTTON1 |
1050186 | 0:84e4649e7707 | 46 | #define YPOS_BUTTON4 420 |
1050186 | 0:84e4649e7707 | 47 | #define XPOS_BUTTON5 XPOS_BUTTON2 |
1050186 | 0:84e4649e7707 | 48 | #define YPOS_BUTTON5 YPOS_BUTTON4 |
1050186 | 0:84e4649e7707 | 49 | #define XPOS_BUTTON6 XPOS_BUTTON3 |
1050186 | 0:84e4649e7707 | 50 | #define YPOS_BUTTON6 YPOS_BUTTON4 |
1050186 | 0:84e4649e7707 | 51 | #define XPOS_BUTTON7 615 |
1050186 | 0:84e4649e7707 | 52 | #define YPOS_BUTTON7 YPOS_BUTTON4 |
1050186 | 0:84e4649e7707 | 53 | /* Func Button Image Size */ |
1050186 | 0:84e4649e7707 | 54 | #define WIDTH_BUTTON 120 |
1050186 | 0:84e4649e7707 | 55 | #define HEIGHT_BUTTON 40 |
1050186 | 0:84e4649e7707 | 56 | /* Return Button Image */ |
1050186 | 0:84e4649e7707 | 57 | #define XPOS_RET_BUTTON 640 |
1050186 | 0:84e4649e7707 | 58 | #define YPOS_RET_BUTTON 10 |
1050186 | 0:84e4649e7707 | 59 | /* Return Button Image Size */ |
1050186 | 0:84e4649e7707 | 60 | #define WIDTH_RET_BUTTON 150 |
1050186 | 0:84e4649e7707 | 61 | #define HEIGHT_RET_BUTTON 84 |
1050186 | 0:84e4649e7707 | 62 | |
1050186 | 0:84e4649e7707 | 63 | /* FRAME BUFFER Parameter */ |
1050186 | 0:84e4649e7707 | 64 | #define FRAME_BUFFER_BYTE_PER_PIXEL 2 |
1050186 | 0:84e4649e7707 | 65 | #define FRAME_BUFFER_STRIDE (((LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL) + 31u) & ~31u) |
1050186 | 0:84e4649e7707 | 66 | |
1050186 | 0:84e4649e7707 | 67 | typedef enum { |
1050186 | 0:84e4649e7707 | 68 | RGA_FUNC_DRAW_RECTANGLE = 0x00, |
1050186 | 0:84e4649e7707 | 69 | RGA_FUNC_DRAW_IMAGE, |
1050186 | 0:84e4649e7707 | 70 | RGA_FUNC_DISSOLVE, |
1050186 | 0:84e4649e7707 | 71 | RGA_FUNC_SCROLL, |
1050186 | 0:84e4649e7707 | 72 | RGA_FUNC_ZOOM, |
1050186 | 0:84e4649e7707 | 73 | RGA_FUNC_ROTATION, |
1050186 | 0:84e4649e7707 | 74 | RGA_FUNC_ACCELERATE, |
1050186 | 0:84e4649e7707 | 75 | RGA_FUNC_MAX_NUM, |
1050186 | 0:84e4649e7707 | 76 | RGA_FUNC_RETURN = 0xFE, |
1050186 | 0:84e4649e7707 | 77 | RGA_FUNC_NON = 0xFF |
1050186 | 0:84e4649e7707 | 78 | }func_code_t; |
1050186 | 0:84e4649e7707 | 79 | |
1050186 | 0:84e4649e7707 | 80 | DigitalOut lcd_pwon(P7_15); |
1050186 | 0:84e4649e7707 | 81 | DigitalOut lcd_blon(P8_1); |
1050186 | 0:84e4649e7707 | 82 | PwmOut lcd_cntrst(P8_15); |
1050186 | 0:84e4649e7707 | 83 | I2C i2c(I2C_SDA, I2C_SCL); |
1050186 | 0:84e4649e7707 | 84 | DisplayBase Display; |
1050186 | 0:84e4649e7707 | 85 | |
1050186 | 0:84e4649e7707 | 86 | typedef struct { |
1050186 | 0:84e4649e7707 | 87 | uint8_t y_h: 3, |
1050186 | 0:84e4649e7707 | 88 | reserved: 1, |
1050186 | 0:84e4649e7707 | 89 | x_h: 3, |
1050186 | 0:84e4649e7707 | 90 | valid: 1; |
1050186 | 0:84e4649e7707 | 91 | uint8_t x_l; |
1050186 | 0:84e4649e7707 | 92 | uint8_t y_l; |
1050186 | 0:84e4649e7707 | 93 | uint8_t z; |
1050186 | 0:84e4649e7707 | 94 | } xyz_data_t; |
1050186 | 0:84e4649e7707 | 95 | |
1050186 | 0:84e4649e7707 | 96 | typedef struct { |
1050186 | 0:84e4649e7707 | 97 | uint8_t fingers: 4, |
1050186 | 0:84e4649e7707 | 98 | reserved: 4; |
1050186 | 0:84e4649e7707 | 99 | uint8_t keys; |
1050186 | 0:84e4649e7707 | 100 | xyz_data_t xyz_data; |
1050186 | 0:84e4649e7707 | 101 | } stx_report_data_t; |
1050186 | 0:84e4649e7707 | 102 | |
1050186 | 0:84e4649e7707 | 103 | typedef struct { |
1050186 | 0:84e4649e7707 | 104 | uint32_t pic_pos_x; /* X position of the key picture. */ |
1050186 | 0:84e4649e7707 | 105 | uint32_t pic_pos_y; /* Y position of the key picture. */ |
1050186 | 0:84e4649e7707 | 106 | uint32_t pic_width; /* Width of the key picture. */ |
1050186 | 0:84e4649e7707 | 107 | uint32_t pic_height; /* Height of the key picture. */ |
1050186 | 0:84e4649e7707 | 108 | func_code_t func_code; /* func code of the key picture. */ |
1050186 | 0:84e4649e7707 | 109 | } key_pic_info_t; |
1050186 | 0:84e4649e7707 | 110 | |
1050186 | 0:84e4649e7707 | 111 | static uint8_t user_frame_buffer[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32))); /* 32 bytes aligned */ |
1050186 | 0:84e4649e7707 | 112 | static uint8_t user_frame_buffer2[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32))); /* 32 bytes aligned */ |
1050186 | 0:84e4649e7707 | 113 | static frame_buffer_t frame_buffer_info; |
1050186 | 0:84e4649e7707 | 114 | static volatile int32_t vsync_count = 0; |
1050186 | 0:84e4649e7707 | 115 | |
1050186 | 0:84e4649e7707 | 116 | static const key_pic_info_t key_tbl[RGA_FUNC_MAX_NUM] = { |
1050186 | 0:84e4649e7707 | 117 | /* X position */ /* Y position */ /* Width size */ /* Height size */ /* Func code */ |
1050186 | 0:84e4649e7707 | 118 | { XPOS_BUTTON1, YPOS_BUTTON1, WIDTH_BUTTON, HEIGHT_BUTTON, RGA_FUNC_DRAW_RECTANGLE }, /* RGA Func1 */ |
1050186 | 0:84e4649e7707 | 119 | { XPOS_BUTTON2, YPOS_BUTTON2, WIDTH_BUTTON, HEIGHT_BUTTON, RGA_FUNC_DRAW_IMAGE }, /* RGA Func2 */ |
1050186 | 0:84e4649e7707 | 120 | { XPOS_BUTTON3, YPOS_BUTTON3, WIDTH_BUTTON, HEIGHT_BUTTON, RGA_FUNC_DISSOLVE }, /* RGA Func3 */ |
1050186 | 0:84e4649e7707 | 121 | { XPOS_BUTTON4, YPOS_BUTTON4, WIDTH_BUTTON, HEIGHT_BUTTON, RGA_FUNC_SCROLL }, /* RGA Func4 */ |
1050186 | 0:84e4649e7707 | 122 | { XPOS_BUTTON5, YPOS_BUTTON5, WIDTH_BUTTON, HEIGHT_BUTTON, RGA_FUNC_ZOOM }, /* RGA Func5 */ |
1050186 | 0:84e4649e7707 | 123 | { XPOS_BUTTON6, YPOS_BUTTON6, WIDTH_BUTTON, HEIGHT_BUTTON, RGA_FUNC_ROTATION }, /* RGA Func6 */ |
1050186 | 0:84e4649e7707 | 124 | { XPOS_BUTTON7, YPOS_BUTTON7, WIDTH_BUTTON, HEIGHT_BUTTON, RGA_FUNC_ACCELERATE } /* RGA Func7 */ |
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 | |
1050186 | 0:84e4649e7707 | 219 | static void Update_LCD_Display(uint8_t* disp_buf) { |
1050186 | 0:84e4649e7707 | 220 | Display.Graphics_Read_Change(DisplayBase::GRAPHICS_LAYER_0, (void *)disp_buf); |
1050186 | 0:84e4649e7707 | 221 | Wait_Vsync(1); |
1050186 | 0:84e4649e7707 | 222 | } |
1050186 | 0:84e4649e7707 | 223 | |
1050186 | 0:84e4649e7707 | 224 | static int Get_Coordinates(uint8_t *count, uint32_t *x0, uint32_t *y0) { |
1050186 | 0:84e4649e7707 | 225 | char buf[6]; |
1050186 | 0:84e4649e7707 | 226 | stx_report_data_t *pdata; |
1050186 | 0:84e4649e7707 | 227 | int ret = -1; |
1050186 | 0:84e4649e7707 | 228 | *count = 0; // Set point detected count to 0 |
1050186 | 0:84e4649e7707 | 229 | |
1050186 | 0:84e4649e7707 | 230 | if (i2c.read((0x55 << 1), buf, sizeof(buf)) == 0) { |
1050186 | 0:84e4649e7707 | 231 | pdata = (stx_report_data_t *)buf; |
1050186 | 0:84e4649e7707 | 232 | if (pdata->fingers) { |
1050186 | 0:84e4649e7707 | 233 | if (pdata->xyz_data.valid) { |
1050186 | 0:84e4649e7707 | 234 | *x0 = (pdata->xyz_data.x_h << 8) | pdata->xyz_data.x_l; |
1050186 | 0:84e4649e7707 | 235 | *y0 = (pdata->xyz_data.y_h << 8) | pdata->xyz_data.y_l; |
1050186 | 0:84e4649e7707 | 236 | (*count)++; |
1050186 | 0:84e4649e7707 | 237 | } |
1050186 | 0:84e4649e7707 | 238 | } |
1050186 | 0:84e4649e7707 | 239 | ret = 0; |
1050186 | 0:84e4649e7707 | 240 | } |
1050186 | 0:84e4649e7707 | 241 | |
1050186 | 0:84e4649e7707 | 242 | return ret; |
1050186 | 0:84e4649e7707 | 243 | } |
1050186 | 0:84e4649e7707 | 244 | |
1050186 | 0:84e4649e7707 | 245 | static func_code_t Scan_FuncCode(uint32_t pos_x, const uint32_t pos_y) { |
1050186 | 0:84e4649e7707 | 246 | int func_cnt; |
1050186 | 0:84e4649e7707 | 247 | func_code_t ret = RGA_FUNC_NON; |
1050186 | 0:84e4649e7707 | 248 | |
1050186 | 0:84e4649e7707 | 249 | for (func_cnt = 0; ((func_cnt < RGA_FUNC_MAX_NUM) && (ret == RGA_FUNC_NON)); func_cnt++) { |
1050186 | 0:84e4649e7707 | 250 | /* Check the range of the X position */ |
1050186 | 0:84e4649e7707 | 251 | if ((pos_x >= key_tbl[func_cnt].pic_pos_x) && (pos_x <= (key_tbl[func_cnt].pic_pos_x + key_tbl[func_cnt].pic_width))) { |
1050186 | 0:84e4649e7707 | 252 | /* Check the range of the Y position */ |
1050186 | 0:84e4649e7707 | 253 | if ((pos_y >= key_tbl[func_cnt].pic_pos_y) && (pos_y <= (key_tbl[func_cnt].pic_pos_y + key_tbl[func_cnt].pic_height))) { |
1050186 | 0:84e4649e7707 | 254 | /* Decide the func code. */ |
1050186 | 0:84e4649e7707 | 255 | ret = key_tbl[func_cnt].func_code; |
1050186 | 0:84e4649e7707 | 256 | } |
1050186 | 0:84e4649e7707 | 257 | } |
1050186 | 0:84e4649e7707 | 258 | } |
1050186 | 0:84e4649e7707 | 259 | |
1050186 | 0:84e4649e7707 | 260 | return ret; |
1050186 | 0:84e4649e7707 | 261 | } |
1050186 | 0:84e4649e7707 | 262 | |
1050186 | 0:84e4649e7707 | 263 | static func_code_t Scan_ReturnCode(uint32_t pos_x, const uint32_t pos_y) { |
1050186 | 0:84e4649e7707 | 264 | func_code_t ret = RGA_FUNC_NON; |
1050186 | 0:84e4649e7707 | 265 | |
1050186 | 0:84e4649e7707 | 266 | /* Check the range of the X position */ |
1050186 | 0:84e4649e7707 | 267 | if ((pos_x >= XPOS_RET_BUTTON) && (pos_x <= (XPOS_RET_BUTTON + WIDTH_RET_BUTTON))) { |
1050186 | 0:84e4649e7707 | 268 | /* Check the range of the Y position */ |
1050186 | 0:84e4649e7707 | 269 | if ((pos_y >= YPOS_RET_BUTTON) && (pos_y <= (YPOS_RET_BUTTON + HEIGHT_RET_BUTTON))) { |
1050186 | 0:84e4649e7707 | 270 | /* Decide the func code. */ |
1050186 | 0:84e4649e7707 | 271 | ret = RGA_FUNC_RETURN; |
1050186 | 0:84e4649e7707 | 272 | } |
1050186 | 0:84e4649e7707 | 273 | } |
1050186 | 0:84e4649e7707 | 274 | |
1050186 | 0:84e4649e7707 | 275 | return ret; |
1050186 | 0:84e4649e7707 | 276 | } |
1050186 | 0:84e4649e7707 | 277 | |
1050186 | 0:84e4649e7707 | 278 | static void Swap_FrameBuffer(frame_buffer_t * frmbuf_info) { |
1050186 | 0:84e4649e7707 | 279 | if (frmbuf_info->draw_buffer_index == 1) { |
1050186 | 0:84e4649e7707 | 280 | frmbuf_info->draw_buffer_index = 0; |
1050186 | 0:84e4649e7707 | 281 | } else { |
1050186 | 0:84e4649e7707 | 282 | frmbuf_info->draw_buffer_index = 1; |
1050186 | 0:84e4649e7707 | 283 | } |
1050186 | 0:84e4649e7707 | 284 | } |
1050186 | 0:84e4649e7707 | 285 | |
1050186 | 0:84e4649e7707 | 286 | static void Exe_RGA_Func(int func_name, frame_buffer_t* frmbuf_info) { |
1050186 | 0:84e4649e7707 | 287 | uint8_t* disp_buf; |
1050186 | 0:84e4649e7707 | 288 | |
1050186 | 0:84e4649e7707 | 289 | switch (func_name) { |
1050186 | 0:84e4649e7707 | 290 | case RGA_FUNC_DRAW_RECTANGLE: |
1050186 | 0:84e4649e7707 | 291 | /* Swap frame buffer */ |
1050186 | 0:84e4649e7707 | 292 | Swap_FrameBuffer(frmbuf_info); |
1050186 | 0:84e4649e7707 | 293 | disp_buf = frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]; |
1050186 | 0:84e4649e7707 | 294 | RGA_Func_DrawRectangle(frmbuf_info); |
1050186 | 0:84e4649e7707 | 295 | Update_LCD_Display(disp_buf); |
1050186 | 0:84e4649e7707 | 296 | break; |
1050186 | 0:84e4649e7707 | 297 | case RGA_FUNC_DRAW_IMAGE: |
1050186 | 0:84e4649e7707 | 298 | /* Swap frame buffer */ |
1050186 | 0:84e4649e7707 | 299 | Swap_FrameBuffer(frmbuf_info); |
1050186 | 0:84e4649e7707 | 300 | disp_buf = frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]; |
1050186 | 0:84e4649e7707 | 301 | RGA_Func_DrawImage(frmbuf_info); |
1050186 | 0:84e4649e7707 | 302 | Update_LCD_Display(disp_buf); |
1050186 | 0:84e4649e7707 | 303 | break; |
1050186 | 0:84e4649e7707 | 304 | case RGA_FUNC_DISSOLVE: |
1050186 | 0:84e4649e7707 | 305 | int diss_frame_num; |
1050186 | 0:84e4649e7707 | 306 | float32_t work_alpha; |
1050186 | 0:84e4649e7707 | 307 | for (diss_frame_num = 0; diss_frame_num < DISSOLVE_MAX_NUM; diss_frame_num += 1) { |
1050186 | 0:84e4649e7707 | 308 | /* Swap frame buffer */ |
1050186 | 0:84e4649e7707 | 309 | Swap_FrameBuffer(frmbuf_info); |
1050186 | 0:84e4649e7707 | 310 | disp_buf = frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]; |
1050186 | 0:84e4649e7707 | 311 | work_alpha = diss_frame_num / (float32_t)(DISSOLVE_MAX_NUM - 1); |
1050186 | 0:84e4649e7707 | 312 | RGA_Func_Dissolve(frmbuf_info, work_alpha); |
1050186 | 0:84e4649e7707 | 313 | Update_LCD_Display(disp_buf); |
1050186 | 0:84e4649e7707 | 314 | } |
1050186 | 0:84e4649e7707 | 315 | break; |
1050186 | 0:84e4649e7707 | 316 | case RGA_FUNC_SCROLL: |
1050186 | 0:84e4649e7707 | 317 | int work_width_pos; |
1050186 | 0:84e4649e7707 | 318 | for (work_width_pos = 0; work_width_pos < SCROLL_MAX_NUM; work_width_pos++) { |
1050186 | 0:84e4649e7707 | 319 | /* Swap frame buffer */ |
1050186 | 0:84e4649e7707 | 320 | Swap_FrameBuffer(frmbuf_info); |
1050186 | 0:84e4649e7707 | 321 | disp_buf = frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]; |
1050186 | 0:84e4649e7707 | 322 | RGA_Func_Scroll(frmbuf_info, work_width_pos); |
1050186 | 0:84e4649e7707 | 323 | Update_LCD_Display(disp_buf); |
1050186 | 0:84e4649e7707 | 324 | } |
1050186 | 0:84e4649e7707 | 325 | break; |
1050186 | 0:84e4649e7707 | 326 | case RGA_FUNC_ZOOM: |
1050186 | 0:84e4649e7707 | 327 | int work_height_pos; |
1050186 | 0:84e4649e7707 | 328 | for (work_height_pos = 0; work_height_pos <= ZOOM_MAX_NUM; work_height_pos++) { |
1050186 | 0:84e4649e7707 | 329 | /* Swap frame buffer */ |
1050186 | 0:84e4649e7707 | 330 | Swap_FrameBuffer(frmbuf_info); |
1050186 | 0:84e4649e7707 | 331 | disp_buf = frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]; |
1050186 | 0:84e4649e7707 | 332 | RGA_Func_Zoom(frmbuf_info, work_height_pos); |
1050186 | 0:84e4649e7707 | 333 | Update_LCD_Display(disp_buf); |
1050186 | 0:84e4649e7707 | 334 | } |
1050186 | 0:84e4649e7707 | 335 | break; |
1050186 | 0:84e4649e7707 | 336 | case RGA_FUNC_ROTATION: |
1050186 | 0:84e4649e7707 | 337 | graphics_matrix_float_t work_angle; |
1050186 | 0:84e4649e7707 | 338 | for (work_angle = 0; work_angle <= ROTATION_MAX_NUM; work_angle++) { |
1050186 | 0:84e4649e7707 | 339 | /* Swap frame buffer */ |
1050186 | 0:84e4649e7707 | 340 | Swap_FrameBuffer(frmbuf_info); |
1050186 | 0:84e4649e7707 | 341 | disp_buf = frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]; |
1050186 | 0:84e4649e7707 | 342 | RGA_Func_Rotation(frmbuf_info, work_angle); |
1050186 | 0:84e4649e7707 | 343 | Update_LCD_Display(disp_buf); |
1050186 | 0:84e4649e7707 | 344 | } |
1050186 | 0:84e4649e7707 | 345 | break; |
1050186 | 0:84e4649e7707 | 346 | case RGA_FUNC_ACCELERATE: |
1050186 | 0:84e4649e7707 | 347 | int acce_frame_num; |
1050186 | 0:84e4649e7707 | 348 | float32_t work_relative_pos; |
1050186 | 0:84e4649e7707 | 349 | Get_AnimationTiming("ease"); |
1050186 | 0:84e4649e7707 | 350 | for (acce_frame_num = 0; acce_frame_num <= ACCELERATE_MAX_NUM; acce_frame_num++) { |
1050186 | 0:84e4649e7707 | 351 | /* Swap frame buffer */ |
1050186 | 0:84e4649e7707 | 352 | Swap_FrameBuffer(frmbuf_info); |
1050186 | 0:84e4649e7707 | 353 | disp_buf = frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]; |
1050186 | 0:84e4649e7707 | 354 | work_relative_pos = acce_frame_num / (float32_t)ACCELERATE_MAX_NUM; |
1050186 | 0:84e4649e7707 | 355 | RGA_Func_Accelerate(frmbuf_info, work_relative_pos); |
1050186 | 0:84e4649e7707 | 356 | Update_LCD_Display(disp_buf); |
1050186 | 0:84e4649e7707 | 357 | } |
1050186 | 0:84e4649e7707 | 358 | break; |
1050186 | 0:84e4649e7707 | 359 | default : |
1050186 | 0:84e4649e7707 | 360 | /* Do nothing */ |
1050186 | 0:84e4649e7707 | 361 | break; |
1050186 | 0:84e4649e7707 | 362 | } |
1050186 | 0:84e4649e7707 | 363 | } |
1050186 | 0:84e4649e7707 | 364 | |
1050186 | 0:84e4649e7707 | 365 | int main(void) { |
1050186 | 0:84e4649e7707 | 366 | func_code_t func_code; |
1050186 | 0:84e4649e7707 | 367 | frame_buffer_t* work_frm_buf; |
1050186 | 0:84e4649e7707 | 368 | uint8_t* disp_buffer; |
1050186 | 0:84e4649e7707 | 369 | uint8_t touch_num = 0; |
1050186 | 0:84e4649e7707 | 370 | uint32_t pos_x0 = 0; |
1050186 | 0:84e4649e7707 | 371 | uint32_t pos_y0 = 0; |
1050186 | 0:84e4649e7707 | 372 | |
1050186 | 0:84e4649e7707 | 373 | memset(user_frame_buffer, 0, sizeof(user_frame_buffer)); |
1050186 | 0:84e4649e7707 | 374 | memset(user_frame_buffer2, 0, sizeof(user_frame_buffer2)); |
1050186 | 0:84e4649e7707 | 375 | frame_buffer_info.buffer_address[0] = user_frame_buffer; |
1050186 | 0:84e4649e7707 | 376 | frame_buffer_info.buffer_address[1] = user_frame_buffer2; |
1050186 | 0:84e4649e7707 | 377 | frame_buffer_info.buffer_count = 2; |
1050186 | 0:84e4649e7707 | 378 | frame_buffer_info.show_buffer_index = 0; |
1050186 | 0:84e4649e7707 | 379 | frame_buffer_info.draw_buffer_index = 0; |
1050186 | 0:84e4649e7707 | 380 | frame_buffer_info.width = LCD_PIXEL_WIDTH; |
1050186 | 0:84e4649e7707 | 381 | frame_buffer_info.byte_per_pixel = FRAME_BUFFER_BYTE_PER_PIXEL; |
1050186 | 0:84e4649e7707 | 382 | frame_buffer_info.stride = LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL; |
1050186 | 0:84e4649e7707 | 383 | frame_buffer_info.height = LCD_PIXEL_HEIGHT; |
1050186 | 0:84e4649e7707 | 384 | frame_buffer_info.pixel_format = PIXEL_FORMAT_RGB565; |
1050186 | 0:84e4649e7707 | 385 | disp_buffer = frame_buffer_info.buffer_address[0]; |
1050186 | 0:84e4649e7707 | 386 | Init_LCD_Display(disp_buffer); |
1050186 | 0:84e4649e7707 | 387 | |
1050186 | 0:84e4649e7707 | 388 | /* Display Top Screen */ |
1050186 | 0:84e4649e7707 | 389 | work_frm_buf = &frame_buffer_info; |
1050186 | 0:84e4649e7707 | 390 | Set_RGAObject(work_frm_buf); |
1050186 | 0:84e4649e7707 | 391 | RGA_Func_DrawTopScreen(work_frm_buf); |
1050186 | 0:84e4649e7707 | 392 | Start_LCD_Display(); |
1050186 | 0:84e4649e7707 | 393 | |
1050186 | 0:84e4649e7707 | 394 | while (1) { |
1050186 | 0:84e4649e7707 | 395 | Get_Coordinates(&touch_num, &pos_x0, &pos_y0); |
1050186 | 0:84e4649e7707 | 396 | if (touch_num != 0) { |
1050186 | 0:84e4649e7707 | 397 | func_code = Scan_FuncCode(pos_x0, pos_y0); |
1050186 | 0:84e4649e7707 | 398 | if (func_code != RGA_FUNC_NON) { |
1050186 | 0:84e4649e7707 | 399 | /* Execute RGA functions */ |
1050186 | 0:84e4649e7707 | 400 | Exe_RGA_Func(func_code, work_frm_buf); |
1050186 | 0:84e4649e7707 | 401 | Thread::wait(1000); |
1050186 | 0:84e4649e7707 | 402 | /* Display Return Button */ |
1050186 | 0:84e4649e7707 | 403 | disp_buffer = work_frm_buf->buffer_address[work_frm_buf->draw_buffer_index]; |
1050186 | 0:84e4649e7707 | 404 | RGA_Func_DrawReturnButton(work_frm_buf); |
1050186 | 0:84e4649e7707 | 405 | Update_LCD_Display(disp_buffer); |
1050186 | 0:84e4649e7707 | 406 | /* Wait until Return Code is pressed */ |
1050186 | 0:84e4649e7707 | 407 | while (func_code != RGA_FUNC_RETURN) { |
1050186 | 0:84e4649e7707 | 408 | Get_Coordinates(&touch_num, &pos_x0, &pos_y0); |
1050186 | 0:84e4649e7707 | 409 | if (touch_num != 0) { |
1050186 | 0:84e4649e7707 | 410 | func_code = Scan_ReturnCode(pos_x0, pos_y0); |
1050186 | 0:84e4649e7707 | 411 | } |
1050186 | 0:84e4649e7707 | 412 | Thread::wait(100); |
1050186 | 0:84e4649e7707 | 413 | } |
1050186 | 0:84e4649e7707 | 414 | /* Return Top Screen */ |
1050186 | 0:84e4649e7707 | 415 | Swap_FrameBuffer(work_frm_buf); |
1050186 | 0:84e4649e7707 | 416 | disp_buffer = work_frm_buf->buffer_address[work_frm_buf->draw_buffer_index]; |
1050186 | 0:84e4649e7707 | 417 | RGA_Func_DrawTopScreen(work_frm_buf); |
1050186 | 0:84e4649e7707 | 418 | Update_LCD_Display(disp_buffer); |
1050186 | 0:84e4649e7707 | 419 | } |
1050186 | 0:84e4649e7707 | 420 | } |
1050186 | 0:84e4649e7707 | 421 | Thread::wait(100); |
1050186 | 0:84e4649e7707 | 422 | } |
1050186 | 0:84e4649e7707 | 423 | } |