1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2021 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_common.h"
14 #include "fsl_gpio.h"
15 
16 /*******************************************************************************
17  * Definitions
18  ******************************************************************************/
19 /*! @brief The board name */
20 #define BOARD_NAME "LPCXPRESSO54S018M"
21 
22 #define BOARD_EXTCLKINRATE (0)
23 
24 /*! @brief The UART to use for debug messages. */
25 /* TODO: rename UART to USART */
26 #define BOARD_DEBUG_UART_TYPE       kSerialPort_Uart
27 #define BOARD_DEBUG_UART_BASEADDR   (uint32_t) USART0
28 #define BOARD_DEBUG_UART_INSTANCE   0U
29 #define BOARD_DEBUG_UART_CLK_FREQ   CLOCK_GetFlexCommClkFreq(0U)
30 #define BOARD_DEBUG_UART_CLK_ATTACH kFRO12M_to_FLEXCOMM0
31 #define BOARD_DEBUG_UART_RST        kFC0_RST_SHIFT_RSTn
32 #define BOARD_UART_IRQ_HANDLER      FLEXCOMM0_IRQHandler
33 #define BOARD_UART_IRQ              FLEXCOMM0_IRQn
34 /* TODO: obsolete */
35 #define BOARD_DEBUG_SPI_CLK_FREQ 12000000
36 
37 #ifndef BOARD_DEBUG_UART_BAUDRATE
38 #define BOARD_DEBUG_UART_BAUDRATE 115200
39 #endif /* BOARD_DEBUG_UART_BAUDRATE */
40 
41 #ifndef BOARD_LED_RED_GPIO
42 #define BOARD_LED_RED_GPIO GPIO
43 #endif
44 #define BOARD_LED_RED_GPIO_PORT 3U
45 #ifndef BOARD_LED_RED_GPIO_PIN
46 #define BOARD_LED_RED_GPIO_PIN 14U
47 #endif
48 #ifndef BOARD_LED_GREEN_GPIO
49 #define BOARD_LED_GREEN_GPIO GPIO
50 #endif
51 #define BOARD_LED_GREEN_GPIO_PORT 2U
52 #ifndef BOARD_LED_GREEN_GPIO_PIN
53 #define BOARD_LED_GREEN_GPIO_PIN 2U
54 #endif
55 #ifndef BOARD_LED_BLUE_GPIO
56 #define BOARD_LED_BLUE_GPIO GPIO
57 #endif
58 #define BOARD_LED_BLUE_GPIO_PORT 3U
59 #ifndef BOARD_LED_BLUE_GPIO_PIN
60 #define BOARD_LED_BLUE_GPIO_PIN 3U
61 #endif
62 
63 /* Board led color mapping */
64 #define LOGIC_LED_ON  0U
65 #define LOGIC_LED_OFF 1U
66 
67 #define LED_RED_INIT(output)                                                          \
68     GPIO_PinInit(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN, \
69                  &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED_RED */
70 #define LED_RED_ON()                                            \
71     GPIO_PortClear(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \
72                    1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED_RED */
73 #define LED_RED_OFF()                                         \
74     GPIO_PortSet(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \
75                  1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn off target LED_RED */
76 #define LED_RED_TOGGLE()                                         \
77     GPIO_PortToggle(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \
78                     1U << BOARD_LED_RED_GPIO_PIN) /*!< Toggle on target LED_RED */
79 
80 #define LED_GREEN_INIT(output)                                                              \
81     GPIO_PinInit(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, BOARD_LED_GREEN_GPIO_PIN, \
82                  &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED_GREEN */
83 #define LED_GREEN_ON()                                              \
84     GPIO_PortClear(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \
85                    1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn on target LED_GREEN */
86 #define LED_GREEN_OFF()                                           \
87     GPIO_PortSet(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \
88                  1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn off target LED_GREEN */
89 #define LED_GREEN_TOGGLE()                                           \
90     GPIO_PortToggle(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \
91                     1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED_GREEN */
92 
93 #define LED_BLUE_INIT(output)                                                            \
94     GPIO_PinInit(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN, \
95                  &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED_BLUE */
96 #define LED_BLUE_ON()                                             \
97     GPIO_PortClear(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \
98                    1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn on target LED_BLUE */
99 #define LED_BLUE_OFF()                                          \
100     GPIO_PortSet(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \
101                  1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn off target LED_BLUE */
102 #define LED_BLUE_TOGGLE()                                          \
103     GPIO_PortToggle(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \
104                     1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Toggle on target LED_BLUE */
105 
106 /*! @brief Memory ranges not usable by the ENET DMA. */
107 #ifndef BOARD_ENET_NON_DMA_MEMORY_ARRAY
108 #define BOARD_ENET_NON_DMA_MEMORY_ARRAY                                                     \
109     {                                                                                       \
110         {0x10000000U, 0x17FFFFFFU}, {0x80000000U, 0xDFFFFFFFU}, {0x00000000U, 0x00000000U}, \
111     }
112 #endif /* BOARD_ENET_NON_DMA_MEMORY_ARRAY */
113 
114 #if defined(__cplusplus)
115 extern "C" {
116 #endif /* __cplusplus */
117 
118 /*******************************************************************************
119  * API
120  ******************************************************************************/
121 
122 status_t BOARD_InitDebugConsole(void);
123 
124 #if defined(__cplusplus)
125 }
126 #endif /* __cplusplus */
127 
128 #endif /* _BOARD_H_ */
129