aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/spim.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-03-26 16:01:37 +0100
committerDario Nieuwenhuis <[email protected]>2025-03-27 15:18:06 +0100
commitd41eeeae79388f219bf6a84e2f7bde9f6b532516 (patch)
tree678b6fc732216e529dc38e6f65b72a309917ac32 /embassy-nrf/src/spim.rs
parent9edf5b7f049f95742b60b041e4443967d8a6b708 (diff)
Remove Peripheral trait, rename PeripheralRef->Peri.
Diffstat (limited to 'embassy-nrf/src/spim.rs')
-rw-r--r--embassy-nrf/src/spim.rs60
1 files changed, 24 insertions, 36 deletions
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs
index bd193cfe8..59f5b6d58 100644
--- a/embassy-nrf/src/spim.rs
+++ b/embassy-nrf/src/spim.rs
@@ -10,7 +10,7 @@ use core::sync::atomic::{compiler_fence, Ordering};
10use core::task::Poll; 10use core::task::Poll;
11 11
12use embassy_embedded_hal::SetConfig; 12use embassy_embedded_hal::SetConfig;
13use embassy_hal_internal::{into_ref, PeripheralRef}; 13use embassy_hal_internal::{Peri, PeripheralType};
14use embassy_sync::waitqueue::AtomicWaker; 14use embassy_sync::waitqueue::AtomicWaker;
15pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; 15pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
16pub use pac::spim::vals::{Frequency, Order as BitOrder}; 16pub use pac::spim::vals::{Frequency, Order as BitOrder};
@@ -21,7 +21,7 @@ use crate::interrupt::typelevel::Interrupt;
21use crate::pac::gpio::vals as gpiovals; 21use crate::pac::gpio::vals as gpiovals;
22use crate::pac::spim::vals; 22use crate::pac::spim::vals;
23use crate::util::slice_in_ram_or; 23use crate::util::slice_in_ram_or;
24use crate::{interrupt, pac, Peripheral}; 24use crate::{interrupt, pac};
25 25
26/// SPIM error 26/// SPIM error
27#[derive(Debug, Clone, Copy, PartialEq, Eq)] 27#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -100,73 +100,61 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl
100 100
101/// SPIM driver. 101/// SPIM driver.
102pub struct Spim<'d, T: Instance> { 102pub struct Spim<'d, T: Instance> {
103 _p: PeripheralRef<'d, T>, 103 _p: Peri<'d, T>,
104} 104}
105 105
106impl<'d, T: Instance> Spim<'d, T> { 106impl<'d, T: Instance> Spim<'d, T> {
107 /// Create a new SPIM driver. 107 /// Create a new SPIM driver.
108 pub fn new( 108 pub fn new(
109 spim: impl Peripheral<P = T> + 'd, 109 spim: Peri<'d, T>,
110 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 110 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
111 sck: impl Peripheral<P = impl GpioPin> + 'd, 111 sck: Peri<'d, impl GpioPin>,
112 miso: impl Peripheral<P = impl GpioPin> + 'd, 112 miso: Peri<'d, impl GpioPin>,
113 mosi: impl Peripheral<P = impl GpioPin> + 'd, 113 mosi: Peri<'d, impl GpioPin>,
114 config: Config, 114 config: Config,
115 ) -> Self { 115 ) -> Self {
116 into_ref!(sck, miso, mosi); 116 Self::new_inner(spim, Some(sck.into()), Some(miso.into()), Some(mosi.into()), config)
117 Self::new_inner(
118 spim,
119 Some(sck.map_into()),
120 Some(miso.map_into()),
121 Some(mosi.map_into()),
122 config,
123 )
124 } 117 }
125 118
126 /// Create a new SPIM driver, capable of TX only (MOSI only). 119 /// Create a new SPIM driver, capable of TX only (MOSI only).
127 pub fn new_txonly( 120 pub fn new_txonly(
128 spim: impl Peripheral<P = T> + 'd, 121 spim: Peri<'d, T>,
129 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 122 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
130 sck: impl Peripheral<P = impl GpioPin> + 'd, 123 sck: Peri<'d, impl GpioPin>,
131 mosi: impl Peripheral<P = impl GpioPin> + 'd, 124 mosi: Peri<'d, impl GpioPin>,
132 config: Config, 125 config: Config,
133 ) -> Self { 126 ) -> Self {
134 into_ref!(sck, mosi); 127 Self::new_inner(spim, Some(sck.into()), None, Some(mosi.into()), config)
135 Self::new_inner(spim, Some(sck.map_into()), None, Some(mosi.map_into()), config)
136 } 128 }
137 129
138 /// Create a new SPIM driver, capable of RX only (MISO only). 130 /// Create a new SPIM driver, capable of RX only (MISO only).
139 pub fn new_rxonly( 131 pub fn new_rxonly(
140 spim: impl Peripheral<P = T> + 'd, 132 spim: Peri<'d, T>,
141 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 133 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
142 sck: impl Peripheral<P = impl GpioPin> + 'd, 134 sck: Peri<'d, impl GpioPin>,
143 miso: impl Peripheral<P = impl GpioPin> + 'd, 135 miso: Peri<'d, impl GpioPin>,
144 config: Config, 136 config: Config,
145 ) -> Self { 137 ) -> Self {
146 into_ref!(sck, miso); 138 Self::new_inner(spim, Some(sck.into()), Some(miso.into()), None, config)
147 Self::new_inner(spim, Some(sck.map_into()), Some(miso.map_into()), None, config)
148 } 139 }
149 140
150 /// Create a new SPIM driver, capable of TX only (MOSI only), without SCK pin. 141 /// Create a new SPIM driver, capable of TX only (MOSI only), without SCK pin.
151 pub fn new_txonly_nosck( 142 pub fn new_txonly_nosck(
152 spim: impl Peripheral<P = T> + 'd, 143 spim: Peri<'d, T>,
153 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, 144 _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
154 mosi: impl Peripheral<P = impl GpioPin> + 'd, 145 mosi: Peri<'d, impl GpioPin>,
155 config: Config, 146 config: Config,
156 ) -> Self { 147 ) -> Self {
157 into_ref!(mosi); 148 Self::new_inner(spim, None, None, Some(mosi.into()), config)
158 Self::new_inner(spim, None, None, Some(mosi.map_into()), config)
159 } 149 }
160 150
161 fn new_inner( 151 fn new_inner(
162 spim: impl Peripheral<P = T> + 'd, 152 spim: Peri<'d, T>,
163 sck: Option<PeripheralRef<'d, AnyPin>>, 153 sck: Option<Peri<'d, AnyPin>>,
164 miso: Option<PeripheralRef<'d, AnyPin>>, 154 miso: Option<Peri<'d, AnyPin>>,
165 mosi: Option<PeripheralRef<'d, AnyPin>>, 155 mosi: Option<Peri<'d, AnyPin>>,
166 config: Config, 156 config: Config,
167 ) -> Self { 157 ) -> Self {
168 into_ref!(spim);
169
170 let r = T::regs(); 158 let r = T::regs();
171 159
172 // Configure pins 160 // Configure pins
@@ -511,7 +499,7 @@ pub(crate) trait SealedInstance {
511 499
512/// SPIM peripheral instance 500/// SPIM peripheral instance
513#[allow(private_bounds)] 501#[allow(private_bounds)]
514pub trait Instance: Peripheral<P = Self> + SealedInstance + 'static { 502pub trait Instance: SealedInstance + PeripheralType + 'static {
515 /// Interrupt for this peripheral. 503 /// Interrupt for this peripheral.
516 type Interrupt: interrupt::typelevel::Interrupt; 504 type Interrupt: interrupt::typelevel::Interrupt;
517} 505}