Example for reading and writing SD card using SPI mode. SD カード書き込み,読み出しの例 インターフェース:SPI モード使用

Dependencies:   mbed

Committer:
MikamiUitOpen
Date:
Sun Nov 13 11:37:35 2016 +0000
Revision:
0:08b4a59451e5
1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikamiUitOpen 0:08b4a59451e5 1 /* mbed Microcontroller Library
MikamiUitOpen 0:08b4a59451e5 2 * Copyright (c) 2006-2012 ARM Limited
MikamiUitOpen 0:08b4a59451e5 3 *
MikamiUitOpen 0:08b4a59451e5 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
MikamiUitOpen 0:08b4a59451e5 5 * of this software and associated documentation files (the "Software"), to deal
MikamiUitOpen 0:08b4a59451e5 6 * in the Software without restriction, including without limitation the rights
MikamiUitOpen 0:08b4a59451e5 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
MikamiUitOpen 0:08b4a59451e5 8 * copies of the Software, and to permit persons to whom the Software is
MikamiUitOpen 0:08b4a59451e5 9 * furnished to do so, subject to the following conditions:
MikamiUitOpen 0:08b4a59451e5 10 *
MikamiUitOpen 0:08b4a59451e5 11 * The above copyright notice and this permission notice shall be included in
MikamiUitOpen 0:08b4a59451e5 12 * all copies or substantial portions of the Software.
MikamiUitOpen 0:08b4a59451e5 13 *
MikamiUitOpen 0:08b4a59451e5 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
MikamiUitOpen 0:08b4a59451e5 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
MikamiUitOpen 0:08b4a59451e5 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
MikamiUitOpen 0:08b4a59451e5 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
MikamiUitOpen 0:08b4a59451e5 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
MikamiUitOpen 0:08b4a59451e5 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
MikamiUitOpen 0:08b4a59451e5 20 * SOFTWARE.
MikamiUitOpen 0:08b4a59451e5 21 */
MikamiUitOpen 0:08b4a59451e5 22 #ifndef MBED_FATFILESYSTEM_H
MikamiUitOpen 0:08b4a59451e5 23 #define MBED_FATFILESYSTEM_H
MikamiUitOpen 0:08b4a59451e5 24
MikamiUitOpen 0:08b4a59451e5 25 #include "FileSystemLike.h"
MikamiUitOpen 0:08b4a59451e5 26 #include "FileHandle.h"
MikamiUitOpen 0:08b4a59451e5 27 #include "ff.h"
MikamiUitOpen 0:08b4a59451e5 28 #include <stdint.h>
MikamiUitOpen 0:08b4a59451e5 29
MikamiUitOpen 0:08b4a59451e5 30 using namespace mbed;
MikamiUitOpen 0:08b4a59451e5 31
MikamiUitOpen 0:08b4a59451e5 32 /**
MikamiUitOpen 0:08b4a59451e5 33 * FATFileSystem based on ChaN's Fat Filesystem library v0.8
MikamiUitOpen 0:08b4a59451e5 34 */
MikamiUitOpen 0:08b4a59451e5 35 class FATFileSystem : public FileSystemLike {
MikamiUitOpen 0:08b4a59451e5 36 public:
MikamiUitOpen 0:08b4a59451e5 37
MikamiUitOpen 0:08b4a59451e5 38 FATFileSystem(const char* n);
MikamiUitOpen 0:08b4a59451e5 39 virtual ~FATFileSystem();
MikamiUitOpen 0:08b4a59451e5 40
MikamiUitOpen 0:08b4a59451e5 41 static FATFileSystem * _ffs[_VOLUMES]; // FATFileSystem objects, as parallel to FatFs drives array
MikamiUitOpen 0:08b4a59451e5 42 FATFS _fs; // Work area (file system object) for logical drive
MikamiUitOpen 0:08b4a59451e5 43 int _fsid;
MikamiUitOpen 0:08b4a59451e5 44
MikamiUitOpen 0:08b4a59451e5 45 /**
MikamiUitOpen 0:08b4a59451e5 46 * Opens a file on the filesystem
MikamiUitOpen 0:08b4a59451e5 47 */
MikamiUitOpen 0:08b4a59451e5 48 virtual FileHandle *open(const char* name, int flags);
MikamiUitOpen 0:08b4a59451e5 49
MikamiUitOpen 0:08b4a59451e5 50 /**
MikamiUitOpen 0:08b4a59451e5 51 * Removes a file path
MikamiUitOpen 0:08b4a59451e5 52 */
MikamiUitOpen 0:08b4a59451e5 53 virtual int remove(const char *filename);
MikamiUitOpen 0:08b4a59451e5 54
MikamiUitOpen 0:08b4a59451e5 55 /**
MikamiUitOpen 0:08b4a59451e5 56 * Formats a logical drive, FDISK artitioning rule, 512 bytes per cluster
MikamiUitOpen 0:08b4a59451e5 57 */
MikamiUitOpen 0:08b4a59451e5 58 virtual int format();
MikamiUitOpen 0:08b4a59451e5 59
MikamiUitOpen 0:08b4a59451e5 60 /**
MikamiUitOpen 0:08b4a59451e5 61 * Opens a directory on the filesystem
MikamiUitOpen 0:08b4a59451e5 62 */
MikamiUitOpen 0:08b4a59451e5 63 virtual DirHandle *opendir(const char *name);
MikamiUitOpen 0:08b4a59451e5 64
MikamiUitOpen 0:08b4a59451e5 65 /**
MikamiUitOpen 0:08b4a59451e5 66 * Creates a directory path
MikamiUitOpen 0:08b4a59451e5 67 */
MikamiUitOpen 0:08b4a59451e5 68 virtual int mkdir(const char *name, mode_t mode);
MikamiUitOpen 0:08b4a59451e5 69
MikamiUitOpen 0:08b4a59451e5 70 virtual int disk_initialize() { return 0; }
MikamiUitOpen 0:08b4a59451e5 71 virtual int disk_status() { return 0; }
MikamiUitOpen 0:08b4a59451e5 72 virtual int disk_read(uint8_t * buffer, uint64_t sector) = 0;
MikamiUitOpen 0:08b4a59451e5 73 virtual int disk_write(const uint8_t * buffer, uint64_t sector) = 0;
MikamiUitOpen 0:08b4a59451e5 74 virtual int disk_sync() { return 0; }
MikamiUitOpen 0:08b4a59451e5 75 virtual uint64_t disk_sectors() = 0;
MikamiUitOpen 0:08b4a59451e5 76
MikamiUitOpen 0:08b4a59451e5 77 };
MikamiUitOpen 0:08b4a59451e5 78
MikamiUitOpen 0:08b4a59451e5 79 #endif