help :(

Dependencies:   FFT

Committer:
annieluo2
Date:
Wed Dec 02 18:02:03 2020 +0000
Revision:
0:d6c9b09b4042
boo

Who changed what in which revision?

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