File tree Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -340,7 +340,7 @@ impl MainPll {
340
340
}
341
341
}
342
342
343
- fn best_divider (
343
+ const fn best_divider (
344
344
vco_out : u32 ,
345
345
min : u32 ,
346
346
target : u32 ,
@@ -349,25 +349,43 @@ impl MainPll {
349
349
max_div : u32 ,
350
350
) -> Option < ( u32 , u32 , u32 ) > {
351
351
let div = ( vco_out + target / 2 ) / target;
352
- let min_div = u32 :: max (
352
+ let min_div = max_u32 (
353
353
min_div,
354
354
if max != 0 {
355
355
( vco_out + max - 1 ) / max
356
356
} else {
357
357
0
358
358
} ,
359
359
) ;
360
- let max_div = u32 :: min ( max_div, if min != 0 { vco_out / min } else { u32:: MAX } ) ;
360
+ let max_div = min_u32 ( max_div, if min != 0 { vco_out / min } else { u32:: MAX } ) ;
361
361
if min_div > max_div {
362
362
return None ;
363
363
}
364
- let div = u32 :: min ( u32 :: max ( div, min_div) , max_div) ;
364
+ let div = min_u32 ( max_u32 ( div, min_div) , max_div) ;
365
365
let output = vco_out / div;
366
366
let error = ( output as i32 - target as i32 ) . abs ( ) as u32 ;
367
367
Some ( ( div, output, error) )
368
368
}
369
369
}
370
370
371
+ #[ cfg( feature = "gpio-f410" ) ]
372
+ const fn max_u32 ( first : u32 , second : u32 ) -> u32 {
373
+ if second > first {
374
+ second
375
+ } else {
376
+ first
377
+ }
378
+ }
379
+
380
+ #[ cfg( feature = "gpio-f410" ) ]
381
+ const fn min_u32 ( first : u32 , second : u32 ) -> u32 {
382
+ if second < first {
383
+ second
384
+ } else {
385
+ first
386
+ }
387
+ }
388
+
371
389
#[ cfg( not( feature = "gpio-f410" ) ) ]
372
390
pub struct I2sPll {
373
391
pub use_pll : bool ,
You can’t perform that action at this time.
0 commit comments