VS1053 Library Program demonstration

Dependencies:   mbed VS1053lib MI0283QTlib

Committer:
clemente
Date:
Sat May 26 17:42:43 2012 +0000
Revision:
0:bc68fb9d73a4

        

Who changed what in which revision?

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