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
DMBoard.cpp@42:bbfe299d4a0c, 2019-11-04 (annotated)
- Committer:
- embeddedartists
- Date:
- Mon Nov 04 14:32:50 2019 +0000
- Revision:
- 42:bbfe299d4a0c
- Parent:
- 41:e06e764ff4fd
More updates related to mbed OS 5
Who changed what in which revision?
User | Revision | Line number | New 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 | |
embeddedartists | 10:1ac4b213f0f7 | 20 | #if defined(DM_BOARD_USE_DISPLAY) |
embeddedartists | 22:1a58a518435c | 21 | #include "BiosDisplay.h" |
embeddedartists | 22:1a58a518435c | 22 | #endif |
embeddedartists | 22:1a58a518435c | 23 | #if defined(DM_BOARD_USE_TOUCH) |
embeddedartists | 22:1a58a518435c | 24 | #include "BiosTouch.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 | 42:bbfe299d4a0c | 29 | #endif |
embeddedartists | 42:bbfe299d4a0c | 30 | |
embeddedartists | 42:bbfe299d4a0c | 31 | #include "dm_rtc.h" |
embeddedartists | 4:6fdcdf7aff8d | 32 | |
embeddedartists | 5:c77fdb6e3438 | 33 | /****************************************************************************** |
embeddedartists | 5:c77fdb6e3438 | 34 | * Configuration Compatibility Control |
embeddedartists | 5:c77fdb6e3438 | 35 | *****************************************************************************/ |
embeddedartists | 5:c77fdb6e3438 | 36 | |
embeddedartists | 5:c77fdb6e3438 | 37 | #if defined(DM_BOARD_USE_USB_DEVICE) && defined(DM_BOARD_USE_USB_HOST) |
embeddedartists | 5:c77fdb6e3438 | 38 | #error The hardware supports either USB Device or USB Host - not both at the same time |
embeddedartists | 5:c77fdb6e3438 | 39 | #endif |
embeddedartists | 34:fc366bab393f | 40 | |
embeddedartists | 34:fc366bab393f | 41 | #if defined(DM_BOARD_USE_USBSERIAL_IN_RTOSLOG) && !defined(DM_BOARD_USE_USB_DEVICE) |
embeddedartists | 34:fc366bab393f | 42 | #error Cannot use USBSerial in RtosLog without DM_BOARD_USE_USB_DEVICE |
embeddedartists | 34:fc366bab393f | 43 | #endif |
embeddedartists | 5:c77fdb6e3438 | 44 | |
embeddedartists | 10:1ac4b213f0f7 | 45 | #if defined(DM_BOARD_USE_TOUCH) && !defined(DM_BOARD_USE_DISPLAY) |
embeddedartists | 10:1ac4b213f0f7 | 46 | #error Cannot have touch controller without a display! |
embeddedartists | 10:1ac4b213f0f7 | 47 | #endif |
embeddedartists | 10:1ac4b213f0f7 | 48 | |
embeddedartists | 0:6b68dac0d986 | 49 | /****************************************************************************** |
embeddedartists | 0:6b68dac0d986 | 50 | * Defines and typedefs |
embeddedartists | 0:6b68dac0d986 | 51 | *****************************************************************************/ |
embeddedartists | 0:6b68dac0d986 | 52 | |
embeddedartists | 2:887c6b45e7fa | 53 | #if defined(DM_BOARD_DISABLE_STANDARD_PRINTF) |
embeddedartists | 2:887c6b45e7fa | 54 | class DevNull : public Stream { |
embeddedartists | 2:887c6b45e7fa | 55 | |
embeddedartists | 2:887c6b45e7fa | 56 | public: |
embeddedartists | 2:887c6b45e7fa | 57 | DevNull(const char *name=NULL) : Stream(name) {} |
embeddedartists | 2:887c6b45e7fa | 58 | |
embeddedartists | 2:887c6b45e7fa | 59 | protected: |
embeddedartists | 2:887c6b45e7fa | 60 | virtual int _getc() {return 0;} |
embeddedartists | 2:887c6b45e7fa | 61 | virtual int _putc(int c) {return c;} |
embeddedartists | 2:887c6b45e7fa | 62 | }; |
embeddedartists | 2:887c6b45e7fa | 63 | |
embeddedartists | 2:887c6b45e7fa | 64 | static DevNull null("null"); |
embeddedartists | 2:887c6b45e7fa | 65 | #endif |
embeddedartists | 2:887c6b45e7fa | 66 | |
embeddedartists | 17:4ea2509445ac | 67 | |
embeddedartists | 0:6b68dac0d986 | 68 | /****************************************************************************** |
embeddedartists | 0:6b68dac0d986 | 69 | * Local variables |
embeddedartists | 0:6b68dac0d986 | 70 | *****************************************************************************/ |
embeddedartists | 0:6b68dac0d986 | 71 | |
embeddedartists | 0:6b68dac0d986 | 72 | /****************************************************************************** |
embeddedartists | 0:6b68dac0d986 | 73 | * Private Functions |
embeddedartists | 0:6b68dac0d986 | 74 | *****************************************************************************/ |
embeddedartists | 0:6b68dac0d986 | 75 | |
embeddedartists | 0:6b68dac0d986 | 76 | DMBoard::DMBoard() : |
embeddedartists | 0:6b68dac0d986 | 77 | _initialized(false), |
embeddedartists | 0:6b68dac0d986 | 78 | #if defined(DM_BOARD_USE_MCI_FS) |
embeddedartists | 42:bbfe299d4a0c | 79 | _mcifs(P4_16), |
embeddedartists | 42:bbfe299d4a0c | 80 | _mciFatFs("mci"), |
embeddedartists | 0:6b68dac0d986 | 81 | #endif |
embeddedartists | 0:6b68dac0d986 | 82 | #if defined(DM_BOARD_USE_QSPI_FS) |
embeddedartists | 0:6b68dac0d986 | 83 | _qspifs("qspi"), |
embeddedartists | 0:6b68dac0d986 | 84 | #endif |
embeddedartists | 0:6b68dac0d986 | 85 | _buzzer(P1_5), |
embeddedartists | 33:8a0a99d54bf8 | 86 | _button(P2_10), |
embeddedartists | 0:6b68dac0d986 | 87 | _led1(LED1), |
embeddedartists | 0:6b68dac0d986 | 88 | _led2(LED2), |
embeddedartists | 0:6b68dac0d986 | 89 | _led3(LED3), |
embeddedartists | 0:6b68dac0d986 | 90 | _led4(LED4) |
embeddedartists | 0:6b68dac0d986 | 91 | { |
embeddedartists | 0:6b68dac0d986 | 92 | } |
embeddedartists | 0:6b68dac0d986 | 93 | |
embeddedartists | 0:6b68dac0d986 | 94 | DMBoard::~DMBoard() |
embeddedartists | 0:6b68dac0d986 | 95 | { |
embeddedartists | 0:6b68dac0d986 | 96 | } |
embeddedartists | 0:6b68dac0d986 | 97 | |
embeddedartists | 0:6b68dac0d986 | 98 | /****************************************************************************** |
embeddedartists | 0:6b68dac0d986 | 99 | * Public Functions |
embeddedartists | 0:6b68dac0d986 | 100 | *****************************************************************************/ |
embeddedartists | 0:6b68dac0d986 | 101 | |
embeddedartists | 0:6b68dac0d986 | 102 | DMBoard::BoardError DMBoard::init() |
embeddedartists | 0:6b68dac0d986 | 103 | { |
embeddedartists | 0:6b68dac0d986 | 104 | BoardError err = Ok; |
embeddedartists | 0:6b68dac0d986 | 105 | if (!_initialized) { |
embeddedartists | 0:6b68dac0d986 | 106 | do { |
embeddedartists | 42:bbfe299d4a0c | 107 | |
embeddedartists | 42:bbfe299d4a0c | 108 | /* |
embeddedartists | 42:bbfe299d4a0c | 109 | * By default mbed OS 5 comes with the MPU enabled and prevents execution |
embeddedartists | 42:bbfe299d4a0c | 110 | * from RAM and writes to ROM. We need to be able to execute from EAM |
embeddedartists | 42:bbfe299d4a0c | 111 | * (e.g. the BIOS functionality) and also write to ROM area (we are e.g. |
embeddedartists | 42:bbfe299d4a0c | 112 | * using the EEPROM peripheral in the LPC4088 which has an address space |
embeddedartists | 42:bbfe299d4a0c | 113 | * within the ROM area). |
embeddedartists | 42:bbfe299d4a0c | 114 | */ |
embeddedartists | 42:bbfe299d4a0c | 115 | mbed_mpu_manager_lock_ram_execution(); |
embeddedartists | 42:bbfe299d4a0c | 116 | mbed_mpu_manager_lock_rom_write(); |
embeddedartists | 42:bbfe299d4a0c | 117 | |
embeddedartists | 0:6b68dac0d986 | 118 | // Turn off the buzzer |
embeddedartists | 0:6b68dac0d986 | 119 | _buzzer.period_ms(1); |
embeddedartists | 0:6b68dac0d986 | 120 | _buzzer = 0; |
embeddedartists | 0:6b68dac0d986 | 121 | |
embeddedartists | 0:6b68dac0d986 | 122 | // Make sure the button is configured correctly |
embeddedartists | 0:6b68dac0d986 | 123 | _button.mode(PullUp); |
embeddedartists | 0:6b68dac0d986 | 124 | |
embeddedartists | 0:6b68dac0d986 | 125 | // Turn off all LEDs |
embeddedartists | 0:6b68dac0d986 | 126 | _led1 = 1; |
embeddedartists | 0:6b68dac0d986 | 127 | _led2 = 1; |
embeddedartists | 0:6b68dac0d986 | 128 | _led3 = 0; |
embeddedartists | 0:6b68dac0d986 | 129 | _led4 = 0; |
embeddedartists | 10:1ac4b213f0f7 | 130 | |
embeddedartists | 2:887c6b45e7fa | 131 | // Make sure that the logger is always initialized even if |
embeddedartists | 2:887c6b45e7fa | 132 | // other initialization tasks fail |
embeddedartists | 2:887c6b45e7fa | 133 | _logger.init(); |
embeddedartists | 4:6fdcdf7aff8d | 134 | |
embeddedartists | 4:6fdcdf7aff8d | 135 | #if defined(DM_BOARD_ENABLE_MEASSURING_PINS) |
embeddedartists | 4:6fdcdf7aff8d | 136 | _INTERNAL_INIT_MEAS(); |
embeddedartists | 4:6fdcdf7aff8d | 137 | #endif |
embeddedartists | 2:887c6b45e7fa | 138 | |
embeddedartists | 2:887c6b45e7fa | 139 | #if defined(DM_BOARD_DISABLE_STANDARD_PRINTF) |
embeddedartists | 2:887c6b45e7fa | 140 | // Kill all ouput of calls to printf() so that there is no |
embeddedartists | 2:887c6b45e7fa | 141 | // simultaneous calls into the non-thread-safe standard libraries. |
embeddedartists | 2:887c6b45e7fa | 142 | // User code should use the RtosLogger anyway. |
embeddedartists | 2:887c6b45e7fa | 143 | freopen("/null", "w", stdout); |
embeddedartists | 2:887c6b45e7fa | 144 | #endif |
embeddedartists | 2:887c6b45e7fa | 145 | |
embeddedartists | 42:bbfe299d4a0c | 146 | #if defined(DM_BOARD_USE_MCI_FS) |
embeddedartists | 42:bbfe299d4a0c | 147 | _mciFatFs.mount(&_mcifs); |
embeddedartists | 42:bbfe299d4a0c | 148 | #endif |
embeddedartists | 42:bbfe299d4a0c | 149 | |
embeddedartists | 3:2fa7755f2cef | 150 | #if defined(DM_BOARD_USE_QSPI) || defined(DM_BOARD_USE_QSPI_FS) |
embeddedartists | 0:6b68dac0d986 | 151 | if (SPIFI::instance().init() != SPIFI::Ok) { |
embeddedartists | 0:6b68dac0d986 | 152 | err = SpifiError; |
embeddedartists | 0:6b68dac0d986 | 153 | break; |
embeddedartists | 0:6b68dac0d986 | 154 | } |
embeddedartists | 0:6b68dac0d986 | 155 | #endif |
embeddedartists | 0:6b68dac0d986 | 156 | |
embeddedartists | 0:6b68dac0d986 | 157 | #if defined(DM_BOARD_USE_DISPLAY) |
embeddedartists | 41:e06e764ff4fd | 158 | if (display()->init() != Display::DisplayError_Ok) { |
embeddedartists | 0:6b68dac0d986 | 159 | err = DisplayError; |
embeddedartists | 0:6b68dac0d986 | 160 | break; |
embeddedartists | 0:6b68dac0d986 | 161 | } |
embeddedartists | 0:6b68dac0d986 | 162 | #endif |
embeddedartists | 0:6b68dac0d986 | 163 | |
embeddedartists | 0:6b68dac0d986 | 164 | #if defined(DM_BOARD_USE_TOUCH) |
embeddedartists | 22:1a58a518435c | 165 | if (BiosTouch::instance().init() != TouchPanel::TouchError_Ok) { |
embeddedartists | 10:1ac4b213f0f7 | 166 | err = TouchError; |
embeddedartists | 10:1ac4b213f0f7 | 167 | break; |
embeddedartists | 10:1ac4b213f0f7 | 168 | } |
embeddedartists | 0:6b68dac0d986 | 169 | #endif |
embeddedartists | 20:9df19da50290 | 170 | |
embeddedartists | 20:9df19da50290 | 171 | #if defined(DM_BOARD_USE_REGISTRY) |
embeddedartists | 20:9df19da50290 | 172 | if (Registry::instance().load() != Registry::Ok) { |
embeddedartists | 20:9df19da50290 | 173 | err = RegistryError; |
embeddedartists | 20:9df19da50290 | 174 | break; |
embeddedartists | 20:9df19da50290 | 175 | } |
embeddedartists | 20:9df19da50290 | 176 | #endif |
embeddedartists | 42:bbfe299d4a0c | 177 | /* |
embeddedartists | 42:bbfe299d4a0c | 178 | * With mbed OS 5 the rtc driver in target/hal has been disabled |
embeddedartists | 42:bbfe299d4a0c | 179 | * Adding an external rtc driver instead. |
embeddedartists | 42:bbfe299d4a0c | 180 | */ |
embeddedartists | 42:bbfe299d4a0c | 181 | attach_rtc(&dm_read_rtc, &dm_write_rtc, &dm_init_rtc, &dm_isenabled_rtc); |
embeddedartists | 42:bbfe299d4a0c | 182 | |
embeddedartists | 0:6b68dac0d986 | 183 | _initialized = true; |
embeddedartists | 0:6b68dac0d986 | 184 | } while(0); |
embeddedartists | 0:6b68dac0d986 | 185 | } |
embeddedartists | 0:6b68dac0d986 | 186 | return err; |
embeddedartists | 0:6b68dac0d986 | 187 | } |
embeddedartists | 0:6b68dac0d986 | 188 | |
embeddedartists | 2:887c6b45e7fa | 189 | void DMBoard::setLED(Leds led, bool on) |
embeddedartists | 0:6b68dac0d986 | 190 | { |
embeddedartists | 0:6b68dac0d986 | 191 | switch(led) { |
embeddedartists | 2:887c6b45e7fa | 192 | case Led1: |
embeddedartists | 0:6b68dac0d986 | 193 | _led1 = (on ? 0 : 1); |
embeddedartists | 0:6b68dac0d986 | 194 | break; |
embeddedartists | 2:887c6b45e7fa | 195 | case Led2: |
embeddedartists | 0:6b68dac0d986 | 196 | _led2 = (on ? 0 : 1); |
embeddedartists | 0:6b68dac0d986 | 197 | break; |
embeddedartists | 2:887c6b45e7fa | 198 | case Led3: |
embeddedartists | 0:6b68dac0d986 | 199 | _led3 = (on ? 1 : 0); |
embeddedartists | 0:6b68dac0d986 | 200 | break; |
embeddedartists | 2:887c6b45e7fa | 201 | case Led4: |
embeddedartists | 0:6b68dac0d986 | 202 | _led4 = (on ? 1 : 0); |
embeddedartists | 0:6b68dac0d986 | 203 | break; |
embeddedartists | 0:6b68dac0d986 | 204 | } |
embeddedartists | 0:6b68dac0d986 | 205 | } |
embeddedartists | 0:6b68dac0d986 | 206 | |
embeddedartists | 5:c77fdb6e3438 | 207 | void DMBoard::buzzer(int frequency, int duration_ms) |
embeddedartists | 0:6b68dac0d986 | 208 | { |
embeddedartists | 5:c77fdb6e3438 | 209 | if (frequency <= 0) { |
embeddedartists | 5:c77fdb6e3438 | 210 | _buzzer = 0; |
embeddedartists | 5:c77fdb6e3438 | 211 | } else { |
embeddedartists | 5:c77fdb6e3438 | 212 | _buzzer.period_us(1000000/frequency); |
embeddedartists | 5:c77fdb6e3438 | 213 | _buzzer = 0.5; |
embeddedartists | 0:6b68dac0d986 | 214 | } |
embeddedartists | 5:c77fdb6e3438 | 215 | if (duration_ms > 0) { |
embeddedartists | 41:e06e764ff4fd | 216 | ThisThread::sleep_for(duration_ms); |
embeddedartists | 5:c77fdb6e3438 | 217 | _buzzer = 0; |
embeddedartists | 5:c77fdb6e3438 | 218 | } |
embeddedartists | 0:6b68dac0d986 | 219 | } |
embeddedartists | 0:6b68dac0d986 | 220 | |
embeddedartists | 0:6b68dac0d986 | 221 | bool DMBoard::buttonPressed() |
embeddedartists | 0:6b68dac0d986 | 222 | { |
embeddedartists | 0:6b68dac0d986 | 223 | return _button.read() == 0; |
embeddedartists | 0:6b68dac0d986 | 224 | } |
embeddedartists | 10:1ac4b213f0f7 | 225 | |
alindvall | 36:92193dc72995 | 226 | TouchPanel* DMBoard::touchPanel() |
alindvall | 36:92193dc72995 | 227 | { |
embeddedartists | 22:1a58a518435c | 228 | #if defined(DM_BOARD_USE_TOUCH) |
alindvall | 36:92193dc72995 | 229 | if (BiosTouch::instance().isTouchSupported()) { |
alindvall | 36:92193dc72995 | 230 | return &BiosTouch::instance(); |
embeddedartists | 13:2c60e28503f8 | 231 | } |
embeddedartists | 13:2c60e28503f8 | 232 | #endif |
alindvall | 36:92193dc72995 | 233 | return NULL; |
alindvall | 36:92193dc72995 | 234 | } |
embeddedartists | 13:2c60e28503f8 | 235 | |
alindvall | 36:92193dc72995 | 236 | Display* DMBoard::display() |
alindvall | 36:92193dc72995 | 237 | { |
embeddedartists | 13:2c60e28503f8 | 238 | #if defined(DM_BOARD_USE_DISPLAY) |
alindvall | 36:92193dc72995 | 239 | return &BiosDisplay::instance(); |
alindvall | 36:92193dc72995 | 240 | #else |
alindvall | 36:92193dc72995 | 241 | return NULL; |
embeddedartists | 13:2c60e28503f8 | 242 | #endif |
alindvall | 36:92193dc72995 | 243 | } |