Joe Body 201215898

Dependencies:   mbed

Navigation

  • From the Main Menu the A button will take you into one of the play, highscore or instructions options.
  • The B button will return you to the Main Menu from either the highscore or instruction screens, though this is prompted on screen.
  • When in the Main Menu Pot1 can be used to adjust the contrast and the volume control by the speaker is active.
  • When the game is over the B button can be used to return to the Main Menu, again this is prompted.
  • To return to the Main Menu while the game is being played the reset button must be pressed, this will not save your score or anything about the game.

In Game

  • While in the game the A button is used to shoot while you aim with the Joystick.
  • You have control over the cross while the objective of the game is to rack up as many points shooting the moving head.
  • There is a slight reload time on each shot so you are unable to spam A if you miss.
  • Once you miss 6 times the game will end and your score will be saved.
  • When hit by a falling spike the game will transition and the head will vanish.
  • 4 new spikes will spawn which you need to avoid, being hit by 1 of these will decrease your remaining miss chances by 5.
  • When the game is in this state you must avoid these spikes by tilting the device, the Joystick will have no effect.
  • The head will move progressively faster as the game goes on, make use of the clock power up by shooting it when it appears, this will slow the head down to a more manageable level hopefully helping you to reach a higher score.

Highscore

  • If you have a SD card inserted into the device the game can save your highest score.
  • A decent score is somewhere around 25.
Committer:
el18jgb
Date:
Wed May 20 14:37:02 2020 +0000
Revision:
18:c600a6545e81
spikemode uses accelerometer ;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el18jgb 18:c600a6545e81 1 /* SD/MMC File System Library
el18jgb 18:c600a6545e81 2 * Copyright (c) 2016 Neil Thiessen
el18jgb 18:c600a6545e81 3 *
el18jgb 18:c600a6545e81 4 * Licensed under the Apache License, Version 2.0 (the "License");
el18jgb 18:c600a6545e81 5 * you may not use this file except in compliance with the License.
el18jgb 18:c600a6545e81 6 * You may obtain a copy of the License at
el18jgb 18:c600a6545e81 7 *
el18jgb 18:c600a6545e81 8 * http://www.apache.org/licenses/LICENSE-2.0
el18jgb 18:c600a6545e81 9 *
el18jgb 18:c600a6545e81 10 * Unless required by applicable law or agreed to in writing, software
el18jgb 18:c600a6545e81 11 * distributed under the License is distributed on an "AS IS" BASIS,
el18jgb 18:c600a6545e81 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
el18jgb 18:c600a6545e81 13 * See the License for the specific language governing permissions and
el18jgb 18:c600a6545e81 14 * limitations under the License.
el18jgb 18:c600a6545e81 15 */
el18jgb 18:c600a6545e81 16
el18jgb 18:c600a6545e81 17 #ifndef SD_FILE_SYSTEM_H
el18jgb 18:c600a6545e81 18 #define SD_FILE_SYSTEM_H
el18jgb 18:c600a6545e81 19
el18jgb 18:c600a6545e81 20 #include "mbed.h"
el18jgb 18:c600a6545e81 21 #include "FATFileSystem.h"
el18jgb 18:c600a6545e81 22
el18jgb 18:c600a6545e81 23 /** SDFileSystem class.
el18jgb 18:c600a6545e81 24 * Used for creating a virtual file system for accessing SD/MMC cards via SPI.
el18jgb 18:c600a6545e81 25 *
el18jgb 18:c600a6545e81 26 * Example:
el18jgb 18:c600a6545e81 27 * @code
el18jgb 18:c600a6545e81 28 * #include "mbed.h"
el18jgb 18:c600a6545e81 29 * #include "SDFileSystem.h"
el18jgb 18:c600a6545e81 30 *
el18jgb 18:c600a6545e81 31 * //Create an SDFileSystem object
el18jgb 18:c600a6545e81 32 * SDFileSystem sd(p5, p6, p7, p20, "sd");
el18jgb 18:c600a6545e81 33 *
el18jgb 18:c600a6545e81 34 * int main()
el18jgb 18:c600a6545e81 35 * {
el18jgb 18:c600a6545e81 36 * //Mount the filesystem
el18jgb 18:c600a6545e81 37 * sd.mount();
el18jgb 18:c600a6545e81 38 *
el18jgb 18:c600a6545e81 39 * //Perform a write test
el18jgb 18:c600a6545e81 40 * printf("\nWriting to SD card...");
el18jgb 18:c600a6545e81 41 * FILE *fp = fopen("/sd/sdtest.txt", "w");
el18jgb 18:c600a6545e81 42 * if (fp != NULL) {
el18jgb 18:c600a6545e81 43 * fprintf(fp, "We're writing to an SD card!");
el18jgb 18:c600a6545e81 44 * fclose(fp);
el18jgb 18:c600a6545e81 45 * printf("success!\n");
el18jgb 18:c600a6545e81 46 * } else {
el18jgb 18:c600a6545e81 47 * printf("failed!\n");
el18jgb 18:c600a6545e81 48 * }
el18jgb 18:c600a6545e81 49 *
el18jgb 18:c600a6545e81 50 * //Perform a read test
el18jgb 18:c600a6545e81 51 * printf("Reading from SD card...");
el18jgb 18:c600a6545e81 52 * fp = fopen("/sd/sdtest.txt", "r");
el18jgb 18:c600a6545e81 53 * if (fp != NULL) {
el18jgb 18:c600a6545e81 54 * char c = fgetc(fp);
el18jgb 18:c600a6545e81 55 * if (c == 'W')
el18jgb 18:c600a6545e81 56 * printf("success!\n");
el18jgb 18:c600a6545e81 57 * else
el18jgb 18:c600a6545e81 58 * printf("incorrect char (%c)!\n", c);
el18jgb 18:c600a6545e81 59 * fclose(fp);
el18jgb 18:c600a6545e81 60 * } else {
el18jgb 18:c600a6545e81 61 * printf("failed!\n");
el18jgb 18:c600a6545e81 62 * }
el18jgb 18:c600a6545e81 63 *
el18jgb 18:c600a6545e81 64 * //Unmount the filesystem
el18jgb 18:c600a6545e81 65 * sd.unmount();
el18jgb 18:c600a6545e81 66 * }
el18jgb 18:c600a6545e81 67 * @endcode
el18jgb 18:c600a6545e81 68 */
el18jgb 18:c600a6545e81 69 class SDFileSystem : public FATFileSystem
el18jgb 18:c600a6545e81 70 {
el18jgb 18:c600a6545e81 71 public:
el18jgb 18:c600a6545e81 72 /** Represents the different card detect switch types
el18jgb 18:c600a6545e81 73 */
el18jgb 18:c600a6545e81 74 enum SwitchType {
el18jgb 18:c600a6545e81 75 SWITCH_NONE, /**< No card detect switch (assumes socket is always occupied) */
el18jgb 18:c600a6545e81 76 SWITCH_POS_NO, /**< Switch shorts to VDD when the socket is occupied (positive logic, normally open) */
el18jgb 18:c600a6545e81 77 SWITCH_POS_NC, /**< Switch shorts to VDD when the socket is empty (positive logic, normally closed) */
el18jgb 18:c600a6545e81 78 SWITCH_NEG_NO, /**< Switch shorts to GND when the socket is occupied (negative logic, normally open) */
el18jgb 18:c600a6545e81 79 SWITCH_NEG_NC /**< Switch shorts to GND when the socket is empty (negative logic, normally closed) */
el18jgb 18:c600a6545e81 80 };
el18jgb 18:c600a6545e81 81
el18jgb 18:c600a6545e81 82 /** Represents the different SD/MMC card types
el18jgb 18:c600a6545e81 83 */
el18jgb 18:c600a6545e81 84 enum CardType {
el18jgb 18:c600a6545e81 85 CARD_NONE, /**< No card is present */
el18jgb 18:c600a6545e81 86 CARD_MMC, /**< MMC card */
el18jgb 18:c600a6545e81 87 CARD_SD, /**< Standard capacity SD card */
el18jgb 18:c600a6545e81 88 CARD_SDHC, /**< High capacity SD card */
el18jgb 18:c600a6545e81 89 CARD_UNKNOWN /**< Unknown or unsupported card */
el18jgb 18:c600a6545e81 90 };
el18jgb 18:c600a6545e81 91
el18jgb 18:c600a6545e81 92 /** Create a virtual file system for accessing SD/MMC cards via SPI
el18jgb 18:c600a6545e81 93 *
el18jgb 18:c600a6545e81 94 * @param mosi The SPI data out pin.
el18jgb 18:c600a6545e81 95 * @param miso The SPI data in pin.
el18jgb 18:c600a6545e81 96 * @param sclk The SPI clock pin.
el18jgb 18:c600a6545e81 97 * @param cs The SPI chip select pin.
el18jgb 18:c600a6545e81 98 * @param name The name used to access the virtual filesystem.
el18jgb 18:c600a6545e81 99 * @param cd The card detect pin.
el18jgb 18:c600a6545e81 100 * @param cdtype The type of card detect switch.
el18jgb 18:c600a6545e81 101 * @param hz The SPI bus frequency (defaults to 1MHz).
el18jgb 18:c600a6545e81 102 */
el18jgb 18:c600a6545e81 103 SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name, PinName cd = NC, SwitchType cdtype = SWITCH_NONE, int hz = 1000000);
el18jgb 18:c600a6545e81 104
el18jgb 18:c600a6545e81 105 /** Determine whether or not a card is present
el18jgb 18:c600a6545e81 106 *
el18jgb 18:c600a6545e81 107 * @returns
el18jgb 18:c600a6545e81 108 * 'true' if a card is present,
el18jgb 18:c600a6545e81 109 * 'false' if no card is present.
el18jgb 18:c600a6545e81 110 */
el18jgb 18:c600a6545e81 111 bool card_present();
el18jgb 18:c600a6545e81 112
el18jgb 18:c600a6545e81 113 /** Get the detected SD/MMC card type
el18jgb 18:c600a6545e81 114 *
el18jgb 18:c600a6545e81 115 * @returns The detected card type as a CardType enum.
el18jgb 18:c600a6545e81 116 *
el18jgb 18:c600a6545e81 117 * @note Valid after the filesystem has been mounted.
el18jgb 18:c600a6545e81 118 */
el18jgb 18:c600a6545e81 119 SDFileSystem::CardType card_type();
el18jgb 18:c600a6545e81 120
el18jgb 18:c600a6545e81 121 /** Get whether or not CRC is enabled for commands and data
el18jgb 18:c600a6545e81 122 *
el18jgb 18:c600a6545e81 123 * @returns
el18jgb 18:c600a6545e81 124 * 'true' if CRC is enabled for commands and data,
el18jgb 18:c600a6545e81 125 * 'false' if CRC is disabled for commands and data.
el18jgb 18:c600a6545e81 126 */
el18jgb 18:c600a6545e81 127 bool crc();
el18jgb 18:c600a6545e81 128
el18jgb 18:c600a6545e81 129 /** Set whether or not CRC is enabled for commands and data
el18jgb 18:c600a6545e81 130 *
el18jgb 18:c600a6545e81 131 * @param enabled Whether or not to enable CRC for commands and data.
el18jgb 18:c600a6545e81 132 */
el18jgb 18:c600a6545e81 133 void crc(bool enabled);
el18jgb 18:c600a6545e81 134
el18jgb 18:c600a6545e81 135 /** Get whether or not 16-bit frames are enabled for data read/write operations
el18jgb 18:c600a6545e81 136 *
el18jgb 18:c600a6545e81 137 * @returns
el18jgb 18:c600a6545e81 138 * 'true' if 16-bit frames will be used during data read/write operations,
el18jgb 18:c600a6545e81 139 * 'false' if 8-bit frames will be used during data read/write operations.
el18jgb 18:c600a6545e81 140 */
el18jgb 18:c600a6545e81 141 bool large_frames();
el18jgb 18:c600a6545e81 142
el18jgb 18:c600a6545e81 143 /** Set whether or not 16-bit frames are enabled for data read/write operations
el18jgb 18:c600a6545e81 144 *
el18jgb 18:c600a6545e81 145 * @param enabled Whether or not 16-bit frames are enabled for data read/write operations.
el18jgb 18:c600a6545e81 146 */
el18jgb 18:c600a6545e81 147 void large_frames(bool enabled);
el18jgb 18:c600a6545e81 148
el18jgb 18:c600a6545e81 149 /** Get whether or not write validation is enabled for data write operations
el18jgb 18:c600a6545e81 150 *
el18jgb 18:c600a6545e81 151 * @returns
el18jgb 18:c600a6545e81 152 * 'true' if data writes will be verified using CMD13,
el18jgb 18:c600a6545e81 153 * 'false' if data writes will not be verified.
el18jgb 18:c600a6545e81 154 */
el18jgb 18:c600a6545e81 155 bool write_validation();
el18jgb 18:c600a6545e81 156
el18jgb 18:c600a6545e81 157 /** Set whether or not write validation is enabled for data write operations
el18jgb 18:c600a6545e81 158 *
el18jgb 18:c600a6545e81 159 * @param enabled Whether or not write validation is enabled for data write operations.
el18jgb 18:c600a6545e81 160 */
el18jgb 18:c600a6545e81 161 void write_validation(bool enabled);
el18jgb 18:c600a6545e81 162
el18jgb 18:c600a6545e81 163 virtual int unmount();
el18jgb 18:c600a6545e81 164 virtual int disk_initialize();
el18jgb 18:c600a6545e81 165 virtual int disk_status();
el18jgb 18:c600a6545e81 166 virtual int disk_read(uint8_t* buffer, uint32_t sector, uint32_t count);
el18jgb 18:c600a6545e81 167 virtual int disk_write(const uint8_t* buffer, uint32_t sector, uint32_t count);
el18jgb 18:c600a6545e81 168 virtual int disk_sync();
el18jgb 18:c600a6545e81 169 virtual uint32_t disk_sectors();
el18jgb 18:c600a6545e81 170
el18jgb 18:c600a6545e81 171 private:
el18jgb 18:c600a6545e81 172 //Commands
el18jgb 18:c600a6545e81 173 enum Command {
el18jgb 18:c600a6545e81 174 CMD0 = (0x40 | 0), /**< GO_IDLE_STATE */
el18jgb 18:c600a6545e81 175 CMD1 = (0x40 | 1), /**< SEND_OP_COND */
el18jgb 18:c600a6545e81 176 CMD6 = (0x40 | 6), /**< SWITCH_FUNC */
el18jgb 18:c600a6545e81 177 CMD8 = (0x40 | 8), /**< SEND_IF_COND */
el18jgb 18:c600a6545e81 178 CMD9 = (0x40 | 9), /**< SEND_CSD */
el18jgb 18:c600a6545e81 179 CMD12 = (0x40 | 12), /**< STOP_TRANSMISSION */
el18jgb 18:c600a6545e81 180 CMD13 = (0x40 | 13), /**< SEND_STATUS */
el18jgb 18:c600a6545e81 181 CMD16 = (0x40 | 16), /**< SET_BLOCKLEN */
el18jgb 18:c600a6545e81 182 CMD17 = (0x40 | 17), /**< READ_SINGLE_BLOCK */
el18jgb 18:c600a6545e81 183 CMD18 = (0x40 | 18), /**< READ_MULTIPLE_BLOCK */
el18jgb 18:c600a6545e81 184 ACMD22 = (0x40 | 22), /**< SEND_NUM_WR_BLOCKS */
el18jgb 18:c600a6545e81 185 ACMD23 = (0x40 | 23), /**< SET_WR_BLK_ERASE_COUNT */
el18jgb 18:c600a6545e81 186 CMD24 = (0x40 | 24), /**< WRITE_BLOCK */
el18jgb 18:c600a6545e81 187 CMD25 = (0x40 | 25), /**< WRITE_MULTIPLE_BLOCK */
el18jgb 18:c600a6545e81 188 ACMD41 = (0x40 | 41), /**< SD_SEND_OP_COND */
el18jgb 18:c600a6545e81 189 ACMD42 = (0x40 | 42), /**< SET_CLR_CARD_DETECT */
el18jgb 18:c600a6545e81 190 CMD55 = (0x40 | 55), /**< APP_CMD */
el18jgb 18:c600a6545e81 191 CMD58 = (0x40 | 58), /**< READ_OCR */
el18jgb 18:c600a6545e81 192 CMD59 = (0x40 | 59) /**< CRC_ON_OFF */
el18jgb 18:c600a6545e81 193 };
el18jgb 18:c600a6545e81 194
el18jgb 18:c600a6545e81 195 //Member variables
el18jgb 18:c600a6545e81 196 Timer m_Timer;
el18jgb 18:c600a6545e81 197 SPI m_Spi;
el18jgb 18:c600a6545e81 198 DigitalOut m_Cs;
el18jgb 18:c600a6545e81 199 InterruptIn m_Cd;
el18jgb 18:c600a6545e81 200 int m_CdAssert;
el18jgb 18:c600a6545e81 201 const int m_FREQ;
el18jgb 18:c600a6545e81 202 SDFileSystem::CardType m_CardType;
el18jgb 18:c600a6545e81 203 bool m_Crc;
el18jgb 18:c600a6545e81 204 bool m_LargeFrames;
el18jgb 18:c600a6545e81 205 bool m_WriteValidation;
el18jgb 18:c600a6545e81 206 int m_Status;
el18jgb 18:c600a6545e81 207
el18jgb 18:c600a6545e81 208 //Internal methods
el18jgb 18:c600a6545e81 209 void onCardRemoval();
el18jgb 18:c600a6545e81 210 void checkSocket();
el18jgb 18:c600a6545e81 211 bool waitReady(int timeout);
el18jgb 18:c600a6545e81 212 bool select();
el18jgb 18:c600a6545e81 213 void deselect();
el18jgb 18:c600a6545e81 214 char commandTransaction(char cmd, unsigned int arg, unsigned int* resp = NULL);
el18jgb 18:c600a6545e81 215 char writeCommand(char cmd, unsigned int arg, unsigned int* resp = NULL);
el18jgb 18:c600a6545e81 216 bool readData(char* buffer, int length);
el18jgb 18:c600a6545e81 217 char writeData(const char* buffer, char token);
el18jgb 18:c600a6545e81 218 bool readBlock(char* buffer, unsigned int lba);
el18jgb 18:c600a6545e81 219 bool readBlocks(char* buffer, unsigned int lba, unsigned int count);
el18jgb 18:c600a6545e81 220 bool writeBlock(const char* buffer, unsigned int lba);
el18jgb 18:c600a6545e81 221 bool writeBlocks(const char* buffer, unsigned int lba, unsigned int count);
el18jgb 18:c600a6545e81 222 bool enableHighSpeedMode();
el18jgb 18:c600a6545e81 223 };
el18jgb 18:c600a6545e81 224
el18jgb 18:c600a6545e81 225 #endif