1 /*
2 * Copyright 2017-2018, 2020 NXP
3 * All rights reserved.
4 *
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 #include "fsl_common.h"
10 #include "fsl_sccb.h"
11
12 /*******************************************************************************
13 * Definitions
14 ******************************************************************************/
15
16 /*******************************************************************************
17 * Code
18 ******************************************************************************/
19
SCCB_WriteReg(uint8_t i2cAddr,sccb_reg_addr_t addrType,uint32_t reg,uint8_t value,sccb_i2c_send_func_t i2cSendFunc)20 status_t SCCB_WriteReg(
21 uint8_t i2cAddr, sccb_reg_addr_t addrType, uint32_t reg, uint8_t value, sccb_i2c_send_func_t i2cSendFunc)
22 {
23 return i2cSendFunc(i2cAddr, reg, addrType, &value, 1);
24 }
25
SCCB_WriteMultiRegs(uint8_t i2cAddr,sccb_reg_addr_t addrType,uint32_t startReg,const uint8_t * value,uint32_t len,sccb_i2c_send_func_t i2cSendFunc)26 status_t SCCB_WriteMultiRegs(uint8_t i2cAddr,
27 sccb_reg_addr_t addrType,
28 uint32_t startReg,
29 const uint8_t *value,
30 uint32_t len,
31 sccb_i2c_send_func_t i2cSendFunc)
32 {
33 return i2cSendFunc(i2cAddr, startReg, addrType, value, len);
34 }
35
SCCB_ReadReg(uint8_t i2cAddr,sccb_reg_addr_t addrType,uint32_t reg,uint8_t * value,sccb_i2c_receive_func_t i2cReceiveFunc)36 status_t SCCB_ReadReg(
37 uint8_t i2cAddr, sccb_reg_addr_t addrType, uint32_t reg, uint8_t *value, sccb_i2c_receive_func_t i2cReceiveFunc)
38 {
39 return i2cReceiveFunc(i2cAddr, reg, addrType, value, 1);
40 }
41
SCCB_ModifyReg(uint8_t i2cAddr,sccb_reg_addr_t addrType,uint32_t reg,uint8_t clrMask,uint8_t value,sccb_i2c_receive_func_t i2cReceiveFunc,sccb_i2c_send_func_t i2cSendFunc)42 status_t SCCB_ModifyReg(uint8_t i2cAddr,
43 sccb_reg_addr_t addrType,
44 uint32_t reg,
45 uint8_t clrMask,
46 uint8_t value,
47 sccb_i2c_receive_func_t i2cReceiveFunc,
48 sccb_i2c_send_func_t i2cSendFunc)
49 {
50 status_t status;
51 uint8_t regVal = 0U;
52
53 status = SCCB_ReadReg(i2cAddr, addrType, reg, ®Val, i2cReceiveFunc);
54
55 if (kStatus_Success != status)
56 {
57 return status;
58 }
59
60 regVal = (uint8_t)(regVal & ~((uint32_t)clrMask)) | (value & clrMask);
61
62 return SCCB_WriteReg(i2cAddr, addrType, reg, regVal, i2cSendFunc);
63 }
64