wefwe

Dependencies:   mbed C12832 DogM163 FatFileSystem

Committer:
JostBaus
Date:
Wed May 08 13:48:54 2019 +0000
Revision:
28:19aac2daf669
Wavspiller using RiceGulumb

Who changed what in which revision?

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