microSDカードからWaveファイルを再生するサンプルです。

Dependencies:   mbed FATFileSystem

Committer:
jksoft
Date:
Mon May 12 14:45:42 2014 +0000
Revision:
0:e9f196d85a46
First edition

Who changed what in which revision?

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