1 /*
2  * Copyright (c) 2015, 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 /*! @brief The board name */
19 #define BOARD_NAME "TWR-KV58F220M"
20 
21 /*! @brief The UART to use for debug messages. */
22 #define BOARD_USE_UART
23 #define BOARD_DEBUG_UART_TYPE DEBUG_CONSOLE_DEVICE_TYPE_UART
24 #define BOARD_DEBUG_UART_BASEADDR (uint32_t) UART0
25 #define BOARD_DEBUG_UART_INSTANCE 0U
26 #define BOARD_DEBUG_UART_CLKSRC kCLOCK_FastPeriphClk
27 #define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetFastPeriphClkFreq()
28 #define BOARD_UART_IRQ UART0_RX_TX_IRQn
29 #define BOARD_UART_IRQ_HANDLER UART0_RX_TX_IRQHandler
30 
31 #ifndef BOARD_DEBUG_UART_BAUDRATE
32 #define BOARD_DEBUG_UART_BAUDRATE 115200
33 #endif /* BOARD_DEBUG_UART_BAUDRATE */
34 
35 /*! @brief The i2c instance used for i2c connection by default */
36 #define BOARD_I2C_BASEADDR I2C0
37 
38 /*! @brief The bubble level demo information */
39 #define BOARD_FXOS8700_ADDR 0x1D
40 #define BOARD_ACCEL_ADDR BOARD_FXOS8700_ADDR
41 #define BOARD_ACCEL_BAUDRATE 100
42 #define BOARD_ACCEL_I2C_BASEADDR I2C1
43 
44 /*! @brief The dspi instance used for board. */
45 #define BOARD_DSPI_BASEADDR SPI0
46 
47 /* Board led color mapping */
48 #define LOGIC_LED_ON 0U
49 #define LOGIC_LED_OFF 1U
50 #ifndef BOARD_LED_RED_GPIO
51 #define BOARD_LED_RED_GPIO GPIOE
52 #endif
53 #define BOARD_LED_RED_GPIO_PORT PORTE
54 #ifndef BOARD_LED_RED_GPIO_PIN
55 #define BOARD_LED_RED_GPIO_PIN 11U
56 #endif
57 #ifndef BOARD_LED_GREEN_GPIO
58 #define BOARD_LED_GREEN_GPIO GPIOE
59 #endif
60 #define BOARD_LED_GREEN_GPIO_PORT PORTE
61 #ifndef BOARD_LED_GREEN_GPIO_PIN
62 #define BOARD_LED_GREEN_GPIO_PIN 12U
63 #endif
64 #ifndef BOARD_LED_BLUE_GPIO
65 #define BOARD_LED_BLUE_GPIO GPIOE
66 #endif
67 #define BOARD_LED_BLUE_GPIO_PORT PORTE
68 #ifndef BOARD_LED_BLUE_GPIO_PIN
69 #define BOARD_LED_BLUE_GPIO_PIN 29U
70 #endif
71 #ifndef BOARD_LED_ORANGE_GPIO
72 #define BOARD_LED_ORANGE_GPIO GPIOE
73 #endif
74 #define BOARD_LED_ORANGE_GPIO_PORT PORTE
75 #ifndef BOARD_LED_ORANGE_GPIO_PIN
76 #define BOARD_LED_ORANGE_GPIO_PIN 30U
77 #endif
78 
79 #define LED_RED_INIT(output)                                                 \
80     GPIO_PinWrite(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PIN, output); \
81     BOARD_LED_RED_GPIO->PDDR |= (1U << BOARD_LED_RED_GPIO_PIN) /*!< Enable target LED_RED */
82 #define LED_RED_ON() \
83     GPIO_PortClear(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED_RED */
84 #define LED_RED_OFF() \
85     GPIO_PortSet(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn off target LED_RED */
86 #define LED_RED_TOGGLE() \
87     GPIO_PortToggle(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Toggle on target LED_RED */
88 
89 #define LED_GREEN_INIT(output)                                                   \
90     GPIO_PinWrite(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PIN, output); \
91     BOARD_LED_GREEN_GPIO->PDDR |= (1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Enable target LED_GREEN */
92 #define LED_GREEN_ON() \
93     GPIO_PortClear(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn on target LED_GREEN */
94 #define LED_GREEN_OFF() \
95     GPIO_PortSet(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn off target LED_GREEN */
96 #define LED_GREEN_TOGGLE() \
97     GPIO_PortToggle(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED_GREEN */
98 
99 #define LED_BLUE_INIT(output)                                                  \
100     GPIO_PinWrite(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PIN, output); \
101     BOARD_LED_BLUE_GPIO->PDDR |= (1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Enable target LED_BLUE */
102 #define LED_BLUE_ON() \
103     GPIO_PortClear(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn on target LED_BLUE */
104 #define LED_BLUE_OFF() \
105     GPIO_PortSet(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn off target LED_BLUE */
106 #define LED_BLUE_TOGGLE() \
107     GPIO_PortToggle(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Toggle on target LED_BLUE */
108 
109 #define LED_ORANGE_INIT(output)                                                    \
110     GPIO_PinWrite(BOARD_LED_ORANGE_GPIO, BOARD_LED_ORANGE_GPIO_PIN, output); \
111     BOARD_LED_ORANGE_GPIO->PDDR |= (1U << BOARD_LED_ORANGE_GPIO_PIN) /*!< Enable target LED_ORANGE */
112 #define LED_ORANGE_ON() \
113     GPIO_PortClear(BOARD_LED_ORANGE_GPIO, 1U << BOARD_LED_ORANGE_GPIO_PIN) /*!< Turn on target LED_ORANGE */
114 #define LED_ORANGE_OFF() \
115     GPIO_PortSet(BOARD_LED_ORANGE_GPIO, 1U << BOARD_LED_ORANGE_GPIO_PIN) /*!< Turn off target LED_ORANGE */
116 #define LED_ORANGE_TOGGLE() \
117     GPIO_PortToggle(BOARD_LED_ORANGE_GPIO, 1U << BOARD_LED_ORANGE_GPIO_PIN) /*!< Toggle on target LED_ORANGE */
118 
119 #if defined(__cplusplus)
120 extern "C" {
121 #endif /* __cplusplus */
122 
123 /*******************************************************************************
124  * API
125  ******************************************************************************/
126 
127 void BOARD_InitDebugConsole(void);
128 
129 #if defined(__cplusplus)
130 }
131 #endif /* __cplusplus */
132 
133 #endif /* _BOARD_H_ */
134