aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/twim.rs
diff options
context:
space:
mode:
authorAlex Moon <[email protected]>2024-08-19 16:35:13 -0400
committerAlex Moon <[email protected]>2024-10-23 16:44:07 -0400
commit110d87bbd2c4e5b60ed99c0a259b8366e5164d41 (patch)
tree013e00c0e36f9c8645cc800fe3f7365856d63a13 /embassy-nrf/src/twim.rs
parent528a3e43550b5d2ce4a5f44d890feaa3e56c113a (diff)
Remove support for consecutive Read operations
Due to Twim hardware limitations
Diffstat (limited to 'embassy-nrf/src/twim.rs')
-rw-r--r--embassy-nrf/src/twim.rs189
1 files changed, 57 insertions, 132 deletions
diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs
index d0518807c..4a239e8b5 100644
--- a/embassy-nrf/src/twim.rs
+++ b/embassy-nrf/src/twim.rs
@@ -105,14 +105,6 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl
105 let r = T::regs(); 105 let r = T::regs();
106 let s = T::state(); 106 let s = T::state();
107 107
108 // Workaround for lack of LASTRX_SUSPEND short in some nRF chips
109 // Do this first to minimize latency
110 #[cfg(any(feature = "nrf52832", feature = "_nrf5340", feature = "_nrf9120"))]
111 if r.events_lastrx.read().bits() != 0 {
112 r.tasks_suspend.write(|w| unsafe { w.bits(1) });
113 r.events_lastrx.reset();
114 }
115
116 if r.events_suspended.read().bits() != 0 { 108 if r.events_suspended.read().bits() != 0 {
117 s.end_waker.wake(); 109 s.end_waker.wake();
118 r.intenclr.write(|w| w.suspended().clear()); 110 r.intenclr.write(|w| w.suspended().clear());
@@ -381,7 +373,6 @@ impl<'d, T: Instance> Twim<'d, T> {
381 operations: &mut [Operation<'_>], 373 operations: &mut [Operation<'_>],
382 tx_ram_buffer: Option<&mut [MaybeUninit<u8>; FORCE_COPY_BUFFER_SIZE]>, 374 tx_ram_buffer: Option<&mut [MaybeUninit<u8>; FORCE_COPY_BUFFER_SIZE]>,
383 inten: bool, 375 inten: bool,
384 stop: bool,
385 ) -> Result<(), Error> { 376 ) -> Result<(), Error> {
386 let r = T::regs(); 377 let r = T::regs();
387 378
@@ -401,14 +392,12 @@ impl<'d, T: Instance> Twim<'d, T> {
401 r.intenclr 392 r.intenclr
402 .write(|w| w.suspended().clear().stopped().clear().error().clear()); 393 .write(|w| w.suspended().clear().stopped().clear().error().clear());
403 } 394 }
404 #[cfg(any(feature = "nrf52832", feature = "_nrf5340", feature = "_nrf9120"))]
405 r.intenclr.write(|w| w.lastrx().clear());
406 395
407 match operations { 396 match operations {
408 [Operation::Read(rd_buffer), Operation::Write(wr_buffer), rest @ ..] 397 [Operation::Read(rd_buffer), Operation::Write(wr_buffer), rest @ ..]
409 if !rd_buffer.is_empty() && !wr_buffer.is_empty() => 398 if !rd_buffer.is_empty() && !wr_buffer.is_empty() =>
410 { 399 {
411 let stop = stop && rest.is_empty(); 400 let stop = rest.is_empty();
412 401
413 // Set up DMA buffers. 402 // Set up DMA buffers.
414 unsafe { 403 unsafe {
@@ -433,11 +422,9 @@ impl<'d, T: Instance> Twim<'d, T> {
433 r.tasks_resume.write(|w| unsafe { w.bits(1) }); 422 r.tasks_resume.write(|w| unsafe { w.bits(1) });
434 } 423 }
435 } 424 }
436 [Operation::Write(wr_buffer), Operation::Read(rd_buffer), rest @ ..] 425 [Operation::Write(wr_buffer), Operation::Read(rd_buffer)]
437 if !wr_buffer.is_empty() && !rd_buffer.is_empty() => 426 if !wr_buffer.is_empty() && !rd_buffer.is_empty() =>
438 { 427 {
439 let stop = stop && rest.is_empty();
440
441 // Set up DMA buffers. 428 // Set up DMA buffers.
442 unsafe { 429 unsafe {
443 self.set_tx_buffer(wr_buffer, tx_ram_buffer)?; 430 self.set_tx_buffer(wr_buffer, tx_ram_buffer)?;
@@ -447,18 +434,9 @@ impl<'d, T: Instance> Twim<'d, T> {
447 // Start write+read operation. 434 // Start write+read operation.
448 r.shorts.write(|w| { 435 r.shorts.write(|w| {
449 w.lasttx_startrx().enabled(); 436 w.lasttx_startrx().enabled();
450 if stop { 437 w.lastrx_stop().enabled();
451 w.lastrx_stop().enabled();
452 } else {
453 #[cfg(not(any(feature = "nrf52832", feature = "_nrf5340", feature = "_nrf9120")))]
454 w.lastrx_suspend().enabled();
455 }
456 w 438 w
457 }); 439 });
458 #[cfg(any(feature = "nrf52832", feature = "_nrf5340", feature = "_nrf9120"))]
459 if !stop {
460 r.intenset.write(|w| w.lastrx().set());
461 }
462 440
463 r.tasks_starttx.write(|w| unsafe { w.bits(1) }); 441 r.tasks_starttx.write(|w| unsafe { w.bits(1) });
464 442
@@ -466,9 +444,7 @@ impl<'d, T: Instance> Twim<'d, T> {
466 r.tasks_resume.write(|w| unsafe { w.bits(1) }); 444 r.tasks_resume.write(|w| unsafe { w.bits(1) });
467 } 445 }
468 } 446 }
469 [Operation::Read(buffer), rest @ ..] => { 447 [Operation::Read(buffer)] => {
470 let stop = stop && rest.is_empty();
471
472 // Set up DMA buffers. 448 // Set up DMA buffers.
473 unsafe { 449 unsafe {
474 self.set_rx_buffer(buffer)?; 450 self.set_rx_buffer(buffer)?;
@@ -476,18 +452,9 @@ impl<'d, T: Instance> Twim<'d, T> {
476 452
477 // Start read operation. 453 // Start read operation.
478 r.shorts.write(|w| { 454 r.shorts.write(|w| {
479 if stop { 455 w.lastrx_stop().enabled();
480 w.lastrx_stop().enabled();
481 } else {
482 #[cfg(not(any(feature = "nrf52832", feature = "_nrf5340", feature = "_nrf9120")))]
483 w.lastrx_suspend().enabled();
484 }
485 w 456 w
486 }); 457 });
487 #[cfg(any(feature = "nrf52832", feature = "_nrf5340", feature = "_nrf9120"))]
488 if !stop {
489 r.intenset.write(|w| w.lastrx().set());
490 }
491 458
492 r.tasks_startrx.write(|w| unsafe { w.bits(1) }); 459 r.tasks_startrx.write(|w| unsafe { w.bits(1) });
493 460
@@ -496,16 +463,15 @@ impl<'d, T: Instance> Twim<'d, T> {
496 } 463 }
497 464
498 if buffer.is_empty() { 465 if buffer.is_empty() {
499 // With a zero-length buffer, LASTRX doesn't fire (because there's no last byte!), so do the STOP/SUSPEND ourselves. 466 // With a zero-length buffer, LASTRX doesn't fire (because there's no last byte!), so do the STOP ourselves.
500 if stop { 467 r.tasks_stop.write(|w| unsafe { w.bits(1) });
501 r.tasks_stop.write(|w| unsafe { w.bits(1) });
502 } else {
503 r.tasks_suspend.write(|w| unsafe { w.bits(1) });
504 }
505 } 468 }
506 } 469 }
470 [Operation::Read(_), ..] => {
471 panic!("Suspending after a read is not supported!");
472 }
507 [Operation::Write(buffer), rest @ ..] => { 473 [Operation::Write(buffer), rest @ ..] => {
508 let stop = stop && rest.is_empty(); 474 let stop = rest.is_empty();
509 475
510 // Set up DMA buffers. 476 // Set up DMA buffers.
511 unsafe { 477 unsafe {
@@ -538,13 +504,11 @@ impl<'d, T: Instance> Twim<'d, T> {
538 } 504 }
539 } 505 }
540 [] => { 506 [] => {
541 if stop { 507 if was_suspended {
542 if was_suspended { 508 r.tasks_resume.write(|w| unsafe { w.bits(1) });
543 r.tasks_resume.write(|w| unsafe { w.bits(1) });
544 }
545
546 r.tasks_stop.write(|w| unsafe { w.bits(1) });
547 } 509 }
510
511 r.tasks_stop.write(|w| unsafe { w.bits(1) });
548 } 512 }
549 } 513 }
550 514
@@ -557,17 +521,18 @@ impl<'d, T: Instance> Twim<'d, T> {
557 521
558 match operations { 522 match operations {
559 [Operation::Read(rd_buffer), Operation::Write(wr_buffer), ..] 523 [Operation::Read(rd_buffer), Operation::Write(wr_buffer), ..]
560 | [Operation::Write(wr_buffer), Operation::Read(rd_buffer), ..] 524 | [Operation::Write(wr_buffer), Operation::Read(rd_buffer)]
561 if !rd_buffer.is_empty() && !wr_buffer.is_empty() => 525 if !rd_buffer.is_empty() && !wr_buffer.is_empty() =>
562 { 526 {
563 self.check_tx(wr_buffer.len())?; 527 self.check_tx(wr_buffer.len())?;
564 self.check_rx(rd_buffer.len())?; 528 self.check_rx(rd_buffer.len())?;
565 Ok(2) 529 Ok(2)
566 } 530 }
567 [Operation::Read(buffer), ..] => { 531 [Operation::Read(buffer)] => {
568 self.check_rx(buffer.len())?; 532 self.check_rx(buffer.len())?;
569 Ok(1) 533 Ok(1)
570 } 534 }
535 [Operation::Read(_), ..] => unreachable!(),
571 [Operation::Write(buffer), ..] => { 536 [Operation::Write(buffer), ..] => {
572 self.check_tx(buffer.len())?; 537 self.check_tx(buffer.len())?;
573 Ok(1) 538 Ok(1)
@@ -583,26 +548,17 @@ impl<'d, T: Instance> Twim<'d, T> {
583 /// Each buffer must have a length of at most 255 bytes on the nRF52832 548 /// Each buffer must have a length of at most 255 bytes on the nRF52832
584 /// and at most 65535 bytes on the nRF52840. 549 /// and at most 65535 bytes on the nRF52840.
585 /// 550 ///
586 /// If `stop` is set, the transaction will be terminated with a STOP 551 /// Consecutive `Read` operations are not supported because the Twim
587 /// condition and the Twim will be stopped. Otherwise, the bus will be 552 /// hardware does not support suspending after a read operation. (Setting
588 /// left busy via clock stretching and Twim will be suspended. 553 /// the SUSPEND task in response to a LASTRX event causes the final byte of
589 /// 554 /// the operation to be ACKed instead of NAKed. When the TWIM is resumed,
590 /// The nrf52832, nrf5340, and nrf9120 do not have hardware support for 555 /// one more byte will be read before the new operation is started, leading
591 /// suspending following a read operation therefore it is emulated by the 556 /// to an Overrun error if the RXD has not been updated, or an extraneous
592 /// interrupt handler. If the latency of servicing that interrupt is 557 /// byte read into the new buffer if the RXD has been updated.)
593 /// longer than a byte worth of clocks on the bus, the SCL clock will 558 pub fn blocking_transaction(&mut self, address: u8, mut operations: &mut [Operation<'_>]) -> Result<(), Error> {
594 /// continue to run for one or more additional bytes. This applies to
595 /// consecutive read operations, certain write-read-write sequences, or
596 /// any sequence of operations ending in a read when `stop == false`.
597 pub fn blocking_transaction(
598 &mut self,
599 address: u8,
600 mut operations: &mut [Operation<'_>],
601 stop: bool,
602 ) -> Result<(), Error> {
603 let mut tx_ram_buffer = [MaybeUninit::uninit(); FORCE_COPY_BUFFER_SIZE]; 559 let mut tx_ram_buffer = [MaybeUninit::uninit(); FORCE_COPY_BUFFER_SIZE];
604 while !operations.is_empty() { 560 while !operations.is_empty() {
605 self.setup_operations(address, operations, Some(&mut tx_ram_buffer), false, stop)?; 561 self.setup_operations(address, operations, Some(&mut tx_ram_buffer), false)?;
606 self.blocking_wait(); 562 self.blocking_wait();
607 let consumed = self.check_operations(operations)?; 563 let consumed = self.check_operations(operations)?;
608 operations = &mut operations[consumed..]; 564 operations = &mut operations[consumed..];
@@ -615,10 +571,9 @@ impl<'d, T: Instance> Twim<'d, T> {
615 &mut self, 571 &mut self,
616 address: u8, 572 address: u8,
617 mut operations: &mut [Operation<'_>], 573 mut operations: &mut [Operation<'_>],
618 stop: bool,
619 ) -> Result<(), Error> { 574 ) -> Result<(), Error> {
620 while !operations.is_empty() { 575 while !operations.is_empty() {
621 self.setup_operations(address, operations, None, false, stop)?; 576 self.setup_operations(address, operations, None, false)?;
622 self.blocking_wait(); 577 self.blocking_wait();
623 let consumed = self.check_operations(operations)?; 578 let consumed = self.check_operations(operations)?;
624 operations = &mut operations[consumed..]; 579 operations = &mut operations[consumed..];
@@ -634,12 +589,11 @@ impl<'d, T: Instance> Twim<'d, T> {
634 &mut self, 589 &mut self,
635 address: u8, 590 address: u8,
636 mut operations: &mut [Operation<'_>], 591 mut operations: &mut [Operation<'_>],
637 stop: bool,
638 timeout: Duration, 592 timeout: Duration,
639 ) -> Result<(), Error> { 593 ) -> Result<(), Error> {
640 let mut tx_ram_buffer = [MaybeUninit::uninit(); FORCE_COPY_BUFFER_SIZE]; 594 let mut tx_ram_buffer = [MaybeUninit::uninit(); FORCE_COPY_BUFFER_SIZE];
641 while !operations.is_empty() { 595 while !operations.is_empty() {
642 self.setup_operations(address, operations, Some(&mut tx_ram_buffer), false, stop)?; 596 self.setup_operations(address, operations, Some(&mut tx_ram_buffer), false)?;
643 self.blocking_wait_timeout(timeout)?; 597 self.blocking_wait_timeout(timeout)?;
644 let consumed = self.check_operations(operations)?; 598 let consumed = self.check_operations(operations)?;
645 operations = &mut operations[consumed..]; 599 operations = &mut operations[consumed..];
@@ -653,11 +607,10 @@ impl<'d, T: Instance> Twim<'d, T> {
653 &mut self, 607 &mut self,
654 address: u8, 608 address: u8,
655 mut operations: &mut [Operation<'_>], 609 mut operations: &mut [Operation<'_>],
656 stop: bool,
657 timeout: Duration, 610 timeout: Duration,
658 ) -> Result<(), Error> { 611 ) -> Result<(), Error> {
659 while !operations.is_empty() { 612 while !operations.is_empty() {
660 self.setup_operations(address, operations, None, false, stop)?; 613 self.setup_operations(address, operations, None, false)?;
661 self.blocking_wait_timeout(timeout)?; 614 self.blocking_wait_timeout(timeout)?;
662 let consumed = self.check_operations(operations)?; 615 let consumed = self.check_operations(operations)?;
663 operations = &mut operations[consumed..]; 616 operations = &mut operations[consumed..];
@@ -670,26 +623,17 @@ impl<'d, T: Instance> Twim<'d, T> {
670 /// Each buffer must have a length of at most 255 bytes on the nRF52832 623 /// Each buffer must have a length of at most 255 bytes on the nRF52832
671 /// and at most 65535 bytes on the nRF52840. 624 /// and at most 65535 bytes on the nRF52840.
672 /// 625 ///
673 /// If `stop` is set, the transaction will be terminated with a STOP 626 /// Consecutive `Read` operations are not supported because the Twim
674 /// condition and the Twim will be stopped. Otherwise, the bus will be 627 /// hardware does not support suspending after a read operation. (Setting
675 /// left busy via clock stretching and Twim will be suspended. 628 /// the SUSPEND task in response to a LASTRX event causes the final byte of
676 /// 629 /// the operation to be ACKed instead of NAKed. When the TWIM is resumed,
677 /// The nrf52832, nrf5340, and nrf9120 do not have hardware support for 630 /// one more byte will be read before the new operation is started, leading
678 /// suspending following a read operation therefore it is emulated by the 631 /// to an Overrun error if the RXD has not been updated, or an extraneous
679 /// interrupt handler. If the latency of servicing that interrupt is 632 /// byte read into the new buffer if the RXD has been updated.)
680 /// longer than a byte worth of clocks on the bus, the SCL clock will 633 pub async fn transaction(&mut self, address: u8, mut operations: &mut [Operation<'_>]) -> Result<(), Error> {
681 /// continue to run for one or more additional bytes. This applies to
682 /// consecutive read operations, certain write-read-write sequences, or
683 /// any sequence of operations ending in a read when `stop == false`.
684 pub async fn transaction(
685 &mut self,
686 address: u8,
687 mut operations: &mut [Operation<'_>],
688 stop: bool,
689 ) -> Result<(), Error> {
690 let mut tx_ram_buffer = [MaybeUninit::uninit(); FORCE_COPY_BUFFER_SIZE]; 634 let mut tx_ram_buffer = [MaybeUninit::uninit(); FORCE_COPY_BUFFER_SIZE];
691 while !operations.is_empty() { 635 while !operations.is_empty() {
692 self.setup_operations(address, operations, Some(&mut tx_ram_buffer), true, stop)?; 636 self.setup_operations(address, operations, Some(&mut tx_ram_buffer), true)?;
693 self.async_wait().await; 637 self.async_wait().await;
694 let consumed = self.check_operations(operations)?; 638 let consumed = self.check_operations(operations)?;
695 operations = &mut operations[consumed..]; 639 operations = &mut operations[consumed..];
@@ -702,10 +646,9 @@ impl<'d, T: Instance> Twim<'d, T> {
702 &mut self, 646 &mut self,
703 address: u8, 647 address: u8,
704 mut operations: &mut [Operation<'_>], 648 mut operations: &mut [Operation<'_>],
705 stop: bool,
706 ) -> Result<(), Error> { 649 ) -> Result<(), Error> {
707 while !operations.is_empty() { 650 while !operations.is_empty() {
708 self.setup_operations(address, operations, None, true, stop)?; 651 self.setup_operations(address, operations, None, true)?;
709 self.async_wait().await; 652 self.async_wait().await;
710 let consumed = self.check_operations(operations)?; 653 let consumed = self.check_operations(operations)?;
711 operations = &mut operations[consumed..]; 654 operations = &mut operations[consumed..];
@@ -720,12 +663,12 @@ impl<'d, T: Instance> Twim<'d, T> {
720 /// The buffer must have a length of at most 255 bytes on the nRF52832 663 /// The buffer must have a length of at most 255 bytes on the nRF52832
721 /// and at most 65535 bytes on the nRF52840. 664 /// and at most 65535 bytes on the nRF52840.
722 pub fn blocking_write(&mut self, address: u8, buffer: &[u8]) -> Result<(), Error> { 665 pub fn blocking_write(&mut self, address: u8, buffer: &[u8]) -> Result<(), Error> {
723 self.blocking_transaction(address, &mut [Operation::Write(buffer)], true) 666 self.blocking_transaction(address, &mut [Operation::Write(buffer)])
724 } 667 }
725 668
726 /// Same as [`blocking_write`](Twim::blocking_write) but will fail instead of copying data into RAM. Consult the module level documentation to learn more. 669 /// Same as [`blocking_write`](Twim::blocking_write) but will fail instead of copying data into RAM. Consult the module level documentation to learn more.
727 pub fn blocking_write_from_ram(&mut self, address: u8, buffer: &[u8]) -> Result<(), Error> { 670 pub fn blocking_write_from_ram(&mut self, address: u8, buffer: &[u8]) -> Result<(), Error> {
728 self.blocking_transaction_from_ram(address, &mut [Operation::Write(buffer)], true) 671 self.blocking_transaction_from_ram(address, &mut [Operation::Write(buffer)])
729 } 672 }
730 673
731 /// Read from an I2C slave. 674 /// Read from an I2C slave.
@@ -733,7 +676,7 @@ impl<'d, T: Instance> Twim<'d, T> {
733 /// The buffer must have a length of at most 255 bytes on the nRF52832 676 /// The buffer must have a length of at most 255 bytes on the nRF52832
734 /// and at most 65535 bytes on the nRF52840. 677 /// and at most 65535 bytes on the nRF52840.
735 pub fn blocking_read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error> { 678 pub fn blocking_read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error> {
736 self.blocking_transaction(address, &mut [Operation::Read(buffer)], true) 679 self.blocking_transaction(address, &mut [Operation::Read(buffer)])
737 } 680 }
738 681
739 /// Write data to an I2C slave, then read data from the slave without 682 /// Write data to an I2C slave, then read data from the slave without
@@ -742,11 +685,7 @@ impl<'d, T: Instance> Twim<'d, T> {
742 /// The buffers must have a length of at most 255 bytes on the nRF52832 685 /// The buffers must have a length of at most 255 bytes on the nRF52832
743 /// and at most 65535 bytes on the nRF52840. 686 /// and at most 65535 bytes on the nRF52840.
744 pub fn blocking_write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Error> { 687 pub fn blocking_write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Error> {
745 self.blocking_transaction( 688 self.blocking_transaction(address, &mut [Operation::Write(wr_buffer), Operation::Read(rd_buffer)])
746 address,
747 &mut [Operation::Write(wr_buffer), Operation::Read(rd_buffer)],
748 true,
749 )
750 } 689 }
751 690
752 /// Same as [`blocking_write_read`](Twim::blocking_write_read) but will fail instead of copying data into RAM. Consult the module level documentation to learn more. 691 /// Same as [`blocking_write_read`](Twim::blocking_write_read) but will fail instead of copying data into RAM. Consult the module level documentation to learn more.
@@ -756,11 +695,7 @@ impl<'d, T: Instance> Twim<'d, T> {
756 wr_buffer: &[u8], 695 wr_buffer: &[u8],
757 rd_buffer: &mut [u8], 696 rd_buffer: &mut [u8],
758 ) -> Result<(), Error> { 697 ) -> Result<(), Error> {
759 self.blocking_transaction_from_ram( 698 self.blocking_transaction_from_ram(address, &mut [Operation::Write(wr_buffer), Operation::Read(rd_buffer)])
760 address,
761 &mut [Operation::Write(wr_buffer), Operation::Read(rd_buffer)],
762 true,
763 )
764 } 699 }
765 700
766 // =========================================== 701 // ===========================================
@@ -770,7 +705,7 @@ impl<'d, T: Instance> Twim<'d, T> {
770 /// See [`blocking_write`]. 705 /// See [`blocking_write`].
771 #[cfg(feature = "time")] 706 #[cfg(feature = "time")]
772 pub fn blocking_write_timeout(&mut self, address: u8, buffer: &[u8], timeout: Duration) -> Result<(), Error> { 707 pub fn blocking_write_timeout(&mut self, address: u8, buffer: &[u8], timeout: Duration) -> Result<(), Error> {
773 self.blocking_transaction_timeout(address, &mut [Operation::Write(buffer)], true, timeout) 708 self.blocking_transaction_timeout(address, &mut [Operation::Write(buffer)], timeout)
774 } 709 }
775 710
776 /// Same as [`blocking_write`](Twim::blocking_write) but will fail instead of copying data into RAM. Consult the module level documentation to learn more. 711 /// Same as [`blocking_write`](Twim::blocking_write) but will fail instead of copying data into RAM. Consult the module level documentation to learn more.
@@ -781,7 +716,7 @@ impl<'d, T: Instance> Twim<'d, T> {
781 buffer: &[u8], 716 buffer: &[u8],
782 timeout: Duration, 717 timeout: Duration,
783 ) -> Result<(), Error> { 718 ) -> Result<(), Error> {
784 self.blocking_transaction_from_ram_timeout(address, &mut [Operation::Write(buffer)], true, timeout) 719 self.blocking_transaction_from_ram_timeout(address, &mut [Operation::Write(buffer)], timeout)
785 } 720 }
786 721
787 /// Read from an I2C slave. 722 /// Read from an I2C slave.
@@ -790,7 +725,7 @@ impl<'d, T: Instance> Twim<'d, T> {
790 /// and at most 65535 bytes on the nRF52840. 725 /// and at most 65535 bytes on the nRF52840.
791 #[cfg(feature = "time")] 726 #[cfg(feature = "time")]
792 pub fn blocking_read_timeout(&mut self, address: u8, buffer: &mut [u8], timeout: Duration) -> Result<(), Error> { 727 pub fn blocking_read_timeout(&mut self, address: u8, buffer: &mut [u8], timeout: Duration) -> Result<(), Error> {
793 self.blocking_transaction_timeout(address, &mut [Operation::Read(buffer)], true, timeout) 728 self.blocking_transaction_timeout(address, &mut [Operation::Read(buffer)], timeout)
794 } 729 }
795 730
796 /// Write data to an I2C slave, then read data from the slave without 731 /// Write data to an I2C slave, then read data from the slave without
@@ -809,7 +744,6 @@ impl<'d, T: Instance> Twim<'d, T> {
809 self.blocking_transaction_timeout( 744 self.blocking_transaction_timeout(
810 address, 745 address,
811 &mut [Operation::Write(wr_buffer), Operation::Read(rd_buffer)], 746 &mut [Operation::Write(wr_buffer), Operation::Read(rd_buffer)],
812 true,
813 timeout, 747 timeout,
814 ) 748 )
815 } 749 }
@@ -826,7 +760,6 @@ impl<'d, T: Instance> Twim<'d, T> {
826 self.blocking_transaction_from_ram_timeout( 760 self.blocking_transaction_from_ram_timeout(
827 address, 761 address,
828 &mut [Operation::Write(wr_buffer), Operation::Read(rd_buffer)], 762 &mut [Operation::Write(wr_buffer), Operation::Read(rd_buffer)],
829 true,
830 timeout, 763 timeout,
831 ) 764 )
832 } 765 }
@@ -838,7 +771,7 @@ impl<'d, T: Instance> Twim<'d, T> {
838 /// The buffer must have a length of at most 255 bytes on the nRF52832 771 /// The buffer must have a length of at most 255 bytes on the nRF52832
839 /// and at most 65535 bytes on the nRF52840. 772 /// and at most 65535 bytes on the nRF52840.
840 pub async fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error> { 773 pub async fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error> {
841 self.transaction(address, &mut [Operation::Read(buffer)], true).await 774 self.transaction(address, &mut [Operation::Read(buffer)]).await
842 } 775 }
843 776
844 /// Write to an I2C slave. 777 /// Write to an I2C slave.
@@ -846,12 +779,12 @@ impl<'d, T: Instance> Twim<'d, T> {
846 /// The buffer must have a length of at most 255 bytes on the nRF52832 779 /// The buffer must have a length of at most 255 bytes on the nRF52832
847 /// and at most 65535 bytes on the nRF52840. 780 /// and at most 65535 bytes on the nRF52840.
848 pub async fn write(&mut self, address: u8, buffer: &[u8]) -> Result<(), Error> { 781 pub async fn write(&mut self, address: u8, buffer: &[u8]) -> Result<(), Error> {
849 self.transaction(address, &mut [Operation::Write(buffer)], true).await 782 self.transaction(address, &mut [Operation::Write(buffer)]).await
850 } 783 }
851 784
852 /// Same as [`write`](Twim::write) but will fail instead of copying data into RAM. Consult the module level documentation to learn more. 785 /// Same as [`write`](Twim::write) but will fail instead of copying data into RAM. Consult the module level documentation to learn more.
853 pub async fn write_from_ram(&mut self, address: u8, buffer: &[u8]) -> Result<(), Error> { 786 pub async fn write_from_ram(&mut self, address: u8, buffer: &[u8]) -> Result<(), Error> {
854 self.transaction_from_ram(address, &mut [Operation::Write(buffer)], true) 787 self.transaction_from_ram(address, &mut [Operation::Write(buffer)])
855 .await 788 .await
856 } 789 }
857 790
@@ -861,12 +794,8 @@ impl<'d, T: Instance> Twim<'d, T> {
861 /// The buffers must have a length of at most 255 bytes on the nRF52832 794 /// The buffers must have a length of at most 255 bytes on the nRF52832
862 /// and at most 65535 bytes on the nRF52840. 795 /// and at most 65535 bytes on the nRF52840.
863 pub async fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Error> { 796 pub async fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Error> {
864 self.transaction( 797 self.transaction(address, &mut [Operation::Write(wr_buffer), Operation::Read(rd_buffer)])
865 address, 798 .await
866 &mut [Operation::Write(wr_buffer), Operation::Read(rd_buffer)],
867 true,
868 )
869 .await
870 } 799 }
871 800
872 /// Same as [`write_read`](Twim::write_read) but will fail instead of copying data into RAM. Consult the module level documentation to learn more. 801 /// Same as [`write_read`](Twim::write_read) but will fail instead of copying data into RAM. Consult the module level documentation to learn more.
@@ -876,12 +805,8 @@ impl<'d, T: Instance> Twim<'d, T> {
876 wr_buffer: &[u8], 805 wr_buffer: &[u8],
877 rd_buffer: &mut [u8], 806 rd_buffer: &mut [u8],
878 ) -> Result<(), Error> { 807 ) -> Result<(), Error> {
879 self.transaction_from_ram( 808 self.transaction_from_ram(address, &mut [Operation::Write(wr_buffer), Operation::Read(rd_buffer)])
880 address, 809 .await
881 &mut [Operation::Write(wr_buffer), Operation::Read(rd_buffer)],
882 true,
883 )
884 .await
885 } 810 }
886} 811}
887 812
@@ -999,13 +924,13 @@ impl<'d, T: Instance> embedded_hal_1::i2c::ErrorType for Twim<'d, T> {
999 924
1000impl<'d, T: Instance> embedded_hal_1::i2c::I2c for Twim<'d, T> { 925impl<'d, T: Instance> embedded_hal_1::i2c::I2c for Twim<'d, T> {
1001 fn transaction(&mut self, address: u8, operations: &mut [Operation<'_>]) -> Result<(), Self::Error> { 926 fn transaction(&mut self, address: u8, operations: &mut [Operation<'_>]) -> Result<(), Self::Error> {
1002 self.blocking_transaction(address, operations, true) 927 self.blocking_transaction(address, operations)
1003 } 928 }
1004} 929}
1005 930
1006impl<'d, T: Instance> embedded_hal_async::i2c::I2c for Twim<'d, T> { 931impl<'d, T: Instance> embedded_hal_async::i2c::I2c for Twim<'d, T> {
1007 async fn transaction(&mut self, address: u8, operations: &mut [Operation<'_>]) -> Result<(), Self::Error> { 932 async fn transaction(&mut self, address: u8, operations: &mut [Operation<'_>]) -> Result<(), Self::Error> {
1008 self.transaction(address, operations, true).await 933 self.transaction(address, operations).await
1009 } 934 }
1010} 935}
1011 936