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@36:92193dc72995, 2015-03-20 (annotated)
- Committer:
- alindvall
- Date:
- Fri Mar 20 14:44:06 2015 +0000
- Revision:
- 36:92193dc72995
- Parent:
- 34:fc366bab393f
Modified DMBoard interface to always have the touchPanel() and display() functions even if the touch/display has been disabled in dm_board_config.h to allow e.g. AppTouchCalibration to compile (even if it will never be used it must still compile)
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 | 34:fc366bab393f | 38 | |
embeddedartists | 34:fc366bab393f | 39 | #if defined(DM_BOARD_USE_USBSERIAL_IN_RTOSLOG) && !defined(DM_BOARD_USE_USB_DEVICE) |
embeddedartists | 34:fc366bab393f | 40 | #error Cannot use USBSerial in RtosLog without DM_BOARD_USE_USB_DEVICE |
embeddedartists | 34:fc366bab393f | 41 | #endif |
embeddedartists | 5:c77fdb6e3438 | 42 | |
embeddedartists | 10:1ac4b213f0f7 | 43 | #if defined(DM_BOARD_USE_TOUCH) && !defined(DM_BOARD_USE_DISPLAY) |
embeddedartists | 10:1ac4b213f0f7 | 44 | #error Cannot have touch controller without a display! |
embeddedartists | 10:1ac4b213f0f7 | 45 | #endif |
embeddedartists | 10:1ac4b213f0f7 | 46 | |
embeddedartists | 0:6b68dac0d986 | 47 | /****************************************************************************** |
embeddedartists | 0:6b68dac0d986 | 48 | * Defines and typedefs |
embeddedartists | 0:6b68dac0d986 | 49 | *****************************************************************************/ |
embeddedartists | 0:6b68dac0d986 | 50 | |
embeddedartists | 2:887c6b45e7fa | 51 | #if defined(DM_BOARD_DISABLE_STANDARD_PRINTF) |
embeddedartists | 2:887c6b45e7fa | 52 | class DevNull : public Stream { |
embeddedartists | 2:887c6b45e7fa | 53 | |
embeddedartists | 2:887c6b45e7fa | 54 | public: |
embeddedartists | 2:887c6b45e7fa | 55 | DevNull(const char *name=NULL) : Stream(name) {} |
embeddedartists | 2:887c6b45e7fa | 56 | |
embeddedartists | 2:887c6b45e7fa | 57 | protected: |
embeddedartists | 2:887c6b45e7fa | 58 | virtual int _getc() {return 0;} |
embeddedartists | 2:887c6b45e7fa | 59 | virtual int _putc(int c) {return c;} |
embeddedartists | 2:887c6b45e7fa | 60 | }; |
embeddedartists | 2:887c6b45e7fa | 61 | |
embeddedartists | 2:887c6b45e7fa | 62 | static DevNull null("null"); |
embeddedartists | 2:887c6b45e7fa | 63 | #endif |
embeddedartists | 2:887c6b45e7fa | 64 | |
embeddedartists | 17:4ea2509445ac | 65 | |
embeddedartists | 0:6b68dac0d986 | 66 | /****************************************************************************** |
embeddedartists | 0:6b68dac0d986 | 67 | * Local variables |
embeddedartists | 0:6b68dac0d986 | 68 | *****************************************************************************/ |
embeddedartists | 0:6b68dac0d986 | 69 | |
embeddedartists | 0:6b68dac0d986 | 70 | /****************************************************************************** |
embeddedartists | 0:6b68dac0d986 | 71 | * Private Functions |
embeddedartists | 0:6b68dac0d986 | 72 | *****************************************************************************/ |
embeddedartists | 0:6b68dac0d986 | 73 | |
embeddedartists | 0:6b68dac0d986 | 74 | DMBoard::DMBoard() : |
embeddedartists | 0:6b68dac0d986 | 75 | _initialized(false), |
embeddedartists | 0:6b68dac0d986 | 76 | #if defined(DM_BOARD_USE_MCI_FS) |
embeddedartists | 0:6b68dac0d986 | 77 | _mcifs("mci", P4_16), |
embeddedartists | 0:6b68dac0d986 | 78 | #endif |
embeddedartists | 0:6b68dac0d986 | 79 | #if defined(DM_BOARD_USE_QSPI_FS) |
embeddedartists | 0:6b68dac0d986 | 80 | _qspifs("qspi"), |
embeddedartists | 0:6b68dac0d986 | 81 | #endif |
embeddedartists | 0:6b68dac0d986 | 82 | _buzzer(P1_5), |
embeddedartists | 33:8a0a99d54bf8 | 83 | _button(P2_10), |
embeddedartists | 0:6b68dac0d986 | 84 | _led1(LED1), |
embeddedartists | 0:6b68dac0d986 | 85 | _led2(LED2), |
embeddedartists | 0:6b68dac0d986 | 86 | _led3(LED3), |
embeddedartists | 0:6b68dac0d986 | 87 | _led4(LED4) |
embeddedartists | 0:6b68dac0d986 | 88 | { |
embeddedartists | 0:6b68dac0d986 | 89 | } |
embeddedartists | 0:6b68dac0d986 | 90 | |
embeddedartists | 0:6b68dac0d986 | 91 | DMBoard::~DMBoard() |
embeddedartists | 0:6b68dac0d986 | 92 | { |
embeddedartists | 0:6b68dac0d986 | 93 | } |
embeddedartists | 0:6b68dac0d986 | 94 | |
embeddedartists | 0:6b68dac0d986 | 95 | /****************************************************************************** |
embeddedartists | 0:6b68dac0d986 | 96 | * Public Functions |
embeddedartists | 0:6b68dac0d986 | 97 | *****************************************************************************/ |
embeddedartists | 0:6b68dac0d986 | 98 | |
embeddedartists | 0:6b68dac0d986 | 99 | DMBoard::BoardError DMBoard::init() |
embeddedartists | 0:6b68dac0d986 | 100 | { |
embeddedartists | 0:6b68dac0d986 | 101 | BoardError err = Ok; |
embeddedartists | 0:6b68dac0d986 | 102 | if (!_initialized) { |
embeddedartists | 0:6b68dac0d986 | 103 | do { |
embeddedartists | 0:6b68dac0d986 | 104 | // Turn off the buzzer |
embeddedartists | 0:6b68dac0d986 | 105 | _buzzer.period_ms(1); |
embeddedartists | 0:6b68dac0d986 | 106 | _buzzer = 0; |
embeddedartists | 0:6b68dac0d986 | 107 | |
embeddedartists | 0:6b68dac0d986 | 108 | // Make sure the button is configured correctly |
embeddedartists | 0:6b68dac0d986 | 109 | _button.mode(PullUp); |
embeddedartists | 0:6b68dac0d986 | 110 | |
embeddedartists | 0:6b68dac0d986 | 111 | // Turn off all LEDs |
embeddedartists | 0:6b68dac0d986 | 112 | _led1 = 1; |
embeddedartists | 0:6b68dac0d986 | 113 | _led2 = 1; |
embeddedartists | 0:6b68dac0d986 | 114 | _led3 = 0; |
embeddedartists | 0:6b68dac0d986 | 115 | _led4 = 0; |
embeddedartists | 10:1ac4b213f0f7 | 116 | |
embeddedartists | 2:887c6b45e7fa | 117 | // Make sure that the logger is always initialized even if |
embeddedartists | 2:887c6b45e7fa | 118 | // other initialization tasks fail |
embeddedartists | 2:887c6b45e7fa | 119 | _logger.init(); |
embeddedartists | 4:6fdcdf7aff8d | 120 | |
embeddedartists | 4:6fdcdf7aff8d | 121 | #if defined(DM_BOARD_ENABLE_MEASSURING_PINS) |
embeddedartists | 4:6fdcdf7aff8d | 122 | _INTERNAL_INIT_MEAS(); |
embeddedartists | 4:6fdcdf7aff8d | 123 | #endif |
embeddedartists | 2:887c6b45e7fa | 124 | |
embeddedartists | 2:887c6b45e7fa | 125 | #if defined(DM_BOARD_DISABLE_STANDARD_PRINTF) |
embeddedartists | 2:887c6b45e7fa | 126 | // Kill all ouput of calls to printf() so that there is no |
embeddedartists | 2:887c6b45e7fa | 127 | // simultaneous calls into the non-thread-safe standard libraries. |
embeddedartists | 2:887c6b45e7fa | 128 | // User code should use the RtosLogger anyway. |
embeddedartists | 2:887c6b45e7fa | 129 | freopen("/null", "w", stdout); |
embeddedartists | 2:887c6b45e7fa | 130 | #endif |
embeddedartists | 2:887c6b45e7fa | 131 | |
embeddedartists | 3:2fa7755f2cef | 132 | #if defined(DM_BOARD_USE_QSPI) || defined(DM_BOARD_USE_QSPI_FS) |
embeddedartists | 0:6b68dac0d986 | 133 | if (SPIFI::instance().init() != SPIFI::Ok) { |
embeddedartists | 0:6b68dac0d986 | 134 | err = SpifiError; |
embeddedartists | 0:6b68dac0d986 | 135 | break; |
embeddedartists | 0:6b68dac0d986 | 136 | } |
embeddedartists | 0:6b68dac0d986 | 137 | #endif |
embeddedartists | 0:6b68dac0d986 | 138 | |
embeddedartists | 0:6b68dac0d986 | 139 | #if defined(DM_BOARD_USE_DISPLAY) |
embeddedartists | 22:1a58a518435c | 140 | if (BiosDisplay::instance().init() != Display::DisplayError_Ok) { |
embeddedartists | 0:6b68dac0d986 | 141 | err = DisplayError; |
embeddedartists | 0:6b68dac0d986 | 142 | break; |
embeddedartists | 0:6b68dac0d986 | 143 | } |
embeddedartists | 0:6b68dac0d986 | 144 | #endif |
embeddedartists | 0:6b68dac0d986 | 145 | |
embeddedartists | 0:6b68dac0d986 | 146 | #if defined(DM_BOARD_USE_TOUCH) |
embeddedartists | 22:1a58a518435c | 147 | if (BiosTouch::instance().init() != TouchPanel::TouchError_Ok) { |
embeddedartists | 10:1ac4b213f0f7 | 148 | err = TouchError; |
embeddedartists | 10:1ac4b213f0f7 | 149 | break; |
embeddedartists | 10:1ac4b213f0f7 | 150 | } |
embeddedartists | 0:6b68dac0d986 | 151 | #endif |
embeddedartists | 20:9df19da50290 | 152 | |
embeddedartists | 20:9df19da50290 | 153 | #if defined(DM_BOARD_USE_REGISTRY) |
embeddedartists | 20:9df19da50290 | 154 | if (Registry::instance().load() != Registry::Ok) { |
embeddedartists | 20:9df19da50290 | 155 | err = RegistryError; |
embeddedartists | 20:9df19da50290 | 156 | break; |
embeddedartists | 20:9df19da50290 | 157 | } |
embeddedartists | 20:9df19da50290 | 158 | #endif |
embeddedartists | 0:6b68dac0d986 | 159 | _initialized = true; |
embeddedartists | 0:6b68dac0d986 | 160 | } while(0); |
embeddedartists | 0:6b68dac0d986 | 161 | } |
embeddedartists | 0:6b68dac0d986 | 162 | return err; |
embeddedartists | 0:6b68dac0d986 | 163 | } |
embeddedartists | 0:6b68dac0d986 | 164 | |
embeddedartists | 2:887c6b45e7fa | 165 | void DMBoard::setLED(Leds led, bool on) |
embeddedartists | 0:6b68dac0d986 | 166 | { |
embeddedartists | 0:6b68dac0d986 | 167 | switch(led) { |
embeddedartists | 2:887c6b45e7fa | 168 | case Led1: |
embeddedartists | 0:6b68dac0d986 | 169 | _led1 = (on ? 0 : 1); |
embeddedartists | 0:6b68dac0d986 | 170 | break; |
embeddedartists | 2:887c6b45e7fa | 171 | case Led2: |
embeddedartists | 0:6b68dac0d986 | 172 | _led2 = (on ? 0 : 1); |
embeddedartists | 0:6b68dac0d986 | 173 | break; |
embeddedartists | 2:887c6b45e7fa | 174 | case Led3: |
embeddedartists | 0:6b68dac0d986 | 175 | _led3 = (on ? 1 : 0); |
embeddedartists | 0:6b68dac0d986 | 176 | break; |
embeddedartists | 2:887c6b45e7fa | 177 | case Led4: |
embeddedartists | 0:6b68dac0d986 | 178 | _led4 = (on ? 1 : 0); |
embeddedartists | 0:6b68dac0d986 | 179 | break; |
embeddedartists | 0:6b68dac0d986 | 180 | } |
embeddedartists | 0:6b68dac0d986 | 181 | } |
embeddedartists | 0:6b68dac0d986 | 182 | |
embeddedartists | 5:c77fdb6e3438 | 183 | void DMBoard::buzzer(int frequency, int duration_ms) |
embeddedartists | 0:6b68dac0d986 | 184 | { |
embeddedartists | 5:c77fdb6e3438 | 185 | if (frequency <= 0) { |
embeddedartists | 5:c77fdb6e3438 | 186 | _buzzer = 0; |
embeddedartists | 5:c77fdb6e3438 | 187 | } else { |
embeddedartists | 5:c77fdb6e3438 | 188 | _buzzer.period_us(1000000/frequency); |
embeddedartists | 5:c77fdb6e3438 | 189 | _buzzer = 0.5; |
embeddedartists | 0:6b68dac0d986 | 190 | } |
embeddedartists | 5:c77fdb6e3438 | 191 | if (duration_ms > 0) { |
embeddedartists | 5:c77fdb6e3438 | 192 | Thread::wait(duration_ms); |
embeddedartists | 5:c77fdb6e3438 | 193 | _buzzer = 0; |
embeddedartists | 5:c77fdb6e3438 | 194 | } |
embeddedartists | 0:6b68dac0d986 | 195 | } |
embeddedartists | 0:6b68dac0d986 | 196 | |
embeddedartists | 0:6b68dac0d986 | 197 | bool DMBoard::buttonPressed() |
embeddedartists | 0:6b68dac0d986 | 198 | { |
embeddedartists | 0:6b68dac0d986 | 199 | return _button.read() == 0; |
embeddedartists | 0:6b68dac0d986 | 200 | } |
embeddedartists | 10:1ac4b213f0f7 | 201 | |
alindvall | 36:92193dc72995 | 202 | TouchPanel* DMBoard::touchPanel() |
alindvall | 36:92193dc72995 | 203 | { |
embeddedartists | 22:1a58a518435c | 204 | #if defined(DM_BOARD_USE_TOUCH) |
alindvall | 36:92193dc72995 | 205 | if (BiosTouch::instance().isTouchSupported()) { |
alindvall | 36:92193dc72995 | 206 | return &BiosTouch::instance(); |
embeddedartists | 13:2c60e28503f8 | 207 | } |
embeddedartists | 13:2c60e28503f8 | 208 | #endif |
alindvall | 36:92193dc72995 | 209 | return NULL; |
alindvall | 36:92193dc72995 | 210 | } |
embeddedartists | 13:2c60e28503f8 | 211 | |
alindvall | 36:92193dc72995 | 212 | Display* DMBoard::display() |
alindvall | 36:92193dc72995 | 213 | { |
embeddedartists | 13:2c60e28503f8 | 214 | #if defined(DM_BOARD_USE_DISPLAY) |
alindvall | 36:92193dc72995 | 215 | return &BiosDisplay::instance(); |
alindvall | 36:92193dc72995 | 216 | #else |
alindvall | 36:92193dc72995 | 217 | return NULL; |
embeddedartists | 13:2c60e28503f8 | 218 | #endif |
alindvall | 36:92193dc72995 | 219 | } |