drivers: i2c: stm32 for V2 driver get_config with timings

Change the get_config API for the stm32 I2C V2 driver.
It will also return the value of the content of TIMING register
for the I2C V2 bus.
This is hold by a i2c_config_timing structure of the device data

Signed-off-by: Francois Ramu <francois.ramu@st.com>
This commit is contained in:
Francois Ramu 2023-10-02 16:22:52 +02:00 committed by Johan Hedberg
parent e5048c0c6d
commit 29afef1e7d
3 changed files with 30 additions and 1 deletions

View file

@ -56,6 +56,26 @@ int i2c_stm32_get_config(const struct device *dev, uint32_t *config)
*config = data->dev_config;
#if CONFIG_I2C_STM32_V2_TIMING
/* Print the timing parameter of device data */
LOG_INF("I2C timing value, report to the DTS :");
/* I2C BIT RATE */
if (data->current_timing.i2c_speed == 100000) {
LOG_INF("timings = <%d I2C_BITRATE_STANDARD 0x%X>;",
data->current_timing.periph_clock,
data->current_timing.timing_setting);
} else if (data->current_timing.i2c_speed == 400000) {
LOG_INF("timings = <%d I2C_BITRATE_FAST 0x%X>;",
data->current_timing.periph_clock,
data->current_timing.timing_setting);
} else if (data->current_timing.i2c_speed == 1000000) {
LOG_INF("timings = <%d I2C_SPEED_FAST_PLUS 0x%X>;",
data->current_timing.periph_clock,
data->current_timing.timing_setting);
}
#endif /* CONFIG_I2C_STM32_V2_TIMING */
return 0;
}

View file

@ -56,6 +56,10 @@ struct i2c_stm32_data {
#endif
struct k_sem bus_mutex;
uint32_t dev_config;
#if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2)
/* Store the current timing structure set by runtime config */
struct i2c_config_timing current_timing;
#endif
#ifdef CONFIG_I2C_STM32_V1
uint16_t slave_address;
#endif

View file

@ -1007,6 +1007,7 @@ void i2c_compute_presc_scldel_sdadel(uint32_t clock_src_freq, uint32_t i2c_speed
int stm32_i2c_configure_timing(const struct device *dev, uint32_t clock)
{
const struct i2c_stm32_config *cfg = dev->config;
struct i2c_stm32_data *data = dev->data;
I2C_TypeDef *i2c = cfg->i2c;
uint32_t timing = 0U;
uint32_t idx;
@ -1035,7 +1036,11 @@ int stm32_i2c_configure_timing(const struct device *dev, uint32_t clock)
}
}
LOG_INF("I2C TIMING = 0x%x\n", timing);
/* Fill the current timing value in data structure at runtime */
data->current_timing.periph_clock = clock;
data->current_timing.i2c_speed = i2c_freq;
data->current_timing.timing_setting = timing;
LL_I2C_SetTiming(i2c, timing);
return 0;