@@ -8,10 +8,6 @@ use crate::{
8
8
} ;
9
9
10
10
use cortex_m:: interrupt:: CriticalSection ;
11
- use embedded_time:: {
12
- fixed_point:: FixedPoint ,
13
- rate:: { Extensions , Hertz } ,
14
- } ;
15
11
16
12
/// I2C error
17
13
#[ derive( Debug ) ]
@@ -347,12 +343,12 @@ macro_rules! impl_clocks_reset {
347
343
}
348
344
349
345
/// Returns the frequency of the peripheral clock driver
350
- fn clock( rcc: & RCC ) -> Hertz {
346
+ fn clock( rcc: & RCC ) -> u32 {
351
347
// NOTE(unsafe) atomic read with no side effects
352
348
match rcc. ccipr. read( ) . $i2cXsel( ) . variant( ) . unwrap( ) {
353
- I2C3SEL_A :: HSI16 => Hertz ( 16_000_000 ) ,
354
- I2C3SEL_A :: SYSCLK => Hertz ( sysclk_hz( rcc) ) , // TODO move the HAL to embedded-time?
355
- I2C3SEL_A :: PCLK => Hertz ( pclk1_hz( rcc) ) ,
349
+ I2C3SEL_A :: HSI16 => 16_000_000 ,
350
+ I2C3SEL_A :: SYSCLK => sysclk_hz( rcc) ,
351
+ I2C3SEL_A :: PCLK => pclk1_hz( rcc) ,
356
352
}
357
353
}
358
354
}
@@ -373,12 +369,12 @@ macro_rules! impl_new_free {
373
369
///
374
370
/// * Frequency is greater than 1 MHz
375
371
/// * Resulting TIMINGR fields PRESC, SCLDEL, SCADEL, SCLH, SCLL are out of range
376
- pub fn new( i2c: $I2CX, mut pins: ( SCL , SDA ) , freq : Hertz , rcc: & mut RCC , pullup: bool , cs: & CriticalSection ) -> Self
372
+ pub fn new( i2c: $I2CX, mut pins: ( SCL , SDA ) , freq_hz : u32 , rcc: & mut RCC , pullup: bool , cs: & CriticalSection ) -> Self
377
373
where
378
374
SCL : crate :: gpio:: sealed:: $I2cXScl + crate :: gpio:: sealed:: PinOps ,
379
375
SDA : crate :: gpio:: sealed:: $I2cXSda + crate :: gpio:: sealed:: PinOps ,
380
376
{
381
- assert!( freq . integer ( ) <= 1_000_000 ) ; // TODO Return Error instead of panic
377
+ assert!( freq_hz <= 1_000_000 ) ; // TODO Return Error instead of panic
382
378
383
379
Self :: enable_clock( rcc) ;
384
380
Self :: pulse_reset( rcc) ;
@@ -395,7 +391,7 @@ macro_rules! impl_new_free {
395
391
pins. 1 . set_pull( cs, Pull :: None ) ;
396
392
}
397
393
398
- let ( presc, scll, sclh, sdadel, scldel) = i2c_clocks( Self :: clock( rcc) , freq ) ;
394
+ let ( presc, scll, sclh, sdadel, scldel) = i2c_clocks( Self :: clock( rcc) , freq_hz ) ;
399
395
400
396
// Configure for "fast mode" (400 KHz)
401
397
// NOTE(write): writes all non-reserved bits.
@@ -505,18 +501,18 @@ i2c!([1, 2, 3]);
505
501
/// * SCLH
506
502
/// * SDADEL
507
503
/// * SCLDEL
508
- fn i2c_clocks ( clock : Hertz , freq : Hertz ) -> ( u8 , u8 , u8 , u8 , u8 ) {
509
- let i2cclk = clock . integer ( ) ;
510
- let ratio = i2cclk / freq . integer ( ) - 4 ;
511
- let ( presc, scll, sclh, sdadel, scldel) = if freq >= 100 . kHz ( ) {
504
+ fn i2c_clocks ( clock_hz : u32 , freq_hz : u32 ) -> ( u8 , u8 , u8 , u8 , u8 ) {
505
+ let i2cclk = clock_hz ;
506
+ let ratio = i2cclk / freq_hz - 4 ;
507
+ let ( presc, scll, sclh, sdadel, scldel) = if freq_hz >= 100_000 {
512
508
// fast-mode or fast-mode plus
513
509
// here we pick SCLL + 1 = 2 * (SCLH + 1)
514
510
let presc = ratio / 387 ;
515
511
516
512
let sclh = ( ( ratio / ( presc + 1 ) ) - 3 ) / 3 ;
517
513
let scll = 2 * ( sclh + 1 ) - 1 ;
518
514
519
- let ( sdadel, scldel) = if freq > 400 . kHz ( ) {
515
+ let ( sdadel, scldel) = if freq_hz > 400_000 {
520
516
// fast-mode plus
521
517
let sdadel = 0 ;
522
518
let scldel = i2cclk / 4_000_000 / ( presc + 1 ) - 1 ;
0 commit comments