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