hgftf

Dependencies:   mbed wave_player 4DGL-uLCD-SE MMA8452

Committer:
DCchico
Date:
Fri Oct 23 16:18:39 2020 -0400
Revision:
1:10330bce85cb
shell-code

Who changed what in which revision?

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