Stand-alone HMD demo system built on mbed FRDM-K64F.

Dependencies:   SDFileSystem mbed FATFileSystem

Committer:
maruishi
Date:
Tue Jul 29 11:41:59 2014 +0000
Revision:
0:9bbe50de69d8
FRDM-K64F based 3D Head-mount-display for Interface(CQ Pub)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maruishi 0:9bbe50de69d8 1 /* mbed Microcontroller Library
maruishi 0:9bbe50de69d8 2 * Copyright (c) 2006-2012 ARM Limited
maruishi 0:9bbe50de69d8 3 *
maruishi 0:9bbe50de69d8 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
maruishi 0:9bbe50de69d8 5 * of this software and associated documentation files (the "Software"), to deal
maruishi 0:9bbe50de69d8 6 * in the Software without restriction, including without limitation the rights
maruishi 0:9bbe50de69d8 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
maruishi 0:9bbe50de69d8 8 * copies of the Software, and to permit persons to whom the Software is
maruishi 0:9bbe50de69d8 9 * furnished to do so, subject to the following conditions:
maruishi 0:9bbe50de69d8 10 *
maruishi 0:9bbe50de69d8 11 * The above copyright notice and this permission notice shall be included in
maruishi 0:9bbe50de69d8 12 * all copies or substantial portions of the Software.
maruishi 0:9bbe50de69d8 13 *
maruishi 0:9bbe50de69d8 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
maruishi 0:9bbe50de69d8 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
maruishi 0:9bbe50de69d8 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
maruishi 0:9bbe50de69d8 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
maruishi 0:9bbe50de69d8 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
maruishi 0:9bbe50de69d8 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
maruishi 0:9bbe50de69d8 20 * SOFTWARE.
maruishi 0:9bbe50de69d8 21 */
maruishi 0:9bbe50de69d8 22 #include "ff.h"
maruishi 0:9bbe50de69d8 23 #include "ffconf.h"
maruishi 0:9bbe50de69d8 24 #include "mbed_debug.h"
maruishi 0:9bbe50de69d8 25
maruishi 0:9bbe50de69d8 26 #include "FATFileHandle.h"
maruishi 0:9bbe50de69d8 27
maruishi 0:9bbe50de69d8 28 FATFileHandle::FATFileHandle(FIL fh) {
maruishi 0:9bbe50de69d8 29 _fh = fh;
maruishi 0:9bbe50de69d8 30 }
maruishi 0:9bbe50de69d8 31
maruishi 0:9bbe50de69d8 32 int FATFileHandle::close() {
maruishi 0:9bbe50de69d8 33 int retval = f_close(&_fh);
maruishi 0:9bbe50de69d8 34 delete this;
maruishi 0:9bbe50de69d8 35 return retval;
maruishi 0:9bbe50de69d8 36 }
maruishi 0:9bbe50de69d8 37
maruishi 0:9bbe50de69d8 38 ssize_t FATFileHandle::write(const void* buffer, size_t length) {
maruishi 0:9bbe50de69d8 39 UINT n;
maruishi 0:9bbe50de69d8 40 FRESULT res = f_write(&_fh, buffer, length, &n);
maruishi 0:9bbe50de69d8 41 if (res) {
maruishi 0:9bbe50de69d8 42 debug_if(FFS_DBG, "f_write() failed: %d", res);
maruishi 0:9bbe50de69d8 43 return -1;
maruishi 0:9bbe50de69d8 44 }
maruishi 0:9bbe50de69d8 45 return n;
maruishi 0:9bbe50de69d8 46 }
maruishi 0:9bbe50de69d8 47
maruishi 0:9bbe50de69d8 48 ssize_t FATFileHandle::read(void* buffer, size_t length) {
maruishi 0:9bbe50de69d8 49 debug_if(FFS_DBG, "read(%d)\n", length);
maruishi 0:9bbe50de69d8 50 UINT n;
maruishi 0:9bbe50de69d8 51 FRESULT res = f_read(&_fh, buffer, length, &n);
maruishi 0:9bbe50de69d8 52 if (res) {
maruishi 0:9bbe50de69d8 53 debug_if(FFS_DBG, "f_read() failed: %d\n", res);
maruishi 0:9bbe50de69d8 54 return -1;
maruishi 0:9bbe50de69d8 55 }
maruishi 0:9bbe50de69d8 56 return n;
maruishi 0:9bbe50de69d8 57 }
maruishi 0:9bbe50de69d8 58
maruishi 0:9bbe50de69d8 59 int FATFileHandle::isatty() {
maruishi 0:9bbe50de69d8 60 return 0;
maruishi 0:9bbe50de69d8 61 }
maruishi 0:9bbe50de69d8 62
maruishi 0:9bbe50de69d8 63 off_t FATFileHandle::lseek(off_t position, int whence) {
maruishi 0:9bbe50de69d8 64 if (whence == SEEK_END) {
maruishi 0:9bbe50de69d8 65 position += _fh.fsize;
maruishi 0:9bbe50de69d8 66 } else if(whence==SEEK_CUR) {
maruishi 0:9bbe50de69d8 67 position += _fh.fptr;
maruishi 0:9bbe50de69d8 68 }
maruishi 0:9bbe50de69d8 69 FRESULT res = f_lseek(&_fh, position);
maruishi 0:9bbe50de69d8 70 if (res) {
maruishi 0:9bbe50de69d8 71 debug_if(FFS_DBG, "lseek failed: %d\n", res);
maruishi 0:9bbe50de69d8 72 return -1;
maruishi 0:9bbe50de69d8 73 } else {
maruishi 0:9bbe50de69d8 74 debug_if(FFS_DBG, "lseek OK, returning %i\n", _fh.fptr);
maruishi 0:9bbe50de69d8 75 return _fh.fptr;
maruishi 0:9bbe50de69d8 76 }
maruishi 0:9bbe50de69d8 77 }
maruishi 0:9bbe50de69d8 78
maruishi 0:9bbe50de69d8 79 int FATFileHandle::fsync() {
maruishi 0:9bbe50de69d8 80 FRESULT res = f_sync(&_fh);
maruishi 0:9bbe50de69d8 81 if (res) {
maruishi 0:9bbe50de69d8 82 debug_if(FFS_DBG, "f_sync() failed: %d\n", res);
maruishi 0:9bbe50de69d8 83 return -1;
maruishi 0:9bbe50de69d8 84 }
maruishi 0:9bbe50de69d8 85 return 0;
maruishi 0:9bbe50de69d8 86 }
maruishi 0:9bbe50de69d8 87
maruishi 0:9bbe50de69d8 88 off_t FATFileHandle::flen() {
maruishi 0:9bbe50de69d8 89 return _fh.fsize;
maruishi 0:9bbe50de69d8 90 }