Snake vs Block Game to be run upon K64F.

Dependencies:   mbed

Committer:
AhmedPlaymaker
Date:
Thu May 09 14:52:19 2019 +0000
Revision:
104:17040265b7b4
Parent:
51:387249f9b333
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

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