George Sykes ELEC2645 project

Dependencies:   mbed

https://os.mbed.com/media/uploads/el18gs/pixil-frame-0.png

GHOST HUNTER

In a world of ghostly horrors there is much money to be made in underground ghost fighting rings. You've managed to get hold of a Ghostbuster, a special piece of equipment that allows you to catch, train and fight ghosts.

Instructions

Below you will find the instructions for the game. Please note that due to COVID-19 a large part of the game (fighting ghosts) could not be added as it would have required access to a second gamepad which i could not acquire.

Welcome screen

When first started you will be presented with a welcome screen

  • Pot 1 to adjust the contrast on the screen
  • Press A to continue.

Main menu

You have three options, catch ghosts (add ghosts to your inventory), inventory (sell ghosts) or settings(adjust the games settings).

  • Press X and B to move the selection up and down respectively
  • Press A to enter the selected submenu

Catch Ghost

Will now be presented with two challenges. In the first you need to find a ghost, in the second you catch it. Theses stages will start automatically.

Find ghost

Rotate the gamepad on its roll and pitch axis until all the LED's turn on. The ones on the left indicate roll and the right pitch.

  • Rotate the gamepad on it roll and pitch to light up the LED's

Catch ghost

Return the gamepad to a comfortable position and use the joystick to move the crosshairs onto the ghost sprite. When ready press the A button to catch the ghost. You will be told what kind of ghost you have captured and it will be added to your inventory.

  • Press A to catch the ghost
  • Move the joystick to move the crosshairs

Inventory

The inventory allows you to view your ghosts and sell them.

  • Use Pot 1 to scroll through the ghosts
  • Pot 2 to scroll up and down the details of the individual ghosts
  • Press X to prepare to sell a ghost and press again to confirm, if you don't press again the sale screen will disappear after 5 seconds
  • Press Start to return to the main menu

Settings

This menu allows you to adjust some of the settings of the game.

  • Press X to go up one option
  • Press B to go down one option
  • Press A to enter the selected submenu
  • Press Start to return to the main menu

Contrast

Set the contrast of the LCD screen, the contrast will adjust on this screen so you can see the effect (contrast is bounded between 0.4 and 0.6).

  • Pot 1 to increase or decrease the contrast
  • Press A to set the contrast

Button Delay

Set the minimum time between button presses; if this is too low the game will detect two button presses when there was only one, too high and the buttons will seem unresponsive. So as to ensure these issues do not occur while changing the setting button X temporarily operates on the new delay but none of the others will until A is pressed.

  • Pot 1 to increase or decrease the delay
  • Press X to test the new delay, this will toggle the small circle to be filled in or unfilled
  • Press A to save the setting
Committer:
el18gs
Date:
Tue May 26 13:37:32 2020 +0000
Revision:
17:3ebcf7bba112
Parent:
2:eaf245af2aae
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

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