Skip to content

Commit f7b6268

Browse files
committed
force ws pin alternate
1 parent d59d93b commit f7b6268

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ package = "embedded-hal"
5757

5858
[dependencies.stm32_i2s_v12x]
5959
version = "0.2.0"
60-
path = "../stm32_i2s"
60+
git = "https://github.com/YruamaLairba/stm32_i2s"
61+
branch = "rework"
6162
optional = true
6263

6364
[dev-dependencies]

src/gpio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, MODE> {
369369
unsafe { (*Gpio::<P>::ptr()).odr.read().bits() & (1 << N) == 0 }
370370
}
371371
#[inline(always)]
372-
fn _is_low(&self) -> bool {
372+
pub(crate) fn _is_low(&self) -> bool {
373373
// NOTE(unsafe) atomic read with no side effects
374374
unsafe { (*Gpio::<P>::ptr()).idr.read().bits() & (1 << N) == 0 }
375375
}

src/i2s.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! This module is only available if the `i2s` feature is enabled.
44
5-
use crate::gpio::{Alternate, Const, Input, NoPin, Pin, PinA, PushPull, SetAlternate};
5+
use crate::gpio::{Alternate, Const, NoPin, Pin, PinA, PushPull, SetAlternate};
66
use crate::pac::{self, RCC};
77
use crate::rcc;
88
use crate::{rcc::Clocks, spi};
@@ -56,39 +56,36 @@ impl<
5656
SPI,
5757
const WSP: char,
5858
const WSN: u8,
59-
WSM,
6059
const WSA: u8,
6160
CK,
6261
const CKA: u8,
6362
MCLK,
6463
const MCLKA: u8,
6564
SD,
6665
const SDA: u8,
67-
> Pins<SPI> for (Pin<WSP, WSN, WSM>, CK, MCLK, SD)
66+
> Pins<SPI> for (Pin<WSP, WSN, Alternate<WSA, PushPull>>, CK, MCLK, SD)
6867
where
69-
Pin<WSP, WSN, WSM>: PinA<Ws, SPI, A = Const<WSA>> + SetAlternate<WSA, PushPull>,
68+
Pin<WSP, WSN, Alternate<WSA, PushPull>>: PinA<Ws, SPI, A = Const<WSA>>,
7069
CK: PinA<Ck, SPI, A = Const<CKA>> + SetAlternate<CKA, PushPull>,
7170
MCLK: PinA<Mck, SPI, A = Const<MCLKA>> + SetAlternate<MCLKA, PushPull>,
7271
SD: PinA<Sd, SPI, A = Const<SDA>> + SetAlternate<SDA, PushPull>,
7372
{
7473
type WsPin = Pin<WSP, WSN, Alternate<WSA>>;
7574
fn set_alt_mode(&mut self) {
76-
self.0.set_alt_mode();
7775
self.1.set_alt_mode();
7876
self.2.set_alt_mode();
7977
self.3.set_alt_mode();
8078
}
8179
fn restore_mode(&mut self) {
82-
self.0.restore_mode();
8380
self.1.restore_mode();
8481
self.2.restore_mode();
8582
self.3.restore_mode();
8683
}
8784
fn ws_pin(&self) -> &Self::WsPin {
88-
unsafe { &*(&self.0 as *const _ as *const Self::WsPin) }
85+
&self.0
8986
}
9087
fn ws_pin_mut(&mut self) -> &mut Self::WsPin {
91-
unsafe { &mut *(&mut self.0 as *mut _ as *mut Self::WsPin) }
88+
&mut self.0
9289
}
9390
}
9491

@@ -105,7 +102,9 @@ use sealed::Sealed;
105102
/// probably meaningless.
106103
pub trait WsPin: Sealed {
107104
/// Get the signal level on a WS pin on i2s alternate mode.
108-
fn is_high(&self) -> bool;
105+
fn is_high(&self) -> bool {
106+
!self.is_low()
107+
}
109108
fn is_low(&self) -> bool;
110109
}
111110

@@ -118,13 +117,8 @@ impl<const WSP: char, const WSN: u8, const WSA: u8> WsPin for Pin<WSP, WSN, Alte
118117
where
119118
Self: PinA<Ws, pac::SPI2, A = Const<WSA>>,
120119
{
121-
fn is_high(&self) -> bool {
122-
// I don't want to alter gpio hal so I pretend an Input pin state to get the level
123-
unsafe { (&*(self as *const _ as *const Pin<WSP, WSN, Input>)).is_high() }
124-
}
125120
fn is_low(&self) -> bool {
126-
// I don't want to alter gpio hal so I pretend an Input pin state to get the level
127-
unsafe { (&*(self as *const _ as *const Pin<WSP, WSN, Input>)).is_low() }
121+
self._is_low()
128122
}
129123
}
130124

0 commit comments

Comments
 (0)