EA BaseBoard, playing wav, PC see\'s SD-card through USB port.

Dependencies:   mbed

Committer:
Lerche
Date:
Tue Nov 22 05:45:58 2011 +0000
Revision:
0:fef366d2ed20
Thanks to those who provided EA_WavPlayer and USB_MSC

Who changed what in which revision?

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