ロケット用プログラム

Dependencies:   mbed

Committer:
ishiyamayuto
Date:
Wed Sep 11 06:37:20 2019 +0000
Revision:
0:d58274531d38
BMP180,MPU6050

Who changed what in which revision?

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