ELEC2645 (2018/19) / Mbed 2 deprecated el17cd

Dependencies:   mbed

Committer:
el17cd
Date:
Thu Apr 04 20:13:39 2019 +0000
Revision:
27:e46af658c67a
Added interactive help menu and imported sd card library;

Who changed what in which revision?

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