1 // Copyright (C) 2022 Beken Corporation 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 #include <common/bk_err.h> 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 #define I2C_BAUD_RATE_100KHZ 100000 24 #define I2C_BAUD_RATE_200KHZ 200000 25 #define I2C_BAUD_RATE_400KHZ 400000 26 #define I2C_DEFAULT_BAUD_RATE I2C_BAUD_RATE_100KHZ 27 28 typedef uint8_t i2c_unit_t; /**< i2c uint id */ 29 30 typedef enum { 31 I2C_ID_0 = 0, /**< i2c id 0 */ 32 #if (SOC_I2C_UNIT_NUM > 1) 33 I2C_ID_1, /**< i2c id 1 */ 34 #endif 35 #if (SOC_I2C_UNIT_NUM > 2) 36 I2C_ID_2, /**< i2c id 2 */ 37 #endif 38 I2C_ID_MAX /**< i2c id max */ 39 } i2c_id_t; 40 41 typedef enum { 42 I2C_ADDR_MODE_7BIT = 0, /**< i2c address mode 7bit */ 43 I2C_ADDR_MODE_10BIT, /**< i2c address mode 10bit */ 44 } i2c_addr_mode_t; 45 46 typedef enum { 47 I2C_FIFO_INT_LEVEL_1 = 0, /**< i2c fifo int level 1 */ 48 I2C_FIFO_INT_LEVEL_4, /**< i2c fifo int level 4 */ 49 I2C_FIFO_INT_LEVEL_8, /**< i2c fifo int level 8 */ 50 I2C_FIFO_INT_LEVEL_12, /**< i2c fifo int level 12 */ 51 } i2c_fifo_int_level_t; 52 53 typedef enum { 54 I2C_MEM_ADDR_SIZE_8BIT = 0, /**< i2c memory address size 8bit */ 55 I2C_MEM_ADDR_SIZE_16BIT, /**< i2c memory address size 16bit */ 56 } i2c_mem_addr_size_t; 57 58 typedef struct { 59 uint32_t baud_rate; /**< i2c clock rate */ 60 i2c_addr_mode_t addr_mode; /**< i2c address mode */ 61 uint16_t slave_addr; /**< i2c address for slave mode */ 62 } i2c_config_t; 63 64 #ifdef __cplusplus 65 } 66 #endif 67 68