Subdirectory provided by Embedded Artists
Dependencies: DM_FATFileSystem DM_HttpServer DM_USBHost EthernetInterface USBDevice mbed-rpc mbed-rtos mbed-src
Dependents: lpc4088_displaymodule_hello_world_Sept_2018
Fork of DMSupport by
DMBoard.cpp@22:1a58a518435c, 2015-01-16 (annotated)
- Committer:
- embeddedartists
- Date:
- Fri Jan 16 11:13:39 2015 +0100
- Revision:
- 22:1a58a518435c
- Parent:
- 20:9df19da50290
- Child:
- 33:8a0a99d54bf8
- Updated SPIFI code to allow BIOS to id chips not yet supported by DMSupport
- Updated QSPIFileSystem to be chip independant. Erase block info from SPIFI.cpp
- Split BiosDisplayAndTouch into BiosDisplay and BiosTouch
- Added BiosLoader with common functionallity
- Removed BIOS code from DMBoard
- Added first version of a touch listener
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 | 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 | 0:6b68dac0d986 | 62 | /****************************************************************************** |
embeddedartists | 0:6b68dac0d986 | 63 | * Local variables |
embeddedartists | 0:6b68dac0d986 | 64 | *****************************************************************************/ |
embeddedartists | 0:6b68dac0d986 | 65 | |
embeddedartists | 0:6b68dac0d986 | 66 | /****************************************************************************** |
embeddedartists | 0:6b68dac0d986 | 67 | * Private Functions |
embeddedartists | 0:6b68dac0d986 | 68 | *****************************************************************************/ |
embeddedartists | 0:6b68dac0d986 | 69 | |
embeddedartists | 0:6b68dac0d986 | 70 | DMBoard::DMBoard() : |
embeddedartists | 0:6b68dac0d986 | 71 | _initialized(false), |
embeddedartists | 0:6b68dac0d986 | 72 | #if defined(DM_BOARD_USE_MCI_FS) |
embeddedartists | 0:6b68dac0d986 | 73 | _mcifs("mci", P4_16), |
embeddedartists | 0:6b68dac0d986 | 74 | #endif |
embeddedartists | 0:6b68dac0d986 | 75 | #if defined(DM_BOARD_USE_QSPI_FS) |
embeddedartists | 0:6b68dac0d986 | 76 | _qspifs("qspi"), |
embeddedartists | 0:6b68dac0d986 | 77 | #endif |
embeddedartists | 0:6b68dac0d986 | 78 | _buzzer(P1_5), |
embeddedartists | 0:6b68dac0d986 | 79 | _button(p23), |
embeddedartists | 0:6b68dac0d986 | 80 | _led1(LED1), |
embeddedartists | 0:6b68dac0d986 | 81 | _led2(LED2), |
embeddedartists | 0:6b68dac0d986 | 82 | _led3(LED3), |
embeddedartists | 0:6b68dac0d986 | 83 | _led4(LED4) |
embeddedartists | 0:6b68dac0d986 | 84 | { |
embeddedartists | 0:6b68dac0d986 | 85 | } |
embeddedartists | 0:6b68dac0d986 | 86 | |
embeddedartists | 0:6b68dac0d986 | 87 | DMBoard::~DMBoard() |
embeddedartists | 0:6b68dac0d986 | 88 | { |
embeddedartists | 0:6b68dac0d986 | 89 | } |
embeddedartists | 0:6b68dac0d986 | 90 | |
embeddedartists | 0:6b68dac0d986 | 91 | /****************************************************************************** |
embeddedartists | 0:6b68dac0d986 | 92 | * Public Functions |
embeddedartists | 0:6b68dac0d986 | 93 | *****************************************************************************/ |
embeddedartists | 0:6b68dac0d986 | 94 | |
embeddedartists | 0:6b68dac0d986 | 95 | DMBoard::BoardError DMBoard::init() |
embeddedartists | 0:6b68dac0d986 | 96 | { |
embeddedartists | 0:6b68dac0d986 | 97 | BoardError err = Ok; |
embeddedartists | 0:6b68dac0d986 | 98 | if (!_initialized) { |
embeddedartists | 0:6b68dac0d986 | 99 | do { |
embeddedartists | 0:6b68dac0d986 | 100 | // Turn off the buzzer |
embeddedartists | 0:6b68dac0d986 | 101 | _buzzer.period_ms(1); |
embeddedartists | 0:6b68dac0d986 | 102 | _buzzer = 0; |
embeddedartists | 0:6b68dac0d986 | 103 | |
embeddedartists | 0:6b68dac0d986 | 104 | // Make sure the button is configured correctly |
embeddedartists | 0:6b68dac0d986 | 105 | _button.mode(PullUp); |
embeddedartists | 0:6b68dac0d986 | 106 | |
embeddedartists | 0:6b68dac0d986 | 107 | // Turn off all LEDs |
embeddedartists | 0:6b68dac0d986 | 108 | _led1 = 1; |
embeddedartists | 0:6b68dac0d986 | 109 | _led2 = 1; |
embeddedartists | 0:6b68dac0d986 | 110 | _led3 = 0; |
embeddedartists | 0:6b68dac0d986 | 111 | _led4 = 0; |
embeddedartists | 10:1ac4b213f0f7 | 112 | |
embeddedartists | 2:887c6b45e7fa | 113 | // Make sure that the logger is always initialized even if |
embeddedartists | 2:887c6b45e7fa | 114 | // other initialization tasks fail |
embeddedartists | 2:887c6b45e7fa | 115 | _logger.init(); |
embeddedartists | 4:6fdcdf7aff8d | 116 | |
embeddedartists | 4:6fdcdf7aff8d | 117 | #if defined(DM_BOARD_ENABLE_MEASSURING_PINS) |
embeddedartists | 4:6fdcdf7aff8d | 118 | _INTERNAL_INIT_MEAS(); |
embeddedartists | 4:6fdcdf7aff8d | 119 | #endif |
embeddedartists | 2:887c6b45e7fa | 120 | |
embeddedartists | 2:887c6b45e7fa | 121 | #if defined(DM_BOARD_DISABLE_STANDARD_PRINTF) |
embeddedartists | 2:887c6b45e7fa | 122 | // Kill all ouput of calls to printf() so that there is no |
embeddedartists | 2:887c6b45e7fa | 123 | // simultaneous calls into the non-thread-safe standard libraries. |
embeddedartists | 2:887c6b45e7fa | 124 | // User code should use the RtosLogger anyway. |
embeddedartists | 2:887c6b45e7fa | 125 | freopen("/null", "w", stdout); |
embeddedartists | 2:887c6b45e7fa | 126 | #endif |
embeddedartists | 2:887c6b45e7fa | 127 | |
embeddedartists | 3:2fa7755f2cef | 128 | #if defined(DM_BOARD_USE_QSPI) || defined(DM_BOARD_USE_QSPI_FS) |
embeddedartists | 0:6b68dac0d986 | 129 | if (SPIFI::instance().init() != SPIFI::Ok) { |
embeddedartists | 0:6b68dac0d986 | 130 | err = SpifiError; |
embeddedartists | 0:6b68dac0d986 | 131 | break; |
embeddedartists | 0:6b68dac0d986 | 132 | } |
embeddedartists | 0:6b68dac0d986 | 133 | #endif |
embeddedartists | 0:6b68dac0d986 | 134 | |
embeddedartists | 0:6b68dac0d986 | 135 | #if defined(DM_BOARD_USE_DISPLAY) |
embeddedartists | 22:1a58a518435c | 136 | if (BiosDisplay::instance().init() != Display::DisplayError_Ok) { |
embeddedartists | 0:6b68dac0d986 | 137 | err = DisplayError; |
embeddedartists | 0:6b68dac0d986 | 138 | break; |
embeddedartists | 0:6b68dac0d986 | 139 | } |
embeddedartists | 0:6b68dac0d986 | 140 | #endif |
embeddedartists | 0:6b68dac0d986 | 141 | |
embeddedartists | 0:6b68dac0d986 | 142 | #if defined(DM_BOARD_USE_TOUCH) |
embeddedartists | 22:1a58a518435c | 143 | if (BiosTouch::instance().init() != TouchPanel::TouchError_Ok) { |
embeddedartists | 10:1ac4b213f0f7 | 144 | err = TouchError; |
embeddedartists | 10:1ac4b213f0f7 | 145 | break; |
embeddedartists | 10:1ac4b213f0f7 | 146 | } |
embeddedartists | 0:6b68dac0d986 | 147 | #endif |
embeddedartists | 20:9df19da50290 | 148 | |
embeddedartists | 20:9df19da50290 | 149 | #if defined(DM_BOARD_USE_REGISTRY) |
embeddedartists | 20:9df19da50290 | 150 | if (Registry::instance().load() != Registry::Ok) { |
embeddedartists | 20:9df19da50290 | 151 | err = RegistryError; |
embeddedartists | 20:9df19da50290 | 152 | break; |
embeddedartists | 20:9df19da50290 | 153 | } |
embeddedartists | 20:9df19da50290 | 154 | #endif |
embeddedartists | 0:6b68dac0d986 | 155 | _initialized = true; |
embeddedartists | 0:6b68dac0d986 | 156 | } while(0); |
embeddedartists | 0:6b68dac0d986 | 157 | } |
embeddedartists | 0:6b68dac0d986 | 158 | return err; |
embeddedartists | 0:6b68dac0d986 | 159 | } |
embeddedartists | 0:6b68dac0d986 | 160 | |
embeddedartists | 2:887c6b45e7fa | 161 | void DMBoard::setLED(Leds led, bool on) |
embeddedartists | 0:6b68dac0d986 | 162 | { |
embeddedartists | 0:6b68dac0d986 | 163 | switch(led) { |
embeddedartists | 2:887c6b45e7fa | 164 | case Led1: |
embeddedartists | 0:6b68dac0d986 | 165 | _led1 = (on ? 0 : 1); |
embeddedartists | 0:6b68dac0d986 | 166 | break; |
embeddedartists | 2:887c6b45e7fa | 167 | case Led2: |
embeddedartists | 0:6b68dac0d986 | 168 | _led2 = (on ? 0 : 1); |
embeddedartists | 0:6b68dac0d986 | 169 | break; |
embeddedartists | 2:887c6b45e7fa | 170 | case Led3: |
embeddedartists | 0:6b68dac0d986 | 171 | _led3 = (on ? 1 : 0); |
embeddedartists | 0:6b68dac0d986 | 172 | break; |
embeddedartists | 2:887c6b45e7fa | 173 | case Led4: |
embeddedartists | 0:6b68dac0d986 | 174 | _led4 = (on ? 1 : 0); |
embeddedartists | 0:6b68dac0d986 | 175 | break; |
embeddedartists | 0:6b68dac0d986 | 176 | } |
embeddedartists | 0:6b68dac0d986 | 177 | } |
embeddedartists | 0:6b68dac0d986 | 178 | |
embeddedartists | 5:c77fdb6e3438 | 179 | void DMBoard::buzzer(int frequency, int duration_ms) |
embeddedartists | 0:6b68dac0d986 | 180 | { |
embeddedartists | 5:c77fdb6e3438 | 181 | if (frequency <= 0) { |
embeddedartists | 5:c77fdb6e3438 | 182 | _buzzer = 0; |
embeddedartists | 5:c77fdb6e3438 | 183 | } else { |
embeddedartists | 5:c77fdb6e3438 | 184 | _buzzer.period_us(1000000/frequency); |
embeddedartists | 5:c77fdb6e3438 | 185 | _buzzer = 0.5; |
embeddedartists | 0:6b68dac0d986 | 186 | } |
embeddedartists | 5:c77fdb6e3438 | 187 | if (duration_ms > 0) { |
embeddedartists | 5:c77fdb6e3438 | 188 | Thread::wait(duration_ms); |
embeddedartists | 5:c77fdb6e3438 | 189 | _buzzer = 0; |
embeddedartists | 5:c77fdb6e3438 | 190 | } |
embeddedartists | 0:6b68dac0d986 | 191 | } |
embeddedartists | 0:6b68dac0d986 | 192 | |
embeddedartists | 0:6b68dac0d986 | 193 | bool DMBoard::buttonPressed() |
embeddedartists | 0:6b68dac0d986 | 194 | { |
embeddedartists | 0:6b68dac0d986 | 195 | return _button.read() == 0; |
embeddedartists | 0:6b68dac0d986 | 196 | } |
embeddedartists | 10:1ac4b213f0f7 | 197 | |
embeddedartists | 22:1a58a518435c | 198 | #if defined(DM_BOARD_USE_TOUCH) |
embeddedartists | 13:2c60e28503f8 | 199 | TouchPanel* DMBoard::touchPanel() |
embeddedartists | 13:2c60e28503f8 | 200 | { |
embeddedartists | 22:1a58a518435c | 201 | if (BiosTouch::instance().isTouchSupported()) { |
embeddedartists | 22:1a58a518435c | 202 | return &BiosTouch::instance(); |
embeddedartists | 13:2c60e28503f8 | 203 | } |
embeddedartists | 13:2c60e28503f8 | 204 | return NULL; |
embeddedartists | 13:2c60e28503f8 | 205 | } |
embeddedartists | 13:2c60e28503f8 | 206 | #endif |
embeddedartists | 13:2c60e28503f8 | 207 | |
embeddedartists | 13:2c60e28503f8 | 208 | #if defined(DM_BOARD_USE_DISPLAY) |
embeddedartists | 13:2c60e28503f8 | 209 | Display* DMBoard::display() |
embeddedartists | 13:2c60e28503f8 | 210 | { |
embeddedartists | 22:1a58a518435c | 211 | return &BiosDisplay::instance(); |
embeddedartists | 10:1ac4b213f0f7 | 212 | } |
embeddedartists | 13:2c60e28503f8 | 213 | #endif |