t
Dependencies: DM_FATFileSystem DM_HttpServer DM_USBHost EthernetInterface USBDevice mbed-rpc mbed-rtos
Fork of DMSupport by
DMBoard.h@20:9df19da50290, 2015-01-12 (annotated)
- 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?
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 | #ifndef DMBOARD_H |
embeddedartists | 0:6b68dac0d986 | 18 | #define DMBOARD_H |
embeddedartists | 0:6b68dac0d986 | 19 | |
embeddedartists | 0:6b68dac0d986 | 20 | #include "mbed.h" |
embeddedartists | 0:6b68dac0d986 | 21 | #include "dm_board_config.h" |
embeddedartists | 2:887c6b45e7fa | 22 | #include "RtosLog.h" |
embeddedartists | 0:6b68dac0d986 | 23 | |
embeddedartists | 0:6b68dac0d986 | 24 | #if defined(DM_BOARD_USE_MCI_FS) |
embeddedartists | 0:6b68dac0d986 | 25 | #include "MCIFileSystem.h" |
embeddedartists | 0:6b68dac0d986 | 26 | #endif |
embeddedartists | 0:6b68dac0d986 | 27 | #if defined(DM_BOARD_USE_QSPI_FS) |
embeddedartists | 3:2fa7755f2cef | 28 | #include "SPIFI.h" |
embeddedartists | 0:6b68dac0d986 | 29 | #include "QSPIFileSystem.h" |
embeddedartists | 0:6b68dac0d986 | 30 | #elif defined(DM_BOARD_USE_QSPI) |
embeddedartists | 0:6b68dac0d986 | 31 | #include "SPIFI.h" |
embeddedartists | 0:6b68dac0d986 | 32 | #endif |
embeddedartists | 0:6b68dac0d986 | 33 | #if defined(DM_BOARD_USE_DISPLAY) |
embeddedartists | 0:6b68dac0d986 | 34 | #include "Display.h" |
embeddedartists | 0:6b68dac0d986 | 35 | #include "TouchPanel.h" |
embeddedartists | 0:6b68dac0d986 | 36 | #endif |
embeddedartists | 20:9df19da50290 | 37 | #if defined(DM_BOARD_USE_REGISTRY) |
embeddedartists | 20:9df19da50290 | 38 | #include "Registry.h" |
embeddedartists | 20:9df19da50290 | 39 | #endif |
embeddedartists | 20:9df19da50290 | 40 | |
embeddedartists | 0:6b68dac0d986 | 41 | |
embeddedartists | 0:6b68dac0d986 | 42 | /** |
embeddedartists | 0:6b68dac0d986 | 43 | * Example of using the Board class: |
embeddedartists | 0:6b68dac0d986 | 44 | * |
embeddedartists | 0:6b68dac0d986 | 45 | * @code |
embeddedartists | 0:6b68dac0d986 | 46 | * #include "mbed.h" |
embeddedartists | 0:6b68dac0d986 | 47 | * #include "DMBoard.h" |
embeddedartists | 0:6b68dac0d986 | 48 | * |
embeddedartists | 0:6b68dac0d986 | 49 | * int main(void) { |
embeddedartists | 0:6b68dac0d986 | 50 | * DMBoard* board = &DMBoard::instance(); |
embeddedartists | 0:6b68dac0d986 | 51 | * board->init(); |
embeddedartists | 0:6b68dac0d986 | 52 | * ... |
embeddedartists | 0:6b68dac0d986 | 53 | * board->setLed(1, true); |
embeddedartists | 0:6b68dac0d986 | 54 | * } |
embeddedartists | 0:6b68dac0d986 | 55 | * @endcode |
embeddedartists | 0:6b68dac0d986 | 56 | */ |
embeddedartists | 0:6b68dac0d986 | 57 | class DMBoard { |
embeddedartists | 0:6b68dac0d986 | 58 | public: |
embeddedartists | 2:887c6b45e7fa | 59 | enum Leds { |
embeddedartists | 2:887c6b45e7fa | 60 | Led1, |
embeddedartists | 2:887c6b45e7fa | 61 | Led2, |
embeddedartists | 2:887c6b45e7fa | 62 | Led3, |
embeddedartists | 2:887c6b45e7fa | 63 | Led4, |
embeddedartists | 0:6b68dac0d986 | 64 | }; |
embeddedartists | 0:6b68dac0d986 | 65 | |
embeddedartists | 0:6b68dac0d986 | 66 | enum BoardError { |
embeddedartists | 10:1ac4b213f0f7 | 67 | Ok = 0, |
embeddedartists | 10:1ac4b213f0f7 | 68 | MemoryError, |
embeddedartists | 10:1ac4b213f0f7 | 69 | SpifiError, |
embeddedartists | 10:1ac4b213f0f7 | 70 | DisplayError, |
embeddedartists | 10:1ac4b213f0f7 | 71 | TouchError, |
embeddedartists | 10:1ac4b213f0f7 | 72 | BiosInvalidError, |
embeddedartists | 10:1ac4b213f0f7 | 73 | BiosVersionError, |
embeddedartists | 17:4ea2509445ac | 74 | BiosStorageError, |
embeddedartists | 20:9df19da50290 | 75 | RegistryError, |
embeddedartists | 0:6b68dac0d986 | 76 | }; |
embeddedartists | 0:6b68dac0d986 | 77 | |
embeddedartists | 9:a33326afd686 | 78 | /** Get the only instance of the DMBoard |
embeddedartists | 9:a33326afd686 | 79 | * |
embeddedartists | 9:a33326afd686 | 80 | * @returns The DMBoard |
embeddedartists | 9:a33326afd686 | 81 | */ |
embeddedartists | 0:6b68dac0d986 | 82 | static DMBoard& instance() |
embeddedartists | 0:6b68dac0d986 | 83 | { |
embeddedartists | 0:6b68dac0d986 | 84 | static DMBoard singleton; |
embeddedartists | 0:6b68dac0d986 | 85 | return singleton; |
embeddedartists | 0:6b68dac0d986 | 86 | } |
embeddedartists | 0:6b68dac0d986 | 87 | |
embeddedartists | 0:6b68dac0d986 | 88 | /** Initializes the wanted features |
embeddedartists | 0:6b68dac0d986 | 89 | * |
embeddedartists | 0:6b68dac0d986 | 90 | * @returns |
embeddedartists | 0:6b68dac0d986 | 91 | * Ok on success |
embeddedartists | 0:6b68dac0d986 | 92 | * An error code on failure |
embeddedartists | 0:6b68dac0d986 | 93 | */ |
embeddedartists | 0:6b68dac0d986 | 94 | BoardError init(); |
embeddedartists | 0:6b68dac0d986 | 95 | |
embeddedartists | 9:a33326afd686 | 96 | /** Controls the four LEDs on the Display Module |
embeddedartists | 9:a33326afd686 | 97 | * |
embeddedartists | 9:a33326afd686 | 98 | * @param led One of Led1, Led2, Led3 or Led4 |
embeddedartists | 9:a33326afd686 | 99 | * @param on true to turn the LED on regardless of its polarity |
embeddedartists | 9:a33326afd686 | 100 | */ |
embeddedartists | 2:887c6b45e7fa | 101 | void setLED(Leds led, bool on); |
embeddedartists | 5:c77fdb6e3438 | 102 | |
embeddedartists | 5:c77fdb6e3438 | 103 | /** Controls the buzzer |
embeddedartists | 5:c77fdb6e3438 | 104 | * |
embeddedartists | 5:c77fdb6e3438 | 105 | * Examples: |
embeddedartists | 5:c77fdb6e3438 | 106 | * buzzer() turns it off |
embeddedartists | 5:c77fdb6e3438 | 107 | * buzzer(440) plays an A4 (440Hz) note forever |
embeddedartists | 5:c77fdb6e3438 | 108 | * buzzer(200, 25) plays a 200Hz tone for 25ms and then turns it off |
embeddedartists | 5:c77fdb6e3438 | 109 | * |
embeddedartists | 5:c77fdb6e3438 | 110 | * Note that if duration_ms is >0 this is a blocking call |
embeddedartists | 5:c77fdb6e3438 | 111 | * |
embeddedartists | 5:c77fdb6e3438 | 112 | * @param frequency the frequency of the tone (in Hz) or 0 to turn it off |
embeddedartists | 5:c77fdb6e3438 | 113 | * @param duration_ms the number of milliseconds to play or 0 for forever |
embeddedartists | 5:c77fdb6e3438 | 114 | */ |
embeddedartists | 5:c77fdb6e3438 | 115 | void buzzer(int frequency=0, int duration_ms=0); |
embeddedartists | 9:a33326afd686 | 116 | |
embeddedartists | 9:a33326afd686 | 117 | /** Test if the USER button is pressed or not |
embeddedartists | 9:a33326afd686 | 118 | * |
embeddedartists | 9:a33326afd686 | 119 | * @returns |
embeddedartists | 9:a33326afd686 | 120 | * True if the button is pressed, false if not |
embeddedartists | 9:a33326afd686 | 121 | */ |
embeddedartists | 0:6b68dac0d986 | 122 | bool buttonPressed(); |
embeddedartists | 0:6b68dac0d986 | 123 | |
embeddedartists | 10:1ac4b213f0f7 | 124 | #if defined(DM_BOARD_USE_DISPLAY) |
embeddedartists | 9:a33326afd686 | 125 | /** Returns the TouchPanel interface |
embeddedartists | 9:a33326afd686 | 126 | * |
embeddedartists | 9:a33326afd686 | 127 | * @returns |
embeddedartists | 9:a33326afd686 | 128 | * The touch panel |
embeddedartists | 9:a33326afd686 | 129 | */ |
embeddedartists | 10:1ac4b213f0f7 | 130 | TouchPanel* touchPanel(); |
embeddedartists | 10:1ac4b213f0f7 | 131 | |
embeddedartists | 9:a33326afd686 | 132 | /** Returns the Display interface |
embeddedartists | 9:a33326afd686 | 133 | * |
embeddedartists | 9:a33326afd686 | 134 | * @returns |
embeddedartists | 9:a33326afd686 | 135 | * The display |
embeddedartists | 9:a33326afd686 | 136 | */ |
embeddedartists | 10:1ac4b213f0f7 | 137 | Display* display(); |
embeddedartists | 0:6b68dac0d986 | 138 | |
embeddedartists | 10:1ac4b213f0f7 | 139 | friend class BiosDisplayAndTouch; |
embeddedartists | 0:6b68dac0d986 | 140 | #endif |
embeddedartists | 9:a33326afd686 | 141 | /** Returns the logger interface |
embeddedartists | 9:a33326afd686 | 142 | * |
embeddedartists | 9:a33326afd686 | 143 | * @returns |
embeddedartists | 9:a33326afd686 | 144 | * The logger |
embeddedartists | 9:a33326afd686 | 145 | */ |
embeddedartists | 2:887c6b45e7fa | 146 | RtosLog* logger() { return &_logger; } |
embeddedartists | 0:6b68dac0d986 | 147 | |
embeddedartists | 20:9df19da50290 | 148 | #if defined(DM_BOARD_USE_REGISTRY) |
embeddedartists | 20:9df19da50290 | 149 | /** Returns the Registry interface |
embeddedartists | 20:9df19da50290 | 150 | * |
embeddedartists | 20:9df19da50290 | 151 | * @returns |
embeddedartists | 20:9df19da50290 | 152 | * The registry |
embeddedartists | 20:9df19da50290 | 153 | */ |
embeddedartists | 20:9df19da50290 | 154 | Registry* registry() { return &Registry::instance(); } |
embeddedartists | 20:9df19da50290 | 155 | #endif |
embeddedartists | 20:9df19da50290 | 156 | |
embeddedartists | 0:6b68dac0d986 | 157 | private: |
embeddedartists | 0:6b68dac0d986 | 158 | |
embeddedartists | 0:6b68dac0d986 | 159 | bool _initialized; |
embeddedartists | 10:1ac4b213f0f7 | 160 | uint8_t* _conf; |
embeddedartists | 10:1ac4b213f0f7 | 161 | uint32_t _confSize; |
embeddedartists | 0:6b68dac0d986 | 162 | |
embeddedartists | 0:6b68dac0d986 | 163 | #if defined(DM_BOARD_USE_MCI_FS) |
embeddedartists | 0:6b68dac0d986 | 164 | MCIFileSystem _mcifs; |
embeddedartists | 0:6b68dac0d986 | 165 | #endif |
embeddedartists | 0:6b68dac0d986 | 166 | #if defined(DM_BOARD_USE_QSPI_FS) |
embeddedartists | 0:6b68dac0d986 | 167 | QSPIFileSystem _qspifs; |
embeddedartists | 0:6b68dac0d986 | 168 | #endif |
embeddedartists | 0:6b68dac0d986 | 169 | |
embeddedartists | 0:6b68dac0d986 | 170 | PwmOut _buzzer; |
embeddedartists | 0:6b68dac0d986 | 171 | DigitalIn _button; |
embeddedartists | 0:6b68dac0d986 | 172 | DigitalOut _led1; |
embeddedartists | 0:6b68dac0d986 | 173 | DigitalOut _led2; |
embeddedartists | 0:6b68dac0d986 | 174 | DigitalOut _led3; |
embeddedartists | 0:6b68dac0d986 | 175 | DigitalOut _led4; |
embeddedartists | 0:6b68dac0d986 | 176 | |
embeddedartists | 2:887c6b45e7fa | 177 | RtosLog _logger; |
embeddedartists | 2:887c6b45e7fa | 178 | |
embeddedartists | 0:6b68dac0d986 | 179 | explicit DMBoard(); |
embeddedartists | 0:6b68dac0d986 | 180 | // hide copy constructor |
embeddedartists | 0:6b68dac0d986 | 181 | DMBoard(const DMBoard&); |
embeddedartists | 0:6b68dac0d986 | 182 | // hide assign operator |
embeddedartists | 0:6b68dac0d986 | 183 | DMBoard& operator=(const DMBoard&); |
embeddedartists | 0:6b68dac0d986 | 184 | ~DMBoard(); |
embeddedartists | 0:6b68dac0d986 | 185 | |
embeddedartists | 0:6b68dac0d986 | 186 | #if defined(DM_BOARD_USE_DISPLAY) |
embeddedartists | 0:6b68dac0d986 | 187 | BoardError readDisplayConfiguration(uint8_t** data, uint32_t* size); |
embeddedartists | 0:6b68dac0d986 | 188 | #endif |
embeddedartists | 0:6b68dac0d986 | 189 | }; |
embeddedartists | 0:6b68dac0d986 | 190 | |
embeddedartists | 0:6b68dac0d986 | 191 | #endif |