Skip to content

Commit bf89b5e

Browse files
hannobraunYatekii
authored andcommitted
Remove SpimExt
1 parent 101960f commit bf89b5e

File tree

6 files changed

+19
-29
lines changed

6 files changed

+19
-29
lines changed

boards/nRF52840-DK/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl Board {
318318

319319
// The nRF52840-DK has an 64MB SPI flash on board which can be interfaced through SPI or Quad SPI.
320320
// As for now, only the normal SPI mode is available, so we are using this for the interface.
321-
let flash_spim = p.SPIM2.constrain(spim::Pins {
321+
let flash_spim = Spim::new(p.SPIM2, spim::Pins {
322322
sck : pins0.p0_19.into_push_pull_output(Level::Low).degrade(),
323323
mosi: Some(pins0.p0_20.into_push_pull_output(Level::Low).degrade()),
324324
miso: Some(pins0.p0_21.into_floating_input().degrade()),

examples/spi-demo/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use nrf52832_hal::gpio::p0::*;
1515
use nrf52832_hal::gpio::Level;
1616
use nrf52832_hal::gpio::*;
1717
use nrf52832_hal::prelude::GpioExt;
18+
use nrf52832_hal::spim::Spim;
1819

1920
/// SPIM demonstation code.
2021
/// connect a resistor between pin 22 and 23 on to feed MOSI direct back to MISO
@@ -48,7 +49,8 @@ fn main() -> ! {
4849
miso: Some(spimiso),
4950
mosi: Some(spimosi),
5051
};
51-
let mut spi = p.SPIM2.constrain(
52+
let mut spi = Spim::new(
53+
p.SPIM2,
5254
pins,
5355
nrf52832_hal::spim::Frequency::K500,
5456
nrf52832_hal::spim::MODE_0,
@@ -59,7 +61,6 @@ fn main() -> ! {
5961
// Read only test vector
6062
let test_vec1 = *reference_data;
6163
let mut readbuf = [0; 255];
62-
use nrf52832_hal::spim::SpimExt;
6364

6465
// This will write 8 bytes, then shift out ORC
6566

nrf52-hal-common/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ pub mod prelude {
2929

3030
pub use crate::clocks::ClocksExt;
3131
pub use crate::gpio::GpioExt;
32-
pub use crate::spim::SpimExt;
3332
pub use crate::time::U32Ext;
3433
pub use crate::timer::TimerExt;
3534
pub use crate::twim::TwimExt;

nrf52-hal-common/src/spim.rs

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,6 @@ use crate::prelude::*;
1818
use crate::target_constants::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE};
1919
use crate::{slice_in_ram, DmaSlice};
2020

21-
pub trait SpimExt: Deref<Target = spim0::RegisterBlock> + Sized {
22-
fn constrain(self, pins: Pins, frequency: Frequency, mode: Mode, orc: u8) -> Spim<Self>;
23-
}
24-
25-
macro_rules! impl_spim_ext {
26-
($($spim:ty,)*) => {
27-
$(
28-
impl SpimExt for $spim {
29-
fn constrain(self, pins: Pins, frequency: Frequency, mode: Mode, orc: u8) -> Spim<Self> {
30-
Spim::new(self, pins, frequency, mode, orc)
31-
}
32-
}
33-
)*
34-
}
35-
}
36-
37-
impl_spim_ext!(SPIM0,);
38-
39-
#[cfg(any(feature = "52832", feature = "52840"))]
40-
impl_spim_ext!(SPIM1, SPIM2,);
4121

4222
/// Interface to a SPIM instance
4323
///
@@ -49,7 +29,7 @@ pub struct Spim<T>(T);
4929

5030
impl<T> embedded_hal::blocking::spi::Transfer<u8> for Spim<T>
5131
where
52-
T: SpimExt,
32+
T: Instance,
5333
{
5434
type Error = Error;
5535

@@ -70,7 +50,7 @@ where
7050

7151
impl<T> embedded_hal::blocking::spi::Write<u8> for Spim<T>
7252
where
73-
T: SpimExt,
53+
T: Instance,
7454
{
7555
type Error = Error;
7656

@@ -96,7 +76,7 @@ where
9676
}
9777
impl<T> Spim<T>
9878
where
99-
T: SpimExt,
79+
T: Instance,
10080
{
10181
fn spi_dma_no_copy(&mut self, chunk: &[u8]) -> Result<(), Error> {
10282
self.do_spi_dma_transfer(DmaSlice::from_slice(chunk), DmaSlice::null())
@@ -428,3 +408,15 @@ fn ram_slice_check(slice: &[u8]) -> Result<(), Error> {
428408
Err(Error::DMABufferNotInDataMemory)
429409
}
430410
}
411+
412+
413+
/// Implemented by all SPIM instances
414+
pub trait Instance: Deref<Target = spim0::RegisterBlock> {}
415+
416+
impl Instance for SPIM0 {}
417+
418+
#[cfg(any(feature = "52832", feature = "52840"))]
419+
impl Instance for SPIM1 {}
420+
421+
#[cfg(any(feature = "52832", feature = "52840"))]
422+
impl Instance for SPIM2 {}

nrf52810-hal/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pub mod prelude {
1010

1111
pub use crate::clocks::ClocksExt;
1212
pub use crate::gpio::GpioExt;
13-
pub use crate::spim::SpimExt;
1413
pub use crate::time::U32Ext;
1514
pub use crate::timer::TimerExt;
1615
pub use crate::uarte::UarteExt;

nrf52840-hal/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pub mod prelude {
1010

1111
pub use crate::clocks::ClocksExt;
1212
pub use crate::gpio::GpioExt;
13-
pub use crate::spim::SpimExt;
1413
pub use crate::time::U32Ext;
1514
pub use crate::timer::TimerExt;
1615
pub use crate::uarte::UarteExt;

0 commit comments

Comments
 (0)