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 "LPCXpresso55S06"
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 /* Display. */
157 #define BOARD_LCD_DC_GPIO      GPIO
158 #define BOARD_LCD_DC_GPIO_PORT 0U
159 #define BOARD_LCD_DC_GPIO_PIN  24U
160 
161 #if defined(__cplusplus)
162 extern "C" {
163 #endif /* __cplusplus */
164 
165 /*******************************************************************************
166  * API
167  ******************************************************************************/
168 
169 void BOARD_InitDebugConsole(void);
170 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED
171 void BOARD_I2C_Init(I2C_Type *base, uint32_t clkSrc_Hz);
172 status_t BOARD_I2C_Send(I2C_Type *base,
173                         uint8_t deviceAddress,
174                         uint32_t subAddress,
175                         uint8_t subaddressSize,
176                         uint8_t *txBuff,
177                         uint8_t txBuffSize);
178 status_t BOARD_I2C_Receive(I2C_Type *base,
179                            uint8_t deviceAddress,
180                            uint32_t subAddress,
181                            uint8_t subaddressSize,
182                            uint8_t *rxBuff,
183                            uint8_t rxBuffSize);
184 void BOARD_Accel_I2C_Init(void);
185 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff);
186 status_t BOARD_Accel_I2C_Receive(
187     uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, 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 
195 #if defined(__cplusplus)
196 }
197 #endif /* __cplusplus */
198 
199 #endif /* _BOARD_H_ */
200