aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/twim.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-nrf/src/twim.rs')
-rw-r--r--embassy-nrf/src/twim.rs48
1 files changed, 33 insertions, 15 deletions
diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs
index 943ea9d31..6c38ab3fe 100644
--- a/embassy-nrf/src/twim.rs
+++ b/embassy-nrf/src/twim.rs
@@ -4,8 +4,8 @@
4 4
5use core::future::poll_fn; 5use core::future::poll_fn;
6use core::marker::PhantomData; 6use core::marker::PhantomData;
7use core::sync::atomic::compiler_fence;
8use core::sync::atomic::Ordering::SeqCst; 7use core::sync::atomic::Ordering::SeqCst;
8use core::sync::atomic::compiler_fence;
9use core::task::Poll; 9use core::task::Poll;
10 10
11use embassy_embedded_hal::SetConfig; 11use embassy_embedded_hal::SetConfig;
@@ -141,10 +141,19 @@ impl<'d> Twim<'d> {
141 sda.conf().write(|w| { 141 sda.conf().write(|w| {
142 w.set_dir(gpiovals::Dir::OUTPUT); 142 w.set_dir(gpiovals::Dir::OUTPUT);
143 w.set_input(gpiovals::Input::CONNECT); 143 w.set_input(gpiovals::Input::CONNECT);
144 #[cfg(not(feature = "_nrf54l"))]
144 w.set_drive(match config.sda_high_drive { 145 w.set_drive(match config.sda_high_drive {
145 true => gpiovals::Drive::H0D1, 146 true => gpiovals::Drive::H0D1,
146 false => gpiovals::Drive::S0D1, 147 false => gpiovals::Drive::S0D1,
147 }); 148 });
149 #[cfg(feature = "_nrf54l")]
150 {
151 w.set_drive0(match config.sda_high_drive {
152 true => gpiovals::Drive::H,
153 false => gpiovals::Drive::S,
154 });
155 w.set_drive1(gpiovals::Drive::D);
156 }
148 if config.sda_pullup { 157 if config.sda_pullup {
149 w.set_pull(gpiovals::Pull::PULLUP); 158 w.set_pull(gpiovals::Pull::PULLUP);
150 } 159 }
@@ -152,11 +161,20 @@ impl<'d> Twim<'d> {
152 scl.conf().write(|w| { 161 scl.conf().write(|w| {
153 w.set_dir(gpiovals::Dir::OUTPUT); 162 w.set_dir(gpiovals::Dir::OUTPUT);
154 w.set_input(gpiovals::Input::CONNECT); 163 w.set_input(gpiovals::Input::CONNECT);
164 #[cfg(not(feature = "_nrf54l"))]
155 w.set_drive(match config.scl_high_drive { 165 w.set_drive(match config.scl_high_drive {
156 true => gpiovals::Drive::H0D1, 166 true => gpiovals::Drive::H0D1,
157 false => gpiovals::Drive::S0D1, 167 false => gpiovals::Drive::S0D1,
158 }); 168 });
159 if config.sda_pullup { 169 #[cfg(feature = "_nrf54l")]
170 {
171 w.set_drive0(match config.scl_high_drive {
172 true => gpiovals::Drive::H,
173 false => gpiovals::Drive::S,
174 });
175 w.set_drive1(gpiovals::Drive::D);
176 }
177 if config.scl_pullup {
160 w.set_pull(gpiovals::Pull::PULLUP); 178 w.set_pull(gpiovals::Pull::PULLUP);
161 } 179 }
162 }); 180 });
@@ -210,8 +228,8 @@ impl<'d> Twim<'d> {
210 // We're giving the register a pointer to the stack. Since we're 228 // We're giving the register a pointer to the stack. Since we're
211 // waiting for the I2C transaction to end before this stack pointer 229 // waiting for the I2C transaction to end before this stack pointer
212 // becomes invalid, there's nothing wrong here. 230 // becomes invalid, there's nothing wrong here.
213 r.txd().ptr().write_value(buffer.as_ptr() as u32); 231 r.dma().tx().ptr().write_value(buffer.as_ptr() as u32);
214 r.txd().maxcnt().write(|w| 232 r.dma().tx().maxcnt().write(|w|
215 // We're giving it the length of the buffer, so no danger of 233 // We're giving it the length of the buffer, so no danger of
216 // accessing invalid memory. We have verified that the length of the 234 // accessing invalid memory. We have verified that the length of the
217 // buffer fits in an `u8`, so the cast to `u8` is also fine. 235 // buffer fits in an `u8`, so the cast to `u8` is also fine.
@@ -237,8 +255,8 @@ impl<'d> Twim<'d> {
237 // We're giving the register a pointer to the stack. Since we're 255 // We're giving the register a pointer to the stack. Since we're
238 // waiting for the I2C transaction to end before this stack pointer 256 // waiting for the I2C transaction to end before this stack pointer
239 // becomes invalid, there's nothing wrong here. 257 // becomes invalid, there's nothing wrong here.
240 r.rxd().ptr().write_value(buffer.as_mut_ptr() as u32); 258 r.dma().rx().ptr().write_value(buffer.as_mut_ptr() as u32);
241 r.rxd().maxcnt().write(|w| 259 r.dma().rx().maxcnt().write(|w|
242 // We're giving it the length of the buffer, so no danger of 260 // We're giving it the length of the buffer, so no danger of
243 // accessing invalid memory. We have verified that the length of the 261 // accessing invalid memory. We have verified that the length of the
244 // buffer fits in an `u8`, so the cast to the type of maxcnt 262 // buffer fits in an `u8`, so the cast to the type of maxcnt
@@ -281,7 +299,7 @@ impl<'d> Twim<'d> {
281 299
282 fn check_rx(&self, len: usize) -> Result<(), Error> { 300 fn check_rx(&self, len: usize) -> Result<(), Error> {
283 let r = self.r; 301 let r = self.r;
284 if r.rxd().amount().read().0 != len as u32 { 302 if r.dma().rx().amount().read().0 != len as u32 {
285 Err(Error::Receive) 303 Err(Error::Receive)
286 } else { 304 } else {
287 Ok(()) 305 Ok(())
@@ -290,7 +308,7 @@ impl<'d> Twim<'d> {
290 308
291 fn check_tx(&self, len: usize) -> Result<(), Error> { 309 fn check_tx(&self, len: usize) -> Result<(), Error> {
292 let r = self.r; 310 let r = self.r;
293 if r.txd().amount().read().0 != len as u32 { 311 if r.dma().tx().amount().read().0 != len as u32 {
294 Err(Error::Transmit) 312 Err(Error::Transmit)
295 } else { 313 } else {
296 Ok(()) 314 Ok(())
@@ -412,7 +430,7 @@ impl<'d> Twim<'d> {
412 } 430 }
413 431
414 r.shorts().write(|w| { 432 r.shorts().write(|w| {
415 w.set_lastrx_starttx(true); 433 w.set_lastrx_dma_tx_start(true);
416 if stop { 434 if stop {
417 w.set_lasttx_stop(true); 435 w.set_lasttx_stop(true);
418 } else { 436 } else {
@@ -421,7 +439,7 @@ impl<'d> Twim<'d> {
421 }); 439 });
422 440
423 // Start read+write operation. 441 // Start read+write operation.
424 r.tasks_startrx().write_value(1); 442 r.tasks_dma().rx().start().write_value(1);
425 if last_op.is_some() { 443 if last_op.is_some() {
426 r.tasks_resume().write_value(1); 444 r.tasks_resume().write_value(1);
427 } 445 }
@@ -429,7 +447,7 @@ impl<'d> Twim<'d> {
429 // TODO: Handle empty write buffer 447 // TODO: Handle empty write buffer
430 if rd_buffer.is_empty() { 448 if rd_buffer.is_empty() {
431 // With a zero-length buffer, LASTRX doesn't fire (because there's no last byte!), so do the STARTTX ourselves. 449 // With a zero-length buffer, LASTRX doesn't fire (because there's no last byte!), so do the STARTTX ourselves.
432 r.tasks_starttx().write_value(1); 450 r.tasks_dma().tx().start().write_value(1);
433 } 451 }
434 452
435 Ok(2) 453 Ok(2)
@@ -443,7 +461,7 @@ impl<'d> Twim<'d> {
443 r.shorts().write(|w| w.set_lastrx_stop(true)); 461 r.shorts().write(|w| w.set_lastrx_stop(true));
444 462
445 // Start read operation. 463 // Start read operation.
446 r.tasks_startrx().write_value(1); 464 r.tasks_dma().rx().start().write_value(1);
447 if last_op.is_some() { 465 if last_op.is_some() {
448 r.tasks_resume().write_value(1); 466 r.tasks_resume().write_value(1);
449 } 467 }
@@ -466,11 +484,11 @@ impl<'d> Twim<'d> {
466 484
467 // Start write+read operation. 485 // Start write+read operation.
468 r.shorts().write(|w| { 486 r.shorts().write(|w| {
469 w.set_lasttx_startrx(true); 487 w.set_lasttx_dma_rx_start(true);
470 w.set_lastrx_stop(true); 488 w.set_lastrx_stop(true);
471 }); 489 });
472 490
473 r.tasks_starttx().write_value(1); 491 r.tasks_dma().tx().start().write_value(1);
474 if last_op.is_some() { 492 if last_op.is_some() {
475 r.tasks_resume().write_value(1); 493 r.tasks_resume().write_value(1);
476 } 494 }
@@ -494,7 +512,7 @@ impl<'d> Twim<'d> {
494 } 512 }
495 }); 513 });
496 514
497 r.tasks_starttx().write_value(1); 515 r.tasks_dma().tx().start().write_value(1);
498 if last_op.is_some() { 516 if last_op.is_some() {
499 r.tasks_resume().write_value(1); 517 r.tasks_resume().write_value(1);
500 } 518 }