1 /** 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 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 * Description: Provides V150 HAL i2c \n 16 * 17 * History: \n 18 * 2023-03-06, Create file. \n 19 */ 20 21 #ifndef HAL_I2C_V150_MASTER_H 22 #define HAL_I2C_V150_MASTER_H 23 24 #include <stdint.h> 25 #include "hal_i2c.h" 26 #include "hal_i2c_v150_comm.h" 27 28 #ifdef __cplusplus 29 #if __cplusplus 30 extern "C" { 31 #endif /* __cplusplus */ 32 #endif /* __cplusplus */ 33 34 /** 35 * @defgroup drivers_hal_i2c_v150_master I2C_V150 Master 36 * @ingroup drivers_hal_i2c 37 * @{ 38 */ 39 40 #define I2C_10BIT_ADDR_MASK 0x03FF 41 #define I2C_10BIT_ADDR_MASK_H 0x0300 42 #define I2C_10BIT_ADDR_MASK_H_OFFSET 7 43 #define I2C_10BIT_ADDR_MASK_H_TAG 0xF0 44 #define I2C_10BIT_ADDR_MASK_L 0x00FF 45 #define I2C_10BIT_ADDR_MASK_L_OFFSET 0 46 47 #define I2C_7BIT_ADDR_MASK 0x7F 48 49 #define I2C_ADDR_READ_TAG 0x01 50 #define I2C_ADDR_WRITE_TAG 0xFE 51 52 #define I2C_ADDR_TYPE_7BIT 0 53 #define I2C_ADDR_TYPE_10BIT 1 54 #define I2C_ADDR_TYPE_INVALID 2 55 56 /** 57 * @if Eng 58 * @brief Initialize I2C bus as master. 59 * @param [in] bus The I2C bus. see @ref i2c_bus_t 60 * @param [in] baudrate Baudrate to configure I2C SCL_CNT. 61 * @param [in] hscode I2C high speed mode master code. 62 * @param [in] callback I2C interrupt callback function. see @ref hal_i2c_callback_t 63 * @else 64 * @brief 初始化I2C作为主机 65 * @param [in] bus I2C的索引。参考 @ref i2c_bus_t 66 * @param [in] baudrate 配置I2C SCL_CNT所使用的波特率。 67 * @param [in] hscode I2C高速模式下主机码, V150不支持。 68 * @param [in] callback I2C中断回调函数。参考 @ref hal_i2c_callback_t 69 * @endif 70 */ 71 errcode_t hal_i2c_v150_master_init(i2c_bus_t bus, uint32_t baudrate, uint8_t hscode, hal_i2c_callback_t callback); 72 73 /** 74 * @if Eng 75 * @brief Initialize I2C bus as slave. 76 * @param [in] bus The I2C bus. see @ref i2c_bus_t 77 * @param [in] baudrate Baudrate to configure I2C SCL_CNT, slave is same as msater. 78 * @param [in] addr I2C slave address. 79 * @param [in] callback I2C interrupt callback function. see @ref hal_i2c_callback_t 80 * @else 81 * @brief 初始化I2C作为从机。 82 * @param [in] bus I2C的索引。参考 @ref i2c_bus_t 83 * @param [in] baudrate 配置I2C SCL_CNT所使用的波特率,从机与主机一致。 84 * @param [in] addr I2C从机地址。 85 * @param [in] callback I2C中断回调函数。参考 @ref hal_i2c_callback_t 86 * @endif 87 */ 88 errcode_t hal_i2c_v150_slave_init(i2c_bus_t bus, uint32_t baudrate, 89 uint16_t addr, hal_i2c_callback_t callback); 90 91 /** 92 * @} 93 */ 94 95 #ifdef __cplusplus 96 #if __cplusplus 97 } 98 #endif /* __cplusplus */ 99 #endif /* __cplusplus */ 100 101 #endif 102 103