@@ -49,12 +49,18 @@ where
49
49
{
50
50
/// Create a new SD/MMC Card driver using a raw SPI interface.
51
51
///
52
+ /// The card will not be initialised at this time. Initialisation is
53
+ /// deferred until a method is called on the object.
54
+ ///
52
55
/// Uses the default options.
53
56
pub fn new ( spi : SPI , cs : CS , delayer : DELAYER ) -> SdCard < SPI , CS , DELAYER > {
54
57
Self :: new_with_options ( spi, cs, delayer, AcquireOpts :: default ( ) )
55
58
}
56
59
57
60
/// Construct a new SD/MMC Card driver, using a raw SPI interface and the given options.
61
+ ///
62
+ /// The card will not be initialised at this time. Initialisation is
63
+ /// deferred until a method is called on the object.
58
64
pub fn new_with_options (
59
65
spi : SPI ,
60
66
cs : CS ,
72
78
}
73
79
}
74
80
75
- /// Get a temporary borrow on the underlying SPI device. Useful if you
76
- /// need to re-clock the SPI.
81
+ /// Get a temporary borrow on the underlying SPI device.
82
+ ///
83
+ /// The given closure will be called exactly once, and will be passed a
84
+ /// mutable reference to the underlying SPI object.
85
+ ///
86
+ /// Useful if you need to re-clock the SPI, but does not perform card
87
+ /// initialisation.
77
88
pub fn spi < T , F > ( & self , func : F ) -> T
78
89
where
79
90
F : FnOnce ( & mut SPI ) -> T ,
@@ -83,13 +94,17 @@ where
83
94
}
84
95
85
96
/// Return the usable size of this SD card in bytes.
97
+ ///
98
+ /// This will trigger card (re-)initialisation.
86
99
pub fn num_bytes ( & self ) -> Result < u64 , Error > {
87
100
let mut inner = self . inner . borrow_mut ( ) ;
88
101
inner. check_init ( ) ?;
89
102
inner. num_bytes ( )
90
103
}
91
104
92
105
/// Can this card erase single blocks?
106
+ ///
107
+ /// This will trigger card (re-)initialisation.
93
108
pub fn erase_single_block_enabled ( & self ) -> Result < bool , Error > {
94
109
let mut inner = self . inner . borrow_mut ( ) ;
95
110
inner. check_init ( ) ?;
@@ -105,17 +120,30 @@ where
105
120
}
106
121
107
122
/// Get the card type.
123
+ ///
124
+ /// This will trigger card (re-)initialisation.
108
125
pub fn get_card_type ( & self ) -> Option < CardType > {
109
- let inner = self . inner . borrow ( ) ;
126
+ let mut inner = self . inner . borrow_mut ( ) ;
127
+ inner. check_init ( ) . ok ( ) ?;
110
128
inner. card_type
111
129
}
112
130
113
131
/// Tell the driver the card has been initialised.
114
132
///
133
+ /// This is here in case you were previously using the SD Card, and then a
134
+ /// previous instance of this object got destroyed but you know for certain
135
+ /// the SD Card remained powered up and initialised, and you'd just like to
136
+ /// read/write to/from the card again without going through the
137
+ /// initialisation sequence again.
138
+ ///
115
139
/// # Safety
116
140
///
117
- /// Only do this if the card has actually been initialised and is of the
118
- /// indicated type, otherwise corruption may occur.
141
+ /// Only do this if the SD Card has actually been initialised. That is, if
142
+ /// you have been through the card initialisation sequence as specified in
143
+ /// the SD Card Specification by sending each appropriate command in turn,
144
+ /// either manually or using another variable of this [`SdCard`]. The card
145
+ /// must also be of the indicated type. Failure to uphold this will cause
146
+ /// data corruption.
119
147
pub unsafe fn mark_card_as_init ( & self , card_type : CardType ) {
120
148
let mut inner = self . inner . borrow_mut ( ) ;
121
149
inner. card_type = Some ( card_type) ;
@@ -133,6 +161,8 @@ where
133
161
type Error = Error ;
134
162
135
163
/// Read one or more blocks, starting at the given block index.
164
+ ///
165
+ /// This will trigger card (re-)initialisation.
136
166
fn read (
137
167
& self ,
138
168
blocks : & mut [ Block ] ,
@@ -151,6 +181,8 @@ where
151
181
}
152
182
153
183
/// Write one or more blocks, starting at the given block index.
184
+ ///
185
+ /// This will trigger card (re-)initialisation.
154
186
fn write ( & self , blocks : & [ Block ] , start_block_idx : BlockIdx ) -> Result < ( ) , Self :: Error > {
155
187
let mut inner = self . inner . borrow_mut ( ) ;
156
188
debug ! ( "Writing {} blocks @ {}" , blocks. len( ) , start_block_idx. 0 ) ;
@@ -159,6 +191,8 @@ where
159
191
}
160
192
161
193
/// Determine how many blocks this device can hold.
194
+ ///
195
+ /// This will trigger card (re-)initialisation.
162
196
fn num_blocks ( & self ) -> Result < BlockCount , Self :: Error > {
163
197
let mut inner = self . inner . borrow_mut ( ) ;
164
198
inner. check_init ( ) ?;
0 commit comments