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 #if defined(__cplusplus) 170 extern "C" { 171 #endif /* __cplusplus */ 172 173 /******************************************************************************* 174 * API 175 ******************************************************************************/ 176 177 void BOARD_InitDebugConsole(void); 178 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED 179 void BOARD_LPI2C_Init(LPI2C_Type *base, uint32_t clkSrc_Hz); 180 status_t BOARD_LPI2C_Send(LPI2C_Type *base, 181 uint8_t deviceAddress, 182 uint32_t subAddress, 183 uint8_t subaddressSize, 184 uint8_t *txBuff, 185 uint8_t txBuffSize); 186 status_t BOARD_LPI2C_Receive(LPI2C_Type *base, 187 uint8_t deviceAddress, 188 uint32_t subAddress, 189 uint8_t subaddressSize, 190 uint8_t *rxBuff, 191 uint8_t rxBuffSize); 192 void BOARD_Accel_I2C_Init(void); 193 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff); 194 status_t BOARD_Accel_I2C_Receive( 195 uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize); 196 #endif /* SDK_I2C_BASED_COMPONENT_USED */ 197 198 #if defined(__cplusplus) 199 } 200 #endif /* __cplusplus */ 201 202 #endif /* _BOARD_H_ */ 203