Merge branch 'feature/support_i2c_on_esp32h2' into 'master'

i2c: support i2c on esp32h2

Closes IDF-4155

See merge request espressif/esp-idf!17798
pull/8968/head
morris 2022-05-10 22:48:05 +08:00
commit df5872b3a4
4 zmienionych plików z 21 dodań i 11 usunięć

Wyświetl plik

@ -31,7 +31,7 @@
#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 */
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32H2
#define I2C_SLAVE_SCL_IO 5 /*!<gpio number for i2c slave clock */
#define I2C_SLAVE_SDA_IO 6 /*!<gpio number for i2c slave data */
#else
@ -43,7 +43,7 @@
#define I2C_SLAVE_TX_BUF_LEN (2*DATA_LENGTH) /*!<I2C slave tx buffer size */
#define I2C_SLAVE_RX_BUF_LEN (2*DATA_LENGTH) /*!<I2C slave rx buffer size */
#if CONFIG_IDF_TARGET_ESP32C3
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2
#define I2C_MASTER_SCL_IO 5 /*!<gpio number for i2c master clock */
#define I2C_MASTER_SDA_IO 6 /*!<gpio number for i2c master data */
#elif CONFIG_IDF_TARGET_ESP32S3
@ -658,13 +658,12 @@ TEST_CASE("I2C general API test", "[i2c]")
}
}
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S3, ESP32C3, ESP32C2)
//Init uart baud rate detection
static void uart_aut_baud_det_init(int rxd_io_num)
{
gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[rxd_io_num], PIN_FUNC_GPIO);
gpio_set_direction(rxd_io_num, GPIO_MODE_INPUT_OUTPUT);
esp_rom_gpio_connect_out_signal(rxd_io_num, I2CEXT1_SCL_OUT_IDX, 0, 0);
esp_rom_gpio_connect_out_signal(rxd_io_num, I2CEXT0_SCL_OUT_IDX, 0, 0);
esp_rom_gpio_connect_in_signal(rxd_io_num, U1RXD_IN_IDX, 0);
periph_module_enable(PERIPH_UART1_MODULE);
/* Reset all the bits */
@ -676,15 +675,22 @@ static void uart_aut_baud_det_init(int rxd_io_num)
//Calculate I2C scl freq
static void i2c_scl_freq_cal(void)
{
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
const int i2c_source_clk_freq = 80000000;
const float i2c_cource_clk_period = 0.0125;
int expt_cnt = 542;
#else
const int i2c_source_clk_freq = 18000000; // Clock sorce: RTC
const float i2c_cource_clk_period = 0.056;
int expt_cnt = 540;
#endif
int edg_cnt = uart_ll_get_rxd_edge_cnt(&UART1);
int pospulse_cnt = uart_ll_get_pos_pulse_cnt(&UART1);
int negpulse_cnt = uart_ll_get_neg_pulse_cnt(&UART1);
int high_period_cnt = uart_ll_get_high_pulse_cnt(&UART1);
int low_period_cnt = uart_ll_get_low_pulse_cnt(&UART1);
if(edg_cnt != 542) {
printf("\nedg_cnt != 542, test fail\n");
if(edg_cnt != expt_cnt) {
printf("\nedg_cnt != %d, test fail\n", expt_cnt);
return;
}
printf("\nDetected SCL frequency: %d Hz\n", i2c_source_clk_freq / ((pospulse_cnt + negpulse_cnt) / 2) );
@ -697,7 +703,7 @@ static void i2c_scl_freq_cal(void)
TEST_CASE("I2C SCL freq test (local test)", "[i2c][ignore]")
{
//Use the UART baud rate detection function to detect the I2C SCL frequency.
const int i2c_num = 1;
const int i2c_num = 0;
const int uart1_rxd_io = 5;
i2c_config_t conf_master = {
.mode = I2C_MODE_MASTER,
@ -723,6 +729,4 @@ TEST_CASE("I2C SCL freq test (local test)", "[i2c][ignore]")
TEST_ESP_OK(i2c_driver_delete(i2c_num));
}
#endif // TEMPORARY_DISABLED_FOR_TARGETS(ESP32S3, ESP32C3)
#endif // SOC_I2C_SUPPORT_SLAVE

Wyświetl plik

@ -49,6 +49,12 @@ extern "C" {
#define SYSTEM_CPU_DIV_NUM_M (SYSTEM_CPU_DIV_NUM_V << SYSTEM_CPU_DIV_NUM_S)
#define SYSTEM_CPU_DIV_NUM_V 0x000000FFU
#define SYSTEM_CPU_DIV_NUM_S 0
#define SYSTEM_PRE_DIV_CNT SYSTEM_CPU_DIV_NUM
#define SYSTEM_PRE_DIV_CNT_M SYSTEM_CPU_DIV_NUM_M
#define SYSTEM_PRE_DIV_CNT_V SYSTEM_CPU_DIV_NUM_V
#define SYSTEM_PRE_DIV_CNT_S SYSTEM_CPU_DIV_NUM_S
/** SYSTEM_CPU_DIV_NUMERATOR : R/W; bitpos: [13:8]; default: 0;
* Need add description
*/

Wyświetl plik

@ -81,7 +81,7 @@ To run this example, you should have one ESP development board (e.g. ESP32-WROVE
- Connection:
- connect SDA/SCL of BH1750 sensor to GPIO5/GPIO6
**Note:** There is only one i2c device on esp32c3, so you can't try any master-slave example for esp32/s2 in this repo. But you can try external devices. If you find anything wrong with your device, please try connecting pull-up resistors by yourself.
**Note:** There is only one i2c device on ESP32-C3/ESP32-C2/ESP32-H2, so it is not possible to perform any ESP32/ESP32-S2 self-test example from this repo. However it is possible to test I2C with external devices. If you find anything wrong with your device, please try connecting external pull-up resistors.
### Configure the project

Wyświetl plik

@ -12,7 +12,7 @@ If you have a new I2C application to go (for example, read the temperature data
### Hardware Required
To run this example, you should have one ESP32, ESP32-S or ESP32-C based development board as well as a MPU9250. MPU9250 is a inertial measurement unit, which contains a accelerometer, gyroscope as well as a magnetometer, for more information about it, you can read the [datasheet of the MPU9250 sensor](https://invensense.tdk.com/wp-content/uploads/2015/02/PS-MPU-9250A-01-v1.1.pdf).
To run this example, you should have one ESP32, ESP32-S, ESP32-C or ESP32-H based development board as well as a MPU9250. MPU9250 is a inertial measurement unit, which contains a accelerometer, gyroscope as well as a magnetometer, for more information about it, you can read the [datasheet of the MPU9250 sensor](https://invensense.tdk.com/wp-content/uploads/2015/02/PS-MPU-9250A-01-v1.1.pdf).
#### Pin Assignment: