7
7
8
8
use core:: cell:: RefCell ;
9
9
10
+ use embedded_sdmmc:: { Error , SdCardError , TimeSource , Timestamp } ;
11
+
10
12
pub struct DummyCsPin ;
11
13
12
14
impl embedded_hal:: digital:: ErrorType for DummyCsPin {
@@ -80,9 +82,9 @@ impl embedded_hal::delay::DelayNs for FakeDelayer {
80
82
81
83
struct FakeTimesource ( ) ;
82
84
83
- impl embedded_sdmmc :: TimeSource for FakeTimesource {
84
- fn get_timestamp ( & self ) -> embedded_sdmmc :: Timestamp {
85
- embedded_sdmmc :: Timestamp {
85
+ impl TimeSource for FakeTimesource {
86
+ fn get_timestamp ( & self ) -> Timestamp {
87
+ Timestamp {
86
88
year_since_1970 : 0 ,
87
89
zero_indexed_month : 0 ,
88
90
zero_indexed_day : 0 ,
@@ -94,47 +96,48 @@ impl embedded_sdmmc::TimeSource for FakeTimesource {
94
96
}
95
97
96
98
#[ derive( Debug , Clone ) ]
97
- enum Error {
98
- Filesystem ( embedded_sdmmc :: Error < embedded_sdmmc :: SdCardError > ) ,
99
- Disk ( embedded_sdmmc :: SdCardError ) ,
99
+ enum MyError {
100
+ Filesystem ( Error < SdCardError > ) ,
101
+ Disk ( SdCardError ) ,
100
102
}
101
103
102
- impl From < embedded_sdmmc :: Error < embedded_sdmmc :: SdCardError > > for Error {
103
- fn from ( value : embedded_sdmmc :: Error < embedded_sdmmc :: SdCardError > ) -> Error {
104
- Error :: Filesystem ( value)
104
+ impl From < Error < SdCardError > > for MyError {
105
+ fn from ( value : Error < SdCardError > ) -> MyError {
106
+ MyError :: Filesystem ( value)
105
107
}
106
108
}
107
109
108
- impl From < embedded_sdmmc :: SdCardError > for Error {
109
- fn from ( value : embedded_sdmmc :: SdCardError ) -> Error {
110
- Error :: Disk ( value)
110
+ impl From < SdCardError > for MyError {
111
+ fn from ( value : SdCardError ) -> MyError {
112
+ MyError :: Disk ( value)
111
113
}
112
114
}
113
115
114
- fn main ( ) -> Result < ( ) , Error > {
116
+ fn main ( ) -> Result < ( ) , MyError > {
115
117
// BEGIN Fake stuff that will be replaced with real peripherals
116
118
let spi_bus = RefCell :: new ( FakeSpiBus ( ) ) ;
117
119
let delay = FakeDelayer ( ) ;
118
120
let sdmmc_spi = embedded_hal_bus:: spi:: RefCellDevice :: new ( & spi_bus, DummyCsPin , delay) . unwrap ( ) ;
119
121
let time_source = FakeTimesource ( ) ;
120
122
// END Fake stuff that will be replaced with real peripherals
121
123
124
+ use embedded_sdmmc:: { Mode , SdCard , VolumeIdx , VolumeManager } ;
122
125
// Build an SD Card interface out of an SPI device, a chip-select pin and the delay object
123
- let sdcard = embedded_sdmmc :: SdCard :: new ( sdmmc_spi, delay) ;
126
+ let sdcard = SdCard :: new ( sdmmc_spi, delay) ;
124
127
// Get the card size (this also triggers card initialisation because it's not been done yet)
125
128
println ! ( "Card size is {} bytes" , sdcard. num_bytes( ) ?) ;
126
129
// Now let's look for volumes (also known as partitions) on our block device.
127
130
// To do this we need a Volume Manager. It will take ownership of the block device.
128
- let volume_mgr = embedded_sdmmc :: VolumeManager :: new ( sdcard, time_source) ;
131
+ let volume_mgr = VolumeManager :: new ( sdcard, time_source) ;
129
132
// Try and access Volume 0 (i.e. the first partition).
130
133
// The volume object holds information about the filesystem on that volume.
131
- let volume0 = volume_mgr. open_volume ( embedded_sdmmc :: VolumeIdx ( 0 ) ) ?;
134
+ let volume0 = volume_mgr. open_volume ( VolumeIdx ( 0 ) ) ?;
132
135
println ! ( "Volume 0: {:?}" , volume0) ;
133
136
// Open the root directory (mutably borrows from the volume).
134
137
let root_dir = volume0. open_root_dir ( ) ?;
135
138
// Open a file called "MY_FILE.TXT" in the root directory
136
139
// This mutably borrows the directory.
137
- let my_file = root_dir. open_file_in_dir ( "MY_FILE.TXT" , embedded_sdmmc :: Mode :: ReadOnly ) ?;
140
+ let my_file = root_dir. open_file_in_dir ( "MY_FILE.TXT" , Mode :: ReadOnly ) ?;
138
141
// Print the contents of the file, assuming it's in ISO-8859-1 encoding
139
142
while !my_file. is_eof ( ) {
140
143
let mut buffer = [ 0u8 ; 32 ] ;
@@ -143,6 +146,7 @@ fn main() -> Result<(), Error> {
143
146
print ! ( "{}" , * b as char ) ;
144
147
}
145
148
}
149
+
146
150
Ok ( ( ) )
147
151
}
148
152
0 commit comments