Graphical demo for the LPC4088 Experiment Base Board with one of the Display Expansion Kits. This program decodes decodes and shows two png images.

Dependencies:   EALib mbed

Committer:
embeddedartists
Date:
Fri Oct 03 13:30:09 2014 +0000
Revision:
0:b567d56a59d7
First version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:b567d56a59d7 1 /*
embeddedartists 0:b567d56a59d7 2 * Copyright 2013 Embedded Artists AB
embeddedartists 0:b567d56a59d7 3 *
embeddedartists 0:b567d56a59d7 4 * Licensed under the Apache License, Version 2.0 (the "License");
embeddedartists 0:b567d56a59d7 5 * you may not use this file except in compliance with the License.
embeddedartists 0:b567d56a59d7 6 * You may obtain a copy of the License at
embeddedartists 0:b567d56a59d7 7 *
embeddedartists 0:b567d56a59d7 8 * http://www.apache.org/licenses/LICENSE-2.0
embeddedartists 0:b567d56a59d7 9 *
embeddedartists 0:b567d56a59d7 10 * Unless required by applicable law or agreed to in writing, software
embeddedartists 0:b567d56a59d7 11 * distributed under the License is distributed on an "AS IS" BASIS,
embeddedartists 0:b567d56a59d7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
embeddedartists 0:b567d56a59d7 13 * See the License for the specific language governing permissions and
embeddedartists 0:b567d56a59d7 14 * limitations under the License.
embeddedartists 0:b567d56a59d7 15 */
embeddedartists 0:b567d56a59d7 16
embeddedartists 0:b567d56a59d7 17 /******************************************************************************
embeddedartists 0:b567d56a59d7 18 * Includes
embeddedartists 0:b567d56a59d7 19 *****************************************************************************/
embeddedartists 0:b567d56a59d7 20
embeddedartists 0:b567d56a59d7 21 #include "mbed.h"
embeddedartists 0:b567d56a59d7 22 #include "TestDisplay.h"
embeddedartists 0:b567d56a59d7 23 #include "sdram.h"
embeddedartists 0:b567d56a59d7 24
embeddedartists 0:b567d56a59d7 25 #include "PictureDemo.h"
embeddedartists 0:b567d56a59d7 26
embeddedartists 0:b567d56a59d7 27 /******************************************************************************
embeddedartists 0:b567d56a59d7 28 * Defines and typedefs
embeddedartists 0:b567d56a59d7 29 *****************************************************************************/
embeddedartists 0:b567d56a59d7 30
embeddedartists 0:b567d56a59d7 31 #define LCD_CONFIGURATION_43 \
embeddedartists 0:b567d56a59d7 32 40, /* horizontalBackPorch */ \
embeddedartists 0:b567d56a59d7 33 5, /* horizontalFrontPorch */ \
embeddedartists 0:b567d56a59d7 34 2, /* hsync */ \
embeddedartists 0:b567d56a59d7 35 480, /* width */ \
embeddedartists 0:b567d56a59d7 36 8, /* verticalBackPorch */ \
embeddedartists 0:b567d56a59d7 37 8, /* verticalFrontPorch */ \
embeddedartists 0:b567d56a59d7 38 2, /* vsync */ \
embeddedartists 0:b567d56a59d7 39 272, /* height */ \
embeddedartists 0:b567d56a59d7 40 false, /* invertOutputEnable */ \
embeddedartists 0:b567d56a59d7 41 false, /* invertPanelClock */ \
embeddedartists 0:b567d56a59d7 42 true, /* invertHsync */ \
embeddedartists 0:b567d56a59d7 43 true, /* invertVsync */ \
embeddedartists 0:b567d56a59d7 44 1, /* acBias */ \
embeddedartists 0:b567d56a59d7 45 LcdController::Bpp_16_565, /* bpp */ \
embeddedartists 0:b567d56a59d7 46 9000000, /* optimalClock */ \
embeddedartists 0:b567d56a59d7 47 LcdController::Tft, /* panelType */ \
embeddedartists 0:b567d56a59d7 48 false /* dualPanel */
embeddedartists 0:b567d56a59d7 49
embeddedartists 0:b567d56a59d7 50 #define LCD_INIT_STRING_43 (char*)"v1,cd0,c50,cc0,c30,d100,c31,d100,cd1,d10,o,c51,cc100"
embeddedartists 0:b567d56a59d7 51
embeddedartists 0:b567d56a59d7 52 #define LCD_CONFIGURATION_50 \
embeddedartists 0:b567d56a59d7 53 46, /* horizontalBackPorch */ \
embeddedartists 0:b567d56a59d7 54 20, /* horizontalFrontPorch */ \
embeddedartists 0:b567d56a59d7 55 2, /* hsync */ \
embeddedartists 0:b567d56a59d7 56 800, /* width */ \
embeddedartists 0:b567d56a59d7 57 23, /* verticalBackPorch */ \
embeddedartists 0:b567d56a59d7 58 10, /* verticalFrontPorch */ \
embeddedartists 0:b567d56a59d7 59 3, /* vsync */ \
embeddedartists 0:b567d56a59d7 60 480, /* height */ \
embeddedartists 0:b567d56a59d7 61 false, /* invertOutputEnable */ \
embeddedartists 0:b567d56a59d7 62 false, /* invertPanelClock */ \
embeddedartists 0:b567d56a59d7 63 true, /* invertHsync */ \
embeddedartists 0:b567d56a59d7 64 true, /* invertVsync */ \
embeddedartists 0:b567d56a59d7 65 1, /* acBias */ \
embeddedartists 0:b567d56a59d7 66 LcdController::Bpp_16_565, /* bpp */ \
embeddedartists 0:b567d56a59d7 67 30000000, /* optimalClock */ \
embeddedartists 0:b567d56a59d7 68 LcdController::Tft, /* panelType */ \
embeddedartists 0:b567d56a59d7 69 false /* dualPanel */
embeddedartists 0:b567d56a59d7 70
embeddedartists 0:b567d56a59d7 71 #define LCD_INIT_STRING_50 (char*)"v1,cc0,c31,d50,o,d200,c51,cc100"
embeddedartists 0:b567d56a59d7 72
embeddedartists 0:b567d56a59d7 73 #define MY_ABS(__a) (((__a) < 0) ? -(__a) : (__a))
embeddedartists 0:b567d56a59d7 74
embeddedartists 0:b567d56a59d7 75 /******************************************************************************
embeddedartists 0:b567d56a59d7 76 * Public Functions
embeddedartists 0:b567d56a59d7 77 *****************************************************************************/
embeddedartists 0:b567d56a59d7 78
embeddedartists 0:b567d56a59d7 79 /*
embeddedartists 0:b567d56a59d7 80 Prerequisites:
embeddedartists 0:b567d56a59d7 81
embeddedartists 0:b567d56a59d7 82 - A display must be connected to the LPC4088 Experiment Base Board
embeddedartists 0:b567d56a59d7 83 with the FPC connector
embeddedartists 0:b567d56a59d7 84
embeddedartists 0:b567d56a59d7 85 - The touch controller uses the I2C bus so for this test to work
embeddedartists 0:b567d56a59d7 86 jumpers JP8 and JP9 on the LPC4088 Experiment Base Board must
embeddedartists 0:b567d56a59d7 87 both be in positions 1-2
embeddedartists 0:b567d56a59d7 88
embeddedartists 0:b567d56a59d7 89 */
embeddedartists 0:b567d56a59d7 90
embeddedartists 0:b567d56a59d7 91 TestDisplay::TestDisplay(WhichDisplay which) :
embeddedartists 0:b567d56a59d7 92 _initStr(NULL),
embeddedartists 0:b567d56a59d7 93 _lcdCfg(NULL),
embeddedartists 0:b567d56a59d7 94 _lcdBoard(P0_27, P0_28),
embeddedartists 0:b567d56a59d7 95 _touch(P0_27, P0_28, P2_25) {
embeddedartists 0:b567d56a59d7 96
embeddedartists 0:b567d56a59d7 97 switch (which) {
embeddedartists 0:b567d56a59d7 98 case TFT_5:
embeddedartists 0:b567d56a59d7 99 _lcdCfg = new LcdController::Config(LCD_CONFIGURATION_50);
embeddedartists 0:b567d56a59d7 100 _initStr = LCD_INIT_STRING_50;
embeddedartists 0:b567d56a59d7 101 break;
embeddedartists 0:b567d56a59d7 102 case TFT_4_3:
embeddedartists 0:b567d56a59d7 103 _lcdCfg = new LcdController::Config(LCD_CONFIGURATION_43);
embeddedartists 0:b567d56a59d7 104 _initStr = LCD_INIT_STRING_43;
embeddedartists 0:b567d56a59d7 105 break;
embeddedartists 0:b567d56a59d7 106 default:
embeddedartists 0:b567d56a59d7 107 mbed_die();
embeddedartists 0:b567d56a59d7 108 }
embeddedartists 0:b567d56a59d7 109
embeddedartists 0:b567d56a59d7 110 if (sdram_init() == 1) {
embeddedartists 0:b567d56a59d7 111 printf("Failed to initialize SDRAM\n");
embeddedartists 0:b567d56a59d7 112 _framebuffer = 0;
embeddedartists 0:b567d56a59d7 113 } else {
embeddedartists 0:b567d56a59d7 114 _framebuffer = (uint32_t) malloc(_lcdCfg->width * _lcdCfg->height * 2 * 3); // 2 is for 16 bit color, 3 is the number of buffers
embeddedartists 0:b567d56a59d7 115 if (_framebuffer != 0) {
embeddedartists 0:b567d56a59d7 116 memset((uint8_t*)_framebuffer, 0, _lcdCfg->width * _lcdCfg->height * 2 * 3);
embeddedartists 0:b567d56a59d7 117 }
embeddedartists 0:b567d56a59d7 118 }
embeddedartists 0:b567d56a59d7 119 }
embeddedartists 0:b567d56a59d7 120
embeddedartists 0:b567d56a59d7 121 TestDisplay::~TestDisplay() {
embeddedartists 0:b567d56a59d7 122 if (_framebuffer != 0) {
embeddedartists 0:b567d56a59d7 123 free((void*)_framebuffer);
embeddedartists 0:b567d56a59d7 124 _framebuffer = 0;
embeddedartists 0:b567d56a59d7 125 }
embeddedartists 0:b567d56a59d7 126 }
embeddedartists 0:b567d56a59d7 127
embeddedartists 0:b567d56a59d7 128 bool TestDisplay::runTest() {
embeddedartists 0:b567d56a59d7 129 do {
embeddedartists 0:b567d56a59d7 130 if (_framebuffer == 0) {
embeddedartists 0:b567d56a59d7 131 printf("Failed to allocate memory for framebuffer\n");
embeddedartists 0:b567d56a59d7 132 break;
embeddedartists 0:b567d56a59d7 133 }
embeddedartists 0:b567d56a59d7 134
embeddedartists 0:b567d56a59d7 135 EaLcdBoard::Result result = _lcdBoard.open(_lcdCfg, _initStr);
embeddedartists 0:b567d56a59d7 136 if (result != EaLcdBoard::Ok) {
embeddedartists 0:b567d56a59d7 137 printf("Failed to open display, error %d\n", result);
embeddedartists 0:b567d56a59d7 138 break;
embeddedartists 0:b567d56a59d7 139 }
embeddedartists 0:b567d56a59d7 140
embeddedartists 0:b567d56a59d7 141 result = _lcdBoard.setFrameBuffer(_framebuffer);
embeddedartists 0:b567d56a59d7 142 if (result != EaLcdBoard::Ok) {
embeddedartists 0:b567d56a59d7 143 printf("Failed to set framebuffer, error %d\n", result);
embeddedartists 0:b567d56a59d7 144 break;
embeddedartists 0:b567d56a59d7 145 }
embeddedartists 0:b567d56a59d7 146
embeddedartists 0:b567d56a59d7 147 PictureDemo pictureDemo((uint8_t *)_framebuffer, _lcdCfg->width, _lcdCfg->height);
embeddedartists 0:b567d56a59d7 148 while (1) {
embeddedartists 0:b567d56a59d7 149
embeddedartists 0:b567d56a59d7 150 //Display Picture 1 for two seconds
embeddedartists 0:b567d56a59d7 151 pictureDemo.run(_lcdBoard, 1, 2000);
embeddedartists 0:b567d56a59d7 152
embeddedartists 0:b567d56a59d7 153 //Display Picture 2 for three seconds
embeddedartists 0:b567d56a59d7 154 pictureDemo.run(_lcdBoard, 2, 3000);
embeddedartists 0:b567d56a59d7 155 }
embeddedartists 0:b567d56a59d7 156 } while(0);
embeddedartists 0:b567d56a59d7 157
embeddedartists 0:b567d56a59d7 158 return false;
embeddedartists 0:b567d56a59d7 159 }
embeddedartists 0:b567d56a59d7 160
embeddedartists 0:b567d56a59d7 161 void TestDisplay::calibrate_drawMarker(Graphics &g, uint16_t x, uint16_t y, bool erase) {
embeddedartists 0:b567d56a59d7 162 uint16_t color = (erase ? 0x0000 : 0xffff);
embeddedartists 0:b567d56a59d7 163 g.put_line(x-15, y, x+15, y, color);
embeddedartists 0:b567d56a59d7 164 g.put_line(x, y-15, x, y+15, color);
embeddedartists 0:b567d56a59d7 165 g.put_circle(x, y, color, 10, false);
embeddedartists 0:b567d56a59d7 166 }
embeddedartists 0:b567d56a59d7 167
embeddedartists 0:b567d56a59d7 168 bool TestDisplay::calibrate_display() {
embeddedartists 0:b567d56a59d7 169 bool morePoints = true;
embeddedartists 0:b567d56a59d7 170 uint16_t x, y;
embeddedartists 0:b567d56a59d7 171 int point = 0;
embeddedartists 0:b567d56a59d7 172 Graphics g((uint16_t*)_framebuffer, _lcdCfg->width, _lcdCfg->height);
embeddedartists 0:b567d56a59d7 173
embeddedartists 0:b567d56a59d7 174 do {
embeddedartists 0:b567d56a59d7 175 if (!_touch.init(_lcdCfg->width, _lcdCfg->height)) {
embeddedartists 0:b567d56a59d7 176 printf("Failed to initialize touch controller\n");
embeddedartists 0:b567d56a59d7 177 break;
embeddedartists 0:b567d56a59d7 178 }
embeddedartists 0:b567d56a59d7 179 if (!_touch.calibrateStart()) {
embeddedartists 0:b567d56a59d7 180 printf("Failed to start calibration\n");
embeddedartists 0:b567d56a59d7 181 break;
embeddedartists 0:b567d56a59d7 182 }
embeddedartists 0:b567d56a59d7 183 while (morePoints) {
embeddedartists 0:b567d56a59d7 184 if (point++ > 0) {
embeddedartists 0:b567d56a59d7 185 // erase old location
embeddedartists 0:b567d56a59d7 186 calibrate_drawMarker(g, x, y, true);
embeddedartists 0:b567d56a59d7 187 }
embeddedartists 0:b567d56a59d7 188 if (!_touch.getNextCalibratePoint(&x, &y)) {
embeddedartists 0:b567d56a59d7 189 printf("Failed to get calibration point\n");
embeddedartists 0:b567d56a59d7 190 break;
embeddedartists 0:b567d56a59d7 191 }
embeddedartists 0:b567d56a59d7 192 calibrate_drawMarker(g, x, y, false);
embeddedartists 0:b567d56a59d7 193 if (!_touch.waitForCalibratePoint(&morePoints, 0)) {
embeddedartists 0:b567d56a59d7 194 printf("Failed to get user click\n");
embeddedartists 0:b567d56a59d7 195 break;
embeddedartists 0:b567d56a59d7 196 }
embeddedartists 0:b567d56a59d7 197 }
embeddedartists 0:b567d56a59d7 198 if (morePoints) {
embeddedartists 0:b567d56a59d7 199 // aborted calibration due to error(s)
embeddedartists 0:b567d56a59d7 200 break;
embeddedartists 0:b567d56a59d7 201 }
embeddedartists 0:b567d56a59d7 202
embeddedartists 0:b567d56a59d7 203 // erase old location
embeddedartists 0:b567d56a59d7 204 calibrate_drawMarker(g, x, y, true);
embeddedartists 0:b567d56a59d7 205
embeddedartists 0:b567d56a59d7 206 // allow user to draw for 5999 seconds
embeddedartists 0:b567d56a59d7 207 Timer t;
embeddedartists 0:b567d56a59d7 208 t.start();
embeddedartists 0:b567d56a59d7 209 TouchPanel::touchCoordinate_t tc;
embeddedartists 0:b567d56a59d7 210 while(t.read() < 6000) {
embeddedartists 0:b567d56a59d7 211 if (_touch.read(tc)) {
embeddedartists 0:b567d56a59d7 212 //printf("TC: x,y,z = {%5d, %5d, %5d}\n", tc.x, tc.y, tc.z);
embeddedartists 0:b567d56a59d7 213 if (tc.z) {
embeddedartists 0:b567d56a59d7 214 g.put_dot(tc.x, tc.y, 0xffff);
embeddedartists 0:b567d56a59d7 215 }
embeddedartists 0:b567d56a59d7 216 }
embeddedartists 0:b567d56a59d7 217 }
embeddedartists 0:b567d56a59d7 218 } while(0);
embeddedartists 0:b567d56a59d7 219
embeddedartists 0:b567d56a59d7 220 return !morePoints;
embeddedartists 0:b567d56a59d7 221 }