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_SCCB_H_
10 #define _FSL_SCCB_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 typedef status_t (*sccb_i2c_send_func_t)(
28     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
29 typedef status_t (*sccb_i2c_receive_func_t)(
30     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
31 
32 /*! @brief SCCB register address type. */
33 typedef enum _sccb_reg_addr
34 {
35     kSCCB_RegAddr8Bit  = 1, /*!< 8-bit register address. */
36     kSCCB_RegAddr16Bit = 2, /*!< 16-bit register address. */
37 } sccb_reg_addr_t;
38 
39 /*******************************************************************************
40  * API
41  ******************************************************************************/
42 
43 #if defined(__cplusplus)
44 extern "C" {
45 #endif
46 
47 /*!
48  * @brief Write value to the SCCB register.
49  *
50  * @param i2cAddr SCCB I2C address.
51  * @param addrType SCCB register address type.
52  * @param reg The register to write.
53  * @param value The value to write.
54  * @param i2cSendFunc The actual I2C send function.
55  * @return Returns @ref kStatus_Success if success, otherwise returns error code.
56  */
57 status_t SCCB_WriteReg(
58     uint8_t i2cAddr, sccb_reg_addr_t addrType, uint32_t reg, uint8_t value, sccb_i2c_send_func_t i2cSendFunc);
59 
60 /*!
61  * @brief Write values to multiple SCCB registers.
62  *
63  * @param i2cAddr SCCB I2C address.
64  * @param addrType SCCB register address type.
65  * @param startReg The start register to write.
66  * @param value Pointer to the value to write.
67  * @param len Length of the value to write.
68  * @param i2cSendFunc The actual I2C send function.
69  * @return Returns @ref kStatus_Success if success, otherwise returns error code.
70  */
71 status_t SCCB_WriteMultiRegs(uint8_t i2cAddr,
72                              sccb_reg_addr_t addrType,
73                              uint32_t startReg,
74                              const uint8_t *value,
75                              uint32_t len,
76                              sccb_i2c_send_func_t i2cSendFunc);
77 
78 /*!
79  * @brief Read the SCCB register value.
80  *
81  * @param i2cAddr SCCB I2C address.
82  * @param addrType SCCB register address type.
83  * @param reg The register to read.
84  * @param value The value read out.
85  * @param i2cReceiveFunc The actual I2C receive function.
86  * @return Returns @ref kStatus_Success if success, otherwise returns error code.
87  */
88 status_t SCCB_ReadReg(
89     uint8_t i2cAddr, sccb_reg_addr_t addrType, uint32_t reg, uint8_t *value, sccb_i2c_receive_func_t i2cReceiveFunc);
90 
91 /*!
92  * @brief Modify the SCCB register value.
93  *
94  * This function modifies some bit fields of a register.
95  *
96  * @param i2cAddr SCCB I2C address.
97  * @param addrType SCCB register address type.
98  * @param reg The register to modify.
99  * @param clrMask The mask value to clear.
100  * @param value The value to set.
101  * @param i2cReceiveFunc The actual I2C receive function.
102  * @param i2cSendFunc The actual I2C send function.
103  * @return Returns @ref kStatus_Success if success, otherwise returns error code.
104  */
105 status_t SCCB_ModifyReg(uint8_t i2cAddr,
106                         sccb_reg_addr_t addrType,
107                         uint32_t reg,
108                         uint8_t clrMask,
109                         uint8_t value,
110                         sccb_i2c_receive_func_t i2cReceiveFunc,
111                         sccb_i2c_send_func_t i2cSendFunc);
112 
113 #if defined(__cplusplus)
114 }
115 #endif
116 
117 #endif /* _FSL_SCCB_H_ */
118