diff options
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/boards/frdmkv11z/project_template/board.c')
-rw-r--r-- | lib/chibios-contrib/ext/mcux-sdk/boards/frdmkv11z/project_template/board.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/boards/frdmkv11z/project_template/board.c b/lib/chibios-contrib/ext/mcux-sdk/boards/frdmkv11z/project_template/board.c new file mode 100644 index 000000000..46347a0c7 --- /dev/null +++ b/lib/chibios-contrib/ext/mcux-sdk/boards/frdmkv11z/project_template/board.c | |||
@@ -0,0 +1,99 @@ | |||
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_device_registers.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 | #include "fsl_debug_console.h" | ||
16 | |||
17 | /******************************************************************************* | ||
18 | * Variables | ||
19 | ******************************************************************************/ | ||
20 | |||
21 | /******************************************************************************* | ||
22 | * Code | ||
23 | ******************************************************************************/ | ||
24 | /* Initialize debug console. */ | ||
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 | #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED | ||
32 | void BOARD_I2C_Init(I2C_Type *base, uint32_t clkSrc_Hz) | ||
33 | { | ||
34 | i2c_master_config_t i2cConfig = {0}; | ||
35 | |||
36 | I2C_MasterGetDefaultConfig(&i2cConfig); | ||
37 | I2C_MasterInit(base, &i2cConfig, clkSrc_Hz); | ||
38 | } | ||
39 | |||
40 | status_t BOARD_I2C_Send(I2C_Type *base, | ||
41 | uint8_t deviceAddress, | ||
42 | uint32_t subAddress, | ||
43 | uint8_t subaddressSize, | ||
44 | uint8_t *txBuff, | ||
45 | uint8_t txBuffSize) | ||
46 | { | ||
47 | i2c_master_transfer_t masterXfer; | ||
48 | |||
49 | /* Prepare transfer structure. */ | ||
50 | masterXfer.slaveAddress = deviceAddress; | ||
51 | masterXfer.direction = kI2C_Write; | ||
52 | masterXfer.subaddress = subAddress; | ||
53 | masterXfer.subaddressSize = subaddressSize; | ||
54 | masterXfer.data = txBuff; | ||
55 | masterXfer.dataSize = txBuffSize; | ||
56 | masterXfer.flags = kI2C_TransferDefaultFlag; | ||
57 | |||
58 | return I2C_MasterTransferBlocking(base, &masterXfer); | ||
59 | } | ||
60 | |||
61 | status_t BOARD_I2C_Receive(I2C_Type *base, | ||
62 | uint8_t deviceAddress, | ||
63 | uint32_t subAddress, | ||
64 | uint8_t subaddressSize, | ||
65 | uint8_t *rxBuff, | ||
66 | uint8_t rxBuffSize) | ||
67 | { | ||
68 | i2c_master_transfer_t masterXfer; | ||
69 | |||
70 | /* Prepare transfer structure. */ | ||
71 | masterXfer.slaveAddress = deviceAddress; | ||
72 | masterXfer.subaddress = subAddress; | ||
73 | masterXfer.subaddressSize = subaddressSize; | ||
74 | masterXfer.data = rxBuff; | ||
75 | masterXfer.dataSize = rxBuffSize; | ||
76 | masterXfer.direction = kI2C_Read; | ||
77 | masterXfer.flags = kI2C_TransferDefaultFlag; | ||
78 | |||
79 | return I2C_MasterTransferBlocking(base, &masterXfer); | ||
80 | } | ||
81 | |||
82 | void BOARD_Accel_I2C_Init(void) | ||
83 | { | ||
84 | BOARD_I2C_Init(BOARD_ACCEL_I2C_BASEADDR, BOARD_ACCEL_I2C_CLOCK_FREQ); | ||
85 | } | ||
86 | |||
87 | status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff) | ||
88 | { | ||
89 | uint8_t data = (uint8_t)txBuff; | ||
90 | |||
91 | return BOARD_I2C_Send(BOARD_ACCEL_I2C_BASEADDR, deviceAddress, subAddress, subaddressSize, &data, 1); | ||
92 | } | ||
93 | |||
94 | status_t BOARD_Accel_I2C_Receive( | ||
95 | uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize) | ||
96 | { | ||
97 | return BOARD_I2C_Receive(BOARD_ACCEL_I2C_BASEADDR, deviceAddress, subAddress, subaddressSize, rxBuff, rxBuffSize); | ||
98 | } | ||
99 | #endif /* SDK_I2C_BASED_COMPONENT_USED */ | ||