test

Dependencies:   Nanopb iSerial mbed BaseJpegDecode FatFileSystem SDFileSystem RingBuffer Camera_LS_Y201

Committer:
cgraham
Date:
Thu Sep 18 15:21:47 2014 +0000
Revision:
0:d69efd0ee139
test

Who changed what in which revision?

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