James Heavey / Mbed 2 deprecated 2665-Breakout-Game

Dependencies:   mbed

Committer:
jamesheavey
Date:
Tue Jan 05 01:14:11 2021 +0000
Revision:
0:92b180c8d407
test

Who changed what in which revision?

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