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 "LPCXpresso55S06CP"
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   I2C0
36 #define BOARD_ACCEL_I2C_CLOCK_FREQ 12000000
37 
38 #ifndef BOARD_DEBUG_UART_BAUDRATE
39 #define BOARD_DEBUG_UART_BAUDRATE 115200U
40 #endif /* BOARD_DEBUG_UART_BAUDRATE */
41 
42 #define BOARD_CODEC_I2C_BASEADDR   I2C4
43 #define BOARD_CODEC_I2C_CLOCK_FREQ 12000000
44 #define BOARD_CODEC_I2C_INSTANCE   4
45 #ifndef BOARD_LED_RED_GPIO
46 #define BOARD_LED_RED_GPIO GPIO
47 #endif
48 #define BOARD_LED_RED_GPIO_PORT 0U
49 #ifndef BOARD_LED_RED_GPIO_PIN
50 #define BOARD_LED_RED_GPIO_PIN 21U
51 #endif
52 
53 #ifndef BOARD_LED_BLUE_GPIO
54 #define BOARD_LED_BLUE_GPIO GPIO
55 #endif
56 #define BOARD_LED_BLUE_GPIO_PORT 0U
57 #ifndef BOARD_LED_BLUE_GPIO_PIN
58 #define BOARD_LED_BLUE_GPIO_PIN 22U
59 #endif
60 
61 #ifndef BOARD_LED_GREEN_GPIO
62 #define BOARD_LED_GREEN_GPIO GPIO
63 #endif
64 #define BOARD_LED_GREEN_GPIO_PORT 0U
65 #ifndef BOARD_LED_GREEN_GPIO_PIN
66 #define BOARD_LED_GREEN_GPIO_PIN 18U
67 #endif
68 
69 #ifndef BOARD_SW1_GPIO
70 #define BOARD_SW1_GPIO GPIO
71 #endif
72 #define BOARD_SW1_GPIO_PORT 0U
73 #ifndef BOARD_SW1_GPIO_PIN
74 #define BOARD_SW1_GPIO_PIN 28U
75 #endif
76 #define BOARD_SW1_NAME        "SW1"
77 #define BOARD_SW1_IRQ         PIN_INT0_IRQn
78 #define BOARD_SW1_IRQ_HANDLER PIN_INT0_IRQHandler
79 
80 #ifndef BOARD_SW3_GPIO
81 #define BOARD_SW3_GPIO GPIO
82 #endif
83 #define BOARD_SW3_GPIO_PORT 1U
84 #ifndef BOARD_SW3_GPIO_PIN
85 #define BOARD_SW3_GPIO_PIN 9U
86 #endif
87 #define BOARD_SW3_NAME              "SW3"
88 #define BOARD_SW3_IRQ               PIN_INT1_IRQn
89 #define BOARD_SW3_IRQ_HANDLER       PIN_INT1_IRQHandler
90 #define BOARD_SW3_GPIO_PININT_INDEX 1
91 
92 #ifndef BOARD_SW4_GPIO
93 #define BOARD_SW4_GPIO GPIO
94 #endif
95 #define BOARD_SW4_GPIO_PORT 0U
96 #ifndef BOARD_SW4_GPIO_PIN
97 #define BOARD_SW4_GPIO_PIN 5U
98 #endif
99 #define BOARD_SW4_NAME              "SW4"
100 #define BOARD_SW4_IRQ               PIN_INT0_IRQn
101 #define BOARD_SW4_IRQ_HANDLER       PIN_INT0_IRQHandler
102 #define BOARD_SW4_GPIO_PININT_INDEX 1
103 
104 /* Board led color mapping */
105 #define LOGIC_LED_ON  1U
106 #define LOGIC_LED_OFF 0U
107 
108 #define BOARD_SDIF_CLK_ATTACH kMAIN_CLK_to_SDIO_CLK
109 
110 #define LED_RED_INIT(output)                                                                          \
111     {                                                                                                 \
112         IOCON_PinMuxSet(IOCON, BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN, IOCON_DIGITAL_EN);    \
113         GPIO_PinInit(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN,             \
114                      &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}); /*!< Enable target LED1 */ \
115     }
116 #define LED_RED_OFF()                                           \
117     GPIO_PortClear(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \
118                    1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn off target LED1 */
119 #define LED_RED_ON()                                                                        \
120     GPIO_PortSet(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT,                               \
121                  1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED1 \ \ \ \ \ \ \ \ \ \ \
122                                                 */
123 #define LED_RED_TOGGLE()                                         \
124     GPIO_PortToggle(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PORT, \
125                     1U << BOARD_LED_RED_GPIO_PIN) /*!< Toggle on target LED1 */
126 
127 #define LED_BLUE_INIT(output)                                                                         \
128     {                                                                                                 \
129         IOCON_PinMuxSet(IOCON, BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN, IOCON_DIGITAL_EN);  \
130         GPIO_PinInit(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN,          \
131                      &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}); /*!< Enable target LED1 */ \
132     }
133 #define LED_BLUE_OFF()                                            \
134     GPIO_PortClear(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \
135                    1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn off target LED1 */
136 #define LED_BLUE_ON()                                           \
137     GPIO_PortSet(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \
138                  1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn on target LED1 */
139 #define LED_BLUE_TOGGLE()                                          \
140     GPIO_PortToggle(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PORT, \
141                     1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Toggle on target LED1 */
142 
143 #define LED_GREEN_INIT(output)                                                              \
144     GPIO_PinInit(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, BOARD_LED_GREEN_GPIO_PIN, \
145                  &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED1 */
146 #define LED_GREEN_OFF()                                             \
147     GPIO_PortClear(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \
148                    1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn off target LED1 */
149 #define LED_GREEN_ON()                                            \
150     GPIO_PortSet(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \
151                  1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn on target LED1 */
152 #define LED_GREEN_TOGGLE()                                           \
153     GPIO_PortToggle(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PORT, \
154                     1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED1 */
155 
156 /*! @brief The WIFI-QCA shield pin. */
157 #define BOARD_INITGT202SHIELD_PWRON_GPIO GPIO
158 #define BOARD_INITGT202SHIELD_PWRON_PORT 0U
159 #define BOARD_INITGT202SHIELD_PWRON_PIN  10U
160 
161 #define BOARD_INITGT202SHIELD_IRQ_GPIO GPIO
162 #define BOARD_INITGT202SHIELD_IRQ_PORT 0U
163 #define BOARD_INITGT202SHIELD_IRQ_PIN  2U
164 
165 /*! @brief The WIFI-QCA shield pin. */
166 #define BOARD_INITSILEX2401SHIELD_PWRON_GPIO GPIO
167 #define BOARD_INITSILEX2401SHIELD_PWRON_PORT 0U
168 #define BOARD_INITSILEX2401SHIELD_PWRON_PIN  22U
169 
170 #define BOARD_INITSILEX2401SHIELD_IRQ_GPIO     GPIO
171 #define BOARD_INITSILEX2401SHIELD_IRQ_PORT     0U
172 #define BOARD_INITSILEX2401SHIELD_IRQ_GPIO_PIN 15U
173 
174 /*! @brief The WIFI-QCA shield pin. */
175 #define BOARD_INITWIFI10CLICKSHIELD_PWRON_GPIO GPIO
176 #define BOARD_INITWIFI10CLICKSHIELD_PWRON_PORT 1U
177 #define BOARD_INITWIFI10CLICKSHIELD_PWRON_PIN  5U
178 
179 #define BOARD_INITWIFI10CLICKSHIELD_IRQ_GPIO     GPIO
180 #define BOARD_INITWIFI10CLICKSHIELD_IRQ_PORT     0U
181 #define BOARD_INITWIFI10CLICKSHIELD_IRQ_GPIO_PIN 28U
182 
183 /* Display. */
184 #define BOARD_LCD_DC_GPIO      GPIO
185 #define BOARD_LCD_DC_GPIO_PORT 0U
186 #define BOARD_LCD_DC_GPIO_PIN  24U
187 
188 #if defined(__cplusplus)
189 extern "C" {
190 #endif /* __cplusplus */
191 
192 /*******************************************************************************
193  * API
194  ******************************************************************************/
195 
196 void BOARD_InitDebugConsole(void);
197 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED
198 void BOARD_I2C_Init(I2C_Type *base, uint32_t clkSrc_Hz);
199 status_t BOARD_I2C_Send(I2C_Type *base,
200                         uint8_t deviceAddress,
201                         uint32_t subAddress,
202                         uint8_t subaddressSize,
203                         uint8_t *txBuff,
204                         uint8_t txBuffSize);
205 status_t BOARD_I2C_Receive(I2C_Type *base,
206                            uint8_t deviceAddress,
207                            uint32_t subAddress,
208                            uint8_t subaddressSize,
209                            uint8_t *rxBuff,
210                            uint8_t rxBuffSize);
211 void BOARD_Accel_I2C_Init(void);
212 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff);
213 status_t BOARD_Accel_I2C_Receive(
214     uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
215 void BOARD_Codec_I2C_Init(void);
216 status_t BOARD_Codec_I2C_Send(
217     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
218 status_t BOARD_Codec_I2C_Receive(
219     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
220 #endif /* SDK_I2C_BASED_COMPONENT_USED */
221 
222 #if defined(__cplusplus)
223 }
224 #endif /* __cplusplus */
225 
226 #endif /* _BOARD_H_ */
227