1 /*
2  * Copyright 2019 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_gpio.h"
13 #include "fsl_port.h"
14 /*******************************************************************************
15  * Definitions
16  ******************************************************************************/
17 /*! @brief The board name */
18 #define BOARD_NAME "FRDM-K32L3A6"
19 
20 /* The UART to use for debug messages. */
21 #define BOARD_DEBUG_UART_TYPE     kSerialPort_Uart
22 #define BOARD_DEBUG_UART_BAUDRATE 115200U
23 #define BOARD_DEBUG_UART_BASEADDR (uint32_t) LPUART0
24 #define BOARD_DEBUG_UART_INSTANCE 0U
25 #define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetIpFreq(kCLOCK_Lpuart0)
26 #define BOARD_UART_IRQ            LPUART0_IRQn
27 #define BOARD_UART_IRQ_HANDLER    LPUART0_IRQHandler
28 
29 /* @Brief Board accelerator sensor configuration */
30 #define BOARD_ACCEL_I2C_BASEADDR   LPI2C3
31 #define BOARD_ACCEL_I2C_CLOCK_FREQ (CLOCK_GetIpFreq(kCLOCK_Lpi2c3))
32 
33 /* Definitions for eRPC MU transport layer */
34 #if defined(FSL_FEATURE_MU_SIDE_A)
35 #define MU_BASE        MUA
36 #define MU_IRQ         MUA_IRQn
37 #define MU_IRQ_HANDLER MUA_IRQHandler
38 #endif
39 #if defined(FSL_FEATURE_MU_SIDE_B)
40 #define MU_BASE        MUB
41 #define MU_IRQ         MUB_IRQn
42 #define MU_IRQ_HANDLER MUB_IRQHandler
43 #endif
44 #define MU_IRQ_PRIORITY (2)
45 
46 /*! @brief Define the port interrupt number for the board switches */
47 #ifndef BOARD_SW2_GPIO
48 #define BOARD_SW2_GPIO GPIOA
49 #endif
50 #ifndef BOARD_SW2_PORT
51 #define BOARD_SW2_PORT PORTA
52 #endif
53 #ifndef BOARD_SW2_GPIO_PIN
54 #define BOARD_SW2_GPIO_PIN 0U
55 #endif
56 #define BOARD_SW2_IRQ         PORTA_IRQn
57 #define BOARD_SW2_IRQ_HANDLER PORTA_IRQHandler
58 #define BOARD_SW2_NAME        "SW2"
59 
60 /* Board led color mapping */
61 #ifndef BOARD_LED_RED_GPIO
62 #define BOARD_LED_RED_GPIO GPIOA
63 #endif
64 #ifndef BOARD_LED_RED_GPIO_PIN
65 #define BOARD_LED_RED_GPIO_PIN 24U
66 #endif
67 
68 /*! @brief The TPM channel used for board */
69 #define BOARD_TPM_CHANNEL 0U
70 
71 #define LOGIC_LED_ON  1U
72 #define LOGIC_LED_OFF 0U
73 #ifndef BOARD_LED1_GPIO
74 #define BOARD_LED1_GPIO GPIOA
75 #endif
76 #ifndef BOARD_LED1_GPIO_PIN
77 #define BOARD_LED1_GPIO_PIN 24U
78 #endif
79 #ifndef BOARD_LED2_GPIO
80 #define BOARD_LED2_GPIO GPIOA
81 #endif
82 #ifndef BOARD_LED2_GPIO_PIN
83 #define BOARD_LED2_GPIO_PIN 23U
84 #endif
85 #ifndef BOARD_LED3_GPIO
86 #define BOARD_LED3_GPIO GPIOA
87 #endif
88 #ifndef BOARD_LED3_GPIO_PIN
89 #define BOARD_LED3_GPIO_PIN 22U
90 #endif
91 #ifndef BOARD_LED4_GPIO
92 #define BOARD_LED4_GPIO GPIOE
93 #endif
94 #ifndef BOARD_LED4_GPIO_PIN
95 #define BOARD_LED4_GPIO_PIN 0U
96 #endif
97 
98 #define LED1_INIT(output)                                        \
99     GPIO_PinWrite(BOARD_LED1_GPIO, BOARD_LED1_GPIO_PIN, output); \
100     BOARD_LED1_GPIO->PDDR |= (1U << BOARD_LED1_GPIO_PIN)                          /*!< Enable target LED1 */
101 #define LED1_ON()     GPIO_PortSet(BOARD_LED1_GPIO, 1U << BOARD_LED1_GPIO_PIN)    /*!< Turn on target LED1 */
102 #define LED1_OFF()    GPIO_PortClear(BOARD_LED1_GPIO, 1U << BOARD_LED1_GPIO_PIN)  /*!< Turn off target LED1 */
103 #define LED1_TOGGLE() GPIO_PortToggle(BOARD_LED1_GPIO, 1U << BOARD_LED1_GPIO_PIN) /*!< Toggle on target LED1 */
104 
105 #define LED2_INIT(output)                                        \
106     GPIO_PinWrite(BOARD_LED2_GPIO, BOARD_LED2_GPIO_PIN, output); \
107     BOARD_LED2_GPIO->PDDR |= (1U << BOARD_LED2_GPIO_PIN)                          /*!< Enable target LED2 */
108 #define LED2_ON()     GPIO_PortSet(BOARD_LED2_GPIO, 1U << BOARD_LED2_GPIO_PIN)    /*!< Turn on target LED2 */
109 #define LED2_OFF()    GPIO_PortClear(BOARD_LED2_GPIO, 1U << BOARD_LED2_GPIO_PIN)  /*!< Turn off target LED2 */
110 #define LED2_TOGGLE() GPIO_PortToggle(BOARD_LED2_GPIO, 1U << BOARD_LED2_GPIO_PIN) /*!< Toggle on target LED2 */
111 
112 #define LED3_INIT(output)                                        \
113     GPIO_PinWrite(BOARD_LED3_GPIO, BOARD_LED3_GPIO_PIN, output); \
114     BOARD_LED3_GPIO->PDDR |= (1U << BOARD_LED3_GPIO_PIN)                          /*!< Enable target LED3 */
115 #define LED3_ON()     GPIO_PortSet(BOARD_LED3_GPIO, 1U << BOARD_LED3_GPIO_PIN)    /*!< Turn on target LED3 */
116 #define LED3_OFF()    GPIO_PortClear(BOARD_LED3_GPIO, 1U << BOARD_LED3_GPIO_PIN)  /*!< Turn off target LED3 */
117 #define LED3_TOGGLE() GPIO_PortToggle(BOARD_LED3_GPIO, 1U << BOARD_LED3_GPIO_PIN) /*!< Toggle on target LED3 */
118 
119 #define LED4_INIT(output)                                        \
120     GPIO_PinWrite(BOARD_LED4_GPIO, BOARD_LED4_GPIO_PIN, output); \
121     BOARD_LED4_GPIO->PDDR |= (1U << BOARD_LED4_GPIO_PIN)
122 #define LED4_ON()     GPIO_PortSet(BOARD_LED4_GPIO, 1U << BOARD_LED4_GPIO_PIN)    /*!< Turn on target LED */
123 #define LED4_OFF()    GPIO_PortClear(BOARD_LED4_GPIO, 1U << BOARD_LED4_GPIO_PIN)  /*!< Turn off target LED */
124 #define LED4_TOGGLE() GPIO_PortToggle(BOARD_LED4_GPIO, 1U << BOARD_LED4_GPIO_PIN) /*!< Toggle on target LED */
125 
126 #define LLWU_SW_GPIO        BOARD_SW2_GPIO
127 #define LLWU_SW_PORT        BOARD_SW2_PORT
128 #define LLWU_SW_GPIO_PIN    BOARD_SW2_GPIO_PIN
129 #define LLWU_SW_IRQ         BOARD_SW2_IRQ
130 #define LLWU_SW_IRQ_HANDLER BOARD_SW2_IRQ_HANDLER
131 #define LLWU_SW_NAME        BOARD_SW2_NAME
132 
133 #ifndef BOARD_SPI_FLASH_CS_GPIO
134 #define BOARD_SPI_FLASH_CS_GPIO GPIOB
135 #endif
136 #ifndef BOARD_SPI_FLASH_CS_GPIO_PIN
137 #define BOARD_SPI_FLASH_CS_GPIO_PIN 22U
138 #endif
139 #if defined(__cplusplus)
140 extern "C" {
141 #endif /* __cplusplus */
142 
143 /*******************************************************************************
144  * API
145  ******************************************************************************/
146 
147 void BOARD_InitDebugConsole(void);
148 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED
149 void BOARD_LPI2C_Init(LPI2C_Type *base, uint32_t clkSrc_Hz);
150 status_t BOARD_LPI2C_Send(LPI2C_Type *base,
151                           uint8_t deviceAddress,
152                           uint32_t subAddress,
153                           uint8_t subaddressSize,
154                           uint8_t *txBuff,
155                           uint8_t txBuffSize);
156 status_t BOARD_LPI2C_Receive(LPI2C_Type *base,
157                              uint8_t deviceAddress,
158                              uint32_t subAddress,
159                              uint8_t subaddressSize,
160                              uint8_t *rxBuff,
161                              uint8_t rxBuffSize);
162 void BOARD_Accel_I2C_Init(void);
163 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff);
164 status_t BOARD_Accel_I2C_Receive(
165     uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
166 #endif /* SDK_I2C_BASED_COMPONENT_USED */
167 #if defined(__cplusplus)
168 }
169 #endif /* __cplusplus */
170 
171 #endif /* _BOARD_H_ */
172