1 // Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 #include <stdint.h> 22 #include <stdbool.h> 23 #include "soc/soc_caps.h" 24 25 /** 26 * @brief I2C port number, can be I2C_NUM_0 ~ (I2C_NUM_MAX-1). 27 */ 28 typedef int i2c_port_t; 29 30 typedef enum{ 31 I2C_MODE_SLAVE = 0, /*!< I2C slave mode */ 32 I2C_MODE_MASTER, /*!< I2C master mode */ 33 I2C_MODE_MAX, 34 } i2c_mode_t; 35 36 typedef enum { 37 I2C_MASTER_WRITE = 0, /*!< I2C write data */ 38 I2C_MASTER_READ, /*!< I2C read data */ 39 } i2c_rw_t; 40 41 typedef enum { 42 I2C_DATA_MODE_MSB_FIRST = 0, /*!< I2C data msb first */ 43 I2C_DATA_MODE_LSB_FIRST = 1, /*!< I2C data lsb first */ 44 I2C_DATA_MODE_MAX 45 } i2c_trans_mode_t; 46 47 typedef enum { 48 I2C_ADDR_BIT_7 = 0, /*!< I2C 7bit address for slave mode */ 49 I2C_ADDR_BIT_10, /*!< I2C 10bit address for slave mode */ 50 I2C_ADDR_BIT_MAX, 51 } i2c_addr_mode_t; 52 53 typedef enum { 54 I2C_MASTER_ACK = 0x0, /*!< I2C ack for each byte read */ 55 I2C_MASTER_NACK = 0x1, /*!< I2C nack for each byte read */ 56 I2C_MASTER_LAST_NACK = 0x2, /*!< I2C nack for the last byte*/ 57 I2C_MASTER_ACK_MAX, 58 } i2c_ack_type_t; 59 60 /** 61 * @brief I2C clock source, sorting from smallest to largest, 62 * place them in order. 63 * This can be expanded in the future use. 64 */ 65 typedef enum { 66 I2C_SCLK_DEFAULT = 0, /*!< I2C source clock not selected*/ 67 #if SOC_I2C_SUPPORT_APB 68 I2C_SCLK_APB, /*!< I2C source clock from APB, 80M*/ 69 #endif 70 #if SOC_I2C_SUPPORT_XTAL 71 I2C_SCLK_XTAL, /*!< I2C source clock from XTAL, 40M */ 72 #endif 73 #if SOC_I2C_SUPPORT_RTC 74 I2C_SCLK_RTC, /*!< I2C source clock from 8M RTC, 8M */ 75 #endif 76 #if SOC_I2C_SUPPORT_REF_TICK 77 I2C_SCLK_REF_TICK, /*!< I2C source clock from REF_TICK, 1M */ 78 #endif 79 I2C_SCLK_MAX, 80 } i2c_sclk_t; 81 82 /// Use the highest speed that is available for the clock source picked by clk_flags 83 #define I2C_CLK_FREQ_MAX (-1) 84 85 #if CONFIG_IDF_TARGET_ESP32 86 typedef enum{ 87 I2C_CMD_RESTART = 0, /*!<I2C restart command */ 88 I2C_CMD_WRITE, /*!<I2C write command */ 89 I2C_CMD_READ, /*!<I2C read command */ 90 I2C_CMD_STOP, /*!<I2C stop command */ 91 I2C_CMD_END /*!<I2C end command */ 92 } i2c_opmode_t __attribute__((deprecated)); 93 #endif 94 95 #ifdef __cplusplus 96 } 97 #endif 98