Change script for apply upstream code
[platform/upstream/connectedhomeip.git] / examples / platform / efr32 / efr32mg21 / BRD4180A / init_board.c
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    All rights reserved.
5  *
6  *    Licensed under the Apache License, Version 2.0 (the "License");
7  *    you may not use this file except in compliance with the License.
8  *    You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *    Unless required by applicable law or agreed to in writing, software
13  *    distributed under the License is distributed on an "AS IS" BASIS,
14  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *    See the License for the specific language governing permissions and
16  *    limitations under the License.
17  */
18 /*******************************************************************************
19  * @file
20  * @brief init_board.c
21  *******************************************************************************
22  * # License
23  * <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
24  *******************************************************************************
25  *
26  * The licensor of this software is Silicon Laboratories Inc. Your use of this
27  * software is governed by the terms of Silicon Labs Master Software License
28  * Agreement (MSLA) available at
29  * www.silabs.com/about-us/legal/master-software-license-agreement. This
30  * software is distributed to you in Source Code format and is governed by the
31  * sections of the MSLA applicable to Source Code.
32  *
33  ******************************************************************************/
34
35 #if defined(HAL_CONFIG)
36 #include "bsphalconfig.h"
37 #include "hal-config.h"
38 #else
39 #include "bspconfig.h"
40 #endif
41
42 #include "board_features.h"
43 #include "em_cmu.h"
44
45 #include "bsp.h"
46
47 void initBoard(void)
48 {
49
50     // Enable clock for BURTC
51     CMU_ClockEnable(cmuClock_BURTC, true);
52 #if ((HAL_VCOM_ENABLE == 1) || (HAL_USART3_ENABLE == 1) || (HAL_USART1_ENABLE == 1) || (HAL_USART0_ENABLE == 1))
53 #if defined(FEATURE_EXP_HEADER_USART3)
54     // Enable clock for USART3
55     CMU_ClockEnable(cmuClock_USART3, true);
56 #elif defined(FEATURE_EXP_HEADER_USART1)
57     // Enable clock for USART1
58     CMU_ClockEnable(cmuClock_USART1, true);
59 #else
60     // Enable clock for USART0
61     CMU_ClockEnable(cmuClock_USART0, true);
62 #endif
63 #endif //(HAL_VCOM_ENABLE == 1)
64 #if ((HAL_I2CSENSOR_ENABLE == 1) || (HAL_VCOM_ENABLE == 1) || (HAL_SPIDISPLAY_ENABLE == 1) || (HAL_USART3_ENABLE == 1) ||          \
65      (HAL_USART1_ENABLE == 1) || (HAL_USART0_ENABLE == 1))
66     // Enable clock for PRS
67     CMU_ClockEnable(cmuClock_PRS, true);
68     // Enable GPIO clock source
69     CMU_ClockEnable(cmuClock_GPIO, true);
70 #endif /* ((HAL_I2CSENSOR_ENABLE == 1)                                                                                             \
71            || (HAL_VCOM_ENABLE == 1)                                                                                               \
72            || (HAL_SPIDISPLAY_ENABLE == 1)                                                                                         \
73            || (HAL_USART3_ENABLE == 1)                                                                                             \
74            || (HAL_USART1_ENABLE == 1)                                                                                             \
75            || (HAL_USART0_ENABLE == 1)) */
76 }
77
78 void initVcomEnable(void)
79 {
80
81 // "WARNING: This radio board uses the same GPIO pin to enable the VCOM port, the LCD display and the temperature sensor! Enabling
82 // any of these features might disrupt the serial pins of the EXP header!"
83 #if defined(HAL_I2CSENSOR_ENABLE) || defined(HAL_SPIDISPLAY_ENABLE) || defined(HAL_VCOM_ENABLE)
84 #if HAL_I2CSENSOR_ENABLE || HAL_SPIDISPLAY_ENABLE || HAL_VCOM_ENABLE
85 #define COMMON_ENABLE 1
86 #else
87 #define COMMON_ENABLE 0
88 #endif
89
90 #if defined(BSP_I2CSENSOR_ENABLE_PORT)
91 #define ENABLE_PORT BSP_I2CSENSOR_ENABLE_PORT
92 #define ENABLE_PIN BSP_I2CSENSOR_ENABLE_PIN
93 #elif defined(BSP_SPIDISPLAY_ENABLE_PORT)
94 #define ENABLE_PORT BSP_SPIDISPLAY_ENABLE_PORT
95 #define ENABLE_PIN BSP_SPIDISPLAY_ENABLE_PIN
96 #else
97 #define ENABLE_PORT BSP_VCOM_ENABLE_PORT
98 #define ENABLE_PIN BSP_VCOM_ENABLE_PIN
99 #endif
100
101     // Enable if requested
102     GPIO_PinModeSet(ENABLE_PORT, ENABLE_PIN, gpioModePushPull, COMMON_ENABLE);
103
104 #endif
105 }