Use the TLV320 with in-built I2S object to stream audio data from an SD Card and send it to the TLV320 CODEC for audio playback

Dependencies:   I2SSlave mbed TLV320

Committer:
d_worrall
Date:
Fri Aug 05 10:07:47 2011 +0000
Revision:
0:3d6892f6384f
version 2.0

Who changed what in which revision?

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