A board support package for the LPC4088 Display Module.

Dependencies:   DM_HttpServer DM_USBHost

Dependents:   lpc4088_displaymodule_emwin lpc4088_displaymodule_demo_sphere sampleGUI sampleEmptyGUI ... more

Fork of DMSupport by EmbeddedArtists AB

Committer:
embeddedartists
Date:
Fri Nov 21 11:42:51 2014 +0000
Revision:
0:6b68dac0d986
Child:
2:887c6b45e7fa
First version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:6b68dac0d986 1 /*
embeddedartists 0:6b68dac0d986 2 * Copyright 2014 Embedded Artists AB
embeddedartists 0:6b68dac0d986 3 *
embeddedartists 0:6b68dac0d986 4 * Licensed under the Apache License, Version 2.0 (the "License");
embeddedartists 0:6b68dac0d986 5 * you may not use this file except in compliance with the License.
embeddedartists 0:6b68dac0d986 6 * You may obtain a copy of the License at
embeddedartists 0:6b68dac0d986 7 *
embeddedartists 0:6b68dac0d986 8 * http://www.apache.org/licenses/LICENSE-2.0
embeddedartists 0:6b68dac0d986 9 *
embeddedartists 0:6b68dac0d986 10 * Unless required by applicable law or agreed to in writing, software
embeddedartists 0:6b68dac0d986 11 * distributed under the License is distributed on an "AS IS" BASIS,
embeddedartists 0:6b68dac0d986 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
embeddedartists 0:6b68dac0d986 13 * See the License for the specific language governing permissions and
embeddedartists 0:6b68dac0d986 14 * limitations under the License.
embeddedartists 0:6b68dac0d986 15 */
embeddedartists 0:6b68dac0d986 16
embeddedartists 0:6b68dac0d986 17 #include "mbed.h"
embeddedartists 0:6b68dac0d986 18 #include "DMBoard.h"
embeddedartists 0:6b68dac0d986 19 #include "InternalEEPROM.h"
embeddedartists 0:6b68dac0d986 20
embeddedartists 0:6b68dac0d986 21 #if defined(DM_BOARD_USE_TOUCH)
embeddedartists 0:6b68dac0d986 22 #include "AR1021.h"
embeddedartists 0:6b68dac0d986 23 #endif
embeddedartists 0:6b68dac0d986 24
embeddedartists 0:6b68dac0d986 25 /******************************************************************************
embeddedartists 0:6b68dac0d986 26 * Defines and typedefs
embeddedartists 0:6b68dac0d986 27 *****************************************************************************/
embeddedartists 0:6b68dac0d986 28
embeddedartists 0:6b68dac0d986 29 /******************************************************************************
embeddedartists 0:6b68dac0d986 30 * Local variables
embeddedartists 0:6b68dac0d986 31 *****************************************************************************/
embeddedartists 0:6b68dac0d986 32
embeddedartists 0:6b68dac0d986 33 /******************************************************************************
embeddedartists 0:6b68dac0d986 34 * Private Functions
embeddedartists 0:6b68dac0d986 35 *****************************************************************************/
embeddedartists 0:6b68dac0d986 36
embeddedartists 0:6b68dac0d986 37 DMBoard::DMBoard() :
embeddedartists 0:6b68dac0d986 38 _initialized(false),
embeddedartists 0:6b68dac0d986 39 #if defined(DM_BOARD_USE_MCI_FS)
embeddedartists 0:6b68dac0d986 40 _mcifs("mci", P4_16),
embeddedartists 0:6b68dac0d986 41 #endif
embeddedartists 0:6b68dac0d986 42 #if defined(DM_BOARD_USE_QSPI_FS)
embeddedartists 0:6b68dac0d986 43 _qspifs("qspi"),
embeddedartists 0:6b68dac0d986 44 #endif
embeddedartists 0:6b68dac0d986 45 #if defined(DM_BOARD_USE_TOUCH)
embeddedartists 0:6b68dac0d986 46 _touch(NULL),
embeddedartists 0:6b68dac0d986 47 #endif
embeddedartists 0:6b68dac0d986 48 _buzzer(P1_5),
embeddedartists 0:6b68dac0d986 49 _button(p23),
embeddedartists 0:6b68dac0d986 50 _led1(LED1),
embeddedartists 0:6b68dac0d986 51 _led2(LED2),
embeddedartists 0:6b68dac0d986 52 _led3(LED3),
embeddedartists 0:6b68dac0d986 53 _led4(LED4)
embeddedartists 0:6b68dac0d986 54 {
embeddedartists 0:6b68dac0d986 55 }
embeddedartists 0:6b68dac0d986 56
embeddedartists 0:6b68dac0d986 57 DMBoard::~DMBoard()
embeddedartists 0:6b68dac0d986 58 {
embeddedartists 0:6b68dac0d986 59 if (_touch != NULL) {
embeddedartists 0:6b68dac0d986 60 delete _touch;
embeddedartists 0:6b68dac0d986 61 _touch = NULL;
embeddedartists 0:6b68dac0d986 62 }
embeddedartists 0:6b68dac0d986 63 }
embeddedartists 0:6b68dac0d986 64
embeddedartists 0:6b68dac0d986 65 DMBoard::BoardError DMBoard::readConfiguration()
embeddedartists 0:6b68dac0d986 66 {
embeddedartists 0:6b68dac0d986 67 InternalEEPROM mem;
embeddedartists 0:6b68dac0d986 68 mem.init();
embeddedartists 0:6b68dac0d986 69
embeddedartists 0:6b68dac0d986 70 uint8_t* buff = (uint8_t*)malloc(mem.memorySize());
embeddedartists 0:6b68dac0d986 71 mem.read(0, 0, buff, mem.memorySize());
embeddedartists 0:6b68dac0d986 72 mem.powerDown();
embeddedartists 0:6b68dac0d986 73 #if 0
embeddedartists 0:6b68dac0d986 74 uint8_t* p = buff;
embeddedartists 0:6b68dac0d986 75 printf("\n-------\nBEFORE:\n-------\n");
embeddedartists 0:6b68dac0d986 76 for (int i = 0; i < 63; i++) {
embeddedartists 0:6b68dac0d986 77 for (int j = 0; j < 4; j++) {
embeddedartists 0:6b68dac0d986 78 printf("0x%04x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
embeddedartists 0:6b68dac0d986 79 i,
embeddedartists 0:6b68dac0d986 80 p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],
embeddedartists 0:6b68dac0d986 81 p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]);
embeddedartists 0:6b68dac0d986 82 p += 16;
embeddedartists 0:6b68dac0d986 83 }
embeddedartists 0:6b68dac0d986 84 printf("\n");
embeddedartists 0:6b68dac0d986 85 }
embeddedartists 0:6b68dac0d986 86
embeddedartists 0:6b68dac0d986 87 // find first non-zero page and write to that
embeddedartists 0:6b68dac0d986 88 for (int page = 0; page < mem.numPages(); page++) {
embeddedartists 0:6b68dac0d986 89 bool zeroPage = true;
embeddedartists 0:6b68dac0d986 90 for (int i = 0; i < mem.pageSize(); i++) {
embeddedartists 0:6b68dac0d986 91 if (buff[i + page*mem.pageSize()] != 0) {
embeddedartists 0:6b68dac0d986 92 zeroPage = false;
embeddedartists 0:6b68dac0d986 93 break;
embeddedartists 0:6b68dac0d986 94 }
embeddedartists 0:6b68dac0d986 95 }
embeddedartists 0:6b68dac0d986 96 if (zeroPage) {
embeddedartists 0:6b68dac0d986 97 printf("Will fill page 0x%04x (%d) with 0x00..0x3f\n", page, page);
embeddedartists 0:6b68dac0d986 98 p = buff;
embeddedartists 0:6b68dac0d986 99 for (int i = 0; i < mem.pageSize(); i++) {
embeddedartists 0:6b68dac0d986 100 *p++ = i;
embeddedartists 0:6b68dac0d986 101 }
embeddedartists 0:6b68dac0d986 102 mem.write(page, 0, buff, mem.pageSize());
embeddedartists 0:6b68dac0d986 103 memset(buff, 0, mem.memorySize());
embeddedartists 0:6b68dac0d986 104 mem.read(0, 0, buff, mem.memorySize());
embeddedartists 0:6b68dac0d986 105 p = buff;
embeddedartists 0:6b68dac0d986 106 printf("\n-------\nAFTER:\n-------\n");
embeddedartists 0:6b68dac0d986 107 for (int i = 0; i < 63; i++) {
embeddedartists 0:6b68dac0d986 108 for (int j = 0; j < 4; j++) {
embeddedartists 0:6b68dac0d986 109 printf("0x%04x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
embeddedartists 0:6b68dac0d986 110 i,
embeddedartists 0:6b68dac0d986 111 p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],
embeddedartists 0:6b68dac0d986 112 p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]);
embeddedartists 0:6b68dac0d986 113 p += 16;
embeddedartists 0:6b68dac0d986 114 }
embeddedartists 0:6b68dac0d986 115 printf("\n");
embeddedartists 0:6b68dac0d986 116 }
embeddedartists 0:6b68dac0d986 117 break;
embeddedartists 0:6b68dac0d986 118 }
embeddedartists 0:6b68dac0d986 119 }
embeddedartists 0:6b68dac0d986 120 #endif
embeddedartists 0:6b68dac0d986 121 return Ok;
embeddedartists 0:6b68dac0d986 122 }
embeddedartists 0:6b68dac0d986 123
embeddedartists 0:6b68dac0d986 124 #if defined(DM_BOARD_USE_DISPLAY)
embeddedartists 0:6b68dac0d986 125 DMBoard::BoardError DMBoard::readDisplayConfiguration(uint8_t** data, uint32_t* size)
embeddedartists 0:6b68dac0d986 126 {
embeddedartists 0:6b68dac0d986 127 uint32_t allocsize = 17*sizeof(uint32_t);
embeddedartists 0:6b68dac0d986 128 uint32_t* stuff = (uint32_t*)malloc(allocsize);
embeddedartists 0:6b68dac0d986 129 if (stuff == NULL) {
embeddedartists 0:6b68dac0d986 130 return MemoryError;
embeddedartists 0:6b68dac0d986 131 }
embeddedartists 0:6b68dac0d986 132 #if defined(DM_BOARD_USE_4_3_DISPLAY_TMP)
embeddedartists 0:6b68dac0d986 133 // Temporary setup, for a 4.3" display
embeddedartists 0:6b68dac0d986 134
embeddedartists 0:6b68dac0d986 135 stuff[ 0] = 40, //horizontalBackPorch == HSYNC back porch
embeddedartists 0:6b68dac0d986 136 stuff[ 1] = 5, //horizontalFrontPorch == HSYNC front porch
embeddedartists 0:6b68dac0d986 137 stuff[ 2] = 2, //hsync == HSYNC width
embeddedartists 0:6b68dac0d986 138 stuff[ 3] = 480, //width == Horizontal active area
embeddedartists 0:6b68dac0d986 139 stuff[ 4] = 8, //verticalBackPorch == VSYNC back porch
embeddedartists 0:6b68dac0d986 140 stuff[ 5] = 8, //verticalFrontPorch == VSYNC front porch
embeddedartists 0:6b68dac0d986 141 stuff[ 6] = 2, //vsync == VSYNC width
embeddedartists 0:6b68dac0d986 142 stuff[ 7] = 272, //height == Vertical display area
embeddedartists 0:6b68dac0d986 143 stuff[ 8] = false,
embeddedartists 0:6b68dac0d986 144 stuff[ 9] = false,
embeddedartists 0:6b68dac0d986 145 stuff[10] = true,
embeddedartists 0:6b68dac0d986 146 stuff[11] = true,
embeddedartists 0:6b68dac0d986 147 stuff[12] = 1,
embeddedartists 0:6b68dac0d986 148 stuff[13] = Display::Resolution_16bit_rgb565;
embeddedartists 0:6b68dac0d986 149 stuff[14] = 9000000, //clock or 0 for external
embeddedartists 0:6b68dac0d986 150 stuff[15] = 0, //LcdController::Tft,
embeddedartists 0:6b68dac0d986 151 stuff[16] = false;
embeddedartists 0:6b68dac0d986 152 #else
embeddedartists 0:6b68dac0d986 153 // Temporary setup, for a 5" rogin display
embeddedartists 0:6b68dac0d986 154
embeddedartists 0:6b68dac0d986 155 stuff[ 0] = 46, //horizontalBackPorch == HSYNC back porch
embeddedartists 0:6b68dac0d986 156 stuff[ 1] = 20, //horizontalFrontPorch == HSYNC front porch
embeddedartists 0:6b68dac0d986 157 stuff[ 2] = 2, //hsync == HSYNC width
embeddedartists 0:6b68dac0d986 158 stuff[ 3] = 800, //width == Horizontal active area
embeddedartists 0:6b68dac0d986 159 stuff[ 4] = 23, //verticalBackPorch == VSYNC back porch
embeddedartists 0:6b68dac0d986 160 stuff[ 5] = 10, //verticalFrontPorch == VSYNC front porch
embeddedartists 0:6b68dac0d986 161 stuff[ 6] = 3, //vsync == VSYNC width
embeddedartists 0:6b68dac0d986 162 stuff[ 7] = 480, //height == Vertical display area
embeddedartists 0:6b68dac0d986 163 stuff[ 8] = false,
embeddedartists 0:6b68dac0d986 164 stuff[ 9] = false,
embeddedartists 0:6b68dac0d986 165 stuff[10] = true,
embeddedartists 0:6b68dac0d986 166 stuff[11] = true,
embeddedartists 0:6b68dac0d986 167 stuff[12] = 1,
embeddedartists 0:6b68dac0d986 168 stuff[13] = Display::Resolution_16bit_rgb565;
embeddedartists 0:6b68dac0d986 169 stuff[14] = 30000000, //clock or 0 for external
embeddedartists 0:6b68dac0d986 170 stuff[15] = 0, //LcdController::Tft,
embeddedartists 0:6b68dac0d986 171 stuff[16] = false;
embeddedartists 0:6b68dac0d986 172 #endif
embeddedartists 0:6b68dac0d986 173 *data = (uint8_t*)&(stuff[0]);
embeddedartists 0:6b68dac0d986 174 *size = allocsize;
embeddedartists 0:6b68dac0d986 175
embeddedartists 0:6b68dac0d986 176 return Ok;
embeddedartists 0:6b68dac0d986 177 }
embeddedartists 0:6b68dac0d986 178 #endif
embeddedartists 0:6b68dac0d986 179
embeddedartists 0:6b68dac0d986 180 /******************************************************************************
embeddedartists 0:6b68dac0d986 181 * Public Functions
embeddedartists 0:6b68dac0d986 182 *****************************************************************************/
embeddedartists 0:6b68dac0d986 183
embeddedartists 0:6b68dac0d986 184 DMBoard::BoardError DMBoard::init()
embeddedartists 0:6b68dac0d986 185 {
embeddedartists 0:6b68dac0d986 186 BoardError err = Ok;
embeddedartists 0:6b68dac0d986 187 if (!_initialized) {
embeddedartists 0:6b68dac0d986 188 do {
embeddedartists 0:6b68dac0d986 189 // Turn off the buzzer
embeddedartists 0:6b68dac0d986 190 _buzzer.period_ms(1);
embeddedartists 0:6b68dac0d986 191 _buzzer = 0;
embeddedartists 0:6b68dac0d986 192
embeddedartists 0:6b68dac0d986 193 // Make sure the button is configured correctly
embeddedartists 0:6b68dac0d986 194 _button.mode(PullUp);
embeddedartists 0:6b68dac0d986 195
embeddedartists 0:6b68dac0d986 196 // Turn off all LEDs
embeddedartists 0:6b68dac0d986 197 _led1 = 1;
embeddedartists 0:6b68dac0d986 198 _led2 = 1;
embeddedartists 0:6b68dac0d986 199 _led3 = 0;
embeddedartists 0:6b68dac0d986 200 _led4 = 0;
embeddedartists 0:6b68dac0d986 201
embeddedartists 0:6b68dac0d986 202 #if defined(DM_BOARD_USE_QSPI) && !defined(DM_BOARD_USE_QSPI_FS)
embeddedartists 0:6b68dac0d986 203 if (SPIFI::instance().init() != SPIFI::Ok) {
embeddedartists 0:6b68dac0d986 204 err = SpifiError;
embeddedartists 0:6b68dac0d986 205 break;
embeddedartists 0:6b68dac0d986 206 }
embeddedartists 0:6b68dac0d986 207 #endif
embeddedartists 0:6b68dac0d986 208
embeddedartists 0:6b68dac0d986 209 #if defined(DM_BOARD_USE_FAST_UART)
embeddedartists 0:6b68dac0d986 210 // This works because both the default serial (used by printf) and the s instance
embeddedartists 0:6b68dac0d986 211 // (used by s.printf) would use the same underlying UART code so setting the baudrate
embeddedartists 0:6b68dac0d986 212 // in one affects the other.
embeddedartists 0:6b68dac0d986 213 Serial s(USBTX, USBRX);
embeddedartists 0:6b68dac0d986 214 s.baud(115200);
embeddedartists 0:6b68dac0d986 215 #endif
embeddedartists 0:6b68dac0d986 216
embeddedartists 0:6b68dac0d986 217 readConfiguration();
embeddedartists 0:6b68dac0d986 218
embeddedartists 0:6b68dac0d986 219 #if defined(DM_BOARD_USE_DISPLAY)
embeddedartists 0:6b68dac0d986 220 if (Display::instance().init() != Display::Ok) {
embeddedartists 0:6b68dac0d986 221 err = DisplayError;
embeddedartists 0:6b68dac0d986 222 break;
embeddedartists 0:6b68dac0d986 223 }
embeddedartists 0:6b68dac0d986 224 #endif
embeddedartists 0:6b68dac0d986 225
embeddedartists 0:6b68dac0d986 226 #if defined(DM_BOARD_USE_TOUCH)
embeddedartists 0:6b68dac0d986 227 //if (... configuration says AR1021...) {
embeddedartists 0:6b68dac0d986 228 _touch = new AR1021(P2_27, P2_26, P2_22, P2_23, P2_25);
embeddedartists 0:6b68dac0d986 229 if (!_touch->init(Display::instance().width(), Display::instance().height())) {
embeddedartists 0:6b68dac0d986 230 err = TouchError;
embeddedartists 0:6b68dac0d986 231 break;
embeddedartists 0:6b68dac0d986 232 }
embeddedartists 0:6b68dac0d986 233 //}
embeddedartists 0:6b68dac0d986 234 #endif
embeddedartists 0:6b68dac0d986 235
embeddedartists 0:6b68dac0d986 236
embeddedartists 0:6b68dac0d986 237 _initialized = true;
embeddedartists 0:6b68dac0d986 238 } while(0);
embeddedartists 0:6b68dac0d986 239 }
embeddedartists 0:6b68dac0d986 240 return err;
embeddedartists 0:6b68dac0d986 241 }
embeddedartists 0:6b68dac0d986 242
embeddedartists 0:6b68dac0d986 243 void DMBoard::setLED(int led, bool on)
embeddedartists 0:6b68dac0d986 244 {
embeddedartists 0:6b68dac0d986 245 switch(led) {
embeddedartists 0:6b68dac0d986 246 case 1:
embeddedartists 0:6b68dac0d986 247 _led1 = (on ? 0 : 1);
embeddedartists 0:6b68dac0d986 248 break;
embeddedartists 0:6b68dac0d986 249 case 2:
embeddedartists 0:6b68dac0d986 250 _led2 = (on ? 0 : 1);
embeddedartists 0:6b68dac0d986 251 break;
embeddedartists 0:6b68dac0d986 252 case 3:
embeddedartists 0:6b68dac0d986 253 _led3 = (on ? 1 : 0);
embeddedartists 0:6b68dac0d986 254 break;
embeddedartists 0:6b68dac0d986 255 case 4:
embeddedartists 0:6b68dac0d986 256 _led4 = (on ? 1 : 0);
embeddedartists 0:6b68dac0d986 257 break;
embeddedartists 0:6b68dac0d986 258 }
embeddedartists 0:6b68dac0d986 259 }
embeddedartists 0:6b68dac0d986 260
embeddedartists 0:6b68dac0d986 261 void DMBoard::buzzer(float value)
embeddedartists 0:6b68dac0d986 262 {
embeddedartists 0:6b68dac0d986 263 if (value < 0) {
embeddedartists 0:6b68dac0d986 264 value = 0;
embeddedartists 0:6b68dac0d986 265 } else if (value > 1) {
embeddedartists 0:6b68dac0d986 266 value = 1;
embeddedartists 0:6b68dac0d986 267 }
embeddedartists 0:6b68dac0d986 268 _buzzer = value;
embeddedartists 0:6b68dac0d986 269 }
embeddedartists 0:6b68dac0d986 270
embeddedartists 0:6b68dac0d986 271 bool DMBoard::buttonPressed()
embeddedartists 0:6b68dac0d986 272 {
embeddedartists 0:6b68dac0d986 273 return _button.read() == 0;
embeddedartists 0:6b68dac0d986 274 }
embeddedartists 0:6b68dac0d986 275