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