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 <driver/hal/hal_i2c_types.h> 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 #define BK_ERR_I2C_NOT_INIT (BK_ERR_I2C_BASE - 1) /**< I2C driver not init */ 24 #define BK_ERR_I2C_ID_NOT_INIT (BK_ERR_I2C_BASE - 2) /**< I2C id not init */ 25 #define BK_ERR_I2C_SM_BUS_BUSY (BK_ERR_I2C_BASE - 3) /**< I2C bus busy */ 26 #define BK_ERR_I2C_ACK_TIMEOUT (BK_ERR_I2C_BASE - 4) /**< I2C receive ack timeout */ 27 #define BK_ERR_I2C_CHECK_DEFCONFIG (BK_ERR_I2C_BASE - 5) /**< I2C please check defconfig */ 28 29 30 typedef enum { 31 I2C_MASTER_WRITE = 0, /**< I2C master write */ 32 I2C_MASTER_READ, /**< I2C master read */ 33 I2C_SLAVE_WRITE, /**< I2C slave write */ 34 I2C_SLAVE_READ, /**< I2C slave read */ 35 } i2c_work_mode_t; 36 37 typedef void (*i2c_isr_t)(i2c_id_t id, void *param); /**< i2c interrupt service routine */ 38 39 typedef struct { 40 uint32_t dev_addr; /**< I2C slave device address */ 41 uint32_t mem_addr; /**< I2C slave device memerory address */ 42 i2c_mem_addr_size_t mem_addr_size; /**< I2C slave device memerory address size */ 43 uint8_t *data; /**< I2C data pointer */ 44 uint32_t data_size; /**< I2C data size */ 45 uint32_t timeout_ms; /**< I2C timeout ms */ 46 } i2c_mem_param_t; 47 48 #ifdef __cplusplus 49 } 50 #endif 51 52