1 /*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * Copyright 2016-2018 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 #include <stdint.h>
10 #include "fsl_common.h"
11 #include "fsl_debug_console.h"
12 #include "board.h"
13 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED
14 #include "fsl_i2c.h"
15 #endif /* SDK_I2C_BASED_COMPONENT_USED */
16
17 /*******************************************************************************
18 * Variables
19 ******************************************************************************/
20
21 /*******************************************************************************
22 * Code
23 ******************************************************************************/
24 /* Initialize debug console. */
BOARD_InitDebugConsole(void)25 void BOARD_InitDebugConsole(void)
26 {
27 uint32_t uartClkSrcFreq = BOARD_DEBUG_UART_CLK_FREQ;
28
29 DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE, BOARD_DEBUG_UART_BAUDRATE, BOARD_DEBUG_UART_TYPE, uartClkSrcFreq);
30 }
31
32 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED
BOARD_I2C_Init(I2C_Type * base,uint32_t clkSrc_Hz)33 void BOARD_I2C_Init(I2C_Type *base, uint32_t clkSrc_Hz)
34 {
35 i2c_master_config_t i2cConfig = {0};
36
37 I2C_MasterGetDefaultConfig(&i2cConfig);
38 I2C_MasterInit(base, &i2cConfig, clkSrc_Hz);
39 }
40
BOARD_I2C_Send(I2C_Type * base,uint8_t deviceAddress,uint32_t subAddress,uint8_t subaddressSize,uint8_t * txBuff,uint8_t txBuffSize)41 status_t BOARD_I2C_Send(I2C_Type *base,
42 uint8_t deviceAddress,
43 uint32_t subAddress,
44 uint8_t subaddressSize,
45 uint8_t *txBuff,
46 uint8_t txBuffSize)
47 {
48 i2c_master_transfer_t masterXfer;
49
50 /* Prepare transfer structure. */
51 masterXfer.slaveAddress = deviceAddress;
52 masterXfer.direction = kI2C_Write;
53 masterXfer.subaddress = subAddress;
54 masterXfer.subaddressSize = subaddressSize;
55 masterXfer.data = txBuff;
56 masterXfer.dataSize = txBuffSize;
57 masterXfer.flags = kI2C_TransferDefaultFlag;
58
59 return I2C_MasterTransferBlocking(base, &masterXfer);
60 }
61
BOARD_I2C_Receive(I2C_Type * base,uint8_t deviceAddress,uint32_t subAddress,uint8_t subaddressSize,uint8_t * rxBuff,uint8_t rxBuffSize)62 status_t BOARD_I2C_Receive(I2C_Type *base,
63 uint8_t deviceAddress,
64 uint32_t subAddress,
65 uint8_t subaddressSize,
66 uint8_t *rxBuff,
67 uint8_t rxBuffSize)
68 {
69 i2c_master_transfer_t masterXfer;
70
71 /* Prepare transfer structure. */
72 masterXfer.slaveAddress = deviceAddress;
73 masterXfer.subaddress = subAddress;
74 masterXfer.subaddressSize = subaddressSize;
75 masterXfer.data = rxBuff;
76 masterXfer.dataSize = rxBuffSize;
77 masterXfer.direction = kI2C_Read;
78 masterXfer.flags = kI2C_TransferDefaultFlag;
79
80 return I2C_MasterTransferBlocking(base, &masterXfer);
81 }
82
BOARD_Accel_I2C_Init(void)83 void BOARD_Accel_I2C_Init(void)
84 {
85 BOARD_I2C_Init(BOARD_ACCEL_I2C_BASEADDR, BOARD_ACCEL_I2C_CLOCK_FREQ);
86 }
87
BOARD_Accel_I2C_Send(uint8_t deviceAddress,uint32_t subAddress,uint8_t subaddressSize,uint32_t txBuff)88 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff)
89 {
90 uint8_t data = (uint8_t)txBuff;
91
92 return BOARD_I2C_Send(BOARD_ACCEL_I2C_BASEADDR, deviceAddress, subAddress, subaddressSize, &data, 1);
93 }
94
BOARD_Accel_I2C_Receive(uint8_t deviceAddress,uint32_t subAddress,uint8_t subaddressSize,uint8_t * rxBuff,uint8_t rxBuffSize)95 status_t BOARD_Accel_I2C_Receive(
96 uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize)
97 {
98 return BOARD_I2C_Receive(BOARD_ACCEL_I2C_BASEADDR, deviceAddress, subAddress, subaddressSize, rxBuff, rxBuffSize);
99 }
100 #endif /* SDK_I2C_BASED_COMPONENT_USED */
101