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 
14 /*******************************************************************************
15  * Definitions
16  ******************************************************************************/
17 
18 /* The board name */
19 #define BOARD_NAME "FRDM-K32L2B"
20 
21 /* The LPUART to use for debug messages. */
22 #define BOARD_DEBUG_UART_TYPE     kSerialPort_Uart
23 #define BOARD_DEBUG_UART_BASEADDR (uint32_t) LPUART0
24 #define BOARD_DEBUG_UART_INSTANCE 0U
25 #define BOARD_DEBUG_UART_CLKSRC   kCLOCK_McgIrc48MClk
26 #define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetFreq(kCLOCK_McgIrc48MClk)
27 #define BOARD_UART_IRQ            LPUART0_IRQn
28 #define BOARD_UART_IRQ_HANDLER    LPUART0_IRQHandler
29 
30 #ifndef BOARD_DEBUG_UART_BAUDRATE
31 #define BOARD_DEBUG_UART_BAUDRATE 115200
32 #endif /* BOARD_DEBUG_UART_BAUDRATE */
33 
34 #define BOARD_ADC_USE_ALT_VREF 1U
35 
36 #define BOARD_TPM_BASEADDR TPM0
37 #define BOARD_TPM_CHANNEL  5U
38 
39 /*! @brief The bubble level demo information */
40 #define BOARD_BUBBLE_TPM_BASEADDR  TPM0
41 #define BOARD_TPM_X_CHANNEL        4U
42 #define BOARD_TPM_Y_CHANNEL        5U
43 #define BOARD_ACCEL_BAUDRATE       100
44 #define BOARD_ACCEL_I2C_BASEADDR   I2C0
45 #define BOARD_ACCEL_I2C_CLOCK_FREQ CLOCK_GetFreq(I2C0_CLK_SRC)
46 
47 /*! @brief The rtc instance used for board. */
48 #define BOARD_RTC_FUNC_BASEADDR RTC
49 
50 /*! @brief The Compare instance/channel used for board */
51 #define BOARD_CMP_BASEADDR CMP0
52 #define BOARD_CMP_CHANNEL  0U
53 
54 /*! @brief The i2c instance used for i2c connection by default */
55 #define BOARD_I2C_BASEADDR I2C1
56 
57 /*! @brief The spi instance used for board. */
58 #define BOARD_SPI_BASEADDR SPI1
59 
60 /*! @brief Define the port interrupt number for the board switches */
61 #ifndef BOARD_SW1_GPIO
62 #define BOARD_SW1_GPIO GPIOA
63 #endif
64 #ifndef BOARD_SW1_PORT
65 #define BOARD_SW1_PORT PORTA
66 #endif
67 #ifndef BOARD_SW1_GPIO_PIN
68 #define BOARD_SW1_GPIO_PIN 4U
69 #endif
70 #define BOARD_SW1_IRQ         PORTA_IRQn
71 #define BOARD_SW1_IRQ_HANDLER PORTA_IRQHandler
72 #define BOARD_SW1_NAME        "SW1"
73 
74 #ifndef BOARD_SW3_GPIO
75 #define BOARD_SW3_GPIO GPIOC
76 #endif
77 #ifndef BOARD_SW3_PORT
78 #define BOARD_SW3_PORT PORTC
79 #endif
80 #ifndef BOARD_SW3_GPIO_PIN
81 #define BOARD_SW3_GPIO_PIN 3U
82 #endif
83 #define BOARD_SW3_IRQ         PORTC_PORTD_IRQn
84 #define BOARD_SW3_IRQ_HANDLER PORTC_PORTD_IRQHandler
85 #define BOARD_SW3_NAME        "SW3"
86 
87 #define LLWU_SW_GPIO        BOARD_SW3_GPIO
88 #define LLWU_SW_PORT        BOARD_SW3_PORT
89 #define LLWU_SW_GPIO_PIN    BOARD_SW3_GPIO_PIN
90 #define LLWU_SW_IRQ         BOARD_SW3_IRQ
91 #define LLWU_SW_IRQ_HANDLER BOARD_SW3_IRQ_HANDLER
92 #define LLWU_SW_NAME        BOARD_SW3_NAME
93 
94 /* Board led color mapping */
95 #define LOGIC_LED_ON  0U
96 #define LOGIC_LED_OFF 1U
97 #ifndef BOARD_LED_RED_GPIO
98 #define BOARD_LED_RED_GPIO GPIOE
99 #endif
100 #define BOARD_LED_RED_GPIO_PORT PORTE
101 #ifndef BOARD_LED_RED_GPIO_PIN
102 #define BOARD_LED_RED_GPIO_PIN 31U
103 #endif
104 #ifndef BOARD_LED_GREEN_GPIO
105 #define BOARD_LED_GREEN_GPIO GPIOD
106 #endif
107 #define BOARD_LED_GREEN_GPIO_PORT PORTD
108 #ifndef BOARD_LED_GREEN_GPIO_PIN
109 #define BOARD_LED_GREEN_GPIO_PIN 5U
110 #endif
111 
112 #define LED_RED_INIT(output)                                           \
113     GPIO_PinWrite(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PIN, output); \
114     BOARD_LED_RED_GPIO->PDDR |= (1U << BOARD_LED_RED_GPIO_PIN)                         /*!< Enable target LED_RED */
115 #define LED_RED_ON()  GPIO_PortClear(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED_RED */
116 #define LED_RED_OFF() GPIO_PortSet(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN)   /*!< Turn off target LED_RED */
117 #define LED_RED_TOGGLE() \
118     GPIO_PortToggle(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN)                  /*!< Toggle on target LED_RED */
119 
120 #define LED_GREEN_INIT(output)                                             \
121     GPIO_PinWrite(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PIN, output); \
122     BOARD_LED_GREEN_GPIO->PDDR |= (1U << BOARD_LED_GREEN_GPIO_PIN)        /*!< Enable target LED_GREEN */
123 #define LED_GREEN_ON() \
124     GPIO_PortClear(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN)  /*!< Turn on target LED_GREEN */
125 #define LED_GREEN_OFF() \
126     GPIO_PortSet(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN)    /*!< Turn off target LED_GREEN */
127 #define LED_GREEN_TOGGLE() \
128     GPIO_PortToggle(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED_GREEN */
129 
130 /* ERPC SPI configuration */
131 #define ERPC_BOARD_SPI_SLAVE_READY_USE_GPIO (1)
132 #define ERPC_BOARD_SPI_BASEADDR             SPI1
133 #define ERPC_BOARD_SPI_BAUDRATE             500000U
134 #define ERPC_BOARD_SPI_CLKSRC               SPI1_CLK_SRC
135 #define ERPC_BOARD_SPI_CLK_FREQ             CLOCK_GetFreq(SPI1_CLK_SRC)
136 #define ERPC_BOARD_SPI_INT_GPIO             GPIOC
137 #define ERPC_BOARD_SPI_INT_PORT             PORTC
138 #define ERPC_BOARD_SPI_INT_PIN              1U
139 #define ERPC_BOARD_SPI_INT_PIN_IRQ          PORTC_PORTD_IRQn
140 #define ERPC_BOARD_SPI_INT_PIN_IRQ_HANDLER  PORTC_PORTD_IRQHandler
141 
142 /* DAC base address */
143 #define BOARD_DAC_BASEADDR DAC0
144 
145 /* Board accelerometer driver */
146 #define BOARD_ACCEL_FXOS
147 
148 #if defined(__cplusplus)
149 extern "C" {
150 #endif /* __cplusplus */
151 
152 /*******************************************************************************
153  * API
154  ******************************************************************************/
155 
156 void BOARD_InitDebugConsole(void);
157 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED
158 void BOARD_I2C_Init(I2C_Type *base, uint32_t clkSrc_Hz);
159 status_t BOARD_I2C_Send(I2C_Type *base,
160                         uint8_t deviceAddress,
161                         uint32_t subAddress,
162                         uint8_t subaddressSize,
163                         uint8_t *txBuff,
164                         uint8_t txBuffSize);
165 status_t BOARD_I2C_Receive(I2C_Type *base,
166                            uint8_t deviceAddress,
167                            uint32_t subAddress,
168                            uint8_t subaddressSize,
169                            uint8_t *rxBuff,
170                            uint8_t rxBuffSize);
171 void BOARD_Accel_I2C_Init(void);
172 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff);
173 status_t BOARD_Accel_I2C_Receive(
174     uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
175 #endif /* SDK_I2C_BASED_COMPONENT_USED */
176 
177 #if defined(__cplusplus)
178 }
179 #endif /* __cplusplus */
180 
181 #endif /* _BOARD_H_ */
182