Graphical demo for the LPC4088 Experiment Base Board with one of the Display Expansion Kits. This program decodes decodes and shows two png images.
TestDisplay.cpp
00001 /* 00002 * Copyright 2013 Embedded Artists AB 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 /****************************************************************************** 00018 * Includes 00019 *****************************************************************************/ 00020 00021 #include "mbed.h" 00022 #include "TestDisplay.h" 00023 #include "sdram.h" 00024 00025 #include "PictureDemo.h" 00026 00027 /****************************************************************************** 00028 * Defines and typedefs 00029 *****************************************************************************/ 00030 00031 #define LCD_CONFIGURATION_43 \ 00032 40, /* horizontalBackPorch */ \ 00033 5, /* horizontalFrontPorch */ \ 00034 2, /* hsync */ \ 00035 480, /* width */ \ 00036 8, /* verticalBackPorch */ \ 00037 8, /* verticalFrontPorch */ \ 00038 2, /* vsync */ \ 00039 272, /* height */ \ 00040 false, /* invertOutputEnable */ \ 00041 false, /* invertPanelClock */ \ 00042 true, /* invertHsync */ \ 00043 true, /* invertVsync */ \ 00044 1, /* acBias */ \ 00045 LcdController::Bpp_16_565, /* bpp */ \ 00046 9000000, /* optimalClock */ \ 00047 LcdController::Tft, /* panelType */ \ 00048 false /* dualPanel */ 00049 00050 #define LCD_INIT_STRING_43 (char*)"v1,cd0,c50,cc0,c30,d100,c31,d100,cd1,d10,o,c51,cc100" 00051 00052 #define LCD_CONFIGURATION_50 \ 00053 46, /* horizontalBackPorch */ \ 00054 20, /* horizontalFrontPorch */ \ 00055 2, /* hsync */ \ 00056 800, /* width */ \ 00057 23, /* verticalBackPorch */ \ 00058 10, /* verticalFrontPorch */ \ 00059 3, /* vsync */ \ 00060 480, /* height */ \ 00061 false, /* invertOutputEnable */ \ 00062 false, /* invertPanelClock */ \ 00063 true, /* invertHsync */ \ 00064 true, /* invertVsync */ \ 00065 1, /* acBias */ \ 00066 LcdController::Bpp_16_565, /* bpp */ \ 00067 30000000, /* optimalClock */ \ 00068 LcdController::Tft, /* panelType */ \ 00069 false /* dualPanel */ 00070 00071 #define LCD_INIT_STRING_50 (char*)"v1,cc0,c31,d50,o,d200,c51,cc100" 00072 00073 #define MY_ABS(__a) (((__a) < 0) ? -(__a) : (__a)) 00074 00075 /****************************************************************************** 00076 * Public Functions 00077 *****************************************************************************/ 00078 00079 /* 00080 Prerequisites: 00081 00082 - A display must be connected to the LPC4088 Experiment Base Board 00083 with the FPC connector 00084 00085 - The touch controller uses the I2C bus so for this test to work 00086 jumpers JP8 and JP9 on the LPC4088 Experiment Base Board must 00087 both be in positions 1-2 00088 00089 */ 00090 00091 TestDisplay::TestDisplay(WhichDisplay which) : 00092 _initStr(NULL), 00093 _lcdCfg(NULL), 00094 _lcdBoard(P0_27, P0_28), 00095 _touch(P0_27, P0_28, P2_25) { 00096 00097 switch (which) { 00098 case TFT_5: 00099 _lcdCfg = new LcdController::Config(LCD_CONFIGURATION_50); 00100 _initStr = LCD_INIT_STRING_50; 00101 break; 00102 case TFT_4_3: 00103 _lcdCfg = new LcdController::Config(LCD_CONFIGURATION_43); 00104 _initStr = LCD_INIT_STRING_43; 00105 break; 00106 default: 00107 mbed_die(); 00108 } 00109 00110 if (sdram_init() == 1) { 00111 printf("Failed to initialize SDRAM\n"); 00112 _framebuffer = 0; 00113 } else { 00114 _framebuffer = (uint32_t) malloc(_lcdCfg->width * _lcdCfg->height * 2 * 3); // 2 is for 16 bit color, 3 is the number of buffers 00115 if (_framebuffer != 0) { 00116 memset((uint8_t*)_framebuffer, 0, _lcdCfg->width * _lcdCfg->height * 2 * 3); 00117 } 00118 } 00119 } 00120 00121 TestDisplay::~TestDisplay() { 00122 if (_framebuffer != 0) { 00123 free((void*)_framebuffer); 00124 _framebuffer = 0; 00125 } 00126 } 00127 00128 bool TestDisplay::runTest() { 00129 do { 00130 if (_framebuffer == 0) { 00131 printf("Failed to allocate memory for framebuffer\n"); 00132 break; 00133 } 00134 00135 EaLcdBoard::Result result = _lcdBoard.open(_lcdCfg, _initStr); 00136 if (result != EaLcdBoard::Ok) { 00137 printf("Failed to open display, error %d\n", result); 00138 break; 00139 } 00140 00141 result = _lcdBoard.setFrameBuffer(_framebuffer); 00142 if (result != EaLcdBoard::Ok) { 00143 printf("Failed to set framebuffer, error %d\n", result); 00144 break; 00145 } 00146 00147 PictureDemo pictureDemo((uint8_t *)_framebuffer, _lcdCfg->width, _lcdCfg->height); 00148 while (1) { 00149 00150 //Display Picture 1 for two seconds 00151 pictureDemo.run(_lcdBoard, 1, 2000); 00152 00153 //Display Picture 2 for three seconds 00154 pictureDemo.run(_lcdBoard, 2, 3000); 00155 } 00156 } while(0); 00157 00158 return false; 00159 } 00160 00161 void TestDisplay::calibrate_drawMarker(Graphics &g, uint16_t x, uint16_t y, bool erase) { 00162 uint16_t color = (erase ? 0x0000 : 0xffff); 00163 g.put_line(x-15, y, x+15, y, color); 00164 g.put_line(x, y-15, x, y+15, color); 00165 g.put_circle(x, y, color, 10, false); 00166 } 00167 00168 bool TestDisplay::calibrate_display() { 00169 bool morePoints = true; 00170 uint16_t x, y; 00171 int point = 0; 00172 Graphics g((uint16_t*)_framebuffer, _lcdCfg->width, _lcdCfg->height); 00173 00174 do { 00175 if (!_touch.init(_lcdCfg->width, _lcdCfg->height)) { 00176 printf("Failed to initialize touch controller\n"); 00177 break; 00178 } 00179 if (!_touch.calibrateStart()) { 00180 printf("Failed to start calibration\n"); 00181 break; 00182 } 00183 while (morePoints) { 00184 if (point++ > 0) { 00185 // erase old location 00186 calibrate_drawMarker(g, x, y, true); 00187 } 00188 if (!_touch.getNextCalibratePoint(&x, &y)) { 00189 printf("Failed to get calibration point\n"); 00190 break; 00191 } 00192 calibrate_drawMarker(g, x, y, false); 00193 if (!_touch.waitForCalibratePoint(&morePoints, 0)) { 00194 printf("Failed to get user click\n"); 00195 break; 00196 } 00197 } 00198 if (morePoints) { 00199 // aborted calibration due to error(s) 00200 break; 00201 } 00202 00203 // erase old location 00204 calibrate_drawMarker(g, x, y, true); 00205 00206 // allow user to draw for 5999 seconds 00207 Timer t; 00208 t.start(); 00209 TouchPanel::touchCoordinate_t tc; 00210 while(t.read() < 6000) { 00211 if (_touch.read(tc)) { 00212 //printf("TC: x,y,z = {%5d, %5d, %5d}\n", tc.x, tc.y, tc.z); 00213 if (tc.z) { 00214 g.put_dot(tc.x, tc.y, 0xffff); 00215 } 00216 } 00217 } 00218 } while(0); 00219 00220 return !morePoints; 00221 }
Generated on Fri Jul 15 2022 02:02:38 by 1.7.2