1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016-2018 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef _BOARD_H_
10 #define _BOARD_H_
11 
12 #include "clock_config.h"
13 #include "fsl_gpio.h"
14 #include "fsl_port.h"
15 
16 /*******************************************************************************
17  * Definitions
18  ******************************************************************************/
19 
20 /*! @brief The board name */
21 #define BOARD_NAME "FRDM-K66F"
22 
23 /*! @brief The UART to use for debug messages. */
24 #define BOARD_DEBUG_UART_TYPE     kSerialPort_Uart
25 #define BOARD_DEBUG_UART_BASEADDR (uint32_t) UART0
26 #define BOARD_DEBUG_UART_INSTANCE 0U
27 #define BOARD_DEBUG_UART_CLKSRC   SYS_CLK
28 #define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetCoreSysClkFreq()
29 #define BOARD_UART_IRQ            UART0_RX_TX_IRQn
30 #define BOARD_UART_IRQ_HANDLER    UART0_RX_TX_IRQHandler
31 
32 #ifndef BOARD_DEBUG_UART_BAUDRATE
33 #define BOARD_DEBUG_UART_BAUDRATE 115200
34 #endif /* BOARD_DEBUG_UART_BAUDRATE */
35 
36 /*! @brief The CAN instance used for board. */
37 #define BOARD_CAN_BASEADDR CAN0
38 
39 /*! @brief The i2c instance used for i2c connection by default */
40 #define BOARD_I2C_BASEADDR I2C1
41 
42 /*! @brief The ENET PHY address. */
43 #define BOARD_ENET0_PHY_ADDRESS (0x00U) /* Phy address of enet port 0. */
44 
45 /*! @brief The TPM instance/channel used for board */
46 #define BOARD_TPM_BASEADDR TPM2
47 #define BOARD_TPM_CHANNEL  1U
48 
49 #define BOARD_FTM_BASEADDR    FTM3
50 #define BOARD_FTM_X_CHANNEL   0U
51 #define BOARD_FTM_Y_CHANNEL   1U
52 #define BOARD_FTM_PERIOD_HZ   100
53 #define BOARD_FTM_IRQ_HANDLER FTM0_IRQHandler
54 #define BOARD_FTM_IRQ_VECTOR  FTM0_IRQn
55 
56 /*! @brief The bubble level demo information */
57 #define BOARD_FXOS8700_ADDR        0x1D
58 #define BOARD_ACCEL_ADDR           BOARD_FXOS8700_ADDR
59 #define BOARD_ACCEL_BAUDRATE       100
60 #define BOARD_ACCEL_I2C_BASEADDR   I2C0
61 #define BOARD_ACCEL_I2C_CLOCK_FREQ CLOCK_GetFreq(I2C0_CLK_SRC)
62 
63 /*! @brief The FlexBus instance used for board.*/
64 #define BOARD_FLEXBUS_BASEADDR FB
65 
66 /*! @brief The SDHC instance/channel used for board. */
67 #define BOARD_SDHC_BASEADDR            SDHC
68 #define BOARD_SDHC_CD_GPIO_IRQ_HANDLER PORTD_IRQHandler
69 
70 /*! @brief The CMP instance/channel used for board. */
71 #define BOARD_CMP_BASEADDR CMP2
72 #define BOARD_CMP_CHANNEL  2U
73 
74 /*! @brief The i2c instance used for board. */
75 #define BOARD_SAI_DEMO_I2C_BASEADDR I2C0
76 
77 /*! @brief The rtc instance used for board. */
78 #define BOARD_RTC_FUNC_BASEADDR RTC
79 
80 /*! @brief If connected the TWR_MEM, this is spi sd card */
81 #define BOARD_SDCARD_CARD_DETECTION_GPIO_PORT GPIOD
82 #define SDCARD_CARD_DETECTION_GPIO_PIN        10U
83 #define SDCARD_CARD_INSERTED                  0U
84 
85 /*! @brief Define the port interrupt number for the board switches */
86 #ifndef BOARD_SW3_GPIO
87 #define BOARD_SW3_GPIO GPIOA
88 #endif
89 #ifndef BOARD_SW3_PORT
90 #define BOARD_SW3_PORT PORTA
91 #endif
92 #ifndef BOARD_SW3_GPIO_PIN
93 #define BOARD_SW3_GPIO_PIN 10U
94 #endif
95 #define BOARD_SW3_IRQ         PORTA_IRQn
96 #define BOARD_SW3_IRQ_HANDLER PORTA_IRQHandler
97 #define BOARD_SW3_NAME        "SW3"
98 
99 #define LLWU_SW_GPIO        BOARD_SW3_GPIO
100 #define LLWU_SW_PORT        BOARD_SW3_PORT
101 #define LLWU_SW_GPIO_PIN    BOARD_SW3_GPIO_PIN
102 #define LLWU_SW_IRQ         BOARD_SW3_IRQ
103 #define LLWU_SW_IRQ_HANDLER BOARD_SW3_IRQ_HANDLER
104 #define LLWU_SW_NAME        BOARD_SW3_NAME
105 
106 /* Board led color mapping */
107 #define LOGIC_LED_ON  0U
108 #define LOGIC_LED_OFF 1U
109 #ifndef BOARD_LED_RED_GPIO
110 #define BOARD_LED_RED_GPIO GPIOC
111 #endif
112 #define BOARD_LED_RED_GPIO_PORT PORTC
113 #ifndef BOARD_LED_RED_GPIO_PIN
114 #define BOARD_LED_RED_GPIO_PIN 9U
115 #endif
116 #ifndef BOARD_LED_GREEN_GPIO
117 #define BOARD_LED_GREEN_GPIO GPIOE
118 #endif
119 #define BOARD_LED_GREEN_GPIO_PORT PORTE
120 #ifndef BOARD_LED_GREEN_GPIO_PIN
121 #define BOARD_LED_GREEN_GPIO_PIN 6U
122 #endif
123 #ifndef BOARD_LED_BLUE_GPIO
124 #define BOARD_LED_BLUE_GPIO GPIOA
125 #endif
126 #define BOARD_LED_BLUE_GPIO_PORT PORTA
127 #ifndef BOARD_LED_BLUE_GPIO_PIN
128 #define BOARD_LED_BLUE_GPIO_PIN 11U
129 #endif
130 
131 #define LED_RED_INIT(output)                                           \
132     GPIO_PinWrite(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PIN, output); \
133     BOARD_LED_RED_GPIO->PDDR |= (1U << BOARD_LED_RED_GPIO_PIN)                         /*!< Enable target LED_RED */
134 #define LED_RED_ON()  GPIO_PortClear(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED_RED */
135 #define LED_RED_OFF() GPIO_PortSet(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN)   /*!< Turn off target LED_RED */
136 #define LED_RED_TOGGLE() \
137     GPIO_PortToggle(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Toggle on target LED_RED */
138 
139 #define LED_GREEN_INIT(output)                                             \
140     GPIO_PinWrite(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PIN, output); \
141     BOARD_LED_GREEN_GPIO->PDDR |= (1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Enable target LED_GREEN */
142 #define LED_GREEN_ON() \
143     GPIO_PortClear(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn on target LED_GREEN */
144 #define LED_GREEN_OFF() \
145     GPIO_PortSet(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn off target LED_GREEN */
146 #define LED_GREEN_TOGGLE() \
147     GPIO_PortToggle(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED_GREEN */
148 
149 #define LED_BLUE_INIT(output)                                            \
150     GPIO_PinWrite(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PIN, output); \
151     BOARD_LED_BLUE_GPIO->PDDR |= (1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Enable target LED_BLUE */
152 #define LED_BLUE_ON()                                                                                 \
153     GPIO_PortClear(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn on target LED_BLUE \ \
154                                                                         */
155 #define LED_BLUE_OFF()                                                                               \
156     GPIO_PortSet(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn off target LED_BLUE \ \
157                                                                       */
158 #define LED_BLUE_TOGGLE() \
159     GPIO_PortToggle(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Toggle on target LED_BLUE */
160 
161 /*! @brief Define the port interrupt number for the usb id gpio pin */
162 #define BOARD_ID_GPIO     GPIOE
163 #define BOARD_ID_PORT     PORTE
164 #define BOARD_ID_GPIO_PIN 10U
165 #define BOARD_ID_IRQ      PORTE_IRQn
166 
167 /* ERPC DSPI configuration */
168 #define ERPC_BOARD_SPI_SLAVE_READY_USE_GPIO (1)
169 #define ERPC_BOARD_DSPI_BASEADDR            SPI0
170 #define ERPC_BOARD_DSPI_BAUDRATE            500000U
171 #define ERPC_BOARD_DSPI_CLKSRC              DSPI0_CLK_SRC
172 #define ERPC_BOARD_DSPI_CLK_FREQ            CLOCK_GetFreq(DSPI0_CLK_SRC)
173 #define ERPC_BOARD_DSPI_INT_GPIO            GPIOB
174 #define ERPC_BOARD_DSPI_INT_PORT            PORTB
175 #define ERPC_BOARD_DSPI_INT_PIN             2U
176 #define ERPC_BOARD_DSPI_INT_PIN_IRQ         PORTB_IRQn
177 #define ERPC_BOARD_DSPI_INT_PIN_IRQ_HANDLER PORTB_IRQHandler
178 /* USB PHY condfiguration */
179 #define BOARD_USB_PHY_D_CAL     (0x0CU)
180 #define BOARD_USB_PHY_TXCAL45DP (0x06U)
181 #define BOARD_USB_PHY_TXCAL45DM (0x06U)
182 
183 /* DAC base address */
184 #define BOARD_DAC_BASEADDR DAC0
185 
186 /* Board accelerometer driver */
187 #define BOARD_ACCEL_FXOS
188 
189 #define BOARD_CODEC_I2C_BASEADDR   I2C1
190 #define BOARD_CODEC_I2C_INSTANCE   1U
191 #define BOARD_CODEC_I2C_CLOCK_FREQ CLOCK_GetFreq(kCLOCK_BusClk)
192 
193 #if defined(__cplusplus)
194 extern "C" {
195 #endif /* __cplusplus */
196 
197 /*******************************************************************************
198  * API
199  ******************************************************************************/
200 
201 void BOARD_InitDebugConsole(void);
202 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED
203 void BOARD_I2C_Init(I2C_Type *base, uint32_t clkSrc_Hz);
204 status_t BOARD_I2C_Send(I2C_Type *base,
205                         uint8_t deviceAddress,
206                         uint32_t subAddress,
207                         uint8_t subaddressSize,
208                         uint8_t *txBuff,
209                         uint8_t txBuffSize);
210 status_t BOARD_I2C_Receive(I2C_Type *base,
211                            uint8_t deviceAddress,
212                            uint32_t subAddress,
213                            uint8_t subaddressSize,
214                            uint8_t *rxBuff,
215                            uint8_t rxBuffSize);
216 void BOARD_Accel_I2C_Init(void);
217 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff);
218 status_t BOARD_Accel_I2C_Receive(
219     uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
220 void BOARD_Codec_I2C_Init(void);
221 status_t BOARD_Codec_I2C_Send(
222     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, const uint8_t *txBuff, uint8_t txBuffSize);
223 status_t BOARD_Codec_I2C_Receive(
224     uint8_t deviceAddress, uint32_t subAddress, uint8_t subAddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
225 #endif /* SDK_I2C_BASED_COMPONENT_USED */
226 
227 #if defined(__cplusplus)
228 }
229 #endif /* __cplusplus */
230 
231 #endif /* _BOARD_H_ */
232