dd

Dependencies:   C12832 LM75B mbed

Committer:
pfe
Date:
Tue Apr 21 10:16:20 2015 +0000
Revision:
0:05a20e3e3179
dd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pfe 0:05a20e3e3179 1 /* mbed SDFileSystem Library, for providing file access to SD cards
pfe 0:05a20e3e3179 2 * Copyright (c) 2008-2010, sford
pfe 0:05a20e3e3179 3 *
pfe 0:05a20e3e3179 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
pfe 0:05a20e3e3179 5 * of this software and associated documentation files (the "Software"), to deal
pfe 0:05a20e3e3179 6 * in the Software without restriction, including without limitation the rights
pfe 0:05a20e3e3179 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
pfe 0:05a20e3e3179 8 * copies of the Software, and to permit persons to whom the Software is
pfe 0:05a20e3e3179 9 * furnished to do so, subject to the following conditions:
pfe 0:05a20e3e3179 10 *
pfe 0:05a20e3e3179 11 * The above copyright notice and this permission notice shall be included in
pfe 0:05a20e3e3179 12 * all copies or substantial portions of the Software.
pfe 0:05a20e3e3179 13 *
pfe 0:05a20e3e3179 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
pfe 0:05a20e3e3179 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
pfe 0:05a20e3e3179 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
pfe 0:05a20e3e3179 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
pfe 0:05a20e3e3179 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
pfe 0:05a20e3e3179 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
pfe 0:05a20e3e3179 20 * THE SOFTWARE.
pfe 0:05a20e3e3179 21 */
pfe 0:05a20e3e3179 22
pfe 0:05a20e3e3179 23 #ifndef MBED_SDFILESYSTEM_H
pfe 0:05a20e3e3179 24 #define MBED_SDFILESYSTEM_H
pfe 0:05a20e3e3179 25
pfe 0:05a20e3e3179 26 #include "mbed.h"
pfe 0:05a20e3e3179 27 #include "FATFileSystem.h"
pfe 0:05a20e3e3179 28
pfe 0:05a20e3e3179 29 /** Access the filesystem on an SD Card using SPI
pfe 0:05a20e3e3179 30 *
pfe 0:05a20e3e3179 31 * @code
pfe 0:05a20e3e3179 32 * #include "mbed.h"
pfe 0:05a20e3e3179 33 * #include "SDFileSystem.h"
pfe 0:05a20e3e3179 34 *
pfe 0:05a20e3e3179 35 * SDFileSystem sd(p5, p6, p7, p12, "sd"); // mosi, miso, sclk, cs
pfe 0:05a20e3e3179 36 *
pfe 0:05a20e3e3179 37 * int main() {
pfe 0:05a20e3e3179 38 * FILE *fp = fopen("/sd/myfile.txt", "w");
pfe 0:05a20e3e3179 39 * fprintf(fp, "Hello World!\n");
pfe 0:05a20e3e3179 40 * fclose(fp);
pfe 0:05a20e3e3179 41 * }
pfe 0:05a20e3e3179 42 */
pfe 0:05a20e3e3179 43 class SDFileSystem : public FATFileSystem {
pfe 0:05a20e3e3179 44 public:
pfe 0:05a20e3e3179 45
pfe 0:05a20e3e3179 46 /** Create the File System for accessing an SD Card using SPI
pfe 0:05a20e3e3179 47 *
pfe 0:05a20e3e3179 48 * @param mosi SPI mosi pin connected to SD Card
pfe 0:05a20e3e3179 49 * @param miso SPI miso pin conencted to SD Card
pfe 0:05a20e3e3179 50 * @param sclk SPI sclk pin connected to SD Card
pfe 0:05a20e3e3179 51 * @param cs DigitalOut pin used as SD Card chip select
pfe 0:05a20e3e3179 52 * @param name The name used to access the virtual filesystem
pfe 0:05a20e3e3179 53 */
pfe 0:05a20e3e3179 54 SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name);
pfe 0:05a20e3e3179 55 virtual int disk_initialize();
pfe 0:05a20e3e3179 56 virtual int disk_write(const char *buffer, int block_number);
pfe 0:05a20e3e3179 57 virtual int disk_read(char *buffer, int block_number);
pfe 0:05a20e3e3179 58 virtual int disk_status();
pfe 0:05a20e3e3179 59 virtual int disk_sync();
pfe 0:05a20e3e3179 60 virtual int disk_sectors();
pfe 0:05a20e3e3179 61
pfe 0:05a20e3e3179 62 protected:
pfe 0:05a20e3e3179 63
pfe 0:05a20e3e3179 64 int _cmd(int cmd, int arg);
pfe 0:05a20e3e3179 65 int _cmdx(int cmd, int arg);
pfe 0:05a20e3e3179 66 int _cmd8();
pfe 0:05a20e3e3179 67 int _cmd58();
pfe 0:05a20e3e3179 68 int initialise_card();
pfe 0:05a20e3e3179 69 int initialise_card_v1();
pfe 0:05a20e3e3179 70 int initialise_card_v2();
pfe 0:05a20e3e3179 71
pfe 0:05a20e3e3179 72 int _read(char *buffer, int length);
pfe 0:05a20e3e3179 73 int _write(const char *buffer, int length);
pfe 0:05a20e3e3179 74 int _sd_sectors();
pfe 0:05a20e3e3179 75 int _sectors;
pfe 0:05a20e3e3179 76
pfe 0:05a20e3e3179 77 SPI _spi;
pfe 0:05a20e3e3179 78 DigitalOut _cs;
pfe 0:05a20e3e3179 79 };
pfe 0:05a20e3e3179 80
pfe 0:05a20e3e3179 81 #endif