1 /*
2 * Copyright 2017-2018 NXP
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8 #include <stdint.h>
9 #include "fsl_common.h"
10 #include "fsl_debug_console.h"
11 #include "board.h"
12 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED
13 #include "fsl_i2c.h"
14 #endif /* SDK_I2C_BASED_COMPONENT_USED */
15
16 /*******************************************************************************
17 * Variables
18 ******************************************************************************/
19
20 /*******************************************************************************
21 * Code
22 ******************************************************************************/
23 /* Initialize debug console. */
BOARD_InitDebugConsole(void)24 void BOARD_InitDebugConsole(void)
25 {
26 /* attach 12 MHz clock to FLEXCOMM0 (debug console) */
27 CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
28
29 RESET_ClearPeripheralReset(BOARD_DEBUG_UART_RST);
30
31 uint32_t uartClkSrcFreq = BOARD_DEBUG_UART_CLK_FREQ;
32
33 DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE, BOARD_DEBUG_UART_BAUDRATE, BOARD_DEBUG_UART_TYPE, uartClkSrcFreq);
34 }
35
BOARD_InitDebugConsole_Core1(void)36 void BOARD_InitDebugConsole_Core1(void)
37 {
38 /* attach 12 MHz clock to FLEXCOMM1 (debug console) */
39 CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH_CORE1);
40
41 RESET_ClearPeripheralReset(BOARD_DEBUG_UART_RST_CORE1);
42
43 uint32_t uartClkSrcFreq = BOARD_DEBUG_UART_CLK_FREQ_CORE1;
44
45 DbgConsole_Init(BOARD_DEBUG_UART_INSTANCE_CORE1, BOARD_DEBUG_UART_BAUDRATE_CORE1, BOARD_DEBUG_UART_TYPE_CORE1,
46 uartClkSrcFreq);
47 }
48
49 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED
BOARD_I2C_Init(I2C_Type * base,uint32_t clkSrc_Hz)50 void BOARD_I2C_Init(I2C_Type *base, uint32_t clkSrc_Hz)
51 {
52 i2c_master_config_t i2cConfig = {0};
53
54 I2C_MasterGetDefaultConfig(&i2cConfig);
55 I2C_MasterInit(base, &i2cConfig, clkSrc_Hz);
56 }
57
BOARD_I2C_Send(I2C_Type * base,uint8_t deviceAddress,uint32_t subAddress,uint8_t subaddressSize,uint8_t * txBuff,uint8_t txBuffSize)58 status_t BOARD_I2C_Send(I2C_Type *base,
59 uint8_t deviceAddress,
60 uint32_t subAddress,
61 uint8_t subaddressSize,
62 uint8_t *txBuff,
63 uint8_t txBuffSize)
64 {
65 i2c_master_transfer_t masterXfer;
66
67 /* Prepare transfer structure. */
68 masterXfer.slaveAddress = deviceAddress;
69 masterXfer.direction = kI2C_Write;
70 masterXfer.subaddress = subAddress;
71 masterXfer.subaddressSize = subaddressSize;
72 masterXfer.data = txBuff;
73 masterXfer.dataSize = txBuffSize;
74 masterXfer.flags = kI2C_TransferDefaultFlag;
75
76 return I2C_MasterTransferBlocking(base, &masterXfer);
77 }
78
BOARD_I2C_Receive(I2C_Type * base,uint8_t deviceAddress,uint32_t subAddress,uint8_t subaddressSize,uint8_t * rxBuff,uint8_t rxBuffSize)79 status_t BOARD_I2C_Receive(I2C_Type *base,
80 uint8_t deviceAddress,
81 uint32_t subAddress,
82 uint8_t subaddressSize,
83 uint8_t *rxBuff,
84 uint8_t rxBuffSize)
85 {
86 i2c_master_transfer_t masterXfer;
87
88 /* Prepare transfer structure. */
89 masterXfer.slaveAddress = deviceAddress;
90 masterXfer.subaddress = subAddress;
91 masterXfer.subaddressSize = subaddressSize;
92 masterXfer.data = rxBuff;
93 masterXfer.dataSize = rxBuffSize;
94 masterXfer.direction = kI2C_Read;
95 masterXfer.flags = kI2C_TransferDefaultFlag;
96
97 return I2C_MasterTransferBlocking(base, &masterXfer);
98 }
99
BOARD_Accel_I2C_Init(void)100 void BOARD_Accel_I2C_Init(void)
101 {
102 BOARD_I2C_Init(BOARD_ACCEL_I2C_BASEADDR, BOARD_ACCEL_I2C_CLOCK_FREQ);
103 }
104
BOARD_Accel_I2C_Send(uint8_t deviceAddress,uint32_t subAddress,uint8_t subaddressSize,uint32_t txBuff)105 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff)
106 {
107 uint8_t data = (uint8_t)txBuff;
108
109 return BOARD_I2C_Send(BOARD_ACCEL_I2C_BASEADDR, deviceAddress, subAddress, subaddressSize, &data, 1);
110 }
111
BOARD_Accel_I2C_Receive(uint8_t deviceAddress,uint32_t subAddress,uint8_t subaddressSize,uint8_t * rxBuff,uint8_t rxBuffSize)112 status_t BOARD_Accel_I2C_Receive(
113 uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize)
114 {
115 return BOARD_I2C_Receive(BOARD_ACCEL_I2C_BASEADDR, deviceAddress, subAddress, subaddressSize, rxBuff, rxBuffSize);
116 }
117
BOARD_Codec_I2C_Init(void)118 void BOARD_Codec_I2C_Init(void)
119 {
120 BOARD_I2C_Init(BOARD_CODEC_I2C_BASEADDR, BOARD_CODEC_I2C_CLOCK_FREQ);
121 }
122
BOARD_Codec_I2C_Send(uint8_t deviceAddress,uint32_t subAddress,uint8_t subAddressSize,const uint8_t * txBuff,uint8_t txBuffSize)123 status_t BOARD_Codec_I2C_Send(
124 uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize)
125 {
126 return BOARD_I2C_Send(BOARD_CODEC_I2C_BASEADDR, deviceAddress, subAddress, subAddressSize, (uint8_t *)txBuff,
127 txBuffSize);
128 }
129
BOARD_Codec_I2C_Receive(uint8_t deviceAddress,uint32_t subAddress,uint8_t subAddressSize,uint8_t * rxBuff,uint8_t rxBuffSize)130 status_t BOARD_Codec_I2C_Receive(
131 uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize)
132 {
133 return BOARD_I2C_Receive(BOARD_CODEC_I2C_BASEADDR, deviceAddress, subAddress, subAddressSize, rxBuff, rxBuffSize);
134 }
135 #endif /* SDK_I2C_BASED_COMPONENT_USED */
136