temp

Dependencies:   mbed SDFileSystem MS5607 ADXL345_I2C FATFileSystem

Committer:
IKobayashi
Date:
Mon Mar 16 23:37:42 2020 +0900
Revision:
0:c88c3b616c00
copy

Who changed what in which revision?

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