dotHR_URG

Dependencies:   FatFileSystem TextLCD mbed

Committer:
higedura
Date:
Tue Sep 29 02:00:59 2015 +0000
Revision:
2:22b200c374cd
Parent:
0:a1accf06b614
150929_URG

Who changed what in which revision?

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