Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bryantaylor 0:eafc3fd41f75 1 /* mbed Microcontroller Library
bryantaylor 0:eafc3fd41f75 2 * Copyright (c) 2006-2013 ARM Limited
bryantaylor 0:eafc3fd41f75 3 *
bryantaylor 0:eafc3fd41f75 4 * Licensed under the Apache License, Version 2.0 (the "License");
bryantaylor 0:eafc3fd41f75 5 * you may not use this file except in compliance with the License.
bryantaylor 0:eafc3fd41f75 6 * You may obtain a copy of the License at
bryantaylor 0:eafc3fd41f75 7 *
bryantaylor 0:eafc3fd41f75 8 * http://www.apache.org/licenses/LICENSE-2.0
bryantaylor 0:eafc3fd41f75 9 *
bryantaylor 0:eafc3fd41f75 10 * Unless required by applicable law or agreed to in writing, software
bryantaylor 0:eafc3fd41f75 11 * distributed under the License is distributed on an "AS IS" BASIS,
bryantaylor 0:eafc3fd41f75 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
bryantaylor 0:eafc3fd41f75 13 * See the License for the specific language governing permissions and
bryantaylor 0:eafc3fd41f75 14 * limitations under the License.
bryantaylor 0:eafc3fd41f75 15 */
bryantaylor 0:eafc3fd41f75 16 #ifndef MBED_LOCALFILESYSTEM_H
bryantaylor 0:eafc3fd41f75 17 #define MBED_LOCALFILESYSTEM_H
bryantaylor 0:eafc3fd41f75 18
bryantaylor 0:eafc3fd41f75 19 #include "platform.h"
bryantaylor 0:eafc3fd41f75 20
bryantaylor 0:eafc3fd41f75 21 #if DEVICE_LOCALFILESYSTEM
bryantaylor 0:eafc3fd41f75 22
bryantaylor 0:eafc3fd41f75 23 #include "FileSystemLike.h"
bryantaylor 0:eafc3fd41f75 24 #include "PlatformMutex.h"
bryantaylor 0:eafc3fd41f75 25
bryantaylor 0:eafc3fd41f75 26 namespace mbed {
bryantaylor 0:eafc3fd41f75 27
bryantaylor 0:eafc3fd41f75 28 FILEHANDLE local_file_open(const char* name, int flags);
bryantaylor 0:eafc3fd41f75 29
bryantaylor 0:eafc3fd41f75 30 class LocalFileHandle : public FileHandle {
bryantaylor 0:eafc3fd41f75 31
bryantaylor 0:eafc3fd41f75 32 public:
bryantaylor 0:eafc3fd41f75 33 LocalFileHandle(FILEHANDLE fh);
bryantaylor 0:eafc3fd41f75 34
bryantaylor 0:eafc3fd41f75 35 virtual int close();
bryantaylor 0:eafc3fd41f75 36
bryantaylor 0:eafc3fd41f75 37 virtual ssize_t write(const void *buffer, size_t length);
bryantaylor 0:eafc3fd41f75 38
bryantaylor 0:eafc3fd41f75 39 virtual ssize_t read(void *buffer, size_t length);
bryantaylor 0:eafc3fd41f75 40
bryantaylor 0:eafc3fd41f75 41 virtual int isatty();
bryantaylor 0:eafc3fd41f75 42
bryantaylor 0:eafc3fd41f75 43 virtual off_t lseek(off_t position, int whence);
bryantaylor 0:eafc3fd41f75 44
bryantaylor 0:eafc3fd41f75 45 virtual int fsync();
bryantaylor 0:eafc3fd41f75 46
bryantaylor 0:eafc3fd41f75 47 virtual off_t flen();
bryantaylor 0:eafc3fd41f75 48
bryantaylor 0:eafc3fd41f75 49 protected:
bryantaylor 0:eafc3fd41f75 50 virtual void lock();
bryantaylor 0:eafc3fd41f75 51 virtual void unlock();
bryantaylor 0:eafc3fd41f75 52 FILEHANDLE _fh;
bryantaylor 0:eafc3fd41f75 53 int pos;
bryantaylor 0:eafc3fd41f75 54 PlatformMutex _mutex;
bryantaylor 0:eafc3fd41f75 55 };
bryantaylor 0:eafc3fd41f75 56
bryantaylor 0:eafc3fd41f75 57 /** A filesystem for accessing the local mbed Microcontroller USB disk drive
bryantaylor 0:eafc3fd41f75 58 *
bryantaylor 0:eafc3fd41f75 59 * This allows programs to read and write files on the same disk drive that is used to program the
bryantaylor 0:eafc3fd41f75 60 * mbed Microcontroller. Once created, the standard C file access functions are used to open,
bryantaylor 0:eafc3fd41f75 61 * read and write files.
bryantaylor 0:eafc3fd41f75 62 *
bryantaylor 0:eafc3fd41f75 63 * @Note Synchronization level: Thread safe
bryantaylor 0:eafc3fd41f75 64 *
bryantaylor 0:eafc3fd41f75 65 * Example:
bryantaylor 0:eafc3fd41f75 66 * @code
bryantaylor 0:eafc3fd41f75 67 * #include "mbed.h"
bryantaylor 0:eafc3fd41f75 68 *
bryantaylor 0:eafc3fd41f75 69 * LocalFileSystem local("local"); // Create the local filesystem under the name "local"
bryantaylor 0:eafc3fd41f75 70 *
bryantaylor 0:eafc3fd41f75 71 * int main() {
bryantaylor 0:eafc3fd41f75 72 * FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
bryantaylor 0:eafc3fd41f75 73 * fprintf(fp, "Hello World!");
bryantaylor 0:eafc3fd41f75 74 * fclose(fp);
bryantaylor 0:eafc3fd41f75 75 * remove("/local/out.txt"); // Removes the file "out.txt" from the local file system
bryantaylor 0:eafc3fd41f75 76 *
bryantaylor 0:eafc3fd41f75 77 * DIR *d = opendir("/local"); // Opens the root directory of the local file system
bryantaylor 0:eafc3fd41f75 78 * struct dirent *p;
bryantaylor 0:eafc3fd41f75 79 * while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system
bryantaylor 0:eafc3fd41f75 80 * printf("%s\n", p->d_name); // to stdout.
bryantaylor 0:eafc3fd41f75 81 * }
bryantaylor 0:eafc3fd41f75 82 * closedir(d);
bryantaylor 0:eafc3fd41f75 83 * }
bryantaylor 0:eafc3fd41f75 84 * @endcode
bryantaylor 0:eafc3fd41f75 85 *
bryantaylor 0:eafc3fd41f75 86 * @note
bryantaylor 0:eafc3fd41f75 87 * If the microcontroller program makes an access to the local drive, it will be marked as "removed"
bryantaylor 0:eafc3fd41f75 88 * on the Host computer. This means it is no longer accessible from the Host Computer.
bryantaylor 0:eafc3fd41f75 89 *
bryantaylor 0:eafc3fd41f75 90 * The drive will only re-appear when the microcontroller program exists. Note that if the program does
bryantaylor 0:eafc3fd41f75 91 * not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again!
bryantaylor 0:eafc3fd41f75 92 */
bryantaylor 0:eafc3fd41f75 93 class LocalFileSystem : public FileSystemLike {
bryantaylor 0:eafc3fd41f75 94 // No modifiable state
bryantaylor 0:eafc3fd41f75 95
bryantaylor 0:eafc3fd41f75 96 public:
bryantaylor 0:eafc3fd41f75 97 LocalFileSystem(const char* n) : FileSystemLike(n) {
bryantaylor 0:eafc3fd41f75 98
bryantaylor 0:eafc3fd41f75 99 }
bryantaylor 0:eafc3fd41f75 100
bryantaylor 0:eafc3fd41f75 101 virtual FileHandle *open(const char* name, int flags);
bryantaylor 0:eafc3fd41f75 102 virtual int remove(const char *filename);
bryantaylor 0:eafc3fd41f75 103 virtual DirHandle *opendir(const char *name);
bryantaylor 0:eafc3fd41f75 104 };
bryantaylor 0:eafc3fd41f75 105
bryantaylor 0:eafc3fd41f75 106 } // namespace mbed
bryantaylor 0:eafc3fd41f75 107
bryantaylor 0:eafc3fd41f75 108 #endif
bryantaylor 0:eafc3fd41f75 109
bryantaylor 0:eafc3fd41f75 110 #endif