77
88use core:: cell:: RefCell ;
99
10+ use embedded_sdmmc:: { Error , SdCardError , TimeSource , Timestamp } ;
11+
1012pub struct DummyCsPin ;
1113
1214impl embedded_hal:: digital:: ErrorType for DummyCsPin {
@@ -80,9 +82,9 @@ impl embedded_hal::delay::DelayNs for FakeDelayer {
8082
8183struct FakeTimesource ( ) ;
8284
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 {
8688 year_since_1970 : 0 ,
8789 zero_indexed_month : 0 ,
8890 zero_indexed_day : 0 ,
@@ -94,47 +96,48 @@ impl embedded_sdmmc::TimeSource for FakeTimesource {
9496}
9597
9698#[ 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 ) ,
100102}
101103
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)
105107 }
106108}
107109
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)
111113 }
112114}
113115
114- fn main ( ) -> Result < ( ) , Error > {
116+ fn main ( ) -> Result < ( ) , MyError > {
115117 // BEGIN Fake stuff that will be replaced with real peripherals
116118 let spi_bus = RefCell :: new ( FakeSpiBus ( ) ) ;
117119 let delay = FakeDelayer ( ) ;
118120 let sdmmc_spi = embedded_hal_bus:: spi:: RefCellDevice :: new ( & spi_bus, DummyCsPin , delay) . unwrap ( ) ;
119121 let time_source = FakeTimesource ( ) ;
120122 // END Fake stuff that will be replaced with real peripherals
121123
124+ use embedded_sdmmc:: { Mode , SdCard , VolumeIdx , VolumeManager } ;
122125 // 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) ;
124127 // Get the card size (this also triggers card initialisation because it's not been done yet)
125128 println ! ( "Card size is {} bytes" , sdcard. num_bytes( ) ?) ;
126129 // Now let's look for volumes (also known as partitions) on our block device.
127130 // 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) ;
129132 // Try and access Volume 0 (i.e. the first partition).
130133 // 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 ) ) ?;
132135 println ! ( "Volume 0: {:?}" , volume0) ;
133136 // Open the root directory (mutably borrows from the volume).
134137 let root_dir = volume0. open_root_dir ( ) ?;
135138 // Open a file called "MY_FILE.TXT" in the root directory
136139 // 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 ) ?;
138141 // Print the contents of the file, assuming it's in ISO-8859-1 encoding
139142 while !my_file. is_eof ( ) {
140143 let mut buffer = [ 0u8 ; 32 ] ;
@@ -143,6 +146,7 @@ fn main() -> Result<(), Error> {
143146 print ! ( "{}" , * b as char ) ;
144147 }
145148 }
149+
146150 Ok ( ( ) )
147151}
148152
0 commit comments