ESP32: Add driver support to I2C

This driver was implemented by Dong Heng <dongheng@espressif.com>
and modified to fix coding style by Alan Carvalho de Assis.

Co-authored-by: Abdelatif Guettouche <abdelatif.guettouche@gmail.com>
This commit is contained in:
Alan C. Assis
2020-07-20 18:43:38 -03:00
committed by Abdelatif Guettouche
parent 904ec767f7
commit cb1d11a499
5 changed files with 2787 additions and 4 deletions
+48 -4
View File
@@ -26,11 +26,8 @@ config ESP32_EMAC
No yet implemented
config ESP32_I2C
bool "I2C"
bool
default n
depends on EXPERIMENTAL
---help---
No yet implemented
config ESP32_I2S0
bool "I2S 0"
@@ -202,6 +199,20 @@ config ESP32_WIRELESS
---help---
No yet implemented
config ESP32_I2C0
bool "I2C 0"
default n
select ESP32_I2C
select I2C
select I2C_DRIVER
config ESP32_I2C1
bool "I2C 1"
default n
select ESP32_I2C
select I2C
select I2C_DRIVER
endmenu # ESP32 Peripheral Selection
menu "Memory Configuration"
@@ -308,6 +319,39 @@ endif # ESP32_UART2
endmenu # UART configuration
menu "I2C configuration"
depends on ESP32_I2C
if ESP32_I2C0
config ESP32_I2C0_SCLPIN
int "I2C0 SCL Pin"
default 24
range 0 39
config ESP32_I2C0_SDAPIN
int "I2C0 SDA Pin"
default 23
range 0 39
endif # ESP32_I2C0
if ESP32_I2C1
config ESP32_I2C1_SCLPIN
int "I2C1 SCL Pin"
default 26
range 0 39
config ESP32_I2C1_SDAPIN
int "I2C1 SDA Pin"
default 25
range 0 39
endif # ESP32_I2C1
endmenu # I2C configuration
menu "SPI configuration"
depends on ESP32_SPI
+4
View File
@@ -100,6 +100,10 @@ CHIP_CSRCS += esp32_gpio.c esp32_intdecode.c esp32_irq.c esp32_region.c
CHIP_CSRCS += esp32_timerisr.c
CHIP_CSRCS += esp32_user.c
ifeq ($(CONFIG_ESP32_I2C),y)
CHIP_CSRCS += esp32_i2c.c
endif
ifeq ($(CONFIG_ESP32_SPI),y)
CHIP_CSRCS += esp32_spi.c
ifeq ($(CONFIG_SPI_SLAVE),y)
File diff suppressed because it is too large Load Diff
+92
View File
@@ -0,0 +1,92 @@
/****************************************************************************
* arch/xtensa/src/esp32/esp32_i2c.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#ifndef __ARCH_XTENSA_SRC_ESP32_ESP32_I2C_H
#define __ARCH_XTENSA_SRC_ESP32_ESP32_I2C_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/i2c/i2c_master.h>
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: esp32_i2cbus_initialize
*
* Description:
* Initialize the selected I2C port. And return a unique instance of struct
* struct i2c_master_s. This function may be called to obtain multiple
* instances of the interface, each of which may be set up with a
* different frequency and slave address.
*
* Input Parameters:
* Port number (for hardware that has multiple I2C interfaces)
*
* Returned Value:
* Valid I2C device structure reference on success; a NULL on failure
*
****************************************************************************/
FAR struct i2c_master_s *esp32_i2cbus_initialize(int port);
/****************************************************************************
* Name: esp32_i2cbus_uninitialize
*
* Description:
* De-initialize the selected I2C port, and power down the device.
*
* Input Parameters:
* Device structure as returned by the esp32_i2cbus_initialize()
*
* Returned Value:
* OK on success, ERROR when internal reference count mismatch or dev
* points to invalid hardware device.
*
****************************************************************************/
int esp32_i2cbus_uninitialize(FAR struct i2c_master_s *dev);
#ifdef __cplusplus
}
#endif
#undef EXTERN
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_XTENSA_SRC_ESP32_ESP32_I2C_H */
File diff suppressed because it is too large Load Diff