1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2018 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 "LPCXPRESSO54114"
21 
22 #define BOARD_EXTCLKINRATE (0)
23 
24 /*! @brief The UART to use for debug messages. */
25 #define BOARD_DEBUG_UART_TYPE       kSerialPort_Uart
26 #define BOARD_DEBUG_UART_BASEADDR   (uint32_t) USART0
27 #define BOARD_DEBUG_UART_INSTANCE   0U
28 #define BOARD_DEBUG_UART_CLK_FREQ   CLOCK_GetFlexCommClkFreq(0)
29 #define BOARD_DEBUG_UART_CLK_ATTACH kFRO12M_to_FLEXCOMM0
30 #define BOARD_DEBUG_UART_RST        kFC0_RST_SHIFT_RSTn
31 #define BOARD_UART_IRQ              FLEXCOMM0_IRQn
32 #define BOARD_UART_IRQ_HANDLER      FLEXCOMM0_IRQHandler
33 
34 #define BOARD_DEBUG_UART_TYPE_CORE1       kSerialPort_Uart
35 #define BOARD_DEBUG_UART_BASEADDR_CORE1   (uint32_t) USART2
36 #define BOARD_DEBUG_UART_INSTANCE_CORE1   2U
37 #define BOARD_DEBUG_UART_CLK_FREQ_CORE1   CLOCK_GetFlexCommClkFreq(2)
38 #define BOARD_DEBUG_UART_CLK_ATTACH_CORE1 kFRO12M_to_FLEXCOMM2
39 #define BOARD_DEBUG_UART_RST_CORE1        kFC2_RST_SHIFT_RSTn
40 #define BOARD_UART_IRQ_CORE1              FLEXCOMM2_IRQn
41 #define BOARD_UART_IRQ_HANDLER_CORE1      FLEXCOMM2_IRQHandler
42 
43 #define BOARD_DEBUG_SPI_CLK_FREQ 12000000
44 
45 #ifndef BOARD_DEBUG_UART_BAUDRATE
46 #define BOARD_DEBUG_UART_BAUDRATE 115200
47 #endif /* BOARD_DEBUG_UART_BAUDRATE */
48 
49 #ifndef BOARD_DEBUG_UART_BAUDRATE_CORE1
50 #define BOARD_DEBUG_UART_BAUDRATE_CORE1 115200
51 #endif /* BOARD_DEBUG_UART_BAUDRATE_CORE1 */
52 
53 #ifndef BOARD_LED_RED_GPIO
54 #define BOARD_LED_RED_GPIO GPIO
55 #endif
56 #define BOARD_LED_RED_GPIO_PORT 0U
57 #ifndef BOARD_LED_RED_GPIO_PIN
58 #define BOARD_LED_RED_GPIO_PIN 29U
59 #endif
60 #ifndef BOARD_LED_GREEN_GPIO
61 #define BOARD_LED_GREEN_GPIO GPIO
62 #endif
63 #define BOARD_LED_GREEN_GPIO_PORT 1U
64 #ifndef BOARD_LED_GREEN_GPIO_PIN
65 #define BOARD_LED_GREEN_GPIO_PIN 10U
66 #endif
67 #ifndef BOARD_LED_BLUE_GPIO
68 #define BOARD_LED_BLUE_GPIO GPIO
69 #endif
70 #define BOARD_LED_BLUE_GPIO_PORT 1U
71 #ifndef BOARD_LED_BLUE_GPIO_PIN
72 #define BOARD_LED_BLUE_GPIO_PIN 9U
73 #endif
74 
75 #ifndef BOARD_SW1_GPIO
76 #define BOARD_SW1_GPIO GPIO
77 #endif
78 #define BOARD_SW1_GPIO_PORT 0U
79 #ifndef BOARD_SW1_GPIO_PIN
80 #define BOARD_SW1_GPIO_PIN 24U
81 #endif
82 #define BOARD_SW1_NAME        "SW1"
83 #define BOARD_SW3_IRQ         PIN_INT0_IRQn
84 #define BOARD_SW3_IRQ_HANDLER PIN_INT0_IRQHandler
85 
86 #ifndef BOARD_SW2_GPIO
87 #define BOARD_SW2_GPIO GPIO
88 #endif
89 #define BOARD_SW2_GPIO_PORT 0U
90 #ifndef BOARD_SW2_GPIO_PIN
91 #define BOARD_SW2_GPIO_PIN 31U
92 #endif
93 #define BOARD_SW2_NAME        "SW2"
94 #define BOARD_SW3_IRQ         PIN_INT0_IRQn
95 #define BOARD_SW3_IRQ_HANDLER PIN_INT0_IRQHandler
96 
97 #ifndef BOARD_SW3_GPIO
98 #define BOARD_SW3_GPIO GPIO
99 #endif
100 #define BOARD_SW3_GPIO_PORT 0U
101 #ifndef BOARD_SW3_GPIO_PIN
102 #define BOARD_SW3_GPIO_PIN 4U
103 #endif
104 #define BOARD_SW3_NAME              "SW3"
105 #define BOARD_SW3_IRQ               PIN_INT0_IRQn
106 #define BOARD_SW3_IRQ_HANDLER       PIN_INT0_IRQHandler
107 #define BOARD_SW3_GPIO_PININT_INDEX 0
108 
109 #define BOARD_ARDUINO_INT_IRQ   (GINT0_IRQn)
110 #define BOARD_ARDUINO_I2C_IRQ   (FLEXCOMM4_IRQn)
111 #define BOARD_ARDUINO_I2C_INDEX (4)
112 /* Board led color mapping */
113 #define LOGIC_LED_ON  0U
114 #define LOGIC_LED_OFF 1U
115 
116 #define LED_RED_INIT(output)                                                          \
117     GPIO_PinInit(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN, \
118                  &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED_RED */
119 #define LED_RED_ON()                                            \
120     GPIO_PortClear(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \
121                    1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED_RED */
122 #define LED_RED_OFF()                                         \
123     GPIO_PortSet(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \
124                  1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn off target LED_RED */
125 #define LED_RED_TOGGLE()                                         \
126     GPIO_PortToggle(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \
127                     1U << BOARD_LED_RED_GPIO_PIN) /*!< Toggle on target LED_RED */
128 
129 #define LED_GREEN_INIT(output)                                                              \
130     GPIO_PinInit(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, BOARD_LED_GREEN_GPIO_PIN, \
131                  &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED_GREEN */
132 #define LED_GREEN_ON()                                              \
133     GPIO_PortClear(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \
134                    1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn on target LED_GREEN */
135 #define LED_GREEN_OFF()                                           \
136     GPIO_PortSet(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \
137                  1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn off target LED_GREEN */
138 #define LED_GREEN_TOGGLE()                                           \
139     GPIO_PortToggle(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \
140                     1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED_GREEN */
141 
142 #define LED_BLUE_INIT(output)                                                            \
143     GPIO_PinInit(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN, \
144                  &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED_BLUE */
145 #define LED_BLUE_ON()                                             \
146     GPIO_PortClear(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \
147                    1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn on target LED_BLUE */
148 #define LED_BLUE_OFF()                                          \
149     GPIO_PortSet(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \
150                  1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn off target LED_BLUE */
151 #define LED_BLUE_TOGGLE()                                          \
152     GPIO_PortToggle(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \
153                     1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Toggle on target LED_BLUE */
154 
155 #define BOARD_CODEC_I2C_BASEADDR   I2C4
156 #define BOARD_CODEC_I2C_INSTANCE   4U
157 #define BOARD_CODEC_I2C_CLOCK_FREQ 12000000
158 
159 /* Display. */
160 #define BOARD_LCD_DC_GPIO      GPIO
161 #define BOARD_LCD_DC_GPIO_PORT 1U
162 #define BOARD_LCD_DC_GPIO_PIN  15U
163 
164 #if defined(__cplusplus)
165 extern "C" {
166 #endif /* __cplusplus */
167 
168 /*******************************************************************************
169  * API
170  ******************************************************************************/
171 
172 status_t BOARD_InitDebugConsole(void);
173 status_t BOARD_InitDebugConsole_Core1(void);
174 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED
175 void BOARD_I2C_Init(I2C_Type *base, uint32_t clkSrc_Hz);
176 status_t BOARD_I2C_Send(I2C_Type *base,
177                         uint8_t deviceAddress,
178                         uint32_t subAddress,
179                         uint8_t subaddressSize,
180                         uint8_t *txBuff,
181                         uint8_t txBuffSize);
182 status_t BOARD_I2C_Receive(I2C_Type *base,
183                            uint8_t deviceAddress,
184                            uint32_t subAddress,
185                            uint8_t subaddressSize,
186                            uint8_t *rxBuff,
187                            uint8_t rxBuffSize);
188 void BOARD_Codec_I2C_Init(void);
189 status_t BOARD_Codec_I2C_Send(
190     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
191 status_t BOARD_Codec_I2C_Receive(
192     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
193 #endif /* SDK_I2C_BASED_COMPONENT_USED */
194 #if defined(__cplusplus)
195 }
196 #endif /* __cplusplus */
197 
198 #endif /* _BOARD_H_ */
199