Show2Me control FW, initial shared version

Dependencies:   SDFileSystem_HelloWorld mbed FATFileSystem

Fork of 000_GEO_SHOW2ME_OK_F411RE by Walter Trovo

/media/uploads/walter76/img-1277.jpg

Committer:
walter76
Date:
Tue Feb 13 08:22:23 2018 +0000
Revision:
2:bbc3e860fa3d
Preliminary version used to test all HW sections

Who changed what in which revision?

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