assignment_2_herpe

Dependencies:   mbed WattBob_TextLCD MCP23017

Committer:
xherpe
Date:
Thu Mar 08 16:32:35 2012 +0000
Revision:
0:aaddc17011a9

        

Who changed what in which revision?

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