Demo of Embedded Artists LPCXpresso baseboard SD card reader and audio facilities. Updated to put wav file player in a separate library and use the high capacity SD card library provided by Klaus Bu.

Dependencies:   mbed

Committer:
tom_coxon
Date:
Sun Jul 25 17:51:19 2010 +0000
Revision:
2:affcc36a50b4

        

Who changed what in which revision?

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