Skip to content

Commit f65bb15

Browse files
author
Henrik Alsér
committed
Revert changes to twim, belongs in another branch
1 parent a5fea4a commit f65bb15

File tree

1 file changed

+10
-53
lines changed

1 file changed

+10
-53
lines changed

nrf-hal-common/src/twim.rs

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,16 @@ where
124124
// values.
125125
unsafe { w.maxcnt().bits(buffer.len() as _) });
126126

127-
// Clear address NACK
128-
self.0.errorsrc.write(|w| w.anack().bit(true));
129-
130127
// Start write operation
131128
self.0.tasks_starttx.write(|w|
132129
// `1` is a valid value to write to task registers.
133130
unsafe { w.bits(1) });
134131

135132
// Wait until write operation is about to end
136-
while self.0.events_lasttx.read().bits() == 0
137-
&& self.0.errorsrc.read().anack().is_not_received()
138-
{}
133+
while self.0.events_lasttx.read().bits() == 0 {}
139134
self.0.events_lasttx.write(|w| w); // reset event
140135

141-
// Stop write operation
136+
// Stop read operation
142137
self.0.tasks_stop.write(|w|
143138
// `1` is a valid value to write to task registers.
144139
unsafe { w.bits(1) });
@@ -152,10 +147,6 @@ where
152147
// after all possible DMA actions have completed
153148
compiler_fence(SeqCst);
154149

155-
if self.0.errorsrc.read().anack().is_received() {
156-
return Err(Error::AddressNack);
157-
}
158-
159150
if self.0.txd.amount.read().bits() != buffer.len() as u32 {
160151
return Err(Error::Transmit);
161152
}
@@ -205,18 +196,13 @@ where
205196
// full range of values that fit in a `u8`.
206197
unsafe { w.maxcnt().bits(buffer.len() as _) });
207198

208-
// Clear address NACK
209-
self.0.errorsrc.write(|w| w.anack().bit(true));
210-
211199
// Start read operation
212200
self.0.tasks_startrx.write(|w|
213201
// `1` is a valid value to write to task registers.
214202
unsafe { w.bits(1) });
215203

216204
// Wait until read operation is about to end
217-
while self.0.events_lastrx.read().bits() == 0
218-
&& self.0.errorsrc.read().anack().is_not_received()
219-
{}
205+
while self.0.events_lastrx.read().bits() == 0 {}
220206
self.0.events_lastrx.write(|w| w); // reset event
221207

222208
// Stop read operation
@@ -233,10 +219,6 @@ where
233219
// after all possible DMA actions have completed
234220
compiler_fence(SeqCst);
235221

236-
if self.0.errorsrc.read().anack().is_received() {
237-
return Err(Error::AddressNack);
238-
}
239-
240222
if self.0.rxd.amount.read().bits() != buffer.len() as u32 {
241223
return Err(Error::Receive);
242224
}
@@ -315,47 +297,23 @@ where
315297
// full range of values that fit in a `u8`.
316298
unsafe { w.maxcnt().bits(rd_buffer.len() as _) });
317299

318-
// Clear address NACK
319-
self.0.errorsrc.write(|w| w.anack().bit(true));
300+
// Immediately start RX after TX, then stop
301+
self.0
302+
.shorts
303+
.modify(|_r, w| w.lasttx_startrx().enabled().lastrx_stop().enabled());
320304

321305
// Start write operation
322-
// `1` is a valid value to write to task registers.
323-
self.0.tasks_starttx.write(|w| unsafe { w.bits(1) });
324-
325-
// Wait until write operation is about to end
326-
while self.0.events_lasttx.read().bits() == 0
327-
&& self.0.errorsrc.read().anack().is_not_received()
328-
{}
329-
self.0.events_lasttx.write(|w| w); // reset event
330-
331-
// Stop operation if address is NACK
332-
if self.0.errorsrc.read().anack().is_received() {
306+
self.0.tasks_starttx.write(|w|
333307
// `1` is a valid value to write to task registers.
334-
self.0.tasks_stop.write(|w| unsafe { w.bits(1) });
335-
// Wait until operation is stopped
336-
while self.0.events_stopped.read().bits() == 0 {}
337-
self.0.events_stopped.write(|w| w); // reset event
338-
return Err(Error::AddressNack);
339-
}
340-
341-
// Start read operation
342-
// `1` is a valid value to write to task registers.
343-
self.0.tasks_startrx.write(|w| unsafe { w.bits(1) });
344-
345-
// Wait until read operation is about to end
346-
while self.0.events_lastrx.read().bits() == 0 {}
347-
self.0.events_lastrx.write(|w| w); // reset event
348-
349-
// Stop read operation
350-
// `1` is a valid value to write to task registers.
351-
self.0.tasks_stop.write(|w| unsafe { w.bits(1) });
308+
unsafe { w.bits(1) });
352309

353310
// Wait until total operation has ended
354311
while self.0.events_stopped.read().bits() == 0 {}
355312

356313
self.0.events_lasttx.write(|w| w); // reset event
357314
self.0.events_lastrx.write(|w| w); // reset event
358315
self.0.events_stopped.write(|w| w); // reset event
316+
self.0.shorts.write(|w| w);
359317

360318
// Conservative compiler fence to prevent optimizations that do not
361319
// take in to account actions by DMA. The fence has been placed here,
@@ -569,7 +527,6 @@ pub enum Error {
569527
Transmit,
570528
Receive,
571529
DMABufferNotInDataMemory,
572-
AddressNack,
573530
}
574531

575532
/// Implemented by all TWIM instances

0 commit comments

Comments
 (0)