2
2
//!
3
3
//! This module is only available if the `i2s` feature is enabled.
4
4
5
- use crate :: gpio:: { Alternate , Const , Input , NoPin , Pin , PinA , PushPull , SetAlternate } ;
5
+ use crate :: gpio:: { Alternate , Const , NoPin , Pin , PinA , PushPull , SetAlternate } ;
6
6
use crate :: pac:: { self , RCC } ;
7
7
use crate :: rcc;
8
8
use crate :: { rcc:: Clocks , spi} ;
@@ -56,39 +56,36 @@ impl<
56
56
SPI ,
57
57
const WSP : char ,
58
58
const WSN : u8 ,
59
- WSM ,
60
59
const WSA : u8 ,
61
60
CK ,
62
61
const CKA : u8 ,
63
62
MCLK ,
64
63
const MCLKA : u8 ,
65
64
SD ,
66
65
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 )
68
67
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 > > ,
70
69
CK : PinA < Ck , SPI , A = Const < CKA > > + SetAlternate < CKA , PushPull > ,
71
70
MCLK : PinA < Mck , SPI , A = Const < MCLKA > > + SetAlternate < MCLKA , PushPull > ,
72
71
SD : PinA < Sd , SPI , A = Const < SDA > > + SetAlternate < SDA , PushPull > ,
73
72
{
74
73
type WsPin = Pin < WSP , WSN , Alternate < WSA > > ;
75
74
fn set_alt_mode ( & mut self ) {
76
- self . 0 . set_alt_mode ( ) ;
77
75
self . 1 . set_alt_mode ( ) ;
78
76
self . 2 . set_alt_mode ( ) ;
79
77
self . 3 . set_alt_mode ( ) ;
80
78
}
81
79
fn restore_mode ( & mut self ) {
82
- self . 0 . restore_mode ( ) ;
83
80
self . 1 . restore_mode ( ) ;
84
81
self . 2 . restore_mode ( ) ;
85
82
self . 3 . restore_mode ( ) ;
86
83
}
87
84
fn ws_pin ( & self ) -> & Self :: WsPin {
88
- unsafe { & * ( & self . 0 as * const _ as * const Self :: WsPin ) }
85
+ & self . 0
89
86
}
90
87
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
92
89
}
93
90
}
94
91
@@ -105,7 +102,9 @@ use sealed::Sealed;
105
102
/// probably meaningless.
106
103
pub trait WsPin : Sealed {
107
104
/// 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
+ }
109
108
fn is_low ( & self ) -> bool ;
110
109
}
111
110
@@ -118,13 +117,8 @@ impl<const WSP: char, const WSN: u8, const WSA: u8> WsPin for Pin<WSP, WSN, Alte
118
117
where
119
118
Self : PinA < Ws , pac:: SPI2 , A = Const < WSA > > ,
120
119
{
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
- }
125
120
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 ( )
128
122
}
129
123
}
130
124
0 commit comments