/*
 * Copyright (c) 2013 - 2016, 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
 ******************************************************************************/
/********* Electrode X0 - X8 ***************/                             
#define BOARD_TSI_ELECTRODE_0 9   /* PTB5 */ 
#define BOARD_TSI_ELECTRODE_1 8   /* PTB4 */ 
#define BOARD_TSI_ELECTRODE_2 10  /* PTD7 */ 
#define BOARD_TSI_ELECTRODE_3 7   /* PTD6 */ 
#define BOARD_TSI_ELECTRODE_4 6   /* PTD5 */ 
#define BOARD_TSI_ELECTRODE_5 23  /* PTC1 */ 
#define BOARD_TSI_ELECTRODE_6 22  /* PTC0 */ 
#define BOARD_TSI_ELECTRODE_7 21  /* PTB3 */ 
#define BOARD_TSI_ELECTRODE_8 20  /* PTB2 */ 

/********* Electrode Y0 - Y7 ***************/
#define BOARD_TSI_ELECTRODE_9 15   /* PTC6 */ 
#define BOARD_TSI_ELECTRODE_10 16  /* PTC7 */ 
#define BOARD_TSI_ELECTRODE_11 17  /* PTA0 */ 
#define BOARD_TSI_ELECTRODE_12 18  /* PTA1 */ 
#define BOARD_TSI_ELECTRODE_13 11  /* PTE8 */ 
#define BOARD_TSI_ELECTRODE_14 24  /* PTE3 */ 
#define BOARD_TSI_ELECTRODE_15 1   /* PTE4 */ 
#define BOARD_TSI_ELECTRODE_16 0   /* PTE5 */ 
    

/*! @brief The board name */
#define BOARD_NAME "Touchpad-KE15Z"

#define BOARD_DEBUG_UART_TYPE DEBUG_CONSOLE_DEVICE_TYPE_LPUART
#define BOARD_DEBUG_UART_BASEADDR (uint32_t) LPUART1
#define BOARD_DEBUG_UART_CLKSRC kCLOCK_IpSrcSysOscAsync
#define BOARD_DEBUG_UART_IRQ LPUART1_IRQn
#define BOARD_DEBUG_UART_IRQ_HANDLER LPUART1_IRQHandler
#define BOARD_DEBUG_UART_CLOCK  kCLOCK_Lpuart1

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

/*! @brief The UART to use for FREEMASTER messages. */
#define BOARD_USE_UART
#define BOARD_FREEMASTER_UART_TYPE DEBUG_CONSOLE_DEVICE_TYPE_LPUART
#define BOARD_FREEMASTER_UART_BASEADDR (uint32_t) LPUART0
#define BOARD_FREEMASTER_UART_CLK kCLOCK_Lpuart0
#define BOARD_FREEMASTER_UART_CLKSRC kCLOCK_IpSrcSysOscAsync
#define BOARD_FREEMASTER_UART_IRQ LPUART0_IRQn
#define BOARD_FREEMASTER_UART_IRQ_HANDLER LPUART0_IRQHandler


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


/* Board led color mapping */
#define LOGIC_LED_ON 0U
#define LOGIC_LED_OFF 1U
#define LED_RED_GPIO GPIOB
#define LED_RED_PIN 11U
   
#define LED_GREEN_GPIO GPIOB
#define LED_GREEN_PIN 9U


#define RGB_RED_GPIO GPIOB
#define RGB_RED_PIN 16U
#define RGB_GREEN_GPIO GPIOB
#define RGB_GREEN_PIN 17U
#define RGB_BLUE_GPIO GPIOA
#define RGB_BLUE_PIN 17U


#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_ */
