fsl_codec_i2c.c
Go to the documentation of this file.
1 /*
2  * Copyright 2019 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #include "fsl_codec_i2c.h"
10 /*******************************************************************************
11  * Definitions
12  ******************************************************************************/
13 
14 /*******************************************************************************
15  * Variables
16  ******************************************************************************/
17 
18 /*******************************************************************************
19  * Code
20  ******************************************************************************/
30 status_t CODEC_I2C_Init(void *handle, uint32_t i2cInstance, uint32_t i2cBaudrate, uint32_t i2cSourceClockHz)
31 {
32  hal_i2c_master_config_t masterConfig;
33 
34  masterConfig.enableMaster = true;
35  masterConfig.baudRate_Bps = i2cBaudrate;
36  masterConfig.srcClock_Hz = i2cSourceClockHz;
37  masterConfig.instance = i2cInstance;
38 
39  return HAL_I2cMasterInit((hal_i2c_master_handle_t *)handle, &masterConfig);
40 }
41 
49 {
51 }
52 
64 status_t CODEC_I2C_Send(void *handle,
65  uint8_t deviceAddress,
66  uint32_t subAddress,
67  uint8_t subaddressSize,
68  uint8_t *txBuff,
69  uint8_t txBuffSize)
70 {
71  hal_i2c_master_transfer_t masterXfer;
72 
73  masterXfer.slaveAddress = deviceAddress;
74  masterXfer.direction = kHAL_I2cWrite;
75  masterXfer.subaddress = (uint32_t)subAddress;
76  masterXfer.subaddressSize = subaddressSize;
77  masterXfer.data = txBuff;
78  masterXfer.dataSize = txBuffSize;
80 
81  return HAL_I2cMasterTransferBlocking((hal_i2c_master_handle_t *)handle, &masterXfer);
82 }
83 
96  uint8_t deviceAddress,
97  uint32_t subAddress,
98  uint8_t subaddressSize,
99  uint8_t *rxBuff,
100  uint8_t rxBuffSize)
101 {
102  hal_i2c_master_transfer_t masterXfer;
103 
104  masterXfer.slaveAddress = deviceAddress;
105  masterXfer.direction = kHAL_I2cRead;
106  masterXfer.subaddress = (uint32_t)subAddress;
107  masterXfer.subaddressSize = subaddressSize;
108  masterXfer.data = rxBuff;
109  masterXfer.dataSize = rxBuffSize;
110  masterXfer.flags = kHAL_I2cTransferDefaultFlag;
111 
112  return HAL_I2cMasterTransferBlocking((hal_i2c_master_handle_t *)handle, &masterXfer);
113 }
CODEC_I2C_Init
status_t CODEC_I2C_Init(void *handle, uint32_t i2cInstance, uint32_t i2cBaudrate, uint32_t i2cSourceClockHz)
Codec i2c bus initilization.
Definition: fsl_codec_i2c.c:30
_hal_i2c_master_transfer::direction
hal_i2c_direction_t direction
Definition: i2c.h:110
_hal_i2c_master_transfer::slaveAddress
uint8_t slaveAddress
Definition: i2c.h:109
_hal_i2c_master_config::baudRate_Bps
uint32_t baudRate_Bps
Definition: i2c.h:43
fsl_codec_i2c.h
_hal_i2c_master_transfer::dataSize
volatile size_t dataSize
Definition: i2c.h:105
_hal_i2c_master_transfer::flags
uint32_t flags
Definition: i2c.h:106
_hal_i2c_master_config::enableMaster
bool enableMaster
Definition: i2c.h:44
_hal_i2c_master_transfer::data
uint8_t *volatile data
Definition: i2c.h:104
_hal_i2c_master_config
HAL I2C master user configuration.
Definition: i2c.h:40
CODEC_I2C_Send
status_t CODEC_I2C_Send(void *handle, uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *txBuff, uint8_t txBuffSize)
codec i2c send function.
Definition: fsl_codec_i2c.c:64
_hal_i2c_master_config::instance
uint8_t instance
Definition: i2c.h:45
kHAL_I2cRead
@ kHAL_I2cRead
Definition: i2c.h:61
CODEC_I2C_Deinit
status_t CODEC_I2C_Deinit(void *handle)
Codec i2c de-initilization.
Definition: fsl_codec_i2c.c:48
kHAL_I2cWrite
@ kHAL_I2cWrite
Definition: i2c.h:60
HAL_I2cMasterInit
hal_i2c_status_t HAL_I2cMasterInit(hal_i2c_master_handle_t handle, const hal_i2c_master_config_t *config)
Initializes the HAL I2C master peripheral.
Definition: lpi2c_adapter.c:129
HAL_I2cMasterTransferBlocking
hal_i2c_status_t HAL_I2cMasterTransferBlocking(hal_i2c_master_handle_t handle, hal_i2c_master_transfer_t *xfer)
Performs a master polling transfer on the HAL I2C bus.
Definition: lpi2c_adapter.c:223
_hal_i2c_master_transfer::subaddress
uint32_t subaddress
Definition: i2c.h:107
kHAL_I2cTransferDefaultFlag
@ kHAL_I2cTransferDefaultFlag
Definition: i2c.h:67
HAL_I2cMasterDeinit
hal_i2c_status_t HAL_I2cMasterDeinit(hal_i2c_master_handle_t handle)
De-initializes the HAL I2C master peripheral. Call this API to gate the HAL I2C clock....
Definition: lpi2c_adapter.c:171
_hal_i2c_master_transfer::subaddressSize
uint8_t subaddressSize
Definition: i2c.h:108
CODEC_I2C_Receive
status_t CODEC_I2C_Receive(void *handle, uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize)
codec i2c receive function.
Definition: fsl_codec_i2c.c:95
hal_i2c_master_handle_t
void * hal_i2c_master_handle_t
HAL I2C master handle.
Definition: i2c.h:126
status_t
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:189
_hal_i2c_master_config::srcClock_Hz
uint32_t srcClock_Hz
Definition: i2c.h:42
_hal_i2c_master_transfer
HAL I2C master transfer structure.
Definition: i2c.h:102


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:13:56