Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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 "BubbleDemo.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 BubbleDemo bubbleDemo((uint8_t *)_framebuffer, _lcdCfg->width, _lcdCfg->height); 00148 while (1) { 00149 bubbleDemo.run(_lcdBoard, 750, 20); 00150 } 00151 } while(0); 00152 00153 return false; 00154 } 00155 00156 void TestDisplay::calibrate_drawMarker(Graphics &g, uint16_t x, uint16_t y, bool erase) { 00157 uint16_t color = (erase ? 0x0000 : 0xffff); 00158 g.put_line(x-15, y, x+15, y, color); 00159 g.put_line(x, y-15, x, y+15, color); 00160 g.put_circle(x, y, color, 10, false); 00161 } 00162 00163 bool TestDisplay::calibrate_display() { 00164 bool morePoints = true; 00165 uint16_t x, y; 00166 int point = 0; 00167 Graphics g((uint16_t*)_framebuffer, _lcdCfg->width, _lcdCfg->height); 00168 00169 do { 00170 if (!_touch.init(_lcdCfg->width, _lcdCfg->height)) { 00171 printf("Failed to initialize touch controller\n"); 00172 break; 00173 } 00174 if (!_touch.calibrateStart()) { 00175 printf("Failed to start calibration\n"); 00176 break; 00177 } 00178 while (morePoints) { 00179 if (point++ > 0) { 00180 // erase old location 00181 calibrate_drawMarker(g, x, y, true); 00182 } 00183 if (!_touch.getNextCalibratePoint(&x, &y)) { 00184 printf("Failed to get calibration point\n"); 00185 break; 00186 } 00187 calibrate_drawMarker(g, x, y, false); 00188 if (!_touch.waitForCalibratePoint(&morePoints, 0)) { 00189 printf("Failed to get user click\n"); 00190 break; 00191 } 00192 } 00193 if (morePoints) { 00194 // aborted calibration due to error(s) 00195 break; 00196 } 00197 00198 // erase old location 00199 calibrate_drawMarker(g, x, y, true); 00200 00201 // allow user to draw for 5999 seconds 00202 Timer t; 00203 t.start(); 00204 TouchPanel::touchCoordinate_t tc; 00205 while(t.read() < 6000) { 00206 if (_touch.read(tc)) { 00207 //printf("TC: x,y,z = {%5d, %5d, %5d}\n", tc.x, tc.y, tc.z); 00208 if (tc.z) { 00209 g.put_dot(tc.x, tc.y, 0xffff); 00210 } 00211 } 00212 } 00213 } while(0); 00214 00215 return !morePoints; 00216 }
Generated on Wed Jul 13 2022 20:04:53 by
1.7.2