1 /*
2  * Copyright  2019 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef _FSL_CODEC_I2C_H_
10 #define _FSL_CODEC_I2C_H_
11 
12 #include "fsl_common.h"
13 #include "fsl_adapter_i2c.h"
14 
15 /*!
16  * @addtogroup codec_i2c
17  * @{
18  */
19 
20 /*******************************************************************************
21  * Definitions
22  ******************************************************************************/
23 /*! @brief codec i2c handler */
24 #ifndef CODEC_I2C_MASTER_HANDLER_SIZE
25 #define CODEC_I2C_MASTER_HANDLER_SIZE HAL_I2C_MASTER_HANDLE_SIZE
26 #endif
27 
28 /*! @brief CODEC device register address type. */
29 typedef enum _codec_reg_addr
30 {
31     kCODEC_RegAddr8Bit  = 1U, /*!< 8-bit register address.  */
32     kCODEC_RegAddr16Bit = 2U, /*!< 16-bit register address. */
33 } codec_reg_addr_t;
34 
35 /*! @brief CODEC device register width. */
36 typedef enum _codec_reg_width
37 {
38     kCODEC_RegWidth8Bit  = 1U, /*!< 8-bit register width.  */
39     kCODEC_RegWidth16Bit = 2U, /*!< 16-bit register width. */
40     kCODEC_RegWidth32Bit = 4U, /*!< 32-bit register width. */
41 } codec_reg_width_t;
42 
43 /*! @brief CODEC I2C configurations structure */
44 typedef struct _codec_i2c_config
45 {
46     uint32_t codecI2CInstance;    /*!< i2c bus instance */
47     uint32_t codecI2CSourceClock; /*!< i2c bus source clock frequency */
48 } codec_i2c_config_t;
49 
50 /*******************************************************************************
51  * API
52  ******************************************************************************/
53 #if defined(__cplusplus)
54 extern "C" {
55 #endif
56 
57 /*!
58  * @brief Codec i2c bus initilization.
59  *
60  * @param handle i2c master handle.
61  * @param i2cInstance instance number of the i2c bus, such as 0 is corresponding to I2C0.
62  * @param i2cBaudrate i2c baudrate.
63  * @param i2cSourceClockHz i2c source clock frequency.
64  * @return kStatus_HAL_I2cSuccess is success, else initial failed.
65  */
66 status_t CODEC_I2C_Init(void *handle, uint32_t i2cInstance, uint32_t i2cBaudrate, uint32_t i2cSourceClockHz);
67 
68 /*!
69  * @brief Codec i2c de-initilization.
70  *
71  * @param handle i2c master handle.
72  * @return kStatus_HAL_I2cSuccess is success, else deinitial failed.
73  */
74 status_t CODEC_I2C_Deinit(void *handle);
75 
76 /*!
77  * @brief codec i2c send function.
78  *
79  * @param handle i2c master handle.
80  * @param deviceAddress codec device address.
81  * @param subAddress register address.
82  * @param subaddressSize register address width.
83  * @param txBuff tx buffer pointer.
84  * @param txBuffSize tx buffer size.
85  * @return kStatus_HAL_I2cSuccess is success, else send failed.
86  */
87 status_t CODEC_I2C_Send(void *handle,
88                         uint8_t deviceAddress,
89                         uint32_t subAddress,
90                         uint8_t subaddressSize,
91                         uint8_t *txBuff,
92                         uint8_t txBuffSize);
93 
94 /*!
95  * @brief codec i2c receive function.
96  *
97  * @param handle i2c master handle.
98  * @param deviceAddress codec device address.
99  * @param subAddress register address.
100  * @param subaddressSize register address width.
101  * @param rxBuff rx buffer pointer.
102  * @param rxBuffSize rx buffer size.
103  * @return kStatus_HAL_I2cSuccess is success, else receive failed.
104  */
105 status_t CODEC_I2C_Receive(void *handle,
106                            uint8_t deviceAddress,
107                            uint32_t subAddress,
108                            uint8_t subaddressSize,
109                            uint8_t *rxBuff,
110                            uint8_t rxBuffSize);
111 
112 #if defined(__cplusplus)
113 }
114 #endif
115 
116 /*! @} */
117 #endif /* _FSL_CODEC_I2C_H_ */
118