Dependencies:   mbed Servo

Committer:
eric11fr
Date:
Tue Oct 27 22:22:14 2020 +0000
Revision:
4:34a8e94c6fd5
Parent:
0:b8bade04f24f
test menu via xbee

Who changed what in which revision?

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