Final tidy of code following installation of new sensor, more comments added prior to submission

Dependencies:   mbed

Committer:
legstar85
Date:
Fri Jan 21 22:33:32 2022 +0000
Revision:
14:3e9991fe64e5
Addition of new menu option, start of coding for writing Temp data to SD card

Who changed what in which revision?

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