Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DM_HttpServer DM_USBHost
Dependents: lpc4088_displaymodule_emwin lpc4088_displaymodule_demo_sphere sampleGUI sampleEmptyGUI ... more
Fork of DMSupport by
Registry.h@33:8a0a99d54bf8, 2015-02-19 (annotated)
- Committer:
- embeddedartists
- Date:
- Thu Feb 19 14:41:14 2015 +0100
- Revision:
- 33:8a0a99d54bf8
- Parent:
- 20:9df19da50290
- Child:
- 34:fc366bab393f
- Added special treatement of touch controller for multitouch
- Corrected button pin name (wrong after switching to LPC4088_DM as target
- Fixed bug in QSPIFileSystem that prevented opening the root folder
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| embeddedartists | 20:9df19da50290 | 1 | /* |
| embeddedartists | 20:9df19da50290 | 2 | * Copyright 2014 Embedded Artists AB |
| embeddedartists | 20:9df19da50290 | 3 | * |
| embeddedartists | 20:9df19da50290 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| embeddedartists | 20:9df19da50290 | 5 | * you may not use this file except in compliance with the License. |
| embeddedartists | 20:9df19da50290 | 6 | * You may obtain a copy of the License at |
| embeddedartists | 20:9df19da50290 | 7 | * |
| embeddedartists | 20:9df19da50290 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| embeddedartists | 20:9df19da50290 | 9 | * |
| embeddedartists | 20:9df19da50290 | 10 | * Unless required by applicable law or agreed to in writing, software |
| embeddedartists | 20:9df19da50290 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| embeddedartists | 20:9df19da50290 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| embeddedartists | 20:9df19da50290 | 13 | * See the License for the specific language governing permissions and |
| embeddedartists | 20:9df19da50290 | 14 | * limitations under the License. |
| embeddedartists | 20:9df19da50290 | 15 | */ |
| embeddedartists | 20:9df19da50290 | 16 | |
| embeddedartists | 20:9df19da50290 | 17 | #ifndef REGISTRY_H |
| embeddedartists | 20:9df19da50290 | 18 | #define REGISTRY_H |
| embeddedartists | 20:9df19da50290 | 19 | |
| embeddedartists | 20:9df19da50290 | 20 | #include "mbed.h" |
| embeddedartists | 20:9df19da50290 | 21 | #include "rtos.h" |
| embeddedartists | 20:9df19da50290 | 22 | #include "InternalEEPROM.h" |
| embeddedartists | 20:9df19da50290 | 23 | |
| embeddedartists | 20:9df19da50290 | 24 | /** |
| embeddedartists | 20:9df19da50290 | 25 | * Example of using the Registry class: |
| embeddedartists | 20:9df19da50290 | 26 | * |
| embeddedartists | 20:9df19da50290 | 27 | * @code |
| embeddedartists | 20:9df19da50290 | 28 | * #include "mbed.h" |
| embeddedartists | 20:9df19da50290 | 29 | * #include "DMBoard.h" |
| embeddedartists | 20:9df19da50290 | 30 | * |
| embeddedartists | 20:9df19da50290 | 31 | * int main(void) { |
| embeddedartists | 20:9df19da50290 | 32 | * DMBoard* board = &DMBoard::instance(); |
| embeddedartists | 20:9df19da50290 | 33 | * board->init(); |
| embeddedartists | 20:9df19da50290 | 34 | * ... |
| embeddedartists | 20:9df19da50290 | 35 | * board->registry() |
| embeddedartists | 20:9df19da50290 | 36 | * } |
| embeddedartists | 20:9df19da50290 | 37 | * @endcode |
| embeddedartists | 20:9df19da50290 | 38 | */ |
| embeddedartists | 20:9df19da50290 | 39 | class Registry { |
| embeddedartists | 20:9df19da50290 | 40 | public: |
| embeddedartists | 20:9df19da50290 | 41 | |
| embeddedartists | 20:9df19da50290 | 42 | enum RegistryError { |
| embeddedartists | 20:9df19da50290 | 43 | Ok = 0, |
| embeddedartists | 20:9df19da50290 | 44 | ReadOnlyError, |
| embeddedartists | 20:9df19da50290 | 45 | MemoryError, |
| embeddedartists | 20:9df19da50290 | 46 | EEPROMReadError, |
| embeddedartists | 20:9df19da50290 | 47 | EEPROMWriteError, |
| embeddedartists | 20:9df19da50290 | 48 | NoSuchKeyError, |
| embeddedartists | 20:9df19da50290 | 49 | KeyLenError, |
| embeddedartists | 20:9df19da50290 | 50 | ValueLenError, |
| embeddedartists | 20:9df19da50290 | 51 | InvalidPositionError, |
| embeddedartists | 20:9df19da50290 | 52 | RegistryFullError, |
| embeddedartists | 20:9df19da50290 | 53 | }; |
| embeddedartists | 20:9df19da50290 | 54 | |
| embeddedartists | 20:9df19da50290 | 55 | /** Get the only instance of the Registry |
| embeddedartists | 20:9df19da50290 | 56 | * |
| embeddedartists | 20:9df19da50290 | 57 | * @returns The Registry |
| embeddedartists | 20:9df19da50290 | 58 | */ |
| embeddedartists | 20:9df19da50290 | 59 | static Registry& instance() |
| embeddedartists | 20:9df19da50290 | 60 | { |
| embeddedartists | 20:9df19da50290 | 61 | static Registry singleton; |
| embeddedartists | 20:9df19da50290 | 62 | return singleton; |
| embeddedartists | 20:9df19da50290 | 63 | } |
| embeddedartists | 20:9df19da50290 | 64 | |
| embeddedartists | 20:9df19da50290 | 65 | /** Loads all (if any) values from the internal EEPROM |
| embeddedartists | 20:9df19da50290 | 66 | * |
| embeddedartists | 20:9df19da50290 | 67 | * @returns |
| embeddedartists | 20:9df19da50290 | 68 | * Ok on success |
| embeddedartists | 20:9df19da50290 | 69 | * An error code on failure |
| embeddedartists | 20:9df19da50290 | 70 | */ |
| embeddedartists | 20:9df19da50290 | 71 | RegistryError load(); |
| embeddedartists | 20:9df19da50290 | 72 | |
| embeddedartists | 20:9df19da50290 | 73 | RegistryError setValue(const char* key, const char* val); |
| embeddedartists | 20:9df19da50290 | 74 | RegistryError getValue(const char* key, char** pVal); |
| embeddedartists | 20:9df19da50290 | 75 | RegistryError entryAt(int pos, char** pKey, char** pVal); |
| embeddedartists | 20:9df19da50290 | 76 | int numEntries() { return _numEntries; } |
| embeddedartists | 20:9df19da50290 | 77 | RegistryError registerListener(); |
| embeddedartists | 20:9df19da50290 | 78 | |
| embeddedartists | 20:9df19da50290 | 79 | /** Stores the registry in the internal EEPROM |
| embeddedartists | 20:9df19da50290 | 80 | * |
| embeddedartists | 20:9df19da50290 | 81 | * @returns |
| embeddedartists | 20:9df19da50290 | 82 | * Ok on success |
| embeddedartists | 20:9df19da50290 | 83 | * An error code on failure |
| embeddedartists | 20:9df19da50290 | 84 | */ |
| embeddedartists | 20:9df19da50290 | 85 | RegistryError store(); |
| embeddedartists | 20:9df19da50290 | 86 | |
| embeddedartists | 20:9df19da50290 | 87 | |
| embeddedartists | 20:9df19da50290 | 88 | private: |
| embeddedartists | 20:9df19da50290 | 89 | enum Constants { |
| embeddedartists | 20:9df19da50290 | 90 | NumEntries = InternalEEPROM::EEPROM_NUM_PAGES, |
| embeddedartists | 20:9df19da50290 | 91 | EntryLen = 32, |
| embeddedartists | 20:9df19da50290 | 92 | EntrySize = 2*EntryLen, |
| embeddedartists | 20:9df19da50290 | 93 | }; |
| embeddedartists | 20:9df19da50290 | 94 | |
| embeddedartists | 20:9df19da50290 | 95 | typedef struct { |
| embeddedartists | 20:9df19da50290 | 96 | char key[EntryLen]; |
| embeddedartists | 20:9df19da50290 | 97 | char val[EntryLen]; |
| embeddedartists | 20:9df19da50290 | 98 | } reg_entry_t; |
| embeddedartists | 20:9df19da50290 | 99 | |
| embeddedartists | 20:9df19da50290 | 100 | uint8_t* _data; |
| embeddedartists | 20:9df19da50290 | 101 | int _numEntries; |
| embeddedartists | 20:9df19da50290 | 102 | reg_entry_t* _entries; |
| embeddedartists | 20:9df19da50290 | 103 | bool _modified[NumEntries]; |
| embeddedartists | 20:9df19da50290 | 104 | Mutex _mutex; |
| embeddedartists | 20:9df19da50290 | 105 | |
| embeddedartists | 20:9df19da50290 | 106 | explicit Registry(); |
| embeddedartists | 20:9df19da50290 | 107 | // hide copy constructor |
| embeddedartists | 20:9df19da50290 | 108 | Registry(const Registry&); |
| embeddedartists | 20:9df19da50290 | 109 | // hide assign operator |
| embeddedartists | 20:9df19da50290 | 110 | Registry& operator=(const Registry&); |
| embeddedartists | 20:9df19da50290 | 111 | ~Registry(); |
| embeddedartists | 20:9df19da50290 | 112 | |
| embeddedartists | 20:9df19da50290 | 113 | RegistryError fromEEPROM(); |
| embeddedartists | 20:9df19da50290 | 114 | RegistryError toEEPROM(); |
| embeddedartists | 20:9df19da50290 | 115 | int find(const char* key); |
| embeddedartists | 20:9df19da50290 | 116 | }; |
| embeddedartists | 20:9df19da50290 | 117 | |
| embeddedartists | 20:9df19da50290 | 118 | #endif |
