This is a code which generates the various zoomed versions of an image stored in an SD card and displays it on a Nokia LCD based on the keys pressed on a capacitive touch pad.
Dependencies: FatFileSystem mbed
Fork of Lab3 by
SDFileSystem/SDFileSystem.h@1:6048138606a0, 2012-10-11 (annotated)
- Committer:
- abarve9
- Date:
- Thu Oct 11 06:10:31 2012 +0000
- Revision:
- 1:6048138606a0
- Parent:
- 0:c546b51ecf0b
This is an image zooming program which reads an image stored in an SD card and displays the various zoomed versions of the image based on the key pressed in the capacitive touch sensor.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
XkLi | 0:c546b51ecf0b | 1 | /* mbed SDFileSystem Library, for providing file access to SD cards |
XkLi | 0:c546b51ecf0b | 2 | * Copyright (c) 2008-2010, sford |
XkLi | 0:c546b51ecf0b | 3 | * |
XkLi | 0:c546b51ecf0b | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
XkLi | 0:c546b51ecf0b | 5 | * of this software and associated documentation files (the "Software"), to deal |
XkLi | 0:c546b51ecf0b | 6 | * in the Software without restriction, including without limitation the rights |
XkLi | 0:c546b51ecf0b | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
XkLi | 0:c546b51ecf0b | 8 | * copies of the Software, and to permit persons to whom the Software is |
XkLi | 0:c546b51ecf0b | 9 | * furnished to do so, subject to the following conditions: |
XkLi | 0:c546b51ecf0b | 10 | * |
XkLi | 0:c546b51ecf0b | 11 | * The above copyright notice and this permission notice shall be included in |
XkLi | 0:c546b51ecf0b | 12 | * all copies or substantial portions of the Software. |
XkLi | 0:c546b51ecf0b | 13 | * |
XkLi | 0:c546b51ecf0b | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
XkLi | 0:c546b51ecf0b | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
XkLi | 0:c546b51ecf0b | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
XkLi | 0:c546b51ecf0b | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
XkLi | 0:c546b51ecf0b | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
XkLi | 0:c546b51ecf0b | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
XkLi | 0:c546b51ecf0b | 20 | * THE SOFTWARE. |
XkLi | 0:c546b51ecf0b | 21 | */ |
XkLi | 0:c546b51ecf0b | 22 | |
XkLi | 0:c546b51ecf0b | 23 | #ifndef MBED_SDFILESYSTEM_H |
XkLi | 0:c546b51ecf0b | 24 | #define MBED_SDFILESYSTEM_H |
XkLi | 0:c546b51ecf0b | 25 | |
XkLi | 0:c546b51ecf0b | 26 | #include "mbed.h" |
XkLi | 0:c546b51ecf0b | 27 | #include "FATFileSystem.h" |
XkLi | 0:c546b51ecf0b | 28 | |
XkLi | 0:c546b51ecf0b | 29 | /** Access the filesystem on an SD Card using SPI |
XkLi | 0:c546b51ecf0b | 30 | * |
XkLi | 0:c546b51ecf0b | 31 | * @code |
XkLi | 0:c546b51ecf0b | 32 | * #include "mbed.h" |
XkLi | 0:c546b51ecf0b | 33 | * #include "SDFileSystem.h" |
XkLi | 0:c546b51ecf0b | 34 | * |
XkLi | 0:c546b51ecf0b | 35 | * SDFileSystem sd(p5, p6, p7, p12, "sd"); // mosi, miso, sclk, cs |
XkLi | 0:c546b51ecf0b | 36 | * |
XkLi | 0:c546b51ecf0b | 37 | * int main() { |
XkLi | 0:c546b51ecf0b | 38 | * FILE *fp = fopen("/sd/myfile.txt", "w"); |
XkLi | 0:c546b51ecf0b | 39 | * fprintf(fp, "Hello World!\n"); |
XkLi | 0:c546b51ecf0b | 40 | * fclose(fp); |
XkLi | 0:c546b51ecf0b | 41 | * } |
XkLi | 0:c546b51ecf0b | 42 | */ |
XkLi | 0:c546b51ecf0b | 43 | class SDFileSystem : public FATFileSystem { |
XkLi | 0:c546b51ecf0b | 44 | public: |
XkLi | 0:c546b51ecf0b | 45 | |
XkLi | 0:c546b51ecf0b | 46 | /** Create the File System for accessing an SD Card using SPI |
XkLi | 0:c546b51ecf0b | 47 | * |
XkLi | 0:c546b51ecf0b | 48 | * @param mosi SPI mosi pin connected to SD Card |
XkLi | 0:c546b51ecf0b | 49 | * @param miso SPI miso pin conencted to SD Card |
XkLi | 0:c546b51ecf0b | 50 | * @param sclk SPI sclk pin connected to SD Card |
XkLi | 0:c546b51ecf0b | 51 | * @param cs DigitalOut pin used as SD Card chip select |
XkLi | 0:c546b51ecf0b | 52 | * @param name The name used to access the virtual filesystem |
XkLi | 0:c546b51ecf0b | 53 | */ |
XkLi | 0:c546b51ecf0b | 54 | SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name); |
XkLi | 0:c546b51ecf0b | 55 | virtual int disk_initialize(); |
XkLi | 0:c546b51ecf0b | 56 | virtual int disk_write(const char *buffer, int block_number); |
XkLi | 0:c546b51ecf0b | 57 | virtual int disk_read(char *buffer, int block_number); |
XkLi | 0:c546b51ecf0b | 58 | virtual int disk_status(); |
XkLi | 0:c546b51ecf0b | 59 | virtual int disk_sync(); |
XkLi | 0:c546b51ecf0b | 60 | virtual int disk_sectors(); |
XkLi | 0:c546b51ecf0b | 61 | |
XkLi | 0:c546b51ecf0b | 62 | protected: |
XkLi | 0:c546b51ecf0b | 63 | |
XkLi | 0:c546b51ecf0b | 64 | int _cmd(int cmd, int arg); |
XkLi | 0:c546b51ecf0b | 65 | int _cmdx(int cmd, int arg); |
XkLi | 0:c546b51ecf0b | 66 | int _cmd8(); |
XkLi | 0:c546b51ecf0b | 67 | int _cmd58(); |
XkLi | 0:c546b51ecf0b | 68 | int initialise_card(); |
XkLi | 0:c546b51ecf0b | 69 | int initialise_card_v1(); |
XkLi | 0:c546b51ecf0b | 70 | int initialise_card_v2(); |
XkLi | 0:c546b51ecf0b | 71 | |
XkLi | 0:c546b51ecf0b | 72 | int _read(char *buffer, int length); |
XkLi | 0:c546b51ecf0b | 73 | int _write(const char *buffer, int length); |
XkLi | 0:c546b51ecf0b | 74 | int _sd_sectors(); |
XkLi | 0:c546b51ecf0b | 75 | int _sectors; |
XkLi | 0:c546b51ecf0b | 76 | |
XkLi | 0:c546b51ecf0b | 77 | SPI _spi; |
XkLi | 0:c546b51ecf0b | 78 | DigitalOut _cs; |
XkLi | 0:c546b51ecf0b | 79 | }; |
XkLi | 0:c546b51ecf0b | 80 | |
XkLi | 0:c546b51ecf0b | 81 | #endif |