diff options
| author | swanandx <[email protected]> | 2024-01-03 19:25:09 +0530 |
|---|---|---|
| committer | swanandx <[email protected]> | 2024-01-03 19:25:39 +0530 |
| commit | 8352d13cfd7ea46abf8bd2bb460ff1ce32e7da8d (patch) | |
| tree | 4a11b6c866bbad2435cf49fe3486c4077200acd9 /embassy-nrf/src/spim.rs | |
| parent | face0312451fd56fb5475472dc793e7397dce563 (diff) | |
feat: new_txonly_nosck in spim
Diffstat (limited to 'embassy-nrf/src/spim.rs')
| -rw-r--r-- | embassy-nrf/src/spim.rs | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index 5d3c3268c..ab16491a5 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 | } |
