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 /*! @brief The board name */ 19 #define BOARD_NAME "FRDM-K32L2A4S" 20 21 /*! @brief The UART to use for debug messages. */ 22 #define BOARD_USE_UART 23 #define BOARD_DEBUG_UART_TYPE kSerialPort_Uart 24 #define BOARD_DEBUG_UART_BASEADDR (uint32_t) LPUART0 25 #define BOARD_DEBUG_UART_INSTANCE 0U 26 #define BOARD_DEBUG_UART_CLKSRC kCLOCK_ScgSircAsyncDiv3Clk 27 #define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetIpFreq(kCLOCK_Lpuart0) 28 #define BOARD_UART_IRQ LPUART0_IRQn 29 #define BOARD_UART_IRQ_HANDLER LPUART0_IRQHandler 30 #define BOARD_DEBUG_UART_PCC_ADDRESS kCLOCK_Lpuart0 31 32 #define BOARD_ACCEL_I2C_BASEADDR LPI2C0 33 #define BOARD_ACCEL_I2C_CLOCK_FREQ (CLOCK_GetIpFreq(kCLOCK_Lpi2c0)) 34 35 #ifndef BOARD_DEBUG_UART_BAUDRATE 36 #define BOARD_DEBUG_UART_BAUDRATE 115200 37 #endif /* BOARD_DEBUG_UART_BAUDRATE */ 38 39 /*! @brief The CMP instance/channel used for board. */ 40 #define BOARD_CMP_BASEADDR CMP0 41 #define BOARD_CMP_CHANNEL 0U 42 43 /*! @brief The rtc instance used for board. */ 44 #define BOARD_RTC_FUNC_BASEADDR RTC 45 46 /*! @brief The tsi instance used for board. */ 47 #define BOARD_TSI_ELECTRODE_CNT 2 48 #ifndef BOARD_TSI_ELECTRODE_1 49 #define BOARD_TSI_ELECTRODE_1 2 50 #endif 51 #ifndef BOARD_TSI_ELECTRODE_2 52 #define BOARD_TSI_ELECTRODE_2 3 53 #endif 54 55 /* @brief The EMVSIM SMARTCARD interface. */ 56 #define BOARD_SMARTCARD_MODULE (EMVSIM0) /*!< SMARTCARD communicational module instance */ 57 #define BOARD_SMARTCARD_MODULE_IRQ (EMVSIM0_IRQn) /*!< SMARTCARD communicational module IRQ handler */ 58 #define BOARD_SMARTCARD_CLOCK_MODULE (0U) /*!< SMARTCARD clock generation module instance (EMVSIM0) */ 59 #define BOARD_SMARTCARD_CLOCK_MODULE_CHANNEL (0U) /*!< SMARTCARD clock generation module channel */ 60 #define BOARD_SMARTCARD_CLOCK_MODULE_SOURCE_CLK \ 61 (kCLOCK_ScgFircAsyncDiv3Clk) /*!< SMARTCARD clock module peripheral source clock */ 62 #define BOARD_SMARTCARD_CLOCK_MODULE_CLK_FREQ CLOCK_GetFreq(kCLOCK_ScgFircAsyncDiv3Clk) 63 #define BOARD_SMARTCARD_CLOCK_VALUE (4000000U) /*!< SMARTCARD clock frequency */ 64 #define BOARD_SMARTCARD_CONTROL_PORT (2U) /*!< SMARTCARD control pin port instance number (PORTC) */ 65 #define BOARD_SMARTCARD_CONTROL_PIN (16U) /*!< SMARTCARD control pin number */ 66 #ifndef BOARD_SMARTCARD_RST_PORT 67 #define BOARD_SMARTCARD_RST_PORT (2U) /*!< SMARTCARD reset pin port instance number (PORTC) */ 68 #endif 69 #ifndef BOARD_SMARTCARD_RST_PIN 70 #define BOARD_SMARTCARD_RST_PIN (15U) /*!< SMARTCARD reset pin number */ 71 #endif 72 #define BOARD_SMARTCARD_IRQ_PORT (4U) /*!< SMARTCARD irq port pin instance number (PORTE) */ 73 #define BOARD_SMARTCARD_IRQ_PIN (2U) /*!< SMARTCARD irq pin number */ 74 #define BOARD_SMARTCARD_IRQ_PIN_IRQ (PORTE_IRQn) /*!< SMARTCARD irq port handler */ 75 #define BOARD_SMARTCARD_VSEL0_PORT (4U) /*!< SMARTCARD Voltage selection pin0 port instance (PORTE) */ 76 #define BOARD_SMARTCARD_VSEL0_PIN (3U) /*!< SMARTCARD Voltage selection pin0 pin number */ 77 #define BOARD_SMARTCARD_VSEL1_PORT (4U) /*!< SMARTCARD Voltage selection pin1 port instance (PORTE) */ 78 #define BOARD_SMARTCARD_VSEL1_PIN (6U) /*!< SMARTCARD Voltage selection pin1 pin number */ 79 80 /*! @brief Define the port interrupt number for the board switches */ 81 #ifndef BOARD_SW2_GPIO 82 #define BOARD_SW2_GPIO GPIOA 83 #endif 84 #ifndef BOARD_SW2_PORT 85 #define BOARD_SW2_PORT PORTA 86 #endif 87 #ifndef BOARD_SW2_GPIO_PIN 88 #define BOARD_SW2_GPIO_PIN 4U 89 #endif 90 #define BOARD_SW2_IRQ PORTA_IRQn 91 #define BOARD_SW2_IRQ_HANDLER PORTA_IRQHandler 92 #define BOARD_SW2_NAME "SW2" 93 94 #ifndef BOARD_SW3_GPIO 95 #define BOARD_SW3_GPIO GPIOE 96 #endif 97 #ifndef BOARD_SW3_PORT 98 #define BOARD_SW3_PORT PORTE 99 #endif 100 #ifndef BOARD_SW3_GPIO_PIN 101 #define BOARD_SW3_GPIO_PIN 4U 102 #endif 103 #define BOARD_SW3_IRQ PORTE_IRQn 104 #define BOARD_SW3_IRQ_HANDLER PORTE_IRQHandler 105 #define BOARD_SW3_NAME "SW3" 106 107 #define LLWU_SW_GPIO BOARD_SW3_GPIO 108 #define LLWU_SW_PORT BOARD_SW3_PORT 109 #define LLWU_SW_GPIO_PIN BOARD_SW3_GPIO_PIN 110 #define LLWU_SW_IRQ BOARD_SW3_IRQ 111 #define LLWU_SW_IRQ_HANDLER BOARD_SW3_IRQ_HANDLER 112 #define LLWU_SW_NAME BOARD_SW3_NAME 113 114 /* Board led color mapping */ 115 #define LOGIC_LED_ON 0U 116 #define LOGIC_LED_OFF 1U 117 #ifndef BOARD_LED_RED_GPIO 118 #define BOARD_LED_RED_GPIO GPIOE 119 #endif 120 #define BOARD_LED_RED_GPIO_PORT PORTE 121 #ifndef BOARD_LED_RED_GPIO_PIN 122 #define BOARD_LED_RED_GPIO_PIN 29U 123 #endif 124 #ifndef BOARD_LED_GREEN_GPIO 125 #define BOARD_LED_GREEN_GPIO GPIOC 126 #endif 127 #define BOARD_LED_GREEN_GPIO_PORT PORTC 128 #ifndef BOARD_LED_GREEN_GPIO_PIN 129 #define BOARD_LED_GREEN_GPIO_PIN 4U 130 #endif 131 #ifndef BOARD_LED_BLUE_GPIO 132 #define BOARD_LED_BLUE_GPIO GPIOE 133 #endif 134 #define BOARD_LED_BLUE_GPIO_PORT PORTE 135 #ifndef BOARD_LED_BLUE_GPIO_PIN 136 #define BOARD_LED_BLUE_GPIO_PIN 31U 137 #endif 138 139 #define LED_RED_INIT(output) \ 140 GPIO_PinWrite(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PIN, output); \ 141 BOARD_LED_RED_GPIO->PDDR |= (1U << BOARD_LED_RED_GPIO_PIN) /*!< Enable target LED_RED */ 142 #define LED_RED_ON() GPIO_PortClear(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED_RED */ 143 #define LED_RED_OFF() GPIO_PortSet(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn off target LED_RED */ 144 #define LED_RED_TOGGLE() \ 145 GPIO_PortToggle(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Toggle on target LED_RED */ 146 147 #define LED_GREEN_INIT(output) \ 148 GPIO_PinWrite(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PIN, output); \ 149 BOARD_LED_GREEN_GPIO->PDDR |= (1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Enable target LED_GREEN */ 150 #define LED_GREEN_ON() \ 151 GPIO_PortClear(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn on target LED_GREEN */ 152 #define LED_GREEN_OFF() \ 153 GPIO_PortSet(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn off target LED_GREEN */ 154 #define LED_GREEN_TOGGLE() \ 155 GPIO_PortToggle(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED_GREEN */ 156 157 #define LED_BLUE_INIT(output) \ 158 GPIO_PinWrite(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PIN, output); \ 159 BOARD_LED_BLUE_GPIO->PDDR |= (1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Enable target LED_BLUE */ 160 #define LED_BLUE_ON() \ 161 GPIO_PortClear(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn on target LED_BLUE \ 162 */ 163 #define LED_BLUE_OFF() \ 164 GPIO_PortSet(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn off target LED_BLUE \ 165 */ 166 #define LED_BLUE_TOGGLE() \ 167 GPIO_PortToggle(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Toggle on target LED_BLUE */ 168 169 /* Serial MWM WIFI */ 170 #define BOARD_SERIAL_MWM_PORT_CLK_FREQ CLOCK_GetIpFreq(kCLOCK_Lpuart0) 171 #define BOARD_SERIAL_MWM_PORT LPUART0 172 #define BOARD_SERIAL_MWM_PORT_IRQn LPUART0_IRQn 173 #define BOARD_SERIAL_MWM_RST_GPIO GPIOC 174 #define BOARD_SERIAL_MWM_RST_PIN 13 175 #define BOARD_SERIAL_MWM_RST_WRITE(output) GPIO_PinWrite(BOARD_SERIAL_MWM_RST_GPIO, BOARD_SERIAL_MWM_RST_PIN, output) 176 177 #if defined(__cplusplus) 178 extern "C" { 179 #endif /* __cplusplus */ 180 181 /******************************************************************************* 182 * API 183 ******************************************************************************/ 184 185 void BOARD_InitDebugConsole(void); 186 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED 187 void BOARD_LPI2C_Init(LPI2C_Type *base, uint32_t clkSrc_Hz); 188 status_t BOARD_LPI2C_Send(LPI2C_Type *base, 189 uint8_t deviceAddress, 190 uint32_t subAddress, 191 uint8_t subaddressSize, 192 uint8_t *txBuff, 193 uint8_t txBuffSize); 194 status_t BOARD_LPI2C_Receive(LPI2C_Type *base, 195 uint8_t deviceAddress, 196 uint32_t subAddress, 197 uint8_t subaddressSize, 198 uint8_t *rxBuff, 199 uint8_t rxBuffSize); 200 void BOARD_Accel_I2C_Init(void); 201 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff); 202 status_t BOARD_Accel_I2C_Receive( 203 uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize); 204 #endif /* SDK_I2C_BASED_COMPONENT_USED */ 205 206 #if defined(__cplusplus) 207 } 208 #endif /* __cplusplus */ 209 210 #endif /* _BOARD_H_ */ 211