Skip to content
This repository was archived by the owner on Aug 9, 2022. It is now read-only.

Commit 6ac5caf

Browse files
committed
Move 80MHz source clock frequency to const
1 parent 4e661fa commit 6ac5caf

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/i2c.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const DPORT_I2C1_ADDR: u32 = DPORT_BASE_ADDR + I2C1_OFFSET;
1414
const AHB_I2C0_ADDR: u32 = AHB_BASE_ADDR + I2C0_OFFSET;
1515
const AHB_I2C1_ADDR: u32 = AHB_BASE_ADDR + I2C1_OFFSET;
1616

17+
// Corresponds to https://github.com/espressif/esp-idf/blob/1cb31e50943bb757966ca91ed7f4852692a5b0ed/components/hal/esp32/include/hal/i2c_ll.h#L90
18+
const SOURCE_CLK_FREQ: u32 = 80_000_000;
19+
1720
pub struct I2C<T>(T);
1821

1922
impl<T> I2C<T>
@@ -174,7 +177,7 @@ where
174177
fn set_frequency(&mut self, freq: u32) {
175178
// i2c_hal_set_bus_timing(&(i2c_context[i2c_num].hal), freq, 1);
176179
// i2c_ll_cal_bus_clk(80000000, freq, 0);
177-
let half_cycle = ((80_000_000 / freq) / 2) as u16;
180+
let half_cycle = ((SOURCE_CLK_FREQ / freq) / 2) as u16;
178181
let scl_low = half_cycle;
179182
let scl_high = half_cycle;
180183
let sda_hold = half_cycle / 2;

0 commit comments

Comments
 (0)