From d5ed5c3ef3d3bc2ad6f22a1f67dfd8021c259621 Mon Sep 17 00:00:00 2001 From: Bob McWhirter Date: Tue, 20 Jul 2021 09:52:03 -0400 Subject: [PATCH] Split up the nRF impls for SPI traits. --- embassy-nrf/src/spim.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index 47d7c5f9..c3d4c5b3 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs @@ -9,7 +9,7 @@ use embassy::traits; use embassy::util::{AtomicWaker, Unborrow}; use embassy_extras::unborrow; use futures::future::poll_fn; -use traits::spi::FullDuplex; +use traits::spi::{ Spi, Read, Write, FullDuplex}; use crate::gpio; use crate::gpio::sealed::Pin as _; @@ -177,22 +177,31 @@ impl<'d, T: Instance> Drop for Spim<'d, T> { } } -impl<'d, T: Instance> FullDuplex for Spim<'d, T> { +impl<'d, T: Instance> Spi for Spim<'d, T> { type Error = Error; +} +impl<'d, T: Instance> Read for Spim<'d, T> { #[rustfmt::skip] - type WriteFuture<'a> where Self: 'a = impl Future> + 'a; - #[rustfmt::skip] - type ReadFuture<'a> where Self: 'a = impl Future> + 'a; - #[rustfmt::skip] - type WriteReadFuture<'a> where Self: 'a = impl Future> + 'a; + type ReadFuture<'a> where Self: 'a = impl Future> + 'a; fn read<'a>(&'a mut self, data: &'a mut [u8]) -> Self::ReadFuture<'a> { self.read_write(data, &[]) } +} + +impl<'d, T: Instance> Write for Spim<'d, T> { + #[rustfmt::skip] + type WriteFuture<'a> where Self: 'a = impl Future> + 'a; + fn write<'a>(&'a mut self, data: &'a [u8]) -> Self::WriteFuture<'a> { self.read_write(&mut [], data) } +} + +impl<'d, T: Instance> FullDuplex for Spim<'d, T> { + #[rustfmt::skip] + type WriteReadFuture<'a> where Self: 'a = impl Future> + 'a; fn read_write<'a>(&'a mut self, rx: &'a mut [u8], tx: &'a [u8]) -> Self::WriteReadFuture<'a> { async move {