aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorswanandx <[email protected]>2024-01-03 19:22:01 +0530
committerswanandx <[email protected]>2024-01-03 19:22:01 +0530
commitface0312451fd56fb5475472dc793e7397dce563 (patch)
treead31b01b852d04819bafb3e50459d3984fcf8601
parent3b6eaf414a92114037a40dcb3ce37a4191c57a2b (diff)
feat: new_txonly_nosck in spis
-rw-r--r--embassy-nrf/src/spis.rs40
1 files changed, 34 insertions, 6 deletions
diff --git a/embassy-nrf/src/spis.rs b/embassy-nrf/src/spis.rs
index e202c6c27..16ac82e5f 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,13 +142,32 @@ 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,
@@ -153,10 +179,12 @@ impl<'d, T: Instance> Spis<'d, T> {
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()) });