Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion esp-hal/src/i2c/master/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ pub enum BusTimeout {
Disabled,

/// Timeout in bus clock cycles.
//#[strum(to_string = "{0} bus clock cycles")] // FIXME uncomment when https://github.com/Peternator7/strum/pull/407 is released
BusCycles(u32),
}

Expand Down Expand Up @@ -1140,6 +1141,24 @@ fn configure_clock(
scl_stop_hold_time: u32,
timeout: BusTimeout,
) -> Result<(), ConfigError> {
debug!(
"Configuring I2C clock: sclk_div: {}, scl_low_period: {}, scl_high_period: {}, \
scl_wait_high_period: {}, sda_hold_time: {}, sda_sample_time: {}, \
scl_rstart_setup_time: {}, scl_stop_setup_time: {}, scl_start_hold_time: {}, \
scl_stop_hold_time: {}, timeout: {}",
sclk_div,
scl_low_period,
scl_high_period,
scl_wait_high_period,
sda_hold_time,
sda_sample_time,
scl_rstart_setup_time,
scl_stop_setup_time,
scl_start_hold_time,
scl_stop_hold_time,
timeout
);

unsafe {
// divider
#[cfg(any(esp32c2, esp32c3, esp32c6, esp32h2, esp32s3))]
Expand Down Expand Up @@ -1578,7 +1597,7 @@ impl Driver<'_> {
};
let scl_high = half_cycle - scl_wait_high;
let sda_hold = half_cycle / 4;
let sda_sample = half_cycle / 2 + scl_wait_high;
let sda_sample = half_cycle / 2;
Copy link
Contributor Author

@bugadani bugadani Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fair, I should probably remove the half_cycle/2 term instead. Technically, we can sample at any point after the rising edge, and scl_wait_high is supposed to be somewhat dependent on the hardware (i.e. it should be tunable, maybe). scl_wait_high represents the rising edge of the clock signal, after which the clock signal is high for scl_high. We should probably aim at the start/middle of the interval covered by scl_high.

Still, this should be good enough to test.

let setup = half_cycle;
let hold = half_cycle;

Expand Down
2 changes: 1 addition & 1 deletion qa-test/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ rustflags = [
]

[env]
ESP_LOG = "info"
ESP_LOG = "debug"
ESP_HAL_EMBASSY_CONFIG_TIMER_QUEUE="multiple-integrated"

[unstable]
Expand Down
1 change: 1 addition & 0 deletions qa-test/src/bin/i2c_bmp180_calibration_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use esp_println::println;

#[main]
fn main() -> ! {
esp_println::logger::init_logger_from_env();
let peripherals = esp_hal::init(esp_hal::Config::default());

// Create a new peripheral object with the described wiring and standard
Expand Down
Loading