1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 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 
15 /*******************************************************************************
16  * Definitions
17  ******************************************************************************/
18 
19 /* The board name */
20 #define BOARD_NAME "FRDM-KL25Z"
21 
22 /* The LPSCI to use for debug messages. */
23 #define BOARD_DEBUG_UART_TYPE DEBUG_CONSOLE_DEVICE_TYPE_LPSCI
24 #define BOARD_DEBUG_UART_BASEADDR (uint32_t) UART0
25 #define BOARD_DEBUG_UART_CLKSRC kCLOCK_PllFllSelClk
26 #define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetPllFllSelClkFreq()
27 #define BOARD_UART_IRQ UART0_IRQn
28 #define BOARD_UART_IRQ_HANDLER UART0_IRQHandler
29 
30 #ifndef BOARD_DEBUG_UART_BAUDRATE
31 #define BOARD_DEBUG_UART_BAUDRATE 115200
32 #endif /* BOARD_DEBUG_UART_BAUDRATE */
33 
34 /* Define the port interrupt number for the board switches */
35 #define BOARD_SW1_GPIO GPIOA
36 #define BOARD_SW1_PORT PORTA
37 #define BOARD_SW1_GPIO_PIN 20U
38 #define BOARD_SW1_IRQ PORTA_IRQn
39 #define BOARD_SW1_IRQ_HANDLER PORTA_IRQHandler
40 #define BOARD_SW1_NAME "SW1"
41 
42 /* Switch simulated by wire */
43 #define BOARD_SW2_GPIO GPIOA
44 #define BOARD_SW2_PORT PORTA
45 #define BOARD_SW2_GPIO_PIN 17U
46 #define BOARD_SW2_IRQ PORTA_IRQn
47 #define BOARD_SW2_IRQ_HANDLER PORTA_IRQHandler
48 #define BOARD_SW2_NAME "SW2"
49 
50 /*! @brief Indexes of the TSI channels for on board electrodes */
51 #define BOARD_TSI_ELECTRODE_1 9U
52 #define BOARD_TSI_ELECTRODE_2 10U
53 
54 /* Board led color mapping */
55 #define LOGIC_LED_ON 0U
56 #define LOGIC_LED_OFF 1U
57 #define BOARD_LED_RED_GPIO GPIOB
58 #define BOARD_LED_RED_GPIO_PORT PORTB
59 #define BOARD_LED_RED_GPIO_PIN 18U
60 #define BOARD_LED_GREEN_GPIO GPIOB
61 #define BOARD_LED_GREEN_GPIO_PORT PORTB
62 #define BOARD_LED_GREEN_GPIO_PIN 19U
63 #define BOARD_LED_BLUE_GPIO GPIOD
64 #define BOARD_LED_BLUE_GPIO_PORT PORTD
65 #define BOARD_LED_BLUE_GPIO_PIN 1U
66 
67 #define LED_RED_INIT(output)                                                 \
68     GPIO_WritePinOutput(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PIN, output); \
69     BOARD_LED_RED_GPIO->PDDR |= (1U << BOARD_LED_RED_GPIO_PIN) /*!< Enable target LED_RED */
70 #define LED_RED_ON() \
71     GPIO_ClearPinsOutput(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED_RED */
72 #define LED_RED_OFF() \
73     GPIO_SetPinsOutput(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn off target LED_RED */
74 #define LED_RED_TOGGLE() \
75     GPIO_TogglePinsOutput(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Toggle on target LED_RED */
76 
77 #define LED_GREEN_INIT(output)                                                   \
78     GPIO_WritePinOutput(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PIN, output); \
79     BOARD_LED_GREEN_GPIO->PDDR |= (1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Enable target LED_GREEN */
80 #define LED_GREEN_ON() \
81     GPIO_ClearPinsOutput(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn on target LED_GREEN */
82 #define LED_GREEN_OFF() \
83     GPIO_SetPinsOutput(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn off target LED_GREEN */
84 #define LED_GREEN_TOGGLE() \
85     GPIO_TogglePinsOutput(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED_GREEN */
86 
87 #define LED_BLUE_INIT(output)                                                  \
88     GPIO_WritePinOutput(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PIN, output); \
89     BOARD_LED_BLUE_GPIO->PDDR |= (1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Enable target LED_BLUE */
90 #define LED_BLUE_ON() \
91     GPIO_ClearPinsOutput(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn on target LED_BLUE */
92 #define LED_BLUE_OFF() \
93     GPIO_SetPinsOutput(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn off target LED_BLUE */
94 #define LED_BLUE_TOGGLE() \
95     GPIO_TogglePinsOutput(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Toggle on target LED_BLUE */
96 
97 #define BOARD_ACCEL_I2C_BASEADDR I2C0
98 
99 /* ERPC SPI configuration */
100 #define ERPC_BOARD_SPI_BASEADDR SPI0
101 #define ERPC_BOARD_SPI_BAUDRATE 500000U
102 #define ERPC_BOARD_SPI_CLKSRC SPI0_CLK_SRC
103 #define ERPC_BOARD_SPI_CLK_FREQ CLOCK_GetFreq(SPI0_CLK_SRC)
104 #define ERPC_BOARD_SPI_INT_GPIO GPIOD
105 #define ERPC_BOARD_SPI_INT_PORT PORTD
106 #define ERPC_BOARD_SPI_INT_PIN 0U
107 #define ERPC_BOARD_SPI_INT_PIN_IRQ PORTD_IRQn
108 #define ERPC_BOARD_SPI_INT_PIN_IRQ_HANDLER PORTD_IRQHandler
109 
110 /* DAC base address */
111 #define BOARD_DAC_BASEADDR DAC0
112 
113 /* Board accelerometer driver */
114 #define BOARD_ACCEL_MMA
115 
116 #if defined(__cplusplus)
117 extern "C" {
118 #endif /* __cplusplus */
119 
120 /*******************************************************************************
121  * API
122  ******************************************************************************/
123 
124 void BOARD_InitDebugConsole(void);
125 
126 #if defined(__cplusplus)
127 }
128 #endif /* __cplusplus */
129 
130 #endif /* _BOARD_H_ */
131