Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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