Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
75 lines (70 loc) · 2.33 KB
/
Copy pathmain.cpp
File metadata and controls
75 lines (70 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// ==========================================================================
//
// File : main.cpp
// Part of : Phat - FAT32 reader - demo application
// Copyright : Florian Humblot - me@florianhumblot.com 2018
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// ==========================================================================
#include "hwlib.hpp"
#include "phat/SDDevice.hpp"
int main() {
// kill the watchdog (ATSAM3X8E specific)
WDT->WDT_MR = WDT_MR_WDDIS;
// wait for the COM port to be setup for IO
hwlib::wait_ms( 1000 );
// char test;
// hwlib::cin >> test;
auto SS = hwlib::target::pin_out( 3, 7 );
auto SCLK = hwlib::target::pin_out( 2, 21 );
auto MOSI = hwlib::target::pin_out( 2, 22 );
auto MISO = hwlib::target::pin_in( 2, 25 );
SS.set( true );
SCLK.set( false );
MOSI.set( true );
hwlib::wait_ms( 500 );
SDDevice SDCard( MOSI, SS, SCLK, MISO );
int status = SDCard.init_card();
if ( status == -1 ) {
hwlib::cout << "Initialization failed, try again" << hwlib::endl;
return 0;
}
status = SDCard.generateDirectoryListing();
if ( status == -1 ) {
hwlib::cout << "The generation of the directory listing failed, try again" << hwlib::endl;
}
SDCard.printDirectoryListing();
for ( ;; ) {
hwlib::cout << "\n\nWhat folder or file would you like to open? (Select by typing the number to the left of the entry or the '/' character for returning to the root)" << hwlib::endl;
hwlib::cout << "CAUTION: by selecting a file, the file will be opened and printed.\n" << hwlib::endl;
char temp;
uint16_t filenumber = 0;
do {
hwlib::cin >> temp;
if ( ( temp >= 48 && temp <= 57 ) ) {
hwlib::cout << "temp: " << temp;
filenumber = (filenumber * 10) + (temp - '0');
hwlib::cout << " || temp after: " << filenumber << hwlib::endl;
} else if ( temp == '/' ) {
break;
}
} while ( temp != 13 );
if ( temp != '/' ) {
if ( SDCard.filenumberIsADirectory( filenumber ) ) {
SDCard.printDirectoryListing( filenumber );
} else {
status = SDCard.openAndPrintFile( filenumber );
if ( status == -1 ) {
hwlib::cout << "Reading the file failed, try again" << hwlib::endl;
return 0;
}
}
} else {
SDCard.printDirectoryListing( 0 );
}
}
return 0;
}