1 /*
2  * Copyright 2017-2018, 2020 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef _FSL_VIDEO_I2C_H_
10 #define _FSL_VIDEO_I2C_H_
11 
12 #include "fsl_common.h"
13 
14 /*
15  * Change log:
16  *
17  *   1.0.1
18  *     - Fixed MISRA-C 2012 issues.
19  *
20  *   1.0.0
21  *     - Initial version
22  */
23 
24 /*******************************************************************************
25  * Definitions
26  ******************************************************************************/
27 
28 /*! @brief Define I2C access function. */
29 typedef status_t (*video_i2c_send_func_t)(
30     uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
31 typedef status_t (*video_i2c_receive_func_t)(
32     uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
33 
34 /*! @brief Video device register address type. */
35 typedef enum _video_reg_addr
36 {
37     kVIDEO_RegAddr8Bit  = 1U, /*!< 8-bit register address.  */
38     kVIDEO_RegAddr16Bit = 2U, /*!< 16-bit register address. */
39 } video_reg_addr_t;
40 
41 /*! @brief Video device register width. */
42 typedef enum _video_reg_width
43 {
44     kVIDEO_RegWidth8Bit  = 1U, /*!< 8-bit register width.  */
45     kVIDEO_RegWidth16Bit = 2U, /*!< 16-bit register width. */
46     kVIDEO_RegWidth32Bit = 4U, /*!< 32-bit register width. */
47 } video_reg_width_t;
48 
49 /*******************************************************************************
50  * API
51  ******************************************************************************/
52 
53 #if defined(__cplusplus)
54 extern "C" {
55 #endif
56 
57 /*!
58  * @brief Write value to the register.
59  *
60  * @param i2cAddr I2C address.
61  * @param addrType Register address type.
62  * @param reg The register to write.
63  * @param regWidth The width of the register.
64  * @param value The value to write.
65  * @param i2cSendFunc The actual I2C send function.
66  * @return Returns @ref kStatus_Success if success, otherwise returns error code.
67  */
68 status_t VIDEO_I2C_WriteReg(uint8_t i2cAddr,
69                             video_reg_addr_t addrType,
70                             uint32_t reg,
71                             video_reg_width_t regWidth,
72                             uint32_t value,
73                             video_i2c_send_func_t i2cSendFunc);
74 
75 /*!
76  * @brief Read the register value.
77  *
78  * @param i2cAddr I2C address.
79  * @param addrType Register address type.
80  * @param reg The register to read.
81  * @param regWidth The width of the register.
82  * @param value The value read out.
83  * @param i2cReceiveFunc The actual I2C receive function.
84  * @return Returns @ref kStatus_Success if success, otherwise returns error code.
85  */
86 status_t VIDEO_I2C_ReadReg(uint8_t i2cAddr,
87                            video_reg_addr_t addrType,
88                            uint32_t reg,
89                            video_reg_width_t regWidth,
90                            void *value,
91                            video_i2c_receive_func_t i2cReceiveFunc);
92 
93 /*!
94  * @brief Modify the register value.
95  *
96  * This function modifies some bit fields of a register.
97  * reg[clrMask] = value & clrMask
98  *
99  * @param i2cAddr I2C address.
100  * @param addrType Register address type.
101  * @param reg The register to modify.
102  * @param regWidth The width of the register.
103  * @param clrMask The mask value to clear.
104  * @param value The value to set.
105  * @param i2cReceiveFunc The actual I2C receive function.
106  * @param i2cSendFunc The actual I2C send function.
107  * @return Returns @ref kStatus_Success if success, otherwise returns error code.
108  */
109 status_t VIDEO_I2C_ModifyReg(uint8_t i2cAddr,
110                              video_reg_addr_t addrType,
111                              uint32_t reg,
112                              video_reg_width_t regWidth,
113                              uint32_t clrMask,
114                              uint32_t value,
115                              video_i2c_receive_func_t i2cReceiveFunc,
116                              video_i2c_send_func_t i2cSendFunc);
117 
118 #if defined(__cplusplus)
119 }
120 #endif
121 
122 #endif /* _FSL_VIDEO_I2C_H_ */
123