xtensa/esp32s3: Add driver for I2C peripheral in Master mode

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
This commit is contained in:
Gustavo Henrique Nihei 2022-06-28 13:49:16 -03:00 committed by Petro Karashchenko
parent 43685aefc8
commit ea829cf7d5
6 changed files with 3718 additions and 6 deletions

View File

@ -14,6 +14,7 @@ choice
config ARCH_CHIP_ESP32S3WROOM1
bool "ESP32-S3-WROOM-1"
select ESP32S3_FLASH_4M
select ARCH_HAVE_I2CRESET
---help---
Generic module with an embedded ESP32-S3.
@ -21,12 +22,14 @@ config ARCH_CHIP_ESP32S3WROOM2
bool "ESP32-S3-WROOM-2"
select ESP32S3_FLASH_16M
select ESP32S3_PSRAM_8M
select ARCH_HAVE_I2CRESET
---help---
Generic module with an embedded ESP32-S3.
config ARCH_CHIP_ESP32S3MINI1
bool "ESP32-S3-MINI-1"
select ESP32S3_FLASH_8M
select ARCH_HAVE_I2CRESET
---help---
Generic module with an embedded ESP32-S3.
@ -306,6 +309,10 @@ config ESP32S3_TIMER
bool
default n
config ESP32S3_I2C
bool
default n
config ESP32S3_SPI
bool
default n
@ -351,11 +358,23 @@ config ESP32S3_UART2
select UART2_SERIALDRIVER
select ARCH_HAVE_SERIAL_TERMIOS
config ESP32S3_I2C0
bool "I2C 0"
default n
select ESP32S3_I2C
select I2C
config ESP32S3_I2C1
bool "I2C 1"
default n
select ESP32S3_I2C
select I2C
config ESP32S3_USBSERIAL
bool "USB-Serial Driver"
default n
select OTHER_UART_SERIALDRIVER
select ARCH_HAVE_SERIAL_TERMIOS
bool "USB-Serial Driver"
default n
select OTHER_UART_SERIALDRIVER
select ARCH_HAVE_SERIAL_TERMIOS
config ESP32S3_TIMER0
bool "54-bit Timer 0 (Group 0 Timer 0)"
@ -484,7 +503,7 @@ config ESP32S3_SPIRAM_RODATA
default n
---help---
If enabled, rodata in flash will be copied into SPIRAM.
If ESP32S3_ESP32S2_SPIRAM_FETCH_INSTRUCTIONS is also enabled,
If ESP32S3_SPIRAM_FETCH_INSTRUCTIONS is also enabled,
you can run the instruction when erasing or programming the
flash.
@ -688,6 +707,47 @@ endif # ESP32S3_UART2
endmenu # UART Configuration
menu "I2C Configuration"
depends on ESP32S3_I2C
if ESP32S3_I2C0
config ESP32S3_I2C0_SCLPIN
int "I2C0 SCL Pin"
default 2
range 0 48
config ESP32S3_I2C0_SDAPIN
int "I2C0 SDA Pin"
default 1
range 0 48
endif # ESP32S3_I2C0
if ESP32S3_I2C1
config ESP32S3_I2C1_SCLPIN
int "I2C1 SCL Pin"
default 5
range 0 48
config ESP32S3_I2C1_SDAPIN
int "I2C1 SDA Pin"
default 4
range 0 48
endif # ESP32S3_I2C1
config ESP32S3_I2CTIMEOSEC
int "Timeout seconds"
default 0
config ESP32S3_I2CTIMEOMS
int "Timeout milliseconds"
default 500
endmenu # I2C Configuration
menu "Timer/Counter Configuration"
depends on ESP32S3_TIMER

View File

@ -125,6 +125,10 @@ ifeq ($(CONFIG_ESP32S3_RT_TIMER),y)
CHIP_CSRCS += esp32s3_rt_timer.c
endif
ifeq ($(CONFIG_ESP32S3_I2C),y)
CHIP_CSRCS += esp32s3_i2c.c
endif
ifeq ($(CONFIG_ESP32S3_SPI),y)
CHIP_CSRCS += esp32s3_spi.c
endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,91 @@
/****************************************************************************
* arch/xtensa/src/esp32s3/esp32s3_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_ESP32S3_ESP32S3_I2C_H
#define __ARCH_XTENSA_SRC_ESP32S3_ESP32S3_I2C_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/i2c/i2c_master.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef __ASSEMBLY__
#ifdef CONFIG_ESP32S3_I2C0
# define ESP32S3_I2C0 0
#endif
#ifdef CONFIG_ESP32S3_I2C1
# define ESP32S3_I2C1 1
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: esp32s3_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
*
****************************************************************************/
struct i2c_master_s *esp32s3_i2cbus_initialize(int port);
/****************************************************************************
* Name: esp32s3_i2cbus_uninitialize
*
* Description:
* De-initialize the selected I2C port, and power down the device.
*
* Input Parameters:
* Device structure as returned by the esp32s3_i2cbus_initialize()
*
* Returned Value:
* OK on success, ERROR when internal reference count mismatch or dev
* points to invalid hardware device.
*
****************************************************************************/
int esp32s3_i2cbus_uninitialize(struct i2c_master_s *dev);
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_XTENSA_SRC_ESP32S3_ESP32S3_I2C_H */

File diff suppressed because it is too large Load Diff

View File

@ -258,7 +258,7 @@
/* Helper to place a value in a field */
#define VALUE_TO_FIELD(_value, _field) ((_value << (_field##_S)) & (_field##_M))
#define VALUE_TO_FIELD(_value, _field) (((_value) << (_field##_S)) & (_field##_M))
/* Peripheral Clock */