Skip to content

Commit

Permalink
Merge pull request #18279 from gschorcht/cpu/esp32/periph_hal_esp32_i2c
Browse files Browse the repository at this point in the history
cpu/esp32: use ESP-IDF i2c HAL for ESP32 periph/i2c
  • Loading branch information
benpicco authored Jul 17, 2022
2 parents 2c9f338 + 06aa8f2 commit 365fbed
Show file tree
Hide file tree
Showing 6 changed files with 496 additions and 663 deletions.
40 changes: 32 additions & 8 deletions boards/common/esp32/include/periph_conf_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

/**
Expand Down Expand Up @@ -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
};

/**
Expand Down
6 changes: 5 additions & 1 deletion cpu/esp32/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -331,15 +332,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 */
Expand Down
Loading

0 comments on commit 365fbed

Please sign in to comment.