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 15 /******************************************************************************* 16 * Definitions 17 ******************************************************************************/ 18 19 /* The board name */ 20 #define BOARD_NAME "FRDM-KL27Z" 21 22 /* The LPUART to use for debug messages. */ 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_McgIrc48MClk 27 #define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetPeriphClkFreq() 28 #define BOARD_UART_IRQ LPUART0_IRQn 29 #define BOARD_UART_IRQ_HANDLER LPUART0_IRQHandler 30 31 #ifndef BOARD_DEBUG_UART_BAUDRATE 32 #define BOARD_DEBUG_UART_BAUDRATE 115200 33 #endif /* BOARD_DEBUG_UART_BAUDRATE */ 34 35 /* Define the port macros for the board switches */ 36 #ifndef BOARD_SW1_GPIO 37 #define BOARD_SW1_GPIO GPIOA 38 #endif 39 #ifndef BOARD_SW1_PORT 40 #define BOARD_SW1_PORT PORTA 41 #endif 42 #ifndef BOARD_SW1_GPIO_PIN 43 #define BOARD_SW1_GPIO_PIN 4U 44 #endif 45 #define BOARD_SW1_IRQ PORTA_IRQn 46 #define BOARD_SW1_IRQ_HANDLER PORTA_IRQHandler 47 #define BOARD_SW1_NAME "SW1" 48 49 #ifndef BOARD_SW3_GPIO 50 #define BOARD_SW3_GPIO GPIOC 51 #endif 52 #ifndef BOARD_SW3_PORT 53 #define BOARD_SW3_PORT PORTC 54 #endif 55 #ifndef BOARD_SW3_GPIO_PIN 56 #define BOARD_SW3_GPIO_PIN 1U 57 #endif 58 #define BOARD_SW3_IRQ PORTB_PORTC_PORTD_PORTE_IRQn 59 #define BOARD_SW3_IRQ_HANDLER PORTB_PORTC_PORTD_PORTE_IRQHandler 60 #define BOARD_SW3_NAME "SW3" 61 62 #define LLWU_SW_GPIO BOARD_SW3_GPIO 63 #define LLWU_SW_PORT BOARD_SW3_PORT 64 #define LLWU_SW_GPIO_PIN BOARD_SW3_GPIO_PIN 65 #define LLWU_SW_IRQ BOARD_SW3_IRQ 66 #define LLWU_SW_IRQ_HANDLER BOARD_SW3_IRQ_HANDLER 67 #define LLWU_SW_NAME BOARD_SW3_NAME 68 69 /* Board led color mapping */ 70 #define LOGIC_LED_ON 0U 71 #define LOGIC_LED_OFF 1U 72 #ifndef BOARD_LED_RED_GPIO 73 #define BOARD_LED_RED_GPIO GPIOB 74 #endif 75 #define BOARD_LED_RED_GPIO_PORT PORTB 76 #ifndef BOARD_LED_RED_GPIO_PIN 77 #define BOARD_LED_RED_GPIO_PIN 18U 78 #endif 79 #ifndef BOARD_LED_GREEN_GPIO 80 #define BOARD_LED_GREEN_GPIO GPIOB 81 #endif 82 #define BOARD_LED_GREEN_GPIO_PORT PORTB 83 #ifndef BOARD_LED_GREEN_GPIO_PIN 84 #define BOARD_LED_GREEN_GPIO_PIN 19U 85 #endif 86 #ifndef BOARD_LED_BLUE_GPIO 87 #define BOARD_LED_BLUE_GPIO GPIOA 88 #endif 89 #define BOARD_LED_BLUE_GPIO_PORT PORTA 90 #ifndef BOARD_LED_BLUE_GPIO_PIN 91 #define BOARD_LED_BLUE_GPIO_PIN 13U 92 #endif 93 94 #define BOARD_ARDUINO_INT_IRQ (PORTB_PORTC_PORTD_PORTE_IRQn) 95 #define BOARD_ARDUINO_I2C_IRQ (I2C1_IRQn) 96 #define BOARD_ARDUINO_I2C_INDEX (1) 97 98 #define LED_RED_INIT(output) \ 99 GPIO_PinWrite(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PIN, output); \ 100 BOARD_LED_RED_GPIO->PDDR |= (1U << BOARD_LED_RED_GPIO_PIN) /*!< Enable target LED_RED */ 101 #define LED_RED_ON() GPIO_PortClear(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn on target LED_RED */ 102 #define LED_RED_OFF() GPIO_PortSet(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Turn off target LED_RED */ 103 #define LED_RED_TOGGLE() \ 104 GPIO_PortToggle(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN) /*!< Toggle on target LED_RED */ 105 106 #define LED_GREEN_INIT(output) \ 107 GPIO_PinWrite(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PIN, output); \ 108 BOARD_LED_GREEN_GPIO->PDDR |= (1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Enable target LED_GREEN */ 109 #define LED_GREEN_ON() \ 110 GPIO_PortClear(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn on target LED_GREEN */ 111 #define LED_GREEN_OFF() \ 112 GPIO_PortSet(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Turn off target LED_GREEN */ 113 #define LED_GREEN_TOGGLE() \ 114 GPIO_PortToggle(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN) /*!< Toggle on target LED_GREEN */ 115 116 #define LED_BLUE_INIT(output) \ 117 GPIO_PinWrite(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PIN, output); \ 118 BOARD_LED_BLUE_GPIO->PDDR |= (1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Enable target LED_BLUE */ 119 #define LED_BLUE_ON() \ 120 GPIO_PortClear(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn on target LED_BLUE \ 121 */ 122 #define LED_BLUE_OFF() \ 123 GPIO_PortSet(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Turn off target LED_BLUE \ 124 */ 125 #define LED_BLUE_TOGGLE() \ 126 GPIO_PortToggle(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN) /*!< Toggle on target LED_BLUE */ 127 128 #define BOARD_ACCEL_I2C_BASEADDR I2C1 129 #define BOARD_ACCEL_I2C_CLOCK_FREQ CLOCK_GetFreq(I2C1_CLK_SRC) 130 131 /* ERPC SPI configuration */ 132 #define ERPC_BOARD_SPI_SLAVE_READY_USE_GPIO (1) 133 #define ERPC_BOARD_SPI_BASEADDR SPI0 134 #define ERPC_BOARD_SPI_BAUDRATE 500000U 135 #define ERPC_BOARD_SPI_CLKSRC SPI0_CLK_SRC 136 #define ERPC_BOARD_SPI_CLK_FREQ CLOCK_GetFreq(SPI0_CLK_SRC) 137 #define ERPC_BOARD_SPI_INT_GPIO GPIOB 138 #define ERPC_BOARD_SPI_INT_PORT PORTB 139 #define ERPC_BOARD_SPI_INT_PIN 0U 140 #define ERPC_BOARD_SPI_INT_PIN_IRQ PORTB_PORTC_PORTD_PORTE_IRQn 141 #define ERPC_BOARD_SPI_INT_PIN_IRQ_HANDLER PORTB_PORTC_PORTD_PORTE_IRQHandler 142 143 /* Board accelerometer driver */ 144 #define BOARD_ACCEL_MMA 145 146 #if defined(__cplusplus) 147 extern "C" { 148 #endif /* __cplusplus */ 149 150 /******************************************************************************* 151 * API 152 ******************************************************************************/ 153 154 void BOARD_InitDebugConsole(void); 155 #if defined(SDK_I2C_BASED_COMPONENT_USED) && SDK_I2C_BASED_COMPONENT_USED 156 void BOARD_I2C_Init(I2C_Type *base, uint32_t clkSrc_Hz); 157 status_t BOARD_I2C_Send(I2C_Type *base, 158 uint8_t deviceAddress, 159 uint32_t subAddress, 160 uint8_t subaddressSize, 161 uint8_t *txBuff, 162 uint8_t txBuffSize); 163 status_t BOARD_I2C_Receive(I2C_Type *base, 164 uint8_t deviceAddress, 165 uint32_t subAddress, 166 uint8_t subaddressSize, 167 uint8_t *rxBuff, 168 uint8_t rxBuffSize); 169 void BOARD_Accel_I2C_Init(void); 170 status_t BOARD_Accel_I2C_Send(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff); 171 status_t BOARD_Accel_I2C_Receive( 172 uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize); 173 #endif /* SDK_I2C_BASED_COMPONENT_USED */ 174 175 #if defined(__cplusplus) 176 } 177 #endif /* __cplusplus */ 178 179 #endif /* _BOARD_H_ */ 180