Merge branch 'bugfix/i2c_example_esp32s3' into 'master'

i2c: bringup on ESP32-S3

Closes IDF-3232 and IDF-3292

See merge request espressif/esp-idf!13985
This commit is contained in:
Michael (XIAO Xufeng) 2021-07-29 07:01:38 +00:00
commit 5569dedd7f
16 changed files with 4543 additions and 2355 deletions

View File

@ -23,13 +23,14 @@
#include "driver/periph_ctrl.h" #include "driver/periph_ctrl.h"
#include "esp_rom_gpio.h" #include "esp_rom_gpio.h"
#include "hal/gpio_hal.h" #include "hal/gpio_hal.h"
#include "hal/uart_ll.h"
#define DATA_LENGTH 512 /*!<Data buffer length for test buffer*/ #define DATA_LENGTH 512 /*!<Data buffer length for test buffer*/
#define RW_TEST_LENGTH 129 /*!<Data length for r/w test, any value from 0-DATA_LENGTH*/ #define RW_TEST_LENGTH 129 /*!<Data length for r/w test, any value from 0-DATA_LENGTH*/
#define DELAY_TIME_BETWEEN_ITEMS_MS 1234 /*!< delay time between different test items */ #define DELAY_TIME_BETWEEN_ITEMS_MS 1234 /*!< delay time between different test items */
#if CONFIG_IDF_TARGET_ESP32C3 #if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3
#define I2C_SLAVE_SCL_IO 5 /*!<gpio number for i2c slave clock */ #define I2C_SLAVE_SCL_IO 5 /*!<gpio number for i2c slave clock */
#define I2C_SLAVE_SDA_IO 6 /*!<gpio number for i2c slave data */ #define I2C_SLAVE_SDA_IO 6 /*!<gpio number for i2c slave data */
#else #else
@ -44,9 +45,12 @@
#if CONFIG_IDF_TARGET_ESP32C3 #if CONFIG_IDF_TARGET_ESP32C3
#define I2C_MASTER_SCL_IO 5 /*!<gpio number for i2c master clock */ #define I2C_MASTER_SCL_IO 5 /*!<gpio number for i2c master clock */
#define I2C_MASTER_SDA_IO 6 /*!<gpio number for i2c master data */ #define I2C_MASTER_SDA_IO 6 /*!<gpio number for i2c master data */
#elif CONFIG_IDF_TARGET_ESP32S3
#define I2C_MASTER_SCL_IO 2 /*!<gpio number for i2c master clock */
#define I2C_MASTER_SDA_IO 1 /*!<gpio number for i2c master data */
#else #else
#define I2C_MASTER_SCL_IO 19 /*!< gpio number for I2C master clock */ #define I2C_MASTER_SCL_IO 19 /*!< gpio number for I2C master clock */
#define I2C_MASTER_SDA_IO 18 /*!< gpio number for I2C master data */ #define I2C_MASTER_SDA_IO 18 /*!< gpio number for I2C master data */
#endif #endif
#define I2C_MASTER_NUM I2C_NUM_0 /*!< I2C port number for master dev */ #define I2C_MASTER_NUM I2C_NUM_0 /*!< I2C port number for master dev */
@ -662,9 +666,10 @@ static void uart_aut_baud_det_init(int rxd_io_num)
esp_rom_gpio_connect_out_signal(rxd_io_num, I2CEXT1_SCL_OUT_IDX, 0, 0); esp_rom_gpio_connect_out_signal(rxd_io_num, I2CEXT1_SCL_OUT_IDX, 0, 0);
esp_rom_gpio_connect_in_signal(rxd_io_num, U1RXD_IN_IDX, 0); esp_rom_gpio_connect_in_signal(rxd_io_num, U1RXD_IN_IDX, 0);
periph_module_enable(PERIPH_UART1_MODULE); periph_module_enable(PERIPH_UART1_MODULE);
UART1.int_ena.val = 0; /* Reset all the bits */
UART1.int_clr.val = ~0; uart_ll_disable_intr_mask(&UART1, ~0);
UART1.auto_baud.en = 1; uart_ll_clr_intsts_mask(&UART1, ~0);
uart_ll_set_autobaud_en(&UART1, true);
} }
//Calculate I2C scl freq //Calculate I2C scl freq
@ -672,11 +677,11 @@ static void i2c_scl_freq_cal(void)
{ {
const int i2c_source_clk_freq = 80000000; const int i2c_source_clk_freq = 80000000;
const float i2c_cource_clk_period = 0.0125; const float i2c_cource_clk_period = 0.0125;
int edg_cnt = UART1.rxd_cnt.edge_cnt; int edg_cnt = uart_ll_get_rxd_edge_cnt(&UART1);
int pospulse_cnt = UART1.pospulse.min_cnt; int pospulse_cnt = uart_ll_get_pos_pulse_cnt(&UART1);
int negpulse_cnt = UART1.negpulse.min_cnt; int negpulse_cnt = uart_ll_get_neg_pulse_cnt(&UART1);
int high_period_cnt = UART1.highpulse.min_cnt; int high_period_cnt = uart_ll_get_high_pulse_cnt(&UART1);
int low_period_cnt = UART1.lowpulse.min_cnt; int low_period_cnt = uart_ll_get_low_pulse_cnt(&UART1);
if(edg_cnt != 542) { if(edg_cnt != 542) {
printf("\nedg_cnt != 542, test fail\n"); printf("\nedg_cnt != 542, test fail\n");
return; return;
@ -684,7 +689,7 @@ static void i2c_scl_freq_cal(void)
printf("\nDetected SCL frequency: %d Hz\n", i2c_source_clk_freq / ((pospulse_cnt + negpulse_cnt) / 2) ); printf("\nDetected SCL frequency: %d Hz\n", i2c_source_clk_freq / ((pospulse_cnt + negpulse_cnt) / 2) );
printf("\nSCL high period %.3f (us), SCL low_period %.3f (us)\n\n", (float)(i2c_cource_clk_period * high_period_cnt), (float)(i2c_cource_clk_period * low_period_cnt)); printf("\nSCL high period %.3f (us), SCL low_period %.3f (us)\n\n", (float)(i2c_cource_clk_period * high_period_cnt), (float)(i2c_cource_clk_period * low_period_cnt));
UART1.auto_baud.en = 0; uart_ll_set_autobaud_en(&UART1, false);
periph_module_disable(PERIPH_UART1_MODULE); periph_module_disable(PERIPH_UART1_MODULE);
} }
@ -717,4 +722,4 @@ TEST_CASE("I2C SCL freq test (local test)", "[i2c][ignore]")
TEST_ESP_OK(i2c_driver_delete(i2c_num)); TEST_ESP_OK(i2c_driver_delete(i2c_num));
} }
#endif // TEMPORARY_DISABLED_FOR_TARGETS(ESP32S3) #endif // TEMPORARY_DISABLED_FOR_TARGETS(ESP32S3, ESP32C3)

View File

@ -895,6 +895,67 @@ FORCE_INLINE_ATTR uint16_t uart_ll_max_tout_thrd(uart_dev_t *hw)
return tout_thrd; return tout_thrd;
} }
/**
* @brief Configure the auto baudrate.
*
* @param hw Beginning address of the peripheral registers.
* @param enable Boolean marking whether the auto baudrate should be enabled or not.
*/
FORCE_INLINE_ATTR void uart_ll_set_autobaud_en(uart_dev_t *hw, bool enable)
{
hw->auto_baud.en = enable ? 1 : 0;
}
/**
* @brief Get the RXD edge count.
*
* @param hw Beginning address of the peripheral registers.
*/
FORCE_INLINE_ATTR uint32_t uart_ll_get_rxd_edge_cnt(uart_dev_t *hw)
{
return hw->rxd_cnt.edge_cnt;
}
/**
* @brief Get the positive pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
FORCE_INLINE_ATTR uint32_t uart_ll_get_pos_pulse_cnt(uart_dev_t *hw)
{
return hw->pospulse.min_cnt;
}
/**
* @brief Get the negative pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
FORCE_INLINE_ATTR uint32_t uart_ll_get_neg_pulse_cnt(uart_dev_t *hw)
{
return hw->negpulse.min_cnt;
}
/**
* @brief Get the high pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
FORCE_INLINE_ATTR uint32_t uart_ll_get_high_pulse_cnt(uart_dev_t *hw)
{
return hw->highpulse.min_cnt;
}
/**
* @brief Get the low pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
FORCE_INLINE_ATTR uint32_t uart_ll_get_low_pulse_cnt(uart_dev_t *hw)
{
return hw->lowpulse.min_cnt;
}
/** /**
* @brief Force UART xoff. * @brief Force UART xoff.
* *

View File

@ -890,6 +890,67 @@ static inline uint16_t uart_ll_max_tout_thrd(uart_dev_t *hw)
return UART_RX_TOUT_THRHD_V; return UART_RX_TOUT_THRHD_V;
} }
/**
* @brief Configure the auto baudrate.
*
* @param hw Beginning address of the peripheral registers.
* @param enable Boolean marking whether the auto baudrate should be enabled or not.
*/
static inline void uart_ll_set_autobaud_en(uart_dev_t *hw, bool enable)
{
hw->conf0.autobaud_en = enable ? 1 : 0;
}
/**
* @brief Get the RXD edge count.
*
* @param hw Beginning address of the peripheral registers.
*/
static inline uint32_t uart_ll_get_rxd_edge_cnt(uart_dev_t *hw)
{
return hw->rxd_cnt.edge_cnt;
}
/**
* @brief Get the positive pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
static inline uint32_t uart_ll_get_pos_pulse_cnt(uart_dev_t *hw)
{
return hw->pospulse.min_cnt;
}
/**
* @brief Get the negative pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
static inline uint32_t uart_ll_get_neg_pulse_cnt(uart_dev_t *hw)
{
return hw->negpulse.min_cnt;
}
/**
* @brief Get the high pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
static inline uint32_t uart_ll_get_high_pulse_cnt(uart_dev_t *hw)
{
return hw->highpulse.min_cnt;
}
/**
* @brief Get the low pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
static inline uint32_t uart_ll_get_low_pulse_cnt(uart_dev_t *hw)
{
return hw->lowpulse.min_cnt;
}
/** /**
* @brief Force UART xoff. * @brief Force UART xoff.
* *

View File

@ -890,6 +890,67 @@ static inline uint16_t uart_ll_max_tout_thrd(uart_dev_t *hw)
return UART_RX_TOUT_THRHD_V; return UART_RX_TOUT_THRHD_V;
} }
/**
* @brief Configure the auto baudrate.
*
* @param hw Beginning address of the peripheral registers.
* @param enable Boolean marking whether the auto baudrate should be enabled or not.
*/
static inline void uart_ll_set_autobaud_en(uart_dev_t *hw, bool enable)
{
hw->conf0.autobaud_en = enable ? 1 : 0;
}
/**
* @brief Get the RXD edge count.
*
* @param hw Beginning address of the peripheral registers.
*/
static inline uint32_t uart_ll_get_rxd_edge_cnt(uart_dev_t *hw)
{
return hw->rxd_cnt.edge_cnt;
}
/**
* @brief Get the positive pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
static inline uint32_t uart_ll_get_pos_pulse_cnt(uart_dev_t *hw)
{
return hw->pospulse.min_cnt;
}
/**
* @brief Get the negative pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
static inline uint32_t uart_ll_get_neg_pulse_cnt(uart_dev_t *hw)
{
return hw->negpulse.min_cnt;
}
/**
* @brief Get the high pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
static inline uint32_t uart_ll_get_high_pulse_cnt(uart_dev_t *hw)
{
return hw->highpulse.min_cnt;
}
/**
* @brief Get the low pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
static inline uint32_t uart_ll_get_low_pulse_cnt(uart_dev_t *hw)
{
return hw->lowpulse.min_cnt;
}
/** /**
* @brief Force UART xoff. * @brief Force UART xoff.
* *

View File

@ -827,6 +827,67 @@ FORCE_INLINE_ATTR uint16_t uart_ll_max_tout_thrd(uart_dev_t *hw)
return UART_RX_TOUT_THRHD_V; return UART_RX_TOUT_THRHD_V;
} }
/**
* @brief Configure the auto baudrate.
*
* @param hw Beginning address of the peripheral registers.
* @param enable Boolean marking whether the auto baudrate should be enabled or not.
*/
FORCE_INLINE_ATTR void uart_ll_set_autobaud_en(uart_dev_t *hw, bool enable)
{
hw->auto_baud.en = enable ? 1 : 0;
}
/**
* @brief Get the RXD edge count.
*
* @param hw Beginning address of the peripheral registers.
*/
FORCE_INLINE_ATTR uint32_t uart_ll_get_rxd_edge_cnt(uart_dev_t *hw)
{
return hw->rxd_cnt.edge_cnt;
}
/**
* @brief Get the positive pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
FORCE_INLINE_ATTR uint32_t uart_ll_get_pos_pulse_cnt(uart_dev_t *hw)
{
return hw->pospulse.min_cnt;
}
/**
* @brief Get the negative pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
FORCE_INLINE_ATTR uint32_t uart_ll_get_neg_pulse_cnt(uart_dev_t *hw)
{
return hw->negpulse.min_cnt;
}
/**
* @brief Get the high pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
FORCE_INLINE_ATTR uint32_t uart_ll_get_high_pulse_cnt(uart_dev_t *hw)
{
return hw->highpulse.min_cnt;
}
/**
* @brief Get the low pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
FORCE_INLINE_ATTR uint32_t uart_ll_get_low_pulse_cnt(uart_dev_t *hw)
{
return hw->lowpulse.min_cnt;
}
/** /**
* @brief Force UART xoff. * @brief Force UART xoff.
* *

View File

@ -58,7 +58,7 @@ typedef enum {
* @brief Data structure for calculating I2C bus timing. * @brief Data structure for calculating I2C bus timing.
*/ */
typedef struct { typedef struct {
uint16_t clkm_div; /*!< I2C core clock devider */ uint16_t clkm_div; /*!< I2C core clock divider */
uint16_t scl_low; /*!< I2C scl low period */ uint16_t scl_low; /*!< I2C scl low period */
uint16_t scl_high; /*!< I2C scl hight period */ uint16_t scl_high; /*!< I2C scl hight period */
uint16_t scl_wait_high; /*!< I2C scl wait_high period */ uint16_t scl_wait_high; /*!< I2C scl wait_high period */
@ -150,19 +150,19 @@ static inline void i2c_ll_set_bus_timing(i2c_dev_t *hw, i2c_clk_cal_t *bus_cfg)
{ {
hw->clk_conf.sclk_div_num = bus_cfg->clkm_div - 1; hw->clk_conf.sclk_div_num = bus_cfg->clkm_div - 1;
//scl period //scl period
hw->scl_low_period.period = bus_cfg->scl_low - 1; hw->scl_low_period.scl_low_period = bus_cfg->scl_low - 1;
hw->scl_high_period.period = bus_cfg->scl_high; hw->scl_high_period.scl_high_period = bus_cfg->scl_high;
//sda sample //sda sample
hw->sda_hold.time = bus_cfg->sda_hold; hw->sda_hold.sda_hold_time = bus_cfg->sda_hold;
hw->sda_sample.time = bus_cfg->sda_sample; hw->sda_sample.sda_sample_time = bus_cfg->sda_sample;
//setup //setup
hw->scl_rstart_setup.time = bus_cfg->setup; hw->scl_rstart_setup.scl_rstart_setup_time = bus_cfg->setup;
hw->scl_stop_setup.time = bus_cfg->setup; hw->scl_stop_setup.scl_stop_setup_time = bus_cfg->setup;
//hold //hold
hw->scl_start_hold.time = bus_cfg->hold - 1; hw->scl_start_hold.scl_start_hold_time = bus_cfg->hold - 1;
hw->scl_stop_hold.time = bus_cfg->hold; hw->scl_stop_hold.scl_stop_hold_time = bus_cfg->hold;
hw->timeout.tout = bus_cfg->tout; hw->to.time_out_value = bus_cfg->tout;
hw->timeout.time_out_en = 1; hw->to.time_out_en = 1;
} }
/** /**
@ -203,8 +203,8 @@ static inline void i2c_ll_rxfifo_rst(i2c_dev_t *hw)
static inline void i2c_ll_set_scl_timing(i2c_dev_t *hw, int high_period, int low_period) static inline void i2c_ll_set_scl_timing(i2c_dev_t *hw, int high_period, int low_period)
{ {
int high_period_output = high_period - 10; // The rising edge by open-drain output + internal pullup (about 50K) is slow int high_period_output = high_period - 10; // The rising edge by open-drain output + internal pullup (about 50K) is slow
hw->scl_low_period.period = low_period - 1; hw->scl_low_period.scl_low_period = low_period - 1;
hw->scl_high_period.period = high_period_output; hw->scl_high_period.scl_high_period = high_period_output;
hw->scl_high_period.scl_wait_high_period = high_period - high_period_output; hw->scl_high_period.scl_wait_high_period = high_period - high_period_output;
} }
@ -282,7 +282,7 @@ static inline void i2c_ll_set_fifo_mode(i2c_dev_t *hw, bool fifo_mode_en)
*/ */
static inline void i2c_ll_set_tout(i2c_dev_t *hw, int tout) static inline void i2c_ll_set_tout(i2c_dev_t *hw, int tout)
{ {
hw->timeout.tout = tout; hw->to.time_out_value = tout;
} }
/** /**
@ -296,8 +296,8 @@ static inline void i2c_ll_set_tout(i2c_dev_t *hw, int tout)
*/ */
static inline void i2c_ll_set_slave_addr(i2c_dev_t *hw, uint16_t slave_addr, bool addr_10bit_en) static inline void i2c_ll_set_slave_addr(i2c_dev_t *hw, uint16_t slave_addr, bool addr_10bit_en)
{ {
hw->slave_addr.addr = slave_addr; hw->slave_addr.slave_addr = slave_addr;
hw->slave_addr.en_10bit = addr_10bit_en; hw->slave_addr.addr_10bit_en = addr_10bit_en;
} }
/** /**
@ -311,7 +311,10 @@ static inline void i2c_ll_set_slave_addr(i2c_dev_t *hw, uint16_t slave_addr, boo
*/ */
static inline void i2c_ll_write_cmd_reg(i2c_dev_t *hw, i2c_hw_cmd_t cmd, int cmd_idx) static inline void i2c_ll_write_cmd_reg(i2c_dev_t *hw, i2c_hw_cmd_t cmd, int cmd_idx)
{ {
hw->command[cmd_idx].val = cmd.val; _Static_assert(sizeof(i2c_comd0_reg_t) == sizeof(i2c_hw_cmd_t),
"i2c_comdX_reg_t structure size must be equal to i2c_hw_cmd_t structure size");
volatile i2c_hw_cmd_t* commands = (volatile i2c_hw_cmd_t*) &hw->comd0;
commands[cmd_idx].val = cmd.val;
} }
/** /**
@ -325,8 +328,8 @@ static inline void i2c_ll_write_cmd_reg(i2c_dev_t *hw, i2c_hw_cmd_t cmd, int cmd
*/ */
static inline void i2c_ll_set_start_timing(i2c_dev_t *hw, int start_setup, int start_hold) static inline void i2c_ll_set_start_timing(i2c_dev_t *hw, int start_setup, int start_hold)
{ {
hw->scl_rstart_setup.time = start_setup; hw->scl_rstart_setup.scl_rstart_setup_time = start_setup;
hw->scl_start_hold.time = start_hold - 1; hw->scl_start_hold.scl_start_hold_time = start_hold - 1;
} }
/** /**
@ -340,8 +343,8 @@ static inline void i2c_ll_set_start_timing(i2c_dev_t *hw, int start_setup, int s
*/ */
static inline void i2c_ll_set_stop_timing(i2c_dev_t *hw, int stop_setup, int stop_hold) static inline void i2c_ll_set_stop_timing(i2c_dev_t *hw, int stop_setup, int stop_hold)
{ {
hw->scl_stop_setup.time = stop_setup; hw->scl_stop_setup.scl_stop_setup_time = stop_setup;
hw->scl_stop_hold.time = stop_hold; hw->scl_stop_hold.scl_stop_hold_time = stop_hold;
} }
/** /**
@ -355,8 +358,8 @@ static inline void i2c_ll_set_stop_timing(i2c_dev_t *hw, int stop_setup, int sto
*/ */
static inline void i2c_ll_set_sda_timing(i2c_dev_t *hw, int sda_sample, int sda_hold) static inline void i2c_ll_set_sda_timing(i2c_dev_t *hw, int sda_sample, int sda_hold)
{ {
hw->sda_hold.time = sda_hold; hw->sda_hold.sda_hold_time = sda_hold;
hw->sda_sample.time = sda_sample; hw->sda_sample.sda_sample_time = sda_sample;
} }
/** /**
@ -369,7 +372,7 @@ static inline void i2c_ll_set_sda_timing(i2c_dev_t *hw, int sda_sample, int sda_
*/ */
static inline void i2c_ll_set_txfifo_empty_thr(i2c_dev_t *hw, uint8_t empty_thr) static inline void i2c_ll_set_txfifo_empty_thr(i2c_dev_t *hw, uint8_t empty_thr)
{ {
hw->fifo_conf.tx_fifo_wm_thrhd = empty_thr; hw->fifo_conf.txfifo_wm_thrhd = empty_thr;
} }
/** /**
@ -382,7 +385,7 @@ static inline void i2c_ll_set_txfifo_empty_thr(i2c_dev_t *hw, uint8_t empty_thr)
*/ */
static inline void i2c_ll_set_rxfifo_full_thr(i2c_dev_t *hw, uint8_t full_thr) static inline void i2c_ll_set_rxfifo_full_thr(i2c_dev_t *hw, uint8_t full_thr)
{ {
hw->fifo_conf.rx_fifo_wm_thrhd = full_thr; hw->fifo_conf.rxfifo_wm_thrhd = full_thr;
} }
/** /**
@ -426,8 +429,8 @@ static inline void i2c_ll_get_data_mode(i2c_dev_t *hw, i2c_trans_mode_t *tx_mode
*/ */
static inline void i2c_ll_get_sda_timing(i2c_dev_t *hw, int *sda_sample, int *sda_hold) static inline void i2c_ll_get_sda_timing(i2c_dev_t *hw, int *sda_sample, int *sda_hold)
{ {
*sda_hold = hw->sda_hold.time; *sda_hold = hw->sda_hold.sda_hold_time;
*sda_sample = hw->sda_sample.time; *sda_sample = hw->sda_sample.sda_sample_time;
} }
/** /**
@ -439,7 +442,7 @@ static inline void i2c_ll_get_sda_timing(i2c_dev_t *hw, int *sda_sample, int *sd
*/ */
static inline uint32_t i2c_ll_get_hw_version(i2c_dev_t *hw) static inline uint32_t i2c_ll_get_hw_version(i2c_dev_t *hw)
{ {
return hw->date; return hw->date.val;
} }
/** /**
@ -475,7 +478,7 @@ static inline bool i2c_ll_is_master_mode(i2c_dev_t *hw)
*/ */
static inline uint32_t i2c_ll_get_rxfifo_cnt(i2c_dev_t *hw) static inline uint32_t i2c_ll_get_rxfifo_cnt(i2c_dev_t *hw)
{ {
return hw->sr.rx_fifo_cnt; return hw->sr.rxfifo_cnt;
} }
/** /**
@ -487,7 +490,7 @@ static inline uint32_t i2c_ll_get_rxfifo_cnt(i2c_dev_t *hw)
*/ */
static inline uint32_t i2c_ll_get_txfifo_len(i2c_dev_t *hw) static inline uint32_t i2c_ll_get_txfifo_len(i2c_dev_t *hw)
{ {
return SOC_I2C_FIFO_LEN - hw->sr.tx_fifo_cnt; return SOC_I2C_FIFO_LEN - hw->sr.txfifo_cnt;
} }
/** /**
@ -499,7 +502,7 @@ static inline uint32_t i2c_ll_get_txfifo_len(i2c_dev_t *hw)
*/ */
static inline uint32_t i2c_ll_get_tout(i2c_dev_t *hw) static inline uint32_t i2c_ll_get_tout(i2c_dev_t *hw)
{ {
return hw->timeout.tout; return hw->to.time_out_value;
} }
/** /**
@ -525,8 +528,8 @@ static inline void i2c_ll_trans_start(i2c_dev_t *hw)
*/ */
static inline void i2c_ll_get_start_timing(i2c_dev_t *hw, int *setup_time, int *hold_time) static inline void i2c_ll_get_start_timing(i2c_dev_t *hw, int *setup_time, int *hold_time)
{ {
*setup_time = hw->scl_rstart_setup.time; *setup_time = hw->scl_rstart_setup.scl_rstart_setup_time;
*hold_time = hw->scl_start_hold.time + 1; *hold_time = hw->scl_start_hold.scl_start_hold_time + 1;
} }
/** /**
@ -540,8 +543,8 @@ static inline void i2c_ll_get_start_timing(i2c_dev_t *hw, int *setup_time, int *
*/ */
static inline void i2c_ll_get_stop_timing(i2c_dev_t *hw, int *setup_time, int *hold_time) static inline void i2c_ll_get_stop_timing(i2c_dev_t *hw, int *setup_time, int *hold_time)
{ {
*setup_time = hw->scl_stop_setup.time; *setup_time = hw->scl_stop_setup.scl_stop_setup_time;
*hold_time = hw->scl_stop_hold.time; *hold_time = hw->scl_stop_hold.scl_stop_hold_time;
} }
/** /**
@ -555,8 +558,8 @@ static inline void i2c_ll_get_stop_timing(i2c_dev_t *hw, int *setup_time, int *h
*/ */
static inline void i2c_ll_get_scl_timing(i2c_dev_t *hw, int *high_period, int *low_period) static inline void i2c_ll_get_scl_timing(i2c_dev_t *hw, int *high_period, int *low_period)
{ {
*high_period = hw->scl_high_period.period + hw->scl_high_period.scl_wait_high_period; *high_period = hw->scl_high_period.scl_high_period + hw->scl_high_period.scl_wait_high_period;
*low_period = hw->scl_low_period.period + 1; *low_period = hw->scl_low_period.scl_low_period + 1;
} }
/** /**
@ -571,7 +574,7 @@ static inline void i2c_ll_get_scl_timing(i2c_dev_t *hw, int *high_period, int *l
static inline void i2c_ll_write_txfifo(i2c_dev_t *hw, uint8_t *ptr, uint8_t len) static inline void i2c_ll_write_txfifo(i2c_dev_t *hw, uint8_t *ptr, uint8_t len)
{ {
for (int i = 0; i< len; i++) { for (int i = 0; i< len; i++) {
hw->fifo_data.data = ptr[i]; hw->data.fifo_rdata = ptr[i];
} }
} }
@ -587,7 +590,7 @@ static inline void i2c_ll_write_txfifo(i2c_dev_t *hw, uint8_t *ptr, uint8_t len)
static inline void i2c_ll_read_rxfifo(i2c_dev_t *hw, uint8_t *ptr, uint8_t len) static inline void i2c_ll_read_rxfifo(i2c_dev_t *hw, uint8_t *ptr, uint8_t len)
{ {
for(int i = 0; i < len; i++) { for(int i = 0; i < len; i++) {
ptr[i] = hw->fifo_data.data; ptr[i] = hw->data.fifo_rdata;
} }
} }
@ -603,13 +606,13 @@ static inline void i2c_ll_read_rxfifo(i2c_dev_t *hw, uint8_t *ptr, uint8_t len)
static inline void i2c_ll_set_filter(i2c_dev_t *hw, uint8_t filter_num) static inline void i2c_ll_set_filter(i2c_dev_t *hw, uint8_t filter_num)
{ {
if (filter_num > 0) { if (filter_num > 0) {
hw->filter_cfg.scl_thres = filter_num; hw->filter_cfg.scl_filter_thres = filter_num;
hw->filter_cfg.sda_thres = filter_num; hw->filter_cfg.sda_filter_thres = filter_num;
hw->filter_cfg.scl_en = 1; hw->filter_cfg.scl_filter_en = 1;
hw->filter_cfg.sda_en = 1; hw->filter_cfg.sda_filter_en = 1;
} else { } else {
hw->filter_cfg.scl_en = 0; hw->filter_cfg.scl_filter_en = 0;
hw->filter_cfg.sda_en = 0; hw->filter_cfg.sda_filter_en = 0;
} }
} }
@ -622,7 +625,7 @@ static inline void i2c_ll_set_filter(i2c_dev_t *hw, uint8_t filter_num)
*/ */
static inline uint8_t i2c_ll_get_filter(i2c_dev_t *hw) static inline uint8_t i2c_ll_get_filter(i2c_dev_t *hw)
{ {
return hw->filter_cfg.scl_thres; return hw->filter_cfg.scl_filter_thres;
} }
/** /**
@ -825,15 +828,15 @@ static inline void i2c_ll_set_source_clk(i2c_dev_t *hw, i2c_sclk_t src_clk)
static inline void i2c_ll_master_get_event(i2c_dev_t *hw, i2c_intr_event_t *event) static inline void i2c_ll_master_get_event(i2c_dev_t *hw, i2c_intr_event_t *event)
{ {
typeof(hw->int_status) int_sts = hw->int_status; typeof(hw->int_status) int_sts = hw->int_status;
if (int_sts.arbitration_lost) { if (int_sts.arbitration_lost_int_st) {
*event = I2C_INTR_EVENT_ARBIT_LOST; *event = I2C_INTR_EVENT_ARBIT_LOST;
} else if (int_sts.nack) { } else if (int_sts.nack_int_st) {
*event = I2C_INTR_EVENT_NACK; *event = I2C_INTR_EVENT_NACK;
} else if (int_sts.time_out) { } else if (int_sts.time_out_int_st) {
*event = I2C_INTR_EVENT_TOUT; *event = I2C_INTR_EVENT_TOUT;
} else if (int_sts.end_detect) { } else if (int_sts.end_detect_int_st) {
*event = I2C_INTR_EVENT_END_DET; *event = I2C_INTR_EVENT_END_DET;
} else if (int_sts.trans_complete) { } else if (int_sts.trans_complete_int_st) {
*event = I2C_INTR_EVENT_TRANS_DONE; *event = I2C_INTR_EVENT_TRANS_DONE;
} else { } else {
*event = I2C_INTR_EVENT_ERR; *event = I2C_INTR_EVENT_ERR;
@ -851,11 +854,11 @@ static inline void i2c_ll_master_get_event(i2c_dev_t *hw, i2c_intr_event_t *even
static inline void i2c_ll_slave_get_event(i2c_dev_t *hw, i2c_intr_event_t *event) static inline void i2c_ll_slave_get_event(i2c_dev_t *hw, i2c_intr_event_t *event)
{ {
typeof(hw->int_status) int_sts = hw->int_status; typeof(hw->int_status) int_sts = hw->int_status;
if (int_sts.tx_fifo_wm) { if (int_sts.txfifo_wm_int_st) {
*event = I2C_INTR_EVENT_TXFIFO_EMPTY; *event = I2C_INTR_EVENT_TXFIFO_EMPTY;
} else if (int_sts.trans_complete) { } else if (int_sts.trans_complete_int_st) {
*event = I2C_INTR_EVENT_TRANS_DONE; *event = I2C_INTR_EVENT_TRANS_DONE;
} else if (int_sts.rx_fifo_wm) { } else if (int_sts.rxfifo_wm_int_st) {
*event = I2C_INTR_EVENT_RXFIFO_FULL; *event = I2C_INTR_EVENT_RXFIFO_FULL;
} else { } else {
*event = I2C_INTR_EVENT_ERR; *event = I2C_INTR_EVENT_ERR;

View File

@ -861,6 +861,67 @@ FORCE_INLINE_ATTR uint16_t uart_ll_max_tout_thrd(uart_dev_t *hw)
return UART_RX_TOUT_THRHD_V; return UART_RX_TOUT_THRHD_V;
} }
/**
* @brief Configure the auto baudrate.
*
* @param hw Beginning address of the peripheral registers.
* @param enable Boolean marking whether the auto baudrate should be enabled or not.
*/
FORCE_INLINE_ATTR void uart_ll_set_autobaud_en(uart_dev_t *hw, bool enable)
{
hw->conf0.autobaud_en = enable ? 1 : 0;
}
/**
* @brief Get the RXD edge count.
*
* @param hw Beginning address of the peripheral registers.
*/
FORCE_INLINE_ATTR uint32_t uart_ll_get_rxd_edge_cnt(uart_dev_t *hw)
{
return hw->rxd_cnt.edge_cnt;
}
/**
* @brief Get the positive pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
FORCE_INLINE_ATTR uint32_t uart_ll_get_pos_pulse_cnt(uart_dev_t *hw)
{
return hw->pospulse.min_cnt;
}
/**
* @brief Get the negative pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
FORCE_INLINE_ATTR uint32_t uart_ll_get_neg_pulse_cnt(uart_dev_t *hw)
{
return hw->negpulse.min_cnt;
}
/**
* @brief Get the high pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
FORCE_INLINE_ATTR uint32_t uart_ll_get_high_pulse_cnt(uart_dev_t *hw)
{
return hw->highpulse.min_cnt;
}
/**
* @brief Get the low pulse minimum count.
*
* @param hw Beginning address of the peripheral registers.
*/
FORCE_INLINE_ATTR uint32_t uart_ll_get_low_pulse_cnt(uart_dev_t *hw)
{
return hw->lowpulse.min_cnt;
}
/** /**
* @brief Force UART xoff. * @brief Force UART xoff.
* *

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -148,6 +148,25 @@ When :cpp:member:`i2c_config_t::clk_flags` is 0, the clock allocator will select
1. :c:macro:`I2C_SCLK_SRC_FLAG_AWARE_DFS`: Clock's baud rate will not change while APB clock is changing. 1. :c:macro:`I2C_SCLK_SRC_FLAG_AWARE_DFS`: Clock's baud rate will not change while APB clock is changing.
2. :c:macro:`I2C_SCLK_SRC_FLAG_LIGHT_SLEEP`: It supports Light-sleep mode, which APB clock cannot do. 2. :c:macro:`I2C_SCLK_SRC_FLAG_LIGHT_SLEEP`: It supports Light-sleep mode, which APB clock cannot do.
.. only:: esp32s3
.. list-table:: Characteristics of {IDF_TARGET_NAME} clock sources
:widths: 5 5 50 20
:header-rows: 1
* - Clock name
- Clock frequency
- MAX freq for SCL
- Clock capabilities
* - XTAL clock
- 40 MHz
- 2 MHz
- /
* - RTC clock
- 20 MHz
- 1 MHz
- :c:macro:`I2C_SCLK_SRC_FLAG_AWARE_DFS`, :c:macro:`I2C_SCLK_SRC_FLAG_LIGHT_SLEEP`
.. only:: esp32c3 .. only:: esp32c3
.. list-table:: Characteristics of {IDF_TARGET_NAME} clock sources .. list-table:: Characteristics of {IDF_TARGET_NAME} clock sources

View File

@ -19,7 +19,7 @@ To run this example, you should have one ESP development board (e.g. ESP32-WROVE
#### Pin Assignment(esp32, esp32s2): #### Pin Assignment(esp32, esp32s2):
**Note:** The following pin assignments are used by default, yout can change these in the `menuconfig` . **Note:** The following pin assignments are used by default, you can change these in the `menuconfig` .
| | SDA | SCL | | | SDA | SCL |
| ------------------------- | ------ | ------ | | ------------------------- | ------ | ------ |
@ -41,6 +41,30 @@ To run this example, you should have one ESP development board (e.g. ESP32-WROVE
**Note:** It is recommended to add external pull-up resistors for SDA/SCL pins to make the communication more stable, though the driver will enable internal pull-up resistors. **Note:** It is recommended to add external pull-up resistors for SDA/SCL pins to make the communication more stable, though the driver will enable internal pull-up resistors.
#### Pin Assignment(esp32s3):
**Note:** The following pin assignments are used by default, you can change these in the `menuconfig` .
| | SDA | SCL |
| ------------------------- | ------ | ------ |
| ESP32-S3 I2C Master | GPIO1 | GPIO2 |
| ESP32-S3 I2C Slave | GPIO4 | GPIO5 |
| BH1750 Sensor | SDA | SCL |
- slave:
- GPIO4 is assigned as the data signal of I2C slave port
- GPIO5 is assigned as the clock signal of I2C slave port
- master:
- GPIO1 is assigned as the data signal of I2C master port
- GPIO2 is assigned as the clock signal of I2C master port
- Connection:
- connect GPIO1 with GPIO4
- connect GPIO2 with GPIO5
- connect SDA/SCL of BH1750 sensor with GPIO18/GPIO19
**Note:** It is recommended to add external pull-up resistors for SDA/SCL pins to make the communication more stable, though the driver will enable internal pull-up resistors.
#### Pin Assignment(esp32c3): #### Pin Assignment(esp32c3):
**Note:** The following pin assignments are used by default, you can change these in the `menuconfig` . **Note:** The following pin assignments are used by default, you can change these in the `menuconfig` .

View File

@ -4,14 +4,16 @@ menu "Example Configuration"
config I2C_MASTER_SCL config I2C_MASTER_SCL
int "SCL GPIO Num" int "SCL GPIO Num"
default 6 if IDF_TARGET_ESP32C3 default 6 if IDF_TARGET_ESP32C3
default 19 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 default 2 if IDF_TARGET_ESP32S3
default 19 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2
help help
GPIO number for I2C Master clock line. GPIO number for I2C Master clock line.
config I2C_MASTER_SDA config I2C_MASTER_SDA
int "SDA GPIO Num" int "SDA GPIO Num"
default 5 if IDF_TARGET_ESP32C3 default 5 if IDF_TARGET_ESP32C3
default 18 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 default 1 if IDF_TARGET_ESP32S3
default 18 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2
help help
GPIO number for I2C Master data line. GPIO number for I2C Master data line.

View File

@ -18,16 +18,19 @@ If you have some trouble in developing I2C related applications, or just want to
### Hardware Required ### Hardware Required
To run this example, you should have one ESP32 dev board (e.g. ESP32-WROVER Kit) or ESP32 core board (e.g. ESP32-DevKitC). For test purpose, you should have a kind of device with I2C interface as well. Here we will take the CCS811 sensor as an example to show how to test the function of this sensor without writing any code (just use the command-line tools supported by this example). For more information about CCS811, you can consult the [online datasheet](http://ams.com/ccs811). To run this example, you should have any ESP32, ESP32-S and ESP32-C based development board. For test purpose, you should have a kind of device with I2C interface as well. Here we will take the CCS811 sensor as an example to show how to test the function of this sensor without writing any code (just use the command-line tools supported by this example). For more information about CCS811, you can consult the [online datasheet](http://ams.com/ccs811).
#### Pin Assignment: #### Pin Assignment:
**Note:** The following pin assignments are used by default, you can change them with `i2cconfig` command at any time. **Note:** The following pin assignments are used by default, you can change them with `i2cconfig` command at any time.
| | SDA | SCL | GND | Other | VCC | | | SDA | SCL | GND | Other | VCC |
| ---------------- | ------ | ------ | ---- | ----- | ---- | | ------------------- | ------ | ------ | ---- | ----- | ---- |
| ESP32 I2C Master | GPIO18 | GPIO19 | GND | GND | 3.3V | | ESP32 I2C Master | GPIO18 | GPIO19 | GND | GND | 3.3V |
| Sensor | SDA | SCL | GND | WAK | VCC | | ESP32-S2 I2C Master | GPIO18 | GPIO19 | GND | GND | 3.3V |
| ESP32-S3 I2C Master | GPIO1 | GPIO2 | GND | GND | 3.3V |
| ESP32-C3 I2C Master | GPIO5 | GPIO6 | GND | GND | 3.3V |
| Sensor | SDA | SCL | GND | WAK | VCC |
**Note: ** Theres no need to add an external pull-up resistors for SDA/SCL pin, because the driver will enable the internal pull-up resistors itself. **Note: ** Theres no need to add an external pull-up resistors for SDA/SCL pin, because the driver will enable the internal pull-up resistors itself.

View File

@ -23,8 +23,17 @@
static const char *TAG = "cmd_i2ctools"; static const char *TAG = "cmd_i2ctools";
#if CONFIG_IDF_TARGET_ESP32S3
static gpio_num_t i2c_gpio_sda = 1;
static gpio_num_t i2c_gpio_scl = 2;
#elif CONFIG_IDF_TARGET_ESP32C3
static gpio_num_t i2c_gpio_sda = 5;
static gpio_num_t i2c_gpio_scl = 6;
#else
static gpio_num_t i2c_gpio_sda = 18; static gpio_num_t i2c_gpio_sda = 18;
static gpio_num_t i2c_gpio_scl = 19; static gpio_num_t i2c_gpio_scl = 19;
#endif
static uint32_t i2c_frequency = 100000; static uint32_t i2c_frequency = 100000;
static i2c_port_t i2c_port = I2C_NUM_0; static i2c_port_t i2c_port = I2C_NUM_0;