GR-MANGO sample using mbed-os library from my repository.
sample_programs/sample_06_lcd_touch_jcu.cpp@0:b4c1e32627f2, 2020-10-12 (annotated)
- Committer:
- RyoheiHagimoto
- Date:
- Mon Oct 12 02:25:49 2020 +0000
- Revision:
- 0:b4c1e32627f2
replaced mbed-os library
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| RyoheiHagimoto | 0:b4c1e32627f2 | 1 | /******************************************************************************* |
| RyoheiHagimoto | 0:b4c1e32627f2 | 2 | * DISCLAIMER |
| RyoheiHagimoto | 0:b4c1e32627f2 | 3 | * This software is supplied by Renesas Electronics Corporation and is only |
| RyoheiHagimoto | 0:b4c1e32627f2 | 4 | * intended for use with Renesas products. No other uses are authorized. This |
| RyoheiHagimoto | 0:b4c1e32627f2 | 5 | * software is owned by Renesas Electronics Corporation and is protected under |
| RyoheiHagimoto | 0:b4c1e32627f2 | 6 | * all applicable laws, including copyright laws. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 7 | * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING |
| RyoheiHagimoto | 0:b4c1e32627f2 | 8 | * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT |
| RyoheiHagimoto | 0:b4c1e32627f2 | 9 | * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE |
| RyoheiHagimoto | 0:b4c1e32627f2 | 10 | * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 11 | * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS |
| RyoheiHagimoto | 0:b4c1e32627f2 | 12 | * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE |
| RyoheiHagimoto | 0:b4c1e32627f2 | 13 | * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR |
| RyoheiHagimoto | 0:b4c1e32627f2 | 14 | * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE |
| RyoheiHagimoto | 0:b4c1e32627f2 | 15 | * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 16 | * Renesas reserves the right, without notice, to make changes to this software |
| RyoheiHagimoto | 0:b4c1e32627f2 | 17 | * and to discontinue the availability of this software. By using this software, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 18 | * you agree to the additional terms and conditions found by accessing the |
| RyoheiHagimoto | 0:b4c1e32627f2 | 19 | * following link: |
| RyoheiHagimoto | 0:b4c1e32627f2 | 20 | * http://www.renesas.com/disclaimer |
| RyoheiHagimoto | 0:b4c1e32627f2 | 21 | * |
| RyoheiHagimoto | 0:b4c1e32627f2 | 22 | * Copyright (C) 2019 Renesas Electronics Corporation. All rights reserved. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 23 | *******************************************************************************/ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 24 | #include "sample_select.h" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 25 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 26 | #if (SAMPLE_PROGRAM_NO == 6) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 27 | // SAMPLE_PROGRAM_NO 6 : LCD, Touch panel and JCU sample (use USB memory or SD card) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 28 | // |
| RyoheiHagimoto | 0:b4c1e32627f2 | 29 | // Decodes the JPEG file in the USB memory and displays it on the LED. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 30 | // Touch information displays on the JPEG image. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 31 | // Up to 2 touch positions can be recognized at the same time. |
| RyoheiHagimoto | 0:b4c1e32627f2 | 32 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 33 | #if defined(TARGET_SEMB1402) || defined(TARGET_RZ_A2M_SBEV) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 34 | #error "LCD is not supported." |
| RyoheiHagimoto | 0:b4c1e32627f2 | 35 | #endif |
| RyoheiHagimoto | 0:b4c1e32627f2 | 36 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 37 | #include "mbed.h" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 38 | #include "FATFileSystem.h" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 39 | #include "SdUsbConnect.h" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 40 | #include "dcache-control.h" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 41 | #include "EasyAttach_CameraAndLCD.h" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 42 | #include "JPEG_Converter.h" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 43 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 44 | #define FRAME_BUFFER_STRIDE (((LCD_PIXEL_WIDTH * 2) + 31u) & ~31u) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 45 | #define FRAME_BUFFER_HEIGHT (LCD_PIXEL_HEIGHT) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 46 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 47 | #define FILE_NAME_LEN (64) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 48 | #define MOUNT_NAME "storage" |
| RyoheiHagimoto | 0:b4c1e32627f2 | 49 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 50 | static uint8_t user_frame_buffer0[FRAME_BUFFER_STRIDE * FRAME_BUFFER_HEIGHT]__attribute((aligned(32))); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 51 | static uint8_t JpegBuffer[128 * 1024]__attribute((aligned(32))); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 52 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 53 | DisplayBase Display; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 54 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 55 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 56 | #if defined(TouckKey_LCD_shield) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 57 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 58 | /* TOUCH BUFFER Parameter GRAPHICS_LAYER_2 */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 59 | #define TOUCH_BUFFER_BYTE_PER_PIXEL (2u) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 60 | #define TOUCH_BUFFER_STRIDE (((LCD_PIXEL_WIDTH * TOUCH_BUFFER_BYTE_PER_PIXEL) + 31u) & ~31u) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 61 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 62 | /* Touch panel parameter */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 63 | #define TOUCH_NUM (2u) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 64 | #define DRAW_POINT (8) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 65 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 66 | static Semaphore sem_touch_int(0); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 67 | static uint8_t user_frame_buffer_touch[TOUCH_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32))); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 68 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 69 | static void draw_touch_pos(uint8_t * p_buf, int id, int x, int y) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 70 | int idx_base; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 71 | int wk_idx; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 72 | int i; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 73 | int j; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 74 | uint8_t coller_pix[TOUCH_BUFFER_BYTE_PER_PIXEL]; /* ARGB4444 */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 75 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 76 | /* A coordinate in the upper left is calculated from a central coordinate. */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 77 | if ((x - (DRAW_POINT / 2)) >= 0) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 78 | x -= (DRAW_POINT / 2); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 79 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 80 | if (x > ((int)LCD_PIXEL_WIDTH - DRAW_POINT)) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 81 | x = ((int)LCD_PIXEL_WIDTH - DRAW_POINT); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 82 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 83 | if ((y - (DRAW_POINT / 2)) >= 0) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 84 | y -= (DRAW_POINT / 2); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 85 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 86 | if (y > ((int)LCD_PIXEL_HEIGHT - DRAW_POINT)) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 87 | y = ((int)LCD_PIXEL_HEIGHT - DRAW_POINT); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 88 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 89 | idx_base = (x + ((int)LCD_PIXEL_WIDTH * y)) * TOUCH_BUFFER_BYTE_PER_PIXEL; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 90 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 91 | /* Select color */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 92 | if (id == 0) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 93 | /* Blue */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 94 | coller_pix[0] = 0x0F; /* 4:Green 4:Blue */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 95 | coller_pix[1] = 0xF0; /* 4:Alpha 4:Red */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 96 | } else { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 97 | /* Pink */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 98 | coller_pix[0] = 0x07; /* 4:Green 4:Blue */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 99 | coller_pix[1] = 0xFF; /* 4:Alpha 4:Red */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 100 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 101 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 102 | /* Drawing */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 103 | for (i = 0; i < DRAW_POINT; i++) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 104 | wk_idx = idx_base + ((int)LCD_PIXEL_WIDTH * TOUCH_BUFFER_BYTE_PER_PIXEL * i); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 105 | for (j = 0; j < DRAW_POINT; j++) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 106 | p_buf[wk_idx++] = coller_pix[0]; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 107 | p_buf[wk_idx++] = coller_pix[1]; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 108 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 109 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 110 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 111 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 112 | static void touch_int_callback(void) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 113 | sem_touch_int.release(); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 114 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 115 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 116 | static void touch_task(void) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 117 | DisplayBase::rect_t rect; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 118 | TouchKey::touch_pos_t touch_pos[TOUCH_NUM]; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 119 | int touch_num = 0; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 120 | int touch_num_last = 0; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 121 | uint32_t i; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 122 | #if defined(TARGET_RZ_A1XX) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 123 | TouckKey_LCD_shield touch(P4_0, P2_13, I2C_SDA, I2C_SCL); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 124 | #elif defined(TARGET_RZ_A2XX) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 125 | TouckKey_LCD_shield touch(NC, P5_7, I2C_SDA, I2C_SCL); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 126 | #endif |
| RyoheiHagimoto | 0:b4c1e32627f2 | 127 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 128 | /* The layer by which the touch panel location is drawn */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 129 | memset(user_frame_buffer_touch, 0, sizeof(user_frame_buffer_touch)); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 130 | dcache_clean(user_frame_buffer_touch, sizeof(user_frame_buffer_touch)); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 131 | rect.vs = 0; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 132 | rect.vw = LCD_PIXEL_HEIGHT; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 133 | rect.hs = 0; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 134 | rect.hw = LCD_PIXEL_WIDTH; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 135 | Display.Graphics_Read_Setting( |
| RyoheiHagimoto | 0:b4c1e32627f2 | 136 | DisplayBase::GRAPHICS_LAYER_2, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 137 | (void *)user_frame_buffer_touch, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 138 | TOUCH_BUFFER_STRIDE, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 139 | DisplayBase::GRAPHICS_FORMAT_ARGB4444, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 140 | DisplayBase::WR_RD_WRSWA_32_16BIT, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 141 | &rect |
| RyoheiHagimoto | 0:b4c1e32627f2 | 142 | ); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 143 | Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_2); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 144 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 145 | /* Callback setting */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 146 | touch.SetCallback(&touch_int_callback); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 147 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 148 | /* Reset touch IC */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 149 | touch.Reset(); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 150 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 151 | while (1) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 152 | /* Wait touch event */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 153 | sem_touch_int.wait(); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 154 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 155 | /* Get touch coordinates */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 156 | touch_num = touch.GetCoordinates(TOUCH_NUM, touch_pos); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 157 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 158 | /* When it's a new touch, touch frame buffer is initialized */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 159 | if ((touch_num != 0) && (touch_num_last == 0)) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 160 | memset(user_frame_buffer_touch, 0, sizeof(user_frame_buffer_touch)); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 161 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 162 | touch_num_last = touch_num; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 163 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 164 | /* Drawing of a touch coordinate */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 165 | for (i = 0; i < TOUCH_NUM; i ++) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 166 | printf("{valid=%d,x=%lu,y=%lu} ", touch_pos[i].valid, touch_pos[i].x, touch_pos[i].y); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 167 | if (touch_pos[i].valid) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 168 | draw_touch_pos(user_frame_buffer_touch, i, touch_pos[i].x, touch_pos[i].y); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 169 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 170 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 171 | printf("\r\n"); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 172 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 173 | /* Data cache clean */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 174 | dcache_clean(user_frame_buffer_touch, sizeof(user_frame_buffer_touch)); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 175 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 176 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 177 | #endif // TouckKey_LCD_shield |
| RyoheiHagimoto | 0:b4c1e32627f2 | 178 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 179 | static void Start_LCD_Display(void) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 180 | DisplayBase::rect_t rect; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 181 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 182 | // Initialize the background to black |
| RyoheiHagimoto | 0:b4c1e32627f2 | 183 | for (uint32_t i = 0; i < sizeof(user_frame_buffer0); i += 2) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 184 | user_frame_buffer0[i + 0] = 0x00; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 185 | user_frame_buffer0[i + 1] = 0x80; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 186 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 187 | dcache_clean(user_frame_buffer0, sizeof(user_frame_buffer0)); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 188 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 189 | rect.vs = 0; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 190 | rect.vw = LCD_PIXEL_HEIGHT; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 191 | rect.hs = 0; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 192 | rect.hw = LCD_PIXEL_WIDTH; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 193 | Display.Graphics_Read_Setting( |
| RyoheiHagimoto | 0:b4c1e32627f2 | 194 | DisplayBase::GRAPHICS_LAYER_0, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 195 | (void *)user_frame_buffer0, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 196 | FRAME_BUFFER_STRIDE, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 197 | DisplayBase::GRAPHICS_FORMAT_YCBCR422, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 198 | DisplayBase::WR_RD_WRSWA_32_16BIT, |
| RyoheiHagimoto | 0:b4c1e32627f2 | 199 | &rect |
| RyoheiHagimoto | 0:b4c1e32627f2 | 200 | ); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 201 | Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 202 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 203 | ThisThread::sleep_for(50); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 204 | EasyAttach_LcdBacklight(true); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 205 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 206 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 207 | int main() { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 208 | FILE * fp; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 209 | DIR * d; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 210 | struct dirent * p; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 211 | char file_path[sizeof("/" MOUNT_NAME "/") + FILE_NAME_LEN]; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 212 | SdUsbConnect storage(MOUNT_NAME); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 213 | JPEG_Converter Jcu; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 214 | long file_size; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 215 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 216 | EasyAttach_Init(Display); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 217 | Start_LCD_Display(); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 218 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 219 | /* Start touch panel processing */ |
| RyoheiHagimoto | 0:b4c1e32627f2 | 220 | #if defined(TouckKey_LCD_shield) |
| RyoheiHagimoto | 0:b4c1e32627f2 | 221 | Thread touchTask; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 222 | touchTask.start(callback(touch_task)); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 223 | #endif // TouckKey_LCD_shield |
| RyoheiHagimoto | 0:b4c1e32627f2 | 224 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 225 | while (1) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 226 | // connect wait |
| RyoheiHagimoto | 0:b4c1e32627f2 | 227 | storage.wait_connect(); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 228 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 229 | // file search |
| RyoheiHagimoto | 0:b4c1e32627f2 | 230 | d = opendir("/" MOUNT_NAME "/"); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 231 | if (d != NULL) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 232 | while ((p = readdir(d)) != NULL) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 233 | size_t len = strlen(p->d_name); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 234 | if (len < FILE_NAME_LEN) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 235 | // make file path |
| RyoheiHagimoto | 0:b4c1e32627f2 | 236 | sprintf(file_path, "/%s/%s", MOUNT_NAME, p->d_name); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 237 | printf("%s\r\n", file_path); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 238 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 239 | char *extension = strstr(file_path, "."); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 240 | if ((extension != NULL) && (memcmp(extension, ".jpg", 4) == 0)) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 241 | fp = fopen(file_path, "rb"); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 242 | if (fp != NULL) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 243 | fseek(fp, 0, SEEK_END); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 244 | file_size = ftell(fp); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 245 | fseek(fp, 0, SEEK_SET); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 246 | if (file_size <= (long)sizeof(JpegBuffer)) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 247 | JPEG_Converter::bitmap_buff_info_t bitmap_buff_info; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 248 | JPEG_Converter::decode_options_t decode_options; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 249 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 250 | bitmap_buff_info.width = LCD_PIXEL_WIDTH; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 251 | bitmap_buff_info.height = LCD_PIXEL_HEIGHT; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 252 | bitmap_buff_info.format = JPEG_Converter::WR_RD_YCbCr422; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 253 | bitmap_buff_info.buffer_address = (void *)user_frame_buffer0; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 254 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 255 | decode_options.output_swapsetting = JPEG_Converter::WR_RD_WRSWA_32_16_8BIT; |
| RyoheiHagimoto | 0:b4c1e32627f2 | 256 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 257 | setvbuf(fp, NULL, _IONBF, 0); // unbuffered |
| RyoheiHagimoto | 0:b4c1e32627f2 | 258 | fread(JpegBuffer, sizeof(char), file_size, fp); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 259 | dcache_clean(JpegBuffer, file_size); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 260 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 261 | if (Jcu.decode((void *)JpegBuffer, &bitmap_buff_info, &decode_options) == JPEG_Converter::JPEG_CONV_OK) { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 262 | printf("Decode ok.\r\n"); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 263 | } else { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 264 | printf("Decode error.\r\n"); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 265 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 266 | } else { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 267 | printf("File size over.\r\n"); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 268 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 269 | fclose(fp); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 270 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 271 | ThisThread::sleep_for(5000); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 272 | } else { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 273 | printf("File open error.\r\n"); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 274 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 275 | } else { |
| RyoheiHagimoto | 0:b4c1e32627f2 | 276 | printf("File skip.\r\n"); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 277 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 278 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 279 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 280 | closedir(d); |
| RyoheiHagimoto | 0:b4c1e32627f2 | 281 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 282 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 283 | } |
| RyoheiHagimoto | 0:b4c1e32627f2 | 284 | |
| RyoheiHagimoto | 0:b4c1e32627f2 | 285 | #endif |