6
6
pub use embedded_hal:: spi:: { Mode , Phase , Polarity } ;
7
7
8
8
use crate :: stm32;
9
+ // TODO Put this inside the macro
10
+ // Currently that causes a compiler panic
9
11
#[ cfg( any( feature = "stm32f042" , feature = "stm32f030" ) ) ]
10
- use crate :: stm32:: { RCC , SPI1 } ;
12
+ use crate :: stm32:: SPI1 ;
13
+ #[ cfg( any( feature = "stm32f030x8" , feature = "stm32f030xc" ) ) ]
14
+ use crate :: stm32:: SPI2 ;
11
15
12
16
use crate :: gpio:: * ;
13
17
use crate :: rcc:: Clocks ;
@@ -74,10 +78,9 @@ spi_pins! {
74
78
}
75
79
76
80
macro_rules! spi {
77
- ( $( $SPI: ident: ( $spi: ident, $spiXen: ident, $spiXrst: ident, $apbrstr : ident, $apbenr : ident) , ) +) => {
81
+ ( $( $SPI: ident: ( $spi: ident, $spiXen: ident, $spiXrst: ident, $apbenr : ident, $apbrstr : ident) , ) +) => {
78
82
$(
79
- use crate :: stm32:: $SPI;
80
- impl <SCKPIN , MISOPIN , MOSIPIN > Spi <SPI1 , SCKPIN , MISOPIN , MOSIPIN > {
83
+ impl <SCKPIN , MISOPIN , MOSIPIN > Spi <$SPI, SCKPIN , MISOPIN , MOSIPIN > {
81
84
pub fn $spi<F >(
82
85
spi: $SPI,
83
86
pins: ( SCKPIN , MISOPIN , MOSIPIN ) ,
@@ -92,12 +95,12 @@ macro_rules! spi {
92
95
F : Into <Hertz >,
93
96
{
94
97
// NOTE(unsafe) This executes only during initialisation
95
- let rcc = unsafe { & ( * RCC :: ptr( ) ) } ;
98
+ let rcc = unsafe { & ( * stm32 :: RCC :: ptr( ) ) } ;
96
99
97
- /* Enable clock for SPI1 */
100
+ /* Enable clock for SPI */
98
101
rcc. $apbenr. modify( |_, w| w. $spiXen( ) . set_bit( ) ) ;
99
102
100
- /* Reset SPI1 */
103
+ /* Reset SPI */
101
104
rcc. $apbrstr. modify( |_, w| w. $spiXrst( ) . set_bit( ) ) ;
102
105
rcc. $apbrstr. modify( |_, w| w. $spiXrst( ) . clear_bit( ) ) ;
103
106
Spi { spi, pins } . spi_init( mode, speed, clocks)
@@ -106,6 +109,7 @@ macro_rules! spi {
106
109
) +
107
110
}
108
111
}
112
+
109
113
#[ cfg( any( feature = "stm32f042" , feature = "stm32f030" ) ) ]
110
114
spi ! {
111
115
SPI1 : ( spi1, spi1en, spi1rst, apb2enr, apb2rstr) ,
0 commit comments