diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-01-03 16:50:58 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-01-03 16:50:58 +0000 |
| commit | 4f3e1fa7380a1cf95d15c010b5d901efed15cf3c (patch) | |
| tree | 6c18efc608af0dd10fb405255db7faad20833254 | |
| parent | 3b6eaf414a92114037a40dcb3ce37a4191c57a2b (diff) | |
| parent | bdaf722cb899504032816d09de63c0f44b2776e8 (diff) | |
Merge pull request #2395 from swanandx/nrf-tx-nosck
add new_tx_nosck for nrf
| -rw-r--r-- | embassy-nrf/src/spim.rs | 31 | ||||
| -rw-r--r-- | embassy-nrf/src/spis.rs | 42 |
2 files changed, 59 insertions, 14 deletions
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index 5d3c3268c..b0723d495 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs | |||
| @@ -99,7 +99,7 @@ impl<'d, T: Instance> Spim<'d, T> { | |||
| 99 | into_ref!(sck, miso, mosi); | 99 | into_ref!(sck, miso, mosi); |
| 100 | Self::new_inner( | 100 | Self::new_inner( |
| 101 | spim, | 101 | spim, |
| 102 | sck.map_into(), | 102 | Some(sck.map_into()), |
| 103 | Some(miso.map_into()), | 103 | Some(miso.map_into()), |
| 104 | Some(mosi.map_into()), | 104 | Some(mosi.map_into()), |
| 105 | config, | 105 | config, |
| @@ -115,7 +115,7 @@ impl<'d, T: Instance> Spim<'d, T> { | |||
| 115 | config: Config, | 115 | config: Config, |
| 116 | ) -> Self { | 116 | ) -> Self { |
| 117 | into_ref!(sck, mosi); | 117 | into_ref!(sck, mosi); |
| 118 | Self::new_inner(spim, sck.map_into(), None, Some(mosi.map_into()), config) | 118 | Self::new_inner(spim, Some(sck.map_into()), None, Some(mosi.map_into()), config) |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | /// Create a new SPIM driver, capable of RX only (MISO only). | 121 | /// Create a new SPIM driver, capable of RX only (MISO only). |
| @@ -127,12 +127,23 @@ impl<'d, T: Instance> Spim<'d, T> { | |||
| 127 | config: Config, | 127 | config: Config, |
| 128 | ) -> Self { | 128 | ) -> Self { |
| 129 | into_ref!(sck, miso); | 129 | into_ref!(sck, miso); |
| 130 | Self::new_inner(spim, sck.map_into(), Some(miso.map_into()), None, config) | 130 | Self::new_inner(spim, Some(sck.map_into()), Some(miso.map_into()), None, config) |
| 131 | } | ||
| 132 | |||
| 133 | /// Create a new SPIM driver, capable of TX only (MOSI only), without SCK pin. | ||
| 134 | pub fn new_txonly_nosck( | ||
| 135 | spim: impl Peripheral<P = T> + 'd, | ||
| 136 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | ||
| 137 | mosi: impl Peripheral<P = impl GpioPin> + 'd, | ||
| 138 | config: Config, | ||
| 139 | ) -> Self { | ||
| 140 | into_ref!(mosi); | ||
| 141 | Self::new_inner(spim, None, None, Some(mosi.map_into()), config) | ||
| 131 | } | 142 | } |
| 132 | 143 | ||
| 133 | fn new_inner( | 144 | fn new_inner( |
| 134 | spim: impl Peripheral<P = T> + 'd, | 145 | spim: impl Peripheral<P = T> + 'd, |
| 135 | sck: PeripheralRef<'d, AnyPin>, | 146 | sck: Option<PeripheralRef<'d, AnyPin>>, |
| 136 | miso: Option<PeripheralRef<'d, AnyPin>>, | 147 | miso: Option<PeripheralRef<'d, AnyPin>>, |
| 137 | mosi: Option<PeripheralRef<'d, AnyPin>>, | 148 | mosi: Option<PeripheralRef<'d, AnyPin>>, |
| 138 | config: Config, | 149 | config: Config, |
| @@ -142,7 +153,9 @@ impl<'d, T: Instance> Spim<'d, T> { | |||
| 142 | let r = T::regs(); | 153 | let r = T::regs(); |
| 143 | 154 | ||
| 144 | // Configure pins | 155 | // Configure pins |
| 145 | sck.conf().write(|w| w.dir().output().drive().h0h1()); | 156 | if let Some(sck) = &sck { |
| 157 | sck.conf().write(|w| w.dir().output().drive().h0h1()); | ||
| 158 | } | ||
| 146 | if let Some(mosi) = &mosi { | 159 | if let Some(mosi) = &mosi { |
| 147 | mosi.conf().write(|w| w.dir().output().drive().h0h1()); | 160 | mosi.conf().write(|w| w.dir().output().drive().h0h1()); |
| 148 | } | 161 | } |
| @@ -152,13 +165,17 @@ impl<'d, T: Instance> Spim<'d, T> { | |||
| 152 | 165 | ||
| 153 | match config.mode.polarity { | 166 | match config.mode.polarity { |
| 154 | Polarity::IdleHigh => { | 167 | Polarity::IdleHigh => { |
| 155 | sck.set_high(); | 168 | if let Some(sck) = &sck { |
| 169 | sck.set_high(); | ||
| 170 | } | ||
| 156 | if let Some(mosi) = &mosi { | 171 | if let Some(mosi) = &mosi { |
| 157 | mosi.set_high(); | 172 | mosi.set_high(); |
| 158 | } | 173 | } |
| 159 | } | 174 | } |
| 160 | Polarity::IdleLow => { | 175 | Polarity::IdleLow => { |
| 161 | sck.set_low(); | 176 | if let Some(sck) = &sck { |
| 177 | sck.set_low(); | ||
| 178 | } | ||
| 162 | if let Some(mosi) = &mosi { | 179 | if let Some(mosi) = &mosi { |
| 163 | mosi.set_low(); | 180 | mosi.set_low(); |
| 164 | } | 181 | } |
diff --git a/embassy-nrf/src/spis.rs b/embassy-nrf/src/spis.rs index e202c6c27..3aad25298 100644 --- a/embassy-nrf/src/spis.rs +++ b/embassy-nrf/src/spis.rs | |||
| @@ -105,7 +105,7 @@ impl<'d, T: Instance> Spis<'d, T> { | |||
| 105 | Self::new_inner( | 105 | Self::new_inner( |
| 106 | spis, | 106 | spis, |
| 107 | cs.map_into(), | 107 | cs.map_into(), |
| 108 | sck.map_into(), | 108 | Some(sck.map_into()), |
| 109 | Some(miso.map_into()), | 109 | Some(miso.map_into()), |
| 110 | Some(mosi.map_into()), | 110 | Some(mosi.map_into()), |
| 111 | config, | 111 | config, |
| @@ -122,7 +122,14 @@ impl<'d, T: Instance> Spis<'d, T> { | |||
| 122 | config: Config, | 122 | config: Config, |
| 123 | ) -> Self { | 123 | ) -> Self { |
| 124 | into_ref!(cs, sck, miso); | 124 | into_ref!(cs, sck, miso); |
| 125 | Self::new_inner(spis, cs.map_into(), sck.map_into(), Some(miso.map_into()), None, config) | 125 | Self::new_inner( |
| 126 | spis, | ||
| 127 | cs.map_into(), | ||
| 128 | Some(sck.map_into()), | ||
| 129 | Some(miso.map_into()), | ||
| 130 | None, | ||
| 131 | config, | ||
| 132 | ) | ||
| 126 | } | 133 | } |
| 127 | 134 | ||
| 128 | /// Create a new SPIS driver, capable of RX only (MOSI only). | 135 | /// Create a new SPIS driver, capable of RX only (MOSI only). |
| @@ -135,28 +142,49 @@ impl<'d, T: Instance> Spis<'d, T> { | |||
| 135 | config: Config, | 142 | config: Config, |
| 136 | ) -> Self { | 143 | ) -> Self { |
| 137 | into_ref!(cs, sck, mosi); | 144 | into_ref!(cs, sck, mosi); |
| 138 | Self::new_inner(spis, cs.map_into(), sck.map_into(), None, Some(mosi.map_into()), config) | 145 | Self::new_inner( |
| 146 | spis, | ||
| 147 | cs.map_into(), | ||
| 148 | Some(sck.map_into()), | ||
| 149 | None, | ||
| 150 | Some(mosi.map_into()), | ||
| 151 | config, | ||
| 152 | ) | ||
| 153 | } | ||
| 154 | |||
| 155 | /// Create a new SPIS driver, capable of TX only (MISO only) without SCK pin. | ||
| 156 | pub fn new_txonly_nosck( | ||
| 157 | spis: impl Peripheral<P = T> + 'd, | ||
| 158 | _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, | ||
| 159 | cs: impl Peripheral<P = impl GpioPin> + 'd, | ||
| 160 | miso: impl Peripheral<P = impl GpioPin> + 'd, | ||
| 161 | config: Config, | ||
| 162 | ) -> Self { | ||
| 163 | into_ref!(cs, miso); | ||
| 164 | Self::new_inner(spis, cs.map_into(), None, Some(miso.map_into()), None, config) | ||
| 139 | } | 165 | } |
| 140 | 166 | ||
| 141 | fn new_inner( | 167 | fn new_inner( |
| 142 | spis: impl Peripheral<P = T> + 'd, | 168 | spis: impl Peripheral<P = T> + 'd, |
| 143 | cs: PeripheralRef<'d, AnyPin>, | 169 | cs: PeripheralRef<'d, AnyPin>, |
| 144 | sck: PeripheralRef<'d, AnyPin>, | 170 | sck: Option<PeripheralRef<'d, AnyPin>>, |
| 145 | miso: Option<PeripheralRef<'d, AnyPin>>, | 171 | miso: Option<PeripheralRef<'d, AnyPin>>, |
| 146 | mosi: Option<PeripheralRef<'d, AnyPin>>, | 172 | mosi: Option<PeripheralRef<'d, AnyPin>>, |
| 147 | config: Config, | 173 | config: Config, |
| 148 | ) -> Self { | 174 | ) -> Self { |
| 149 | compiler_fence(Ordering::SeqCst); | 175 | compiler_fence(Ordering::SeqCst); |
| 150 | 176 | ||
| 151 | into_ref!(spis, cs, sck); | 177 | into_ref!(spis, cs); |
| 152 | 178 | ||
| 153 | let r = T::regs(); | 179 | let r = T::regs(); |
| 154 | 180 | ||
| 155 | // Configure pins. | 181 | // Configure pins. |
| 156 | sck.conf().write(|w| w.input().connect().drive().h0h1()); | ||
| 157 | r.psel.sck.write(|w| unsafe { w.bits(sck.psel_bits()) }); | ||
| 158 | cs.conf().write(|w| w.input().connect().drive().h0h1()); | 182 | cs.conf().write(|w| w.input().connect().drive().h0h1()); |
| 159 | r.psel.csn.write(|w| unsafe { w.bits(cs.psel_bits()) }); | 183 | r.psel.csn.write(|w| unsafe { w.bits(cs.psel_bits()) }); |
| 184 | if let Some(sck) = &sck { | ||
| 185 | sck.conf().write(|w| w.input().connect().drive().h0h1()); | ||
| 186 | r.psel.sck.write(|w| unsafe { w.bits(sck.psel_bits()) }); | ||
| 187 | } | ||
| 160 | if let Some(mosi) = &mosi { | 188 | if let Some(mosi) = &mosi { |
| 161 | mosi.conf().write(|w| w.input().connect().drive().h0h1()); | 189 | mosi.conf().write(|w| w.input().connect().drive().h0h1()); |
| 162 | r.psel.mosi.write(|w| unsafe { w.bits(mosi.psel_bits()) }); | 190 | r.psel.mosi.write(|w| unsafe { w.bits(mosi.psel_bits()) }); |
