/*
 * Copyright (c) 2015, Freescale Semiconductor, Inc.
 * Copyright 2016-2017 NXP
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * o Redistributions of source code must retain the above copyright notice, this list
 *   of conditions and the following disclaimer.
 *
 * o Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * o Neither the name of the copyright holder nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _BOARD_H_
#define _BOARD_H_

#include "clock_config.h"
#include "fsl_gpio.h"

/*******************************************************************************
 * Definitions
 ******************************************************************************/

/* The board name */
#define BOARD_NAME "FRDM-KL25Z"

/* The LPSCI to use for debug messages. */
#define BOARD_DEBUG_UART_TYPE DEBUG_CONSOLE_DEVICE_TYPE_LPSCI
#define BOARD_DEBUG_UART_BASEADDR (uint32_t) UART0
#define BOARD_DEBUG_UART_CLKSRC kCLOCK_PllFllSelClk
#define BOARD_DEBUG_UART_CLK_FREQ CLOCK_GetPllFllSelClkFreq()
#define BOARD_UART_IRQ UART0_IRQn
#define BOARD_UART_IRQ_HANDLER UART0_IRQHandler

#ifndef BOARD_DEBUG_UART_BAUDRATE
#define BOARD_DEBUG_UART_BAUDRATE 19200
#endif /* BOARD_DEBUG_UART_BAUDRATE */



/*! @brief Indexes of the TSI channels for on board electrodes */

#define BOARD_TSI_ELECTRODE_0 7   /* X0*/ 
#define BOARD_TSI_ELECTRODE_1 8   /* X1 */ 
#define BOARD_TSI_ELECTRODE_2 9   /* X2*/ 
#define BOARD_TSI_ELECTRODE_3 10  /* X3 */ 
#define BOARD_TSI_ELECTRODE_4 11  /* X4 */ 
#define BOARD_TSI_ELECTRODE_5 12  /* X5 */ 
#define BOARD_TSI_ELECTRODE_6 13  /* X6 */ 
#define BOARD_TSI_ELECTRODE_7 1   /* X7 */ 
#define BOARD_TSI_ELECTRODE_8 4   /* X8 */

#define BOARD_TSI_ELECTRODE_9 6   /* Y0 */ 
#define BOARD_TSI_ELECTRODE_10 0  /* Y1 */ 
#define BOARD_TSI_ELECTRODE_11 3  /* Y2 */ 
#define BOARD_TSI_ELECTRODE_12 2  /* Y3 */ 
#define BOARD_TSI_ELECTRODE_13 5  /* Y4 */ 
#define BOARD_TSI_ELECTRODE_14 14 /* Y5 */ 
#define BOARD_TSI_ELECTRODE_15 15 /* Y6*/
#define BOARD_TSI_ELECTRODE_16 16 /* Y6*/
 

/* Board led color mapping */
#define LOGIC_LED_ON 0U
#define LOGIC_LED_OFF 1U
#define LED_RED_GPIO GPIOE
#define LED_RED_PIN 29U
#define LED_GREEN_GPIO GPIOE
#define LED_GREEN_PIN 30U


#define RGB_RED_GPIO GPIOD
#define RGB_RED_PIN 1U
#define RGB_GREEN_GPIO GPIOC
#define RGB_GREEN_PIN 9U
#define RGB_BLUE_GPIO GPIOD
#define RGB_BLUE_PIN 0U


#define LED_INIT(led_gpio , led_pin, output) GPIO_PinInit(led_gpio, led_pin, \
                 &(gpio_pin_config_t){kGPIO_DigitalOutput, (output)}) /*!< Enable target LED */
#define LED_ON(led_gpio, led_pin) \
    GPIO_ClearPinsOutput(led_gpio, 1U << led_pin) /*!< Turn on target LED */  
#define LED_OFF(led_gpio, led_pin) \
    GPIO_SetPinsOutput(led_gpio, 1U << led_pin) /*!< Turn off target LED */
#define LED_TOGGLE(led_gpio, led_pin) \
    GPIO_TogglePinsOutput(led_gpio, 1U << led_pin) /*!< Toggle on target LED */ 
      
  
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */

/*******************************************************************************
 * API
 ******************************************************************************/

void BOARD_InitDebugConsole(void);

#if defined(__cplusplus)
}
#endif /* __cplusplus */

#endif /* _BOARD_H_ */
