1 /*
2  * Copyright 2017-2018 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef _BOARD_H_
9 #define _BOARD_H_
10 
11 #include "clock_config.h"
12 #include "fsl_common.h"
13 #include "fsl_reset.h"
14 #include "fsl_gpio.h"
15 #include "fsl_iocon.h"
16 
17 /*******************************************************************************
18  * Definitions
19  ******************************************************************************/
20 /*! @brief The board name */
21 #define BOARD_NAME "LPCXpresso55S69"
22 
23 /*! @brief The UART to use for debug messages. */
24 /* TODO: rename UART to USART */
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   12000000U
29 #define BOARD_DEBUG_UART_CLK_ATTACH kFRO12M_to_FLEXCOMM0
30 #define BOARD_DEBUG_UART_RST        kFC0_RST_SHIFT_RSTn
31 #define BOARD_DEBUG_UART_CLKSRC     kCLOCK_Flexcomm0
32 #define BOARD_UART_IRQ_HANDLER      FLEXCOMM0_IRQHandler
33 #define BOARD_UART_IRQ              FLEXCOMM0_IRQn
34 
35 #define BOARD_ACCEL_I2C_BASEADDR   I2C4
36 #define BOARD_ACCEL_I2C_CLOCK_FREQ 12000000
37 
38 #define BOARD_DEBUG_UART_TYPE_CORE1       kSerialPort_Uart
39 #define BOARD_DEBUG_UART_BASEADDR_CORE1   (uint32_t) USART1
40 #define BOARD_DEBUG_UART_INSTANCE_CORE1   1U
41 #define BOARD_DEBUG_UART_CLK_FREQ_CORE1   12000000U
42 #define BOARD_DEBUG_UART_CLK_ATTACH_CORE1 kFRO12M_to_FLEXCOMM1
43 #define BOARD_DEBUG_UART_RST_CORE1        kFC1_RST_SHIFT_RSTn
44 #define BOARD_DEBUG_UART_CLKSRC_CORE1     kCLOCK_Flexcomm1
45 #define BOARD_UART_IRQ_HANDLER_CORE1      FLEXCOMM1_IRQHandler
46 #define BOARD_UART_IRQ_CORE1              FLEXCOMM1_IRQn
47 
48 #ifndef BOARD_DEBUG_UART_BAUDRATE
49 #define BOARD_DEBUG_UART_BAUDRATE 115200U
50 #endif /* BOARD_DEBUG_UART_BAUDRATE */
51 
52 #ifndef BOARD_DEBUG_UART_BAUDRATE_CORE1
53 #define BOARD_DEBUG_UART_BAUDRATE_CORE1 115200U
54 #endif /* BOARD_DEBUG_UART_BAUDRATE_CORE1 */
55 
56 #define BOARD_CODEC_I2C_BASEADDR   I2C4
57 #define BOARD_CODEC_I2C_CLOCK_FREQ 12000000
58 #define BOARD_CODEC_I2C_INSTANCE   4
59 #ifndef BOARD_LED_RED_GPIO
60 #define BOARD_LED_RED_GPIO GPIO
61 #endif
62 #define BOARD_LED_RED_GPIO_PORT 1U
63 #ifndef BOARD_LED_RED_GPIO_PIN
64 #define BOARD_LED_RED_GPIO_PIN 6U
65 #endif
66 
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 4U
73 #endif
74 
75 #ifndef BOARD_LED_GREEN_GPIO
76 #define BOARD_LED_GREEN_GPIO GPIO
77 #endif
78 #define BOARD_LED_GREEN_GPIO_PORT 1U
79 #ifndef BOARD_LED_GREEN_GPIO_PIN
80 #define BOARD_LED_GREEN_GPIO_PIN 7U
81 #endif
82 
83 #ifndef BOARD_SW1_GPIO
84 #define BOARD_SW1_GPIO GPIO
85 #endif
86 #define BOARD_SW1_GPIO_PORT 0U
87 #ifndef BOARD_SW1_GPIO_PIN
88 #define BOARD_SW1_GPIO_PIN 5U
89 #endif
90 #define BOARD_SW1_NAME        "SW1"
91 #define BOARD_SW1_IRQ         PIN_INT0_IRQn
92 #define BOARD_SW1_IRQ_HANDLER PIN_INT0_IRQHandler
93 
94 #ifndef BOARD_SW2_GPIO
95 #define BOARD_SW2_GPIO GPIO
96 #endif
97 #define BOARD_SW2_GPIO_PORT 1U
98 #ifndef BOARD_SW2_GPIO_PIN
99 #define BOARD_SW2_GPIO_PIN 18U
100 #endif
101 #define BOARD_SW2_NAME              "SW2"
102 #define BOARD_SW2_IRQ               PIN_INT1_IRQn
103 #define BOARD_SW2_IRQ_HANDLER       PIN_INT1_IRQHandler
104 #define BOARD_SW2_GPIO_PININT_INDEX 1
105 
106 #ifndef BOARD_SW3_GPIO
107 #define BOARD_SW3_GPIO GPIO
108 #endif
109 #define BOARD_SW3_GPIO_PORT 1U
110 #ifndef BOARD_SW3_GPIO_PIN
111 #define BOARD_SW3_GPIO_PIN 9U
112 #endif
113 #define BOARD_SW3_NAME              "SW3"
114 #define BOARD_SW3_IRQ               PIN_INT1_IRQn
115 #define BOARD_SW3_IRQ_HANDLER       PIN_INT1_IRQHandler
116 #define BOARD_SW3_GPIO_PININT_INDEX 1
117 
118 /* Board led color mapping */
119 #define LOGIC_LED_ON  0U
120 #define LOGIC_LED_OFF 1U
121 
122 #define LED_RED_INIT(output)                                                                          \
123     {                                                                                                 \
124         IOCON_PinMuxSet(IOCON, BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN, IOCON_DIGITAL_EN);    \
125         GPIO_PinInit(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN,             \
126                      &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}); /*!< Enable target LED1 */ \
127     }
128 #define LED_RED_ON()                                            \
129     GPIO_PortClear(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \
130                    1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED1 */
131 #define LED_RED_OFF()                                                                        \
132     GPIO_PortSet(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT,                                \
133                  1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn off target LED1 \ \ \ \ \ \ \ \ \ \ \
134                                                 */
135 #define LED_RED_TOGGLE()                                         \
136     GPIO_PortToggle(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \
137                     1U << BOARD_LED_RED_GPIO_PIN) /*!< Toggle on target LED1 */
138 
139 #define LED_BLUE_INIT(output)                                                                         \
140     {                                                                                                 \
141         IOCON_PinMuxSet(IOCON, BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN, IOCON_DIGITAL_EN);  \
142         GPIO_PinInit(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN,          \
143                      &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}); /*!< Enable target LED1 */ \
144     }
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 LED1 */
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 LED1 */
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 LED1 */
154 
155 #define LED_GREEN_INIT(output)                                                              \
156     GPIO_PinInit(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, BOARD_LED_GREEN_GPIO_PIN, \
157                  &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED1 */
158 #define LED_GREEN_ON()                                              \
159     GPIO_PortClear(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \
160                    1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn on target LED1 */
161 #define LED_GREEN_OFF()                                           \
162     GPIO_PortSet(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \
163                  1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn off target LED1 */
164 #define LED_GREEN_TOGGLE()                                           \
165     GPIO_PortToggle(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \
166                     1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED1 */
167 
168 /*! @brief The WIFI-QCA shield pin. */
169 #define BOARD_INITGT202SHIELD_PWRON_GPIO GPIO
170 #define BOARD_INITGT202SHIELD_PWRON_PORT 1U
171 #define BOARD_INITGT202SHIELD_PWRON_PIN  8U
172 
173 #define BOARD_INITGT202SHIELD_IRQ_GPIO GPIO
174 #define BOARD_INITGT202SHIELD_IRQ_PORT 1U
175 #define BOARD_INITGT202SHIELD_IRQ_PIN  9U
176 
177 /*! @brief The WIFI-QCA shield pin. */
178 #define BOARD_INITSILEX2401SHIELD_PWRON_GPIO GPIO
179 #define BOARD_INITSILEX2401SHIELD_PWRON_PORT 1U
180 #define BOARD_INITSILEX2401SHIELD_PWRON_PIN  7U
181 
182 #define BOARD_INITSILEX2401SHIELD_IRQ_GPIO     GPIO
183 #define BOARD_INITSILEX2401SHIELD_IRQ_PORT     0U
184 #define BOARD_INITSILEX2401SHIELD_IRQ_GPIO_PIN 15U
185 
186 /*! @brief The WIFI-QCA shield pin. */
187 #define BOARD_INITWIFI10CLICKSHIELD_PWRON_GPIO GPIO
188 #define BOARD_INITWIFI10CLICKSHIELD_PWRON_PORT 1U
189 #define BOARD_INITWIFI10CLICKSHIELD_PWRON_PIN  5U
190 
191 #define BOARD_INITWIFI10CLICKSHIELD_IRQ_GPIO     GPIO
192 #define BOARD_INITWIFI10CLICKSHIELD_IRQ_PORT     1U
193 #define BOARD_INITWIFI10CLICKSHIELD_IRQ_GPIO_PIN 18U
194 
195 /* Display. */
196 #define BOARD_LCD_DC_GPIO      GPIO
197 #define BOARD_LCD_DC_GPIO_PORT 1U
198 #define BOARD_LCD_DC_GPIO_PIN  5U
199 
200 /* Serial MWM WIFI */
201 #define BOARD_SERIAL_MWM_PORT_CLK_FREQ CLOCK_GetFlexCommClkFreq(2)
202 #define BOARD_SERIAL_MWM_PORT          USART2
203 #define BOARD_SERIAL_MWM_PORT_IRQn     FLEXCOMM2_IRQn
204 #define BOARD_SERIAL_MWM_RST_WRITE(output)
205 
206 #if defined(__cplusplus)
207 extern "C" {
208 #endif /* __cplusplus */
209 
210 /*******************************************************************************
211  * API
212  ******************************************************************************/
213 
214 void BOARD_InitDebugConsole(void);
215 void BOARD_InitDebugConsole_Core1(void);
216 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED
217 void BOARD_I2C_Init(I2C_Type *base, uint32_t clkSrc_Hz);
218 status_t BOARD_I2C_Send(I2C_Type *base,
219                         uint8_t deviceAddress,
220                         uint32_t subAddress,
221                         uint8_t subaddressSize,
222                         uint8_t *txBuff,
223                         uint8_t txBuffSize);
224 status_t BOARD_I2C_Receive(I2C_Type *base,
225                            uint8_t deviceAddress,
226                            uint32_t subAddress,
227                            uint8_t subaddressSize,
228                            uint8_t *rxBuff,
229                            uint8_t rxBuffSize);
230 void BOARD_Accel_I2C_Init(void);
231 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff);
232 status_t BOARD_Accel_I2C_Receive(
233     uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
234 void BOARD_Codec_I2C_Init(void);
235 status_t BOARD_Codec_I2C_Send(
236     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
237 status_t BOARD_Codec_I2C_Receive(
238     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
239 #endif /* SDK_I2C_BASED_COMPONENT_USED */
240 
241 #if defined(__cplusplus)
242 }
243 #endif /* __cplusplus */
244 
245 #endif /* _BOARD_H_ */
246