1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef _BOARD_H_
10 #define _BOARD_H_
11 
12 #include "clock_config.h"
13 #include "fsl_gpio.h"
14 
15 /*******************************************************************************
16  * Definitions
17  ******************************************************************************/
18 
19 /*! @brief The board name */
20 #define BOARD_NAME "TWR-KE18F"
21 
22 /*! @brief The UART to use for debug messages. */
23 #define BOARD_USE_UART
24 #define BOARD_DEBUG_UART_TYPE DEBUG_CONSOLE_DEVICE_TYPE_LPUART
25 #define BOARD_DEBUG_UART_BASEADDR (uint32_t) LPUART0
26 #define BOARD_DEBUG_UART_INSTANCE 0U
27 #define BOARD_DEBUG_UART_CLKSRC kCLOCK_ScgSysPllAsyncDiv2Clk
28 #define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetIpFreq(kCLOCK_Lpuart0)
29 
30 #ifndef BOARD_DEBUG_UART_BAUDRATE
31 #define BOARD_DEBUG_UART_BAUDRATE 115200
32 #endif /* BOARD_DEBUG_UART_BAUDRATE */
33 
34 /*! @brief The lpi2c instance used for lpi2c connection by default */
35 #define BOARD_I2C_BASEADDR LPI2C0
36 
37 /*! @brief The rtc instance used for board. */
38 #define BOARD_RTC_FUNC_BASEADDR RTC
39 
40 /* Board led color mapping */
41 #define LOGIC_LED_ON 0U
42 #define LOGIC_LED_OFF 1U
43 #define BOARD_LED_RED1_GPIO GPIOC
44 #define BOARD_LED_RED1_GPIO_PORT PORTC
45 #define BOARD_LED_RED1_GPIO_PIN 10U
46 #define BOARD_LED_GREEN1_GPIO GPIOC
47 #define BOARD_LED_GREEN1_GPIO_PORT PORTC
48 #define BOARD_LED_GREEN1_GPIO_PIN 11U
49 #ifndef BOARD_LED_YELLOW_GPIO
50 #define BOARD_LED_YELLOW_GPIO GPIOC
51 #endif
52 #define BOARD_LED_YELLOW_GPIO_PORT PORTC
53 #ifndef BOARD_LED_YELLOW_GPIO_PIN
54 #define BOARD_LED_YELLOW_GPIO_PIN 12U
55 #endif
56 #ifndef BOARD_LED_ORANGE_GPIO
57 #define BOARD_LED_ORANGE_GPIO GPIOC
58 #endif
59 #define BOARD_LED_ORANGE_GPIO_PORT PORTC
60 #ifndef BOARD_LED_ORANGE_GPIO_PIN
61 #define BOARD_LED_ORANGE_GPIO_PIN 13U
62 #endif
63 #define BOARD_LED_RED2_GPIO GPIOD
64 #define BOARD_LED_RED2_GPIO_PORT PORTD
65 #define BOARD_LED_RED2_GPIO_PIN 16U
66 #define BOARD_LED_GREEN2_GPIO GPIOD
67 #define BOARD_LED_GREEN2_GPIO_PORT PORTD
68 #define BOARD_LED_GREEN2_GPIO_PIN 15U
69 #ifndef BOARD_LED_BLUE_GPIO
70 #define BOARD_LED_BLUE_GPIO GPIOB
71 #endif
72 #define BOARD_LED_BLUE_GPIO_PORT PORTB
73 #ifndef BOARD_LED_BLUE_GPIO_PIN
74 #define BOARD_LED_BLUE_GPIO_PIN 5U
75 #endif
76 
77 #define LED_RED1_INIT(output)                                                  \
78     GPIO_PinWrite(BOARD_LED_RED1_GPIO, BOARD_LED_RED1_GPIO_PIN, output); \
79     BOARD_LED_RED1_GPIO->PDDR |= (1U << BOARD_LED_RED1_GPIO_PIN) /*!< Enable target LED_RED1 */
80 #define LED_RED1_ON() \
81     GPIO_PortClear(BOARD_LED_RED1_GPIO, 1U << BOARD_LED_RED1_GPIO_PIN) /*!< Turn on target LED_RED1 */
82 #define LED_RED1_OFF() \
83     GPIO_PortSet(BOARD_LED_RED1_GPIO, 1U << BOARD_LED_RED1_GPIO_PIN) /*!< Turn off target LED_RED1 */
84 #define LED_RED1_TOGGLE() \
85     GPIO_PortToggle(BOARD_LED_RED1_GPIO, 1U << BOARD_LED_RED1_GPIO_PIN) /*!< Toggle on target LED_RED1 */
86 
87 #define LED_GREEN1_INIT(output)                                                    \
88     GPIO_PinWrite(BOARD_LED_GREEN1_GPIO, BOARD_LED_GREEN1_GPIO_PIN, output); \
89     BOARD_LED_GREEN1_GPIO->PDDR |= (1U << BOARD_LED_GREEN1_GPIO_PIN) /*!< Enable target LED_GREEN1 */
90 #define LED_GREEN1_ON() \
91     GPIO_PortClear(BOARD_LED_GREEN1_GPIO, 1U << BOARD_LED_GREEN1_GPIO_PIN) /*!< Turn on target LED_GREEN1 */
92 #define LED_GREEN1_OFF() \
93     GPIO_PortSet(BOARD_LED_GREEN1_GPIO, 1U << BOARD_LED_GREEN1_GPIO_PIN) /*!< Turn off target LED_GREEN1 */
94 #define LED_GREEN1_TOGGLE() \
95     GPIO_PortToggle(BOARD_LED_GREEN1_GPIO, 1U << BOARD_LED_GREEN1_GPIO_PIN) /*!< Toggle on target LED_GREEN1 */
96 
97 #define LED_YELLOW_INIT(output)                                                    \
98     GPIO_PinWrite(BOARD_LED_YELLOW_GPIO, BOARD_LED_YELLOW_GPIO_PIN, output); \
99     BOARD_LED_YELLOW_GPIO->PDDR |= (1U << BOARD_LED_YELLOW_GPIO_PIN) /*!< Enable target LED_YELLOW */
100 #define LED_YELLOW_ON() \
101     GPIO_PortClear(BOARD_LED_YELLOW_GPIO, 1U << BOARD_LED_YELLOW_GPIO_PIN) /*!< Turn on target LED_YELLOW */
102 #define LED_YELLOW_OFF() \
103     GPIO_PortSet(BOARD_LED_YELLOW_GPIO, 1U << BOARD_LED_YELLOW_GPIO_PIN) /*!< Turn off target LED_YELLOW */
104 #define LED_YELLOW_TOGGLE() \
105     GPIO_PortToggle(BOARD_LED_YELLOW_GPIO, 1U << BOARD_LED_YELLOW_GPIO_PIN) /*!< Toggle on target LED_YELLOW */
106 
107 #define LED_ORANGE_INIT(output)                                                    \
108     GPIO_PinWrite(BOARD_LED_ORANGE_GPIO, BOARD_LED_ORANGE_GPIO_PIN, output); \
109     BOARD_LED_ORANGE_GPIO->PDDR |= (1U << BOARD_LED_ORANGE_GPIO_PIN) /*!< Enable target LED_ORANGE */
110 #define LED_ORANGE_ON() \
111     GPIO_PortClear(BOARD_LED_ORANGE_GPIO, 1U << BOARD_LED_ORANGE_GPIO_PIN) /*!< Turn on target LED_ORANGE */
112 #define LED_ORANGE_OFF() \
113     GPIO_PortSet(BOARD_LED_ORANGE_GPIO, 1U << BOARD_LED_ORANGE_GPIO_PIN) /*!< Turn off target LED_ORANGE */
114 #define LED_ORANGE_TOGGLE() \
115     GPIO_PortToggle(BOARD_LED_ORANGE_GPIO, 1U << BOARD_LED_ORANGE_GPIO_PIN) /*!< Toggle on target LED_ORANGE */
116 
117 #define LED_RED2_INIT(output)                                                  \
118     GPIO_PinWrite(BOARD_LED_RED2_GPIO, BOARD_LED_RED2_GPIO_PIN, output); \
119     BOARD_LED_RED2_GPIO->PDDR |= (1U << BOARD_LED_RED2_GPIO_PIN) /*!< Enable target LED_RED2 */
120 #define LED_RED2_ON() \
121     GPIO_PortClear(BOARD_LED_RED2_GPIO, 1U << BOARD_LED_RED2_GPIO_PIN) /*!< Turn on target LED_RED2 */
122 #define LED_RED2_OFF() \
123     GPIO_PortSet(BOARD_LED_RED2_GPIO, 1U << BOARD_LED_RED2_GPIO_PIN) /*!< Turn off target LED_RED2 */
124 #define LED_RED2_TOGGLE() \
125     GPIO_PortToggle(BOARD_LED_RED2_GPIO, 1U << BOARD_LED_RED2_GPIO_PIN) /*!< Toggle on target LED_RED2 */
126 
127 #define LED_GREEN2_INIT(output)                                                    \
128     GPIO_PinWrite(BOARD_LED_GREEN2_GPIO, BOARD_LED_GREEN2_GPIO_PIN, output); \
129     BOARD_LED_GREEN2_GPIO->PDDR |= (1U << BOARD_LED_GREEN2_GPIO_PIN) /*!< Enable target LED_GREEN2 */
130 #define LED_GREEN2_ON() \
131     GPIO_PortClear(BOARD_LED_GREEN2_GPIO, 1U << BOARD_LED_GREEN2_GPIO_PIN) /*!< Turn on target LED_GREEN2 */
132 #define LED_GREEN2_OFF() \
133     GPIO_PortSet(BOARD_LED_GREEN2_GPIO, 1U << BOARD_LED_GREEN2_GPIO_PIN) /*!< Turn off target LED_GREEN2 */
134 #define LED_GREEN2_TOGGLE() \
135     GPIO_PortToggle(BOARD_LED_GREEN2_GPIO, 1U << BOARD_LED_GREEN2_GPIO_PIN) /*!< Toggle on target LED_GREEN2 */
136 
137 #define LED_BLUE_INIT(output)                                                  \
138     GPIO_PinWrite(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PIN, output); \
139     BOARD_LED_BLUE_GPIO->PDDR |= (1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Enable target LED_BLUE */
140 #define LED_BLUE_ON() \
141     GPIO_PortClear(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn on target LED_BLUE */
142 #define LED_BLUE_OFF() \
143     GPIO_PortSet(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn off target LED_BLUE */
144 #define LED_BLUE_TOGGLE() \
145     GPIO_PortToggle(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Toggle on target LED_BLUE */
146 
147 #if defined(__cplusplus)
148 extern "C" {
149 #endif /* __cplusplus */
150 
151 /*******************************************************************************
152  * API
153  ******************************************************************************/
154 
155 void BOARD_InitDebugConsole(void);
156 
157 #if defined(__cplusplus)
158 }
159 #endif /* __cplusplus */
160 
161 #endif /* _BOARD_H_ */
162