5.2.1 - Updated I2C files
Dependents: mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510
drivers/FileHandle.h@1:f30bdcd2b33b, 2017-02-27 (annotated)
- Committer:
- jacobjohnson
- Date:
- Mon Feb 27 17:45:05 2017 +0000
- Revision:
- 1:f30bdcd2b33b
- Parent:
- 0:098463de4c5d
changed the inputscale from 1 to 7 in analogin_api.c. This will need to be changed later, and accessed from the main level, but for now this allows the adc to read a value from 0 to 3.7V, instead of just up to 1V.;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
group-onsemi | 0:098463de4c5d | 1 | /* mbed Microcontroller Library |
group-onsemi | 0:098463de4c5d | 2 | * Copyright (c) 2006-2013 ARM Limited |
group-onsemi | 0:098463de4c5d | 3 | * |
group-onsemi | 0:098463de4c5d | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
group-onsemi | 0:098463de4c5d | 5 | * you may not use this file except in compliance with the License. |
group-onsemi | 0:098463de4c5d | 6 | * You may obtain a copy of the License at |
group-onsemi | 0:098463de4c5d | 7 | * |
group-onsemi | 0:098463de4c5d | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
group-onsemi | 0:098463de4c5d | 9 | * |
group-onsemi | 0:098463de4c5d | 10 | * Unless required by applicable law or agreed to in writing, software |
group-onsemi | 0:098463de4c5d | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
group-onsemi | 0:098463de4c5d | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
group-onsemi | 0:098463de4c5d | 13 | * See the License for the specific language governing permissions and |
group-onsemi | 0:098463de4c5d | 14 | * limitations under the License. |
group-onsemi | 0:098463de4c5d | 15 | */ |
group-onsemi | 0:098463de4c5d | 16 | #ifndef MBED_FILEHANDLE_H |
group-onsemi | 0:098463de4c5d | 17 | #define MBED_FILEHANDLE_H |
group-onsemi | 0:098463de4c5d | 18 | |
group-onsemi | 0:098463de4c5d | 19 | typedef int FILEHANDLE; |
group-onsemi | 0:098463de4c5d | 20 | |
group-onsemi | 0:098463de4c5d | 21 | #include <stdio.h> |
group-onsemi | 0:098463de4c5d | 22 | |
group-onsemi | 0:098463de4c5d | 23 | #if defined(__ARMCC_VERSION) || defined(__ICCARM__) |
group-onsemi | 0:098463de4c5d | 24 | typedef int ssize_t; |
group-onsemi | 0:098463de4c5d | 25 | typedef long off_t; |
group-onsemi | 0:098463de4c5d | 26 | |
group-onsemi | 0:098463de4c5d | 27 | #else |
group-onsemi | 0:098463de4c5d | 28 | # include <sys/types.h> |
group-onsemi | 0:098463de4c5d | 29 | #endif |
group-onsemi | 0:098463de4c5d | 30 | |
group-onsemi | 0:098463de4c5d | 31 | namespace mbed { |
group-onsemi | 0:098463de4c5d | 32 | /** \addtogroup drivers */ |
group-onsemi | 0:098463de4c5d | 33 | /** @{*/ |
group-onsemi | 0:098463de4c5d | 34 | |
group-onsemi | 0:098463de4c5d | 35 | /** An OO equivalent of the internal FILEHANDLE variable |
group-onsemi | 0:098463de4c5d | 36 | * and associated _sys_* functions. |
group-onsemi | 0:098463de4c5d | 37 | * |
group-onsemi | 0:098463de4c5d | 38 | * FileHandle is an abstract class, needing at least sys_write and |
group-onsemi | 0:098463de4c5d | 39 | * sys_read to be implmented for a simple interactive device. |
group-onsemi | 0:098463de4c5d | 40 | * |
group-onsemi | 0:098463de4c5d | 41 | * No one ever directly tals to/instanciates a FileHandle - it gets |
group-onsemi | 0:098463de4c5d | 42 | * created by FileSystem, and wrapped up by stdio. |
group-onsemi | 0:098463de4c5d | 43 | * |
group-onsemi | 0:098463de4c5d | 44 | * @Note Synchronization level: Set by subclass |
group-onsemi | 0:098463de4c5d | 45 | */ |
group-onsemi | 0:098463de4c5d | 46 | class FileHandle { |
group-onsemi | 0:098463de4c5d | 47 | |
group-onsemi | 0:098463de4c5d | 48 | public: |
group-onsemi | 0:098463de4c5d | 49 | /** Write the contents of a buffer to the file |
group-onsemi | 0:098463de4c5d | 50 | * |
group-onsemi | 0:098463de4c5d | 51 | * @param buffer the buffer to write from |
group-onsemi | 0:098463de4c5d | 52 | * @param length the number of characters to write |
group-onsemi | 0:098463de4c5d | 53 | * |
group-onsemi | 0:098463de4c5d | 54 | * @returns |
group-onsemi | 0:098463de4c5d | 55 | * The number of characters written (possibly 0) on success, -1 on error. |
group-onsemi | 0:098463de4c5d | 56 | */ |
group-onsemi | 0:098463de4c5d | 57 | virtual ssize_t write(const void* buffer, size_t length) = 0; |
group-onsemi | 0:098463de4c5d | 58 | |
group-onsemi | 0:098463de4c5d | 59 | /** Close the file |
group-onsemi | 0:098463de4c5d | 60 | * |
group-onsemi | 0:098463de4c5d | 61 | * @returns |
group-onsemi | 0:098463de4c5d | 62 | * Zero on success, -1 on error. |
group-onsemi | 0:098463de4c5d | 63 | */ |
group-onsemi | 0:098463de4c5d | 64 | virtual int close() = 0; |
group-onsemi | 0:098463de4c5d | 65 | |
group-onsemi | 0:098463de4c5d | 66 | /** Function read |
group-onsemi | 0:098463de4c5d | 67 | * Reads the contents of the file into a buffer |
group-onsemi | 0:098463de4c5d | 68 | * |
group-onsemi | 0:098463de4c5d | 69 | * @param buffer the buffer to read in to |
group-onsemi | 0:098463de4c5d | 70 | * @param length the number of characters to read |
group-onsemi | 0:098463de4c5d | 71 | * |
group-onsemi | 0:098463de4c5d | 72 | * @returns |
group-onsemi | 0:098463de4c5d | 73 | * The number of characters read (zero at end of file) on success, -1 on error. |
group-onsemi | 0:098463de4c5d | 74 | */ |
group-onsemi | 0:098463de4c5d | 75 | virtual ssize_t read(void* buffer, size_t length) = 0; |
group-onsemi | 0:098463de4c5d | 76 | |
group-onsemi | 0:098463de4c5d | 77 | /** Check if the handle is for a interactive terminal device. |
group-onsemi | 0:098463de4c5d | 78 | * If so, line buffered behaviour is used by default |
group-onsemi | 0:098463de4c5d | 79 | * |
group-onsemi | 0:098463de4c5d | 80 | * @returns |
group-onsemi | 0:098463de4c5d | 81 | * 1 if it is a terminal, |
group-onsemi | 0:098463de4c5d | 82 | * 0 otherwise |
group-onsemi | 0:098463de4c5d | 83 | */ |
group-onsemi | 0:098463de4c5d | 84 | virtual int isatty() = 0; |
group-onsemi | 0:098463de4c5d | 85 | |
group-onsemi | 0:098463de4c5d | 86 | /** Move the file position to a given offset from a given location. |
group-onsemi | 0:098463de4c5d | 87 | * |
group-onsemi | 0:098463de4c5d | 88 | * @param offset The offset from whence to move to |
group-onsemi | 0:098463de4c5d | 89 | * @param whence SEEK_SET for the start of the file, SEEK_CUR for the |
group-onsemi | 0:098463de4c5d | 90 | * current file position, or SEEK_END for the end of the file. |
group-onsemi | 0:098463de4c5d | 91 | * |
group-onsemi | 0:098463de4c5d | 92 | * @returns |
group-onsemi | 0:098463de4c5d | 93 | * new file position on success, |
group-onsemi | 0:098463de4c5d | 94 | * -1 on failure or unsupported |
group-onsemi | 0:098463de4c5d | 95 | */ |
group-onsemi | 0:098463de4c5d | 96 | virtual off_t lseek(off_t offset, int whence) = 0; |
group-onsemi | 0:098463de4c5d | 97 | |
group-onsemi | 0:098463de4c5d | 98 | /** Flush any buffers associated with the FileHandle, ensuring it |
group-onsemi | 0:098463de4c5d | 99 | * is up to date on disk |
group-onsemi | 0:098463de4c5d | 100 | * |
group-onsemi | 0:098463de4c5d | 101 | * @returns |
group-onsemi | 0:098463de4c5d | 102 | * 0 on success or un-needed, |
group-onsemi | 0:098463de4c5d | 103 | * -1 on error |
group-onsemi | 0:098463de4c5d | 104 | */ |
group-onsemi | 0:098463de4c5d | 105 | virtual int fsync() = 0; |
group-onsemi | 0:098463de4c5d | 106 | |
group-onsemi | 0:098463de4c5d | 107 | virtual off_t flen() { |
group-onsemi | 0:098463de4c5d | 108 | lock(); |
group-onsemi | 0:098463de4c5d | 109 | /* remember our current position */ |
group-onsemi | 0:098463de4c5d | 110 | off_t pos = lseek(0, SEEK_CUR); |
group-onsemi | 0:098463de4c5d | 111 | if(pos == -1) { |
group-onsemi | 0:098463de4c5d | 112 | unlock(); |
group-onsemi | 0:098463de4c5d | 113 | return -1; |
group-onsemi | 0:098463de4c5d | 114 | } |
group-onsemi | 0:098463de4c5d | 115 | /* seek to the end to get the file length */ |
group-onsemi | 0:098463de4c5d | 116 | off_t res = lseek(0, SEEK_END); |
group-onsemi | 0:098463de4c5d | 117 | /* return to our old position */ |
group-onsemi | 0:098463de4c5d | 118 | lseek(pos, SEEK_SET); |
group-onsemi | 0:098463de4c5d | 119 | unlock(); |
group-onsemi | 0:098463de4c5d | 120 | return res; |
group-onsemi | 0:098463de4c5d | 121 | } |
group-onsemi | 0:098463de4c5d | 122 | |
group-onsemi | 0:098463de4c5d | 123 | virtual ~FileHandle(); |
group-onsemi | 0:098463de4c5d | 124 | |
group-onsemi | 0:098463de4c5d | 125 | protected: |
group-onsemi | 0:098463de4c5d | 126 | |
group-onsemi | 0:098463de4c5d | 127 | /** Acquire exclusive access to this object. |
group-onsemi | 0:098463de4c5d | 128 | */ |
group-onsemi | 0:098463de4c5d | 129 | virtual void lock() { |
group-onsemi | 0:098463de4c5d | 130 | // Stub |
group-onsemi | 0:098463de4c5d | 131 | } |
group-onsemi | 0:098463de4c5d | 132 | |
group-onsemi | 0:098463de4c5d | 133 | /** Release exclusive access to this object. |
group-onsemi | 0:098463de4c5d | 134 | */ |
group-onsemi | 0:098463de4c5d | 135 | virtual void unlock() { |
group-onsemi | 0:098463de4c5d | 136 | // Stub |
group-onsemi | 0:098463de4c5d | 137 | } |
group-onsemi | 0:098463de4c5d | 138 | }; |
group-onsemi | 0:098463de4c5d | 139 | |
group-onsemi | 0:098463de4c5d | 140 | } // namespace mbed |
group-onsemi | 0:098463de4c5d | 141 | |
group-onsemi | 0:098463de4c5d | 142 | #endif |
group-onsemi | 0:098463de4c5d | 143 | |
group-onsemi | 0:098463de4c5d | 144 | /** @}*/ |