Skip to content

Commit a0971b2

Browse files
Merge #626
626: adapt to use stm32_i2s v4 r=burrbull a=YruamaLairba I, we released an new version of stm32_i2s_V12x (now v0.4). This new version implement fix that require some API change Co-authored-by: Yruama_Lairba <[email protected]>
2 parents e35c575 + 321da16 commit a0971b2

File tree

4 files changed

+48
-31
lines changed

4 files changed

+48
-31
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
- Integrate new version of stm32_i2s (v0.4)
1011
- Fix mstr bit for SPI Master/Slave [#625]
1112
- Add `ReadPin`, `PinSpeed` & `PinPull` traits [#623]
1213
- Add autoimplementations of `DMASet` [#614]

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ version = "=1.0.0-alpha.8"
5757
package = "embedded-hal"
5858

5959
[dependencies.stm32_i2s_v12x]
60-
version = "0.3.0"
60+
version = "0.4.0"
6161
optional = true
6262

6363
[dev-dependencies]

examples/rtic-i2s-audio-in-out.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ mod app {
197197
i2s3_driver.set_error_interrupt(true);
198198

199199
// set up an interrupt on WS pin
200-
let ws_pin = i2s3_driver.i2s_peripheral_mut().ws_pin_mut();
200+
let ws_pin = i2s3_driver.ws_pin_mut();
201201
ws_pin.make_interrupt_source(&mut syscfg);
202202
ws_pin.trigger_on_edge(&mut exti, Edge::Rising);
203203
// we will enable i2s3 in interrupt
@@ -350,10 +350,7 @@ mod app {
350350
if status.fre() {
351351
log::spawn("i2s3 Frame error").ok();
352352
i2s3_driver.disable();
353-
i2s3_driver
354-
.i2s_peripheral_mut()
355-
.ws_pin_mut()
356-
.enable_interrupt(exti);
353+
i2s3_driver.ws_pin_mut().enable_interrupt(exti);
357354
}
358355
if status.udr() {
359356
log::spawn("i2s3 udr").ok();
@@ -367,7 +364,7 @@ mod app {
367364
fn exti4(cx: exti4::Context) {
368365
let i2s3_driver = cx.shared.i2s3_driver;
369366
let exti = cx.shared.exti;
370-
let ws_pin = i2s3_driver.i2s_peripheral_mut().ws_pin_mut();
367+
let ws_pin = i2s3_driver.ws_pin_mut();
371368
ws_pin.clear_interrupt_pending_bit();
372369
// yes, in this case we already know that pin is high, but some other exti can be triggered
373370
// by several pins

src/i2s.rs

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::gpio::{self, NoPin};
66
use crate::pac;
77
use crate::rcc;
88
use crate::rcc::Clocks;
9+
use crate::rcc::Reset;
910
use fugit::HertzU32 as Hertz;
1011

1112
#[cfg(feature = "stm32_i2s_v12x")]
@@ -131,16 +132,16 @@ impl<I: Instance> I2s<I> {
131132
}
132133
}
133134

134-
/// Implements stm32_i2s_v12x::I2sPeripheral for I2s<$SPIX, _> and creates an I2s::$spix function
135+
/// Implements stm32_i2s_v12x::I2sPeripheral for I2s<$SPI> and creates an I2s::$spix function
135136
/// to create and enable the peripheral
136137
///
137-
/// $SPIX: The fully-capitalized name of the SPI peripheral (example: SPI1)
138-
/// $i2sx: The lowercase I2S name of the peripheral (example: i2s1). This is the name of the
139-
/// function that creates an I2s and enables the peripheral clock.
138+
/// $SPI: The fully-capitalized name of the SPI peripheral from pac module (example: SPI1)
139+
/// $I2s: The CamelCase I2S alias name for hal I2s wrapper (example: I2s1).
140+
/// $i2s: module containing the Ws pin definition. (example: i2s1).
140141
/// $clock: The name of the Clocks function that returns the frequency of the I2S clock input
141142
/// to this SPI peripheral (i2s_cl, i2s_apb1_clk, or i2s2_apb_clk)
142143
macro_rules! i2s {
143-
($SPI:ty, $I2s:ident, $clock:ident) => {
144+
($SPI:ty, $I2s:ident, $i2s:ident, $clock:ident) => {
144145
pub type $I2s = I2s<$SPI>;
145146

146147
impl Instance for $SPI {}
@@ -154,18 +155,37 @@ macro_rules! i2s {
154155
}
155156

156157
#[cfg(feature = "stm32_i2s_v12x")]
157-
unsafe impl stm32_i2s_v12x::I2sPeripheral for I2s<$SPI> {
158+
impl stm32_i2s_v12x::WsPin for gpio::alt::$i2s::Ws {
159+
fn is_high(&self) -> bool {
160+
use crate::gpio::ReadPin;
161+
<Self as ReadPin>::is_high(self)
162+
}
163+
fn is_low(&self) -> bool {
164+
use crate::gpio::ReadPin;
165+
<Self as ReadPin>::is_low(self)
166+
}
167+
}
168+
169+
#[cfg(feature = "stm32_i2s_v12x")]
170+
unsafe impl stm32_i2s_v12x::I2sPeripheral for I2s<$SPI>
171+
where
172+
$SPI: rcc::Reset,
173+
{
174+
type WsPin = gpio::alt::$i2s::Ws;
158175
const REGISTERS: *const () = <$SPI>::ptr() as *const _;
159176
fn i2s_freq(&self) -> u32 {
160177
self.input_clock.raw()
161178
}
162-
fn ws_is_high(&self) -> bool {
163-
use crate::gpio::ReadPin;
164-
self.ws_pin().is_high()
179+
fn ws_pin(&self) -> &Self::WsPin {
180+
self.ws_pin()
165181
}
166-
fn ws_is_low(&self) -> bool {
167-
use crate::gpio::ReadPin;
168-
self.ws_pin().is_low()
182+
fn ws_pin_mut(&mut self) -> &mut Self::WsPin {
183+
self.ws_pin_mut()
184+
}
185+
fn rcc_reset(&mut self) {
186+
unsafe {
187+
<$SPI>::reset_unchecked();
188+
}
169189
}
170190
}
171191
};
@@ -176,15 +196,15 @@ macro_rules! i2s {
176196
// have two different I2S clocks while other models have only one.
177197

178198
#[cfg(any(feature = "gpio-f410", feature = "gpio-f411"))]
179-
i2s!(pac::SPI1, I2s1, i2s_clk);
199+
i2s!(pac::SPI1, I2s1, i2s1, i2s_clk);
180200
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446",))]
181-
i2s!(pac::SPI1, I2s1, i2s_apb2_clk);
201+
i2s!(pac::SPI1, I2s1, i2s1, i2s_apb2_clk);
182202

183203
// All STM32F4 models support SPI2/I2S2
184204
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446",)))]
185-
i2s!(pac::SPI2, I2s2, i2s_clk);
205+
i2s!(pac::SPI2, I2s2, i2s2, i2s_clk);
186206
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446",))]
187-
i2s!(pac::SPI2, I2s2, i2s_apb1_clk);
207+
i2s!(pac::SPI2, I2s2, i2s2, i2s_apb1_clk);
188208

189209
// All STM32F4 models except STM32F410 support SPI3/I2S3
190210
#[cfg(any(
@@ -194,19 +214,19 @@ i2s!(pac::SPI2, I2s2, i2s_apb1_clk);
194214
feature = "gpio-f427",
195215
feature = "gpio-f469",
196216
))]
197-
i2s!(pac::SPI3, I2s3, i2s_clk);
217+
i2s!(pac::SPI3, I2s3, i2s3, i2s_clk);
198218
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446",))]
199-
i2s!(pac::SPI3, I2s3, i2s_apb1_clk);
219+
i2s!(pac::SPI3, I2s3, i2s3, i2s_apb1_clk);
200220

201221
#[cfg(feature = "gpio-f411")]
202-
i2s!(pac::SPI4, I2s4, i2s_clk);
222+
i2s!(pac::SPI4, I2s4, i2s4, i2s_clk);
203223
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413"))]
204-
i2s!(pac::SPI4, I2s4, i2s_apb2_clk);
224+
i2s!(pac::SPI4, I2s4, i2s4, i2s_apb2_clk);
205225

206226
#[cfg(any(feature = "gpio-f410", feature = "gpio-f411"))]
207-
i2s!(pac::SPI5, I2s5, i2s_clk);
227+
i2s!(pac::SPI5, I2s5, i2s5, i2s_clk);
208228
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413"))]
209-
i2s!(pac::SPI5, I2s5, i2s_apb2_clk);
229+
i2s!(pac::SPI5, I2s5, i2s5, i2s_apb2_clk);
210230

211231
// DMA support: reuse existing mappings for SPI
212232
#[cfg(feature = "stm32_i2s_v12x")]
@@ -227,8 +247,7 @@ mod dma {
227247
type MemSize = u16;
228248

229249
fn address(&self) -> u32 {
230-
let registers = &*self.i2s_peripheral().spi;
231-
&registers.dr as *const _ as u32
250+
self.data_register_address()
232251
}
233252
}
234253

0 commit comments

Comments
 (0)