I2C_EEPROM

Committer:
jhon309
Date:
Thu Aug 13 00:23:16 2015 +0000
Revision:
0:ac8863619623
I2C

Who changed what in which revision?

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