Skip to content

Commit 9b3d004

Browse files
committed
Clean up SDMMC flags.
1 parent 78e4758 commit 9b3d004

File tree

1 file changed

+27
-36
lines changed

1 file changed

+27
-36
lines changed

src/sdmmc.rs

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,20 @@ macro_rules! sta_tx {
215215
}};
216216
}
217217

218+
#[inline]
219+
fn clear_static_command_flags(icr: &sdmmc1::ICR) {
220+
icr.modify(|_, w| {
221+
w.ccrcfailc()
222+
.set_bit()
223+
.ctimeoutc()
224+
.set_bit()
225+
.cmdrendc()
226+
.set_bit()
227+
.cmdsentc()
228+
.set_bit()
229+
})
230+
}
231+
218232
#[inline]
219233
fn clear_static_data_flags(icr: &sdmmc1::ICR) {
220234
icr.modify(|_, w| {
@@ -235,34 +249,10 @@ fn clear_static_data_flags(icr: &sdmmc1::ICR) {
235249

236250
#[inline]
237251
fn clear_all_interrupts(icr: &sdmmc1::ICR) {
238-
icr.modify(|_, w| {
239-
w.ccrcfailc()
240-
.set_bit()
241-
.ctimeoutc()
242-
.set_bit()
243-
.ceataendc()
244-
.set_bit()
245-
.cmdrendc()
246-
.set_bit()
247-
.cmdsentc()
248-
.set_bit()
249-
.dataendc()
250-
.set_bit()
251-
.dbckendc()
252-
.set_bit()
253-
.dcrcfailc()
254-
.set_bit()
255-
.dtimeoutc()
256-
.set_bit()
257-
.sdioitc()
258-
.set_bit()
259-
.stbiterrc()
260-
.set_bit()
261-
.rxoverrc()
262-
.set_bit()
263-
.txunderrc()
264-
.set_bit()
265-
});
252+
clear_static_command_flags(icr);
253+
clear_static_data_flags(icr);
254+
255+
icr.modify(|_, w| w.sdioitc().set_bit());
266256
}
267257

268258
/// An initialized SD card.
@@ -772,7 +762,9 @@ impl Sdmmc {
772762
for _ in 0..8 {
773763
i -= 1;
774764
let bits = u32::from_be(self.sdmmc.fifo.read().bits());
775-
sd_status[i] = bits.to_le();
765+
unsafe {
766+
*sd_status.get_unchecked_mut(i) = bits.to_le();
767+
}
776768
}
777769
}
778770
}
@@ -808,9 +800,6 @@ impl Sdmmc {
808800
fn cmd<R: common_cmd::Resp>(&self, cmd: Cmd<R>) -> Result<(), Error> {
809801
while self.sdmmc.sta.read().cmdact().bit_is_set() {}
810802

811-
// Clear the interrupts before we start
812-
clear_all_interrupts(&self.sdmmc.icr);
813-
814803
self.sdmmc
815804
.arg
816805
.write(|w| unsafe { w.cmdarg().bits(cmd.arg) });
@@ -842,32 +831,34 @@ impl Sdmmc {
842831
}
843832

844833
if sta.ctimeout().bit() {
845-
self.sdmmc.icr.modify(|_, w| w.ctimeoutc().set_bit());
834+
clear_static_command_flags(&self.sdmmc.icr);
846835

847836
return Err(Error::Timeout);
848837
}
849838

850839
if cmd.response_len() == ResponseLen::Zero {
851840
if sta.cmdsent().bit() {
852-
self.sdmmc.icr.modify(|_, w| w.cmdsentc().set_bit());
841+
clear_static_command_flags(&self.sdmmc.icr);
853842

854843
return Ok(());
855844
}
856845
} else {
857846
if sta.ccrcfail().bit() {
858-
self.sdmmc.icr.modify(|_, w| w.ccrcfailc().set_bit());
847+
clear_static_command_flags(&self.sdmmc.icr);
859848

860849
return Err(Error::CommandCrc);
861850
}
862851

863852
if sta.cmdrend().bit() {
864-
self.sdmmc.icr.modify(|_, w| w.cmdrendc().set_bit());
853+
clear_static_command_flags(&self.sdmmc.icr);
865854

866855
return Ok(());
867856
}
868857
}
869858
}
870859

860+
clear_static_command_flags(&self.sdmmc.icr);
861+
871862
Err(Error::SoftwareTimeout)
872863
}
873864

0 commit comments

Comments
 (0)