@@ -1195,13 +1195,7 @@ pub trait Instance:
1195
1195
macro_rules! usart {
1196
1196
(
1197
1197
$(
1198
- $USARTX: ident: (
1199
- $usartXen: ident,
1200
- $INTERRUPT: path,
1201
- $pclkX: ident,
1202
- $usartXsw: ident,
1203
- $usartXclock: ident
1204
- ) ,
1198
+ $USARTX: ident: ( $INTERRUPT: path) ,
1205
1199
) +
1206
1200
) => {
1207
1201
$(
@@ -1210,16 +1204,6 @@ macro_rules! usart {
1210
1204
const INTERRUPT : Interrupt = $INTERRUPT;
1211
1205
}
1212
1206
1213
- impl Instance for $USARTX {
1214
- fn clock( clocks: & Clocks ) -> Hertz {
1215
- // Use the function created via another macro outside of this one,
1216
- // because the implementation is dependend on the type $USARTX.
1217
- // But macros can not differentiate between types.
1218
- $usartXclock( clocks)
1219
- }
1220
- }
1221
-
1222
-
1223
1207
impl <Tx , Rx > Serial <$USARTX, ( Tx , Rx ) >
1224
1208
where Tx : TxPin <$USARTX>, Rx : RxPin <$USARTX> {
1225
1209
/// Splits the [`Serial`] abstraction into a transmitter and a receiver half.
@@ -1275,17 +1259,11 @@ macro_rules! usart {
1275
1259
) +
1276
1260
} ;
1277
1261
1278
- ( [ $( ( $X: literal, $APB : literal , $ INTERRUPT: path) ) ,+ ] ) => {
1262
+ ( [ $( ( $X: literal, $INTERRUPT: path) ) ,+ ] ) => {
1279
1263
paste:: paste! {
1280
1264
usart!(
1281
1265
$(
1282
- [ <USART $X>] : (
1283
- [ <usart $X en>] ,
1284
- $INTERRUPT,
1285
- [ <pclk $APB>] ,
1286
- [ <usart $X sw>] ,
1287
- [ <usart $X clock>]
1288
- ) ,
1266
+ [ <USART $X>] : ( $INTERRUPT) ,
1289
1267
) +
1290
1268
) ;
1291
1269
}
@@ -1296,19 +1274,19 @@ macro_rules! usart {
1296
1274
/// the only clock source can be the peripheral clock
1297
1275
#[ allow( unused_macros) ]
1298
1276
macro_rules! usart_static_clock {
1299
- ( $( $usartXclock : ident , $pclkX : ident) ,+) => {
1277
+ ( $( $USARTX : ident) ,+) => {
1300
1278
$(
1301
- /// Return the currently set source frequency the UART peripheral
1302
- /// depending on the clock source.
1303
- fn $usartXclock ( clocks : & Clocks ) -> Hertz {
1304
- clocks . $pclkX ( )
1279
+ impl Instance for $USARTX {
1280
+ fn clock( clocks : & Clocks ) -> Hertz {
1281
+ <$USARTX as rcc :: BusClock > :: clock ( clocks )
1282
+ }
1305
1283
}
1306
1284
) +
1307
1285
} ;
1308
- ( [ $ ( ( $X: literal, $APB : literal ) ) ,+ ] ) => {
1286
+ ( $ ( $X: literal) ,+ ) => {
1309
1287
paste:: paste! {
1310
1288
usart_static_clock!(
1311
- $( [ <usart $X clock> ] , [ <pclk $APB >] ) ,+
1289
+ $( [ <USART $X>] ) ,+
1312
1290
) ;
1313
1291
}
1314
1292
} ;
@@ -1317,25 +1295,25 @@ macro_rules! usart_static_clock {
1317
1295
/// Generates a clock function for UART Peripherals, where
1318
1296
/// the clock source can vary.
1319
1297
macro_rules! usart_var_clock {
1320
- ( $( $usartXclock : ident, $usartXsw: ident , $pclkX : ident) ,+) => {
1298
+ ( $( $USARTX : ident, $usartXsw: ident) ,+) => {
1321
1299
$(
1322
- /// Return the currently set source frequency for the UART peripheral
1323
- /// depending on the clock source.
1324
- fn $usartXclock ( clocks : & Clocks ) -> Hertz {
1325
- // NOTE(unsafe): atomic read with no side effects
1326
- match unsafe { ( * RCC :: ptr ( ) ) . cfgr3 . read ( ) . $usartXsw ( ) . variant ( ) } {
1327
- USART1SW_A :: PCLK => clocks . $pclkX ( ) ,
1328
- USART1SW_A :: HSI => crate :: rcc :: HSI ,
1329
- USART1SW_A :: SYSCLK => clocks . sysclk ( ) ,
1330
- USART1SW_A :: LSE => crate :: rcc :: LSE ,
1300
+ impl Instance for $USARTX {
1301
+ fn clock( clocks : & Clocks ) -> Hertz {
1302
+ // NOTE(unsafe): atomic read with no side effects
1303
+ match unsafe { ( * RCC :: ptr ( ) ) . cfgr3 . read ( ) . $usartXsw ( ) . variant ( ) } {
1304
+ USART1SW_A :: PCLK => <$USARTX as rcc :: BusClock > :: clock ( clocks ) ,
1305
+ USART1SW_A :: HSI => crate :: rcc :: HSI ,
1306
+ USART1SW_A :: SYSCLK => clocks . sysclk ( ) ,
1307
+ USART1SW_A :: LSE => crate :: rcc :: LSE ,
1308
+ }
1331
1309
}
1332
1310
}
1333
1311
) +
1334
1312
} ;
1335
- ( [ $ ( ( $X: literal, $APB : literal ) ) ,+ ] ) => {
1313
+ ( $ ( $X: literal) ,+ ) => {
1336
1314
paste:: paste! {
1337
1315
usart_var_clock!(
1338
- $( [ <usart $X clock >] , [ <usart $X sw> ] , [ <pclk $APB >] ) ,+
1316
+ $( [ <USART $X>] , [ <usart $X sw>] ) ,+
1339
1317
) ;
1340
1318
}
1341
1319
} ;
@@ -1357,62 +1335,56 @@ cfg_if::cfg_if! {
1357
1335
) ) ] {
1358
1336
// USART1 is accessed through APB2,
1359
1337
// but USART1SW_A::PCLK will connect its phy to PCLK1.
1360
- usart_var_clock!( [ ( 1 , 1 ) ] ) ;
1338
+ usart_var_clock!( 1 ) ;
1361
1339
// These are uart peripherals, where the only clock source
1362
1340
// is the PCLK (peripheral clock).
1363
- usart_static_clock!( [ ( 2 , 1 ) , ( 3 , 1 ) ] ) ;
1341
+ usart_static_clock!( 2 , 3 ) ;
1364
1342
} else {
1365
- usart_var_clock!( [ ( 1 , 2 ) , ( 2 , 1 ) , ( 3 , 1 ) ] ) ;
1343
+ usart_var_clock!( 1 , 2 , 3 ) ;
1366
1344
}
1367
1345
}
1368
1346
1369
1347
#[ cfg( not( feature = "svd-f373" ) ) ]
1370
1348
usart ! ( [
1371
- ( 1 , 2 , Interrupt :: USART1_EXTI25 ) ,
1372
- ( 2 , 1 , Interrupt :: USART2_EXTI26 ) ,
1373
- ( 3 , 1 , Interrupt :: USART3_EXTI28 )
1349
+ ( 1 , Interrupt :: USART1_EXTI25 ) ,
1350
+ ( 2 , Interrupt :: USART2_EXTI26 ) ,
1351
+ ( 3 , Interrupt :: USART3_EXTI28 )
1374
1352
] ) ;
1375
1353
#[ cfg( feature = "svd-f373" ) ]
1376
1354
usart ! ( [
1377
- ( 1 , 2 , Interrupt :: USART1 ) ,
1378
- ( 2 , 1 , Interrupt :: USART2 ) ,
1379
- ( 3 , 1 , Interrupt :: USART3 )
1355
+ ( 1 , Interrupt :: USART1 ) ,
1356
+ ( 2 , Interrupt :: USART2 ) ,
1357
+ ( 3 , Interrupt :: USART3 )
1380
1358
] ) ;
1381
1359
1382
1360
cfg_if:: cfg_if! {
1383
1361
// See table 29.4 RM0316
1384
1362
if #[ cfg( any( feature = "gpio-f303" , feature = "gpio-f303e" ) ) ] {
1385
1363
1386
1364
macro_rules! uart {
1387
- ( [ $( ( $X : literal, $APB : literal , $ INTERRUPT : path) ) , + ] ) => {
1365
+ ( [ $( ( $X : literal, $INTERRUPT : path) ) , + ] ) => {
1388
1366
paste:: paste! {
1389
1367
usart!(
1390
1368
$(
1391
- [ <UART $X >] : (
1392
- [ <uart $X en>] ,
1393
- $INTERRUPT ,
1394
- [ <pclk $APB >] ,
1395
- [ <uart $X sw>] ,
1396
- [ <usart $X clock>]
1397
- ) ,
1369
+ [ <UART $X >] : ( $INTERRUPT ) ,
1398
1370
) +
1399
1371
) ;
1400
1372
}
1401
1373
} ;
1402
1374
}
1403
1375
1404
1376
macro_rules! uart_var_clock {
1405
- ( [ $ ( ( $X : literal, $ APB : literal ) ) , + ] ) => {
1377
+ ( $ ( $X : literal) , + ) => {
1406
1378
paste:: paste! {
1407
1379
usart_var_clock!(
1408
- $( [ <usart $X clock >] , [ <uart $X sw> ] , [ <pclk $ APB >] ) , +
1380
+ $( [ <UART $X >] , [ <uart $X sw>] ) , +
1409
1381
) ;
1410
1382
}
1411
1383
} ;
1412
1384
}
1413
1385
1414
- uart_var_clock!( [ ( 4 , 1 ) , ( 5 , 1 ) ] ) ;
1415
- uart!( [ ( 4 , 1 , Interrupt :: UART4_EXTI34 ) , ( 5 , 1 , Interrupt :: UART5_EXTI35 ) ] ) ;
1386
+ uart_var_clock!( 4 , 5 ) ;
1387
+ uart!( [ ( 4 , Interrupt :: UART4_EXTI34 ) , ( 5 , Interrupt :: UART5_EXTI35 ) ] ) ;
1416
1388
1417
1389
impl Dma for UART4 { }
1418
1390
0 commit comments