1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-25 22:43:50 +01:00

cpu/esp32: port periph/i2c_hw to ESP-IDF i2c HAL

This commit is contained in:
Gunar Schorcht 2022-06-28 20:51:22 +02:00
parent dd806ce72e
commit c0becd2819
5 changed files with 450 additions and 618 deletions

View File

@ -100,24 +100,48 @@ static const gpio_t dac_channels[] = DAC_GPIOS;
* @{
*/
#if defined(I2C0_SCL) && !defined(I2C0_SCL_PULLUP)
/** Define SCL pullup enabled by default */
#define I2C0_SCL_PULLUP true
#endif
#if defined(I2C0_SDA) && !defined(I2C0_SDA_PULLUP)
/** Define SDA pullup enabled by default */
#define I2C0_SDA_PULLUP true
#endif
#if defined(I2C1_SCL) && !defined(I2C1_SCL_PULLUP)
/** Define SCL pullup enabled by default */
#define I2C1_SCL_PULLUP true
#endif
#if defined(I2C1_SDA) && !defined(I2C1_SDA_PULLUP)
/** Define SDA pullup enabled by default */
#define I2C1_SDA_PULLUP true
#endif
/**
* @brief Static array with configuration for declared I2C devices
*/
static const i2c_conf_t i2c_config[] = {
#if defined(I2C0_SCL) && defined(I2C0_SDA) && defined(I2C0_SPEED)
#if defined(I2C0_SCL) && defined(I2C0_SDA) && defined(I2C0_SPEED)
{
.module = PERIPH_I2C0_MODULE,
.speed = I2C0_SPEED,
.scl = I2C0_SCL,
.sda = I2C0_SDA,
.scl_pullup = I2C0_SCL_PULLUP,
.sda_pullup = I2C0_SCL_PULLUP,
},
#endif
#if defined(I2C1_SCL) && defined(I2C1_SDA) && defined(I2C1_SPEED)
#endif
#if defined(I2C1_SCL) && defined(I2C1_SDA) && defined(I2C1_SPEED)
{
.module = PERIPH_I2C1_MODULE,
.speed = I2C1_SPEED,
.scl = I2C1_SCL,
.sda = I2C1_SDA,
.scl_pullup = I2C1_SCL_PULLUP,
.sda_pullup = I2C1_SCL_PULLUP,
},
#endif
#endif
};
/**
@ -287,18 +311,18 @@ static const uart_conf_t uart_config[] = {
.txd = UART0_TXD,
.rxd = UART0_RXD,
},
#if defined(UART1_TXD) && defined(UART1_RXD)
#if defined(UART1_TXD) && defined(UART1_RXD)
{
.txd = UART1_TXD,
.rxd = UART1_RXD,
},
#endif
#if defined(UART2_TXD) && defined(UART2_RXD)
#endif
#if defined(UART2_TXD) && defined(UART2_RXD)
{
.txd = UART2_TXD,
.rxd = UART2_RXD,
},
#endif
#endif
};
/**

View File

@ -19,6 +19,7 @@
#ifndef PERIPH_CPU_H
#define PERIPH_CPU_H
#include <stdbool.h>
#include <stdint.h>
#include "sdkconfig.h"
#include "hal/ledc_types.h"
@ -349,15 +350,18 @@ typedef enum {
* @brief I2C configuration structure type
*/
typedef struct {
uint8_t module; /**< I2C module identifier */
i2c_speed_t speed; /**< I2C bus speed */
gpio_t scl; /**< GPIO used as SCL pin */
gpio_t sda; /**< GPIO used as SDA pin */
bool scl_pullup; /**< Pullup enabled for SCL pin */
bool sda_pullup; /**< Pullup enabled for SDA pin */
} i2c_conf_t;
/**
* @brief Maximum number of I2C interfaces that can be used by board definitions
*/
#define I2C_NUMOF_MAX (2)
#define I2C_NUMOF_MAX (SOC_I2C_NUM)
#define PERIPH_I2C_NEED_READ_REG /**< i2c_read_reg required */
#define PERIPH_I2C_NEED_READ_REGS /**< i2c_read_regs required */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,38 @@
From 25509b8b61b329d3c4ae5b3874704dae55d62ccd Mon Sep 17 00:00:00 2001
From: Gunar Schorcht <gunar@schorcht.net>
Date: Tue, 8 Mar 2022 11:34:13 +0100
Subject: [PATCH 15/17] driver/i2c: remove the include gpio.h in i2c.h header
Including driver/i2c.h by RIOT code leads to type conflicts with RIOT gpio_t type.
---
components/driver/i2c.c | 1 +
components/driver/include/driver/i2c.h | 1 -
2 files changed, 1 insertion(+), 1 deletion(-)
diff --git a/components/driver/i2c.c b/components/driver/i2c.c
index 438d1efc12d..be26fdeffc3 100644
--- a/components/driver/i2c.c
+++ b/components/driver/i2c.c
@@ -21,6 +21,7 @@
#include "hal/i2c_hal.h"
#include "hal/gpio_hal.h"
#include "soc/i2c_periph.h"
+#include "driver/gpio.h"
#include "driver/i2c.h"
#include "driver/periph_ctrl.h"
#include "esp_rom_gpio.h"
diff --git a/components/driver/include/driver/i2c.h b/components/driver/include/driver/i2c.h
index 22dcc8ab241..e668bba2acd 100644
--- a/components/driver/include/driver/i2c.h
+++ b/components/driver/include/driver/i2c.h
@@ -19,7 +19,6 @@ extern "C" {
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/ringbuf.h"
-#include "driver/gpio.h"
#include "soc/soc_caps.h"
#include "hal/i2c_types.h"
--
2.17.1

View File

@ -0,0 +1,34 @@
From cd8688a55e62094cb6605ee8594985f862d57a95 Mon Sep 17 00:00:00 2001
From: Gunar Schorcht <gunar@schorcht.net>
Date: Tue, 8 Mar 2022 11:35:11 +0100
Subject: [PATCH 16/17] driver/i2c.h: expose i2c_hw_fsm_reset to RIOT code
---
components/driver/i2c.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/components/driver/i2c.c b/components/driver/i2c.c
index be26fdeffc3..cff410b9d1b 100644
--- a/components/driver/i2c.c
+++ b/components/driver/i2c.c
@@ -209,7 +209,7 @@ static i2c_clk_alloc_t i2c_clk_alloc[I2C_SCLK_MAX] = {
static i2c_obj_t *p_i2c_obj[I2C_NUM_MAX] = {0};
static void i2c_isr_handler_default(void *arg);
static void IRAM_ATTR i2c_master_cmd_begin_static(i2c_port_t i2c_num);
-static esp_err_t IRAM_ATTR i2c_hw_fsm_reset(i2c_port_t i2c_num);
+esp_err_t IRAM_ATTR i2c_hw_fsm_reset(i2c_port_t i2c_num);
static void i2c_hw_disable(i2c_port_t i2c_num)
{
@@ -595,7 +595,7 @@ static esp_err_t i2c_master_clear_bus(i2c_port_t i2c_num)
* If we remove the power supply for the slave during I2C is reading, or directly connect SDA or SCL to ground,
* this would cause the I2C FSM get stuck in wrong state, all we can do is to reset the I2C hardware in this case.
**/
-static esp_err_t i2c_hw_fsm_reset(i2c_port_t i2c_num)
+esp_err_t i2c_hw_fsm_reset(i2c_port_t i2c_num)
{
#if !SOC_I2C_SUPPORT_HW_FSM_RST
int scl_low_period, scl_high_period;
--
2.17.1