Record audio data to a .wav file, complete with header, using the TLV320 CODEC and I2S port

Dependencies:   mbed

Committer:
d_worrall
Date:
Fri Aug 05 15:00:51 2011 +0000
Revision:
0:e7efc8468066
version 2.0

Who changed what in which revision?

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