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:
Wed Jan 07 14:02:39 2015 +0100
Revision:
17:4ea2509445ac
Parent:
13:2c60e28503f8
Child:
20:9df19da50290
Moved BIOS from internal to external EEPROM

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 17:4ea2509445ac 19 #include "BiosEEPROM.h"
embeddedartists 10:1ac4b213f0f7 20 #include "bios.h"
embeddedartists 10:1ac4b213f0f7 21 #include "crc.h"
embeddedartists 0:6b68dac0d986 22
embeddedartists 10:1ac4b213f0f7 23 #if defined(DM_BOARD_USE_DISPLAY)
embeddedartists 10:1ac4b213f0f7 24 #include "BiosDisplayAndTouch.h"
embeddedartists 0:6b68dac0d986 25 #endif
embeddedartists 0:6b68dac0d986 26
embeddedartists 4:6fdcdf7aff8d 27 #if defined(DM_BOARD_ENABLE_MEASSURING_PINS)
embeddedartists 4:6fdcdf7aff8d 28 #include "meas.h"
embeddedartists 4:6fdcdf7aff8d 29 #endif
embeddedartists 4:6fdcdf7aff8d 30
embeddedartists 5:c77fdb6e3438 31
embeddedartists 5:c77fdb6e3438 32 /******************************************************************************
embeddedartists 5:c77fdb6e3438 33 * Configuration Compatibility Control
embeddedartists 5:c77fdb6e3438 34 *****************************************************************************/
embeddedartists 5:c77fdb6e3438 35
embeddedartists 5:c77fdb6e3438 36 #if defined(DM_BOARD_USE_USB_DEVICE) && defined(DM_BOARD_USE_USB_HOST)
embeddedartists 5:c77fdb6e3438 37 #error The hardware supports either USB Device or USB Host - not both at the same time
embeddedartists 5:c77fdb6e3438 38 #endif
embeddedartists 5:c77fdb6e3438 39
embeddedartists 10:1ac4b213f0f7 40 #if defined(DM_BOARD_USE_TOUCH) && !defined(DM_BOARD_USE_DISPLAY)
embeddedartists 10:1ac4b213f0f7 41 #error Cannot have touch controller without a display!
embeddedartists 10:1ac4b213f0f7 42 #endif
embeddedartists 10:1ac4b213f0f7 43
embeddedartists 0:6b68dac0d986 44 /******************************************************************************
embeddedartists 0:6b68dac0d986 45 * Defines and typedefs
embeddedartists 0:6b68dac0d986 46 *****************************************************************************/
embeddedartists 0:6b68dac0d986 47
embeddedartists 2:887c6b45e7fa 48 #if defined(DM_BOARD_DISABLE_STANDARD_PRINTF)
embeddedartists 2:887c6b45e7fa 49 class DevNull : public Stream {
embeddedartists 2:887c6b45e7fa 50
embeddedartists 2:887c6b45e7fa 51 public:
embeddedartists 2:887c6b45e7fa 52 DevNull(const char *name=NULL) : Stream(name) {}
embeddedartists 2:887c6b45e7fa 53
embeddedartists 2:887c6b45e7fa 54 protected:
embeddedartists 2:887c6b45e7fa 55 virtual int _getc() {return 0;}
embeddedartists 2:887c6b45e7fa 56 virtual int _putc(int c) {return c;}
embeddedartists 2:887c6b45e7fa 57 };
embeddedartists 2:887c6b45e7fa 58
embeddedartists 2:887c6b45e7fa 59 static DevNull null("null");
embeddedartists 2:887c6b45e7fa 60 #endif
embeddedartists 2:887c6b45e7fa 61
embeddedartists 17:4ea2509445ac 62 /*
embeddedartists 17:4ea2509445ac 63 * Make sure that we reserve at least this amount of RAM for future
embeddedartists 17:4ea2509445ac 64 * expansion of the BIOS. This prevents the user from squeezing out
embeddedartists 17:4ea2509445ac 65 * the last drop of available RAM in his application.
embeddedartists 17:4ea2509445ac 66 */
embeddedartists 17:4ea2509445ac 67 #define BIOS_RESERVED_CHUNK 0x1000
embeddedartists 17:4ea2509445ac 68 #define BIOS_MAX_SIZE 0x100000
embeddedartists 17:4ea2509445ac 69 #ifndef MAX
embeddedartists 17:4ea2509445ac 70 #define MAX(__a, __b) (((__a)>(__b))?(__a):(__b))
embeddedartists 17:4ea2509445ac 71 #endif
embeddedartists 17:4ea2509445ac 72
embeddedartists 0:6b68dac0d986 73 /******************************************************************************
embeddedartists 0:6b68dac0d986 74 * Local variables
embeddedartists 0:6b68dac0d986 75 *****************************************************************************/
embeddedartists 0:6b68dac0d986 76
embeddedartists 0:6b68dac0d986 77 /******************************************************************************
embeddedartists 0:6b68dac0d986 78 * Private Functions
embeddedartists 0:6b68dac0d986 79 *****************************************************************************/
embeddedartists 0:6b68dac0d986 80
embeddedartists 0:6b68dac0d986 81 DMBoard::DMBoard() :
embeddedartists 0:6b68dac0d986 82 _initialized(false),
embeddedartists 10:1ac4b213f0f7 83 _conf(NULL), _confSize(0),
embeddedartists 0:6b68dac0d986 84 #if defined(DM_BOARD_USE_MCI_FS)
embeddedartists 0:6b68dac0d986 85 _mcifs("mci", P4_16),
embeddedartists 0:6b68dac0d986 86 #endif
embeddedartists 0:6b68dac0d986 87 #if defined(DM_BOARD_USE_QSPI_FS)
embeddedartists 0:6b68dac0d986 88 _qspifs("qspi"),
embeddedartists 0:6b68dac0d986 89 #endif
embeddedartists 0:6b68dac0d986 90 _buzzer(P1_5),
embeddedartists 0:6b68dac0d986 91 _button(p23),
embeddedartists 0:6b68dac0d986 92 _led1(LED1),
embeddedartists 0:6b68dac0d986 93 _led2(LED2),
embeddedartists 0:6b68dac0d986 94 _led3(LED3),
embeddedartists 0:6b68dac0d986 95 _led4(LED4)
embeddedartists 0:6b68dac0d986 96 {
embeddedartists 0:6b68dac0d986 97 }
embeddedartists 0:6b68dac0d986 98
embeddedartists 0:6b68dac0d986 99 DMBoard::~DMBoard()
embeddedartists 0:6b68dac0d986 100 {
embeddedartists 10:1ac4b213f0f7 101 if (_conf != NULL) {
embeddedartists 10:1ac4b213f0f7 102 free(_conf);
embeddedartists 10:1ac4b213f0f7 103 _conf = NULL;
embeddedartists 10:1ac4b213f0f7 104 _confSize = 0;
embeddedartists 0:6b68dac0d986 105 }
embeddedartists 0:6b68dac0d986 106 }
embeddedartists 0:6b68dac0d986 107
embeddedartists 0:6b68dac0d986 108 #if defined(DM_BOARD_USE_DISPLAY)
embeddedartists 0:6b68dac0d986 109 DMBoard::BoardError DMBoard::readDisplayConfiguration(uint8_t** data, uint32_t* size)
embeddedartists 0:6b68dac0d986 110 {
embeddedartists 17:4ea2509445ac 111 BoardError err = Ok;
embeddedartists 17:4ea2509445ac 112 BiosEEPROM eeprom;
embeddedartists 17:4ea2509445ac 113 file_header_t fh;
embeddedartists 17:4ea2509445ac 114
embeddedartists 17:4ea2509445ac 115 if (_conf != NULL) {
embeddedartists 17:4ea2509445ac 116 *data = _conf;
embeddedartists 17:4ea2509445ac 117 *size = _confSize;
embeddedartists 17:4ea2509445ac 118 return Ok;
embeddedartists 17:4ea2509445ac 119 }
embeddedartists 10:1ac4b213f0f7 120 do {
embeddedartists 17:4ea2509445ac 121 if (!eeprom.read(0, (char*)&fh, sizeof(file_header_t))) {
embeddedartists 17:4ea2509445ac 122 err = BiosStorageError;
embeddedartists 10:1ac4b213f0f7 123 break;
embeddedartists 10:1ac4b213f0f7 124 }
embeddedartists 10:1ac4b213f0f7 125
embeddedartists 17:4ea2509445ac 126 if (fh.magic != BIOS_MAGIC) {
embeddedartists 10:1ac4b213f0f7 127 err = BiosInvalidError;
embeddedartists 10:1ac4b213f0f7 128 break;
embeddedartists 10:1ac4b213f0f7 129 }
embeddedartists 10:1ac4b213f0f7 130
embeddedartists 17:4ea2509445ac 131 if (fh.version != BIOS_VER) {
embeddedartists 10:1ac4b213f0f7 132 err = BiosVersionError;
embeddedartists 10:1ac4b213f0f7 133 break;
embeddedartists 10:1ac4b213f0f7 134 }
embeddedartists 10:1ac4b213f0f7 135
embeddedartists 17:4ea2509445ac 136 if ((fh.headerSize + fh.size) > BIOS_MAX_SIZE) {
embeddedartists 10:1ac4b213f0f7 137 err = BiosInvalidError;
embeddedartists 10:1ac4b213f0f7 138 break;
embeddedartists 10:1ac4b213f0f7 139 }
embeddedartists 10:1ac4b213f0f7 140
embeddedartists 17:4ea2509445ac 141 _confSize = fh.headerSize + fh.size;
embeddedartists 17:4ea2509445ac 142 _conf = (uint8_t*)malloc(MAX(_confSize,BIOS_RESERVED_CHUNK));
embeddedartists 17:4ea2509445ac 143 if (_conf == NULL) {
embeddedartists 17:4ea2509445ac 144 _confSize = 0;
embeddedartists 17:4ea2509445ac 145 err = MemoryError;
embeddedartists 17:4ea2509445ac 146 break;
embeddedartists 17:4ea2509445ac 147 }
embeddedartists 17:4ea2509445ac 148
embeddedartists 17:4ea2509445ac 149 if (!eeprom.read(0, (char*)_conf, _confSize)) {
embeddedartists 17:4ea2509445ac 150 err = BiosStorageError;
embeddedartists 17:4ea2509445ac 151 break;
embeddedartists 17:4ea2509445ac 152 }
embeddedartists 17:4ea2509445ac 153
embeddedartists 17:4ea2509445ac 154 uint32_t crc = crc_Buffer((uint32_t*)(&_conf[fh.headerSize]), fh.size/4);
embeddedartists 17:4ea2509445ac 155 if (crc != fh.crc) {
embeddedartists 10:1ac4b213f0f7 156 err = BiosInvalidError;
embeddedartists 10:1ac4b213f0f7 157 break;
embeddedartists 10:1ac4b213f0f7 158 }
embeddedartists 10:1ac4b213f0f7 159
embeddedartists 10:1ac4b213f0f7 160 // Bios header has been verified and seems ok
embeddedartists 10:1ac4b213f0f7 161 *data = _conf;
embeddedartists 17:4ea2509445ac 162 *size = _confSize;
embeddedartists 10:1ac4b213f0f7 163 err = Ok;
embeddedartists 10:1ac4b213f0f7 164 } while (false);
embeddedartists 17:4ea2509445ac 165
embeddedartists 17:4ea2509445ac 166 if (err != Ok) {
embeddedartists 17:4ea2509445ac 167 if (_conf != NULL) {
embeddedartists 17:4ea2509445ac 168 free(_conf);
embeddedartists 17:4ea2509445ac 169 _conf = NULL;
embeddedartists 17:4ea2509445ac 170 _confSize = 0;
embeddedartists 17:4ea2509445ac 171 }
embeddedartists 17:4ea2509445ac 172 }
embeddedartists 0:6b68dac0d986 173
embeddedartists 10:1ac4b213f0f7 174 return err;
embeddedartists 0:6b68dac0d986 175 }
embeddedartists 0:6b68dac0d986 176 #endif
embeddedartists 0:6b68dac0d986 177
embeddedartists 0:6b68dac0d986 178 /******************************************************************************
embeddedartists 0:6b68dac0d986 179 * Public Functions
embeddedartists 0:6b68dac0d986 180 *****************************************************************************/
embeddedartists 0:6b68dac0d986 181
embeddedartists 0:6b68dac0d986 182 DMBoard::BoardError DMBoard::init()
embeddedartists 0:6b68dac0d986 183 {
embeddedartists 0:6b68dac0d986 184 BoardError err = Ok;
embeddedartists 0:6b68dac0d986 185 if (!_initialized) {
embeddedartists 0:6b68dac0d986 186 do {
embeddedartists 0:6b68dac0d986 187 // Turn off the buzzer
embeddedartists 0:6b68dac0d986 188 _buzzer.period_ms(1);
embeddedartists 0:6b68dac0d986 189 _buzzer = 0;
embeddedartists 0:6b68dac0d986 190
embeddedartists 0:6b68dac0d986 191 // Make sure the button is configured correctly
embeddedartists 0:6b68dac0d986 192 _button.mode(PullUp);
embeddedartists 0:6b68dac0d986 193
embeddedartists 0:6b68dac0d986 194 // Turn off all LEDs
embeddedartists 0:6b68dac0d986 195 _led1 = 1;
embeddedartists 0:6b68dac0d986 196 _led2 = 1;
embeddedartists 0:6b68dac0d986 197 _led3 = 0;
embeddedartists 0:6b68dac0d986 198 _led4 = 0;
embeddedartists 10:1ac4b213f0f7 199
embeddedartists 2:887c6b45e7fa 200 // Make sure that the logger is always initialized even if
embeddedartists 2:887c6b45e7fa 201 // other initialization tasks fail
embeddedartists 2:887c6b45e7fa 202 _logger.init();
embeddedartists 4:6fdcdf7aff8d 203
embeddedartists 4:6fdcdf7aff8d 204 #if defined(DM_BOARD_ENABLE_MEASSURING_PINS)
embeddedartists 4:6fdcdf7aff8d 205 _INTERNAL_INIT_MEAS();
embeddedartists 4:6fdcdf7aff8d 206 #endif
embeddedartists 2:887c6b45e7fa 207
embeddedartists 2:887c6b45e7fa 208 #if defined(DM_BOARD_DISABLE_STANDARD_PRINTF)
embeddedartists 2:887c6b45e7fa 209 // Kill all ouput of calls to printf() so that there is no
embeddedartists 2:887c6b45e7fa 210 // simultaneous calls into the non-thread-safe standard libraries.
embeddedartists 2:887c6b45e7fa 211 // User code should use the RtosLogger anyway.
embeddedartists 2:887c6b45e7fa 212 freopen("/null", "w", stdout);
embeddedartists 2:887c6b45e7fa 213 #endif
embeddedartists 2:887c6b45e7fa 214
embeddedartists 3:2fa7755f2cef 215 #if defined(DM_BOARD_USE_QSPI) || defined(DM_BOARD_USE_QSPI_FS)
embeddedartists 0:6b68dac0d986 216 if (SPIFI::instance().init() != SPIFI::Ok) {
embeddedartists 0:6b68dac0d986 217 err = SpifiError;
embeddedartists 0:6b68dac0d986 218 break;
embeddedartists 0:6b68dac0d986 219 }
embeddedartists 0:6b68dac0d986 220 #endif
embeddedartists 0:6b68dac0d986 221
embeddedartists 0:6b68dac0d986 222 #if defined(DM_BOARD_USE_DISPLAY)
embeddedartists 10:1ac4b213f0f7 223 if (BiosDisplayAndTouch::instance().initDisplay() != Display::DisplayError_Ok) {
embeddedartists 0:6b68dac0d986 224 err = DisplayError;
embeddedartists 0:6b68dac0d986 225 break;
embeddedartists 0:6b68dac0d986 226 }
embeddedartists 0:6b68dac0d986 227 #endif
embeddedartists 0:6b68dac0d986 228
embeddedartists 0:6b68dac0d986 229 #if defined(DM_BOARD_USE_TOUCH)
embeddedartists 10:1ac4b213f0f7 230 if (BiosDisplayAndTouch::instance().initTouchController() != TouchPanel::TouchError_Ok) {
embeddedartists 10:1ac4b213f0f7 231 err = TouchError;
embeddedartists 10:1ac4b213f0f7 232 break;
embeddedartists 10:1ac4b213f0f7 233 }
embeddedartists 0:6b68dac0d986 234 #endif
embeddedartists 0:6b68dac0d986 235
embeddedartists 0:6b68dac0d986 236 _initialized = true;
embeddedartists 0:6b68dac0d986 237 } while(0);
embeddedartists 0:6b68dac0d986 238 }
embeddedartists 0:6b68dac0d986 239 return err;
embeddedartists 0:6b68dac0d986 240 }
embeddedartists 0:6b68dac0d986 241
embeddedartists 2:887c6b45e7fa 242 void DMBoard::setLED(Leds led, bool on)
embeddedartists 0:6b68dac0d986 243 {
embeddedartists 0:6b68dac0d986 244 switch(led) {
embeddedartists 2:887c6b45e7fa 245 case Led1:
embeddedartists 0:6b68dac0d986 246 _led1 = (on ? 0 : 1);
embeddedartists 0:6b68dac0d986 247 break;
embeddedartists 2:887c6b45e7fa 248 case Led2:
embeddedartists 0:6b68dac0d986 249 _led2 = (on ? 0 : 1);
embeddedartists 0:6b68dac0d986 250 break;
embeddedartists 2:887c6b45e7fa 251 case Led3:
embeddedartists 0:6b68dac0d986 252 _led3 = (on ? 1 : 0);
embeddedartists 0:6b68dac0d986 253 break;
embeddedartists 2:887c6b45e7fa 254 case Led4:
embeddedartists 0:6b68dac0d986 255 _led4 = (on ? 1 : 0);
embeddedartists 0:6b68dac0d986 256 break;
embeddedartists 0:6b68dac0d986 257 }
embeddedartists 0:6b68dac0d986 258 }
embeddedartists 0:6b68dac0d986 259
embeddedartists 5:c77fdb6e3438 260 void DMBoard::buzzer(int frequency, int duration_ms)
embeddedartists 0:6b68dac0d986 261 {
embeddedartists 5:c77fdb6e3438 262 if (frequency <= 0) {
embeddedartists 5:c77fdb6e3438 263 _buzzer = 0;
embeddedartists 5:c77fdb6e3438 264 } else {
embeddedartists 5:c77fdb6e3438 265 _buzzer.period_us(1000000/frequency);
embeddedartists 5:c77fdb6e3438 266 _buzzer = 0.5;
embeddedartists 0:6b68dac0d986 267 }
embeddedartists 5:c77fdb6e3438 268 if (duration_ms > 0) {
embeddedartists 5:c77fdb6e3438 269 Thread::wait(duration_ms);
embeddedartists 5:c77fdb6e3438 270 _buzzer = 0;
embeddedartists 5:c77fdb6e3438 271 }
embeddedartists 0:6b68dac0d986 272 }
embeddedartists 0:6b68dac0d986 273
embeddedartists 0:6b68dac0d986 274 bool DMBoard::buttonPressed()
embeddedartists 0:6b68dac0d986 275 {
embeddedartists 0:6b68dac0d986 276 return _button.read() == 0;
embeddedartists 0:6b68dac0d986 277 }
embeddedartists 10:1ac4b213f0f7 278
embeddedartists 13:2c60e28503f8 279 #if defined(DM_BOARD_USE_DISPLAY)
embeddedartists 13:2c60e28503f8 280 TouchPanel* DMBoard::touchPanel()
embeddedartists 13:2c60e28503f8 281 {
embeddedartists 13:2c60e28503f8 282 if (BiosDisplayAndTouch::instance().isTouchSupported()) {
embeddedartists 13:2c60e28503f8 283 return &BiosDisplayAndTouch::instance();
embeddedartists 13:2c60e28503f8 284 }
embeddedartists 13:2c60e28503f8 285 return NULL;
embeddedartists 13:2c60e28503f8 286 }
embeddedartists 13:2c60e28503f8 287 #endif
embeddedartists 13:2c60e28503f8 288
embeddedartists 13:2c60e28503f8 289 #if defined(DM_BOARD_USE_DISPLAY)
embeddedartists 13:2c60e28503f8 290 Display* DMBoard::display()
embeddedartists 13:2c60e28503f8 291 {
embeddedartists 10:1ac4b213f0f7 292 return &BiosDisplayAndTouch::instance();
embeddedartists 10:1ac4b213f0f7 293 }
embeddedartists 13:2c60e28503f8 294 #endif