#ifndef GPIO_DEF
#define GPIO_DEF

#include "common.h"

#include <drivers/gpio/adi_gpio.h>

/*
 **
 ** Source file generated on January 29, 2018 at 17:16:40.	
 **
 ** Copyright (C) 2018 Analog Devices Inc., All Rights Reserved.
 **
 ** This file is generated automatically based upon the options selected in 
 ** the Pin Multiplexing configuration editor. Changes to the Pin Multiplexing
 ** configuration should be made by changing the appropriate options rather
 ** than editing this file.
 **
 ** Selected Peripherals
 ** --------------------
 ** SPI1 (CLK, MOSI, MISO, CS_1, CS_2)
 ** SPI2 (CLK, MOSI, MISO, CS_0)
 ** I2C0 (SCL, SDA)
 ** UART0 (Tx, Rx)
 ** UART1 (Tx, Rx)
 ** SYS_WAKEUP (sys_wake0, sys_wake1, sys_wake2, sys_wake3)
 ** RTC (RTC_SS2)
 ** SWD0 (SWD0_CLK, SWD0_Data)
 ** SWV (SWV)
 ** ADC0_IN (ADC0_VIN0, ADC0_VIN1, ADC0_VIN2)
 **
 ** GPIO (unavailable)
 ** ------------------
 ** P0_04, P0_05, P0_06, P0_07, P0_10, P0_11, P0_13, P0_15, P1_00, P1_02, P1_03, P1_04,
 ** P1_05, P1_06, P1_07, P1_08, P1_09, P1_12, P1_15, P2_00, P2_01, P2_02, P2_03, P2_04,
 ** P2_05, P2_11
 */

//=========================== GPIO mux ========================================

#define SPI1_CLK_PORTP1_MUX  ((uint16_t) ((uint16_t) 1<<12))
#define SPI1_MOSI_PORTP1_MUX  ((uint16_t) ((uint16_t) 1<<14))
#define SPI1_MISO_PORTP1_MUX  ((uint32_t) ((uint32_t) 1<<16))
#define SPI1_CS_1_PORTP2_MUX  ((uint32_t) ((uint32_t) 1<<22))
//#define SPI1_CS_2_PORTP2_MUX  ((uint16_t) ((uint16_t) 2<<4))
#define SPI2_CLK_PORTP1_MUX  ((uint16_t) ((uint16_t) 1<<4))
#define SPI2_MOSI_PORTP1_MUX  ((uint16_t) ((uint16_t) 1<<6))
#define SPI2_MISO_PORTP1_MUX  ((uint16_t) ((uint16_t) 1<<8))
#define SPI2_CS_0_PORTP1_MUX  ((uint16_t) ((uint16_t) 1<<10))
#define I2C0_SCL_PORTP0_MUX  ((uint16_t) ((uint16_t) 1<<8))
#define I2C0_SDA_PORTP0_MUX  ((uint16_t) ((uint16_t) 1<<10))
#define GPIO_P1_1_PORTP1_MUX  ((uint16_t) ((uint16_t) 1<<2))
#define UART0_TX_PORTP0_MUX  ((uint32_t) ((uint32_t) 1<<20))
#define UART0_RX_PORTP0_MUX  ((uint32_t) ((uint32_t) 1<<22))
#define UART1_TX_PORTP1_MUX  ((uint32_t) ((uint32_t) 2<<30))
#define UART1_RX_PORTP2_MUX  ((uint16_t) ((uint16_t) 2<<0))
//#define SYS_WAKEUP_SYS_WAKE0_PORTP0_MUX  ((uint32_t) ((uint32_t) 1<<30))
//#define SYS_WAKEUP_SYS_WAKE1_PORTP1_MUX  ((uint16_t) ((uint16_t) 1<<0))
//#define SYS_WAKEUP_SYS_WAKE2_PORTP0_MUX  ((uint32_t) ((uint32_t) 1<<26))
//#define SYS_WAKEUP_SYS_WAKE3_PORTP2_MUX  ((uint16_t) ((uint16_t) 1<<2))
#define RTC_RTC_SS2_PORTP1_MUX  ((uint32_t) ((uint32_t) 2<<24))
#define SWD0_SWD0_CLK_PORTP0_MUX  ((uint16_t) ((uint16_t) 0<<12))
#define SWD0_SWD0_DATA_PORTP0_MUX  ((uint16_t) ((uint16_t) 0<<14))
#define SWV_SWV_PORTP1_MUX  ((uint32_t) ((uint32_t) 3<<18))
#define ADC0_IN_ADC0_VIN0_PORTP2_MUX  ((uint16_t) ((uint16_t) 1<<6))
#define ADC0_IN_ADC0_VIN1_PORTP2_MUX  ((uint16_t) ((uint16_t) 1<<8))
#define ADC0_IN_ADC0_VIN2_PORTP2_MUX  ((uint16_t) ((uint16_t) 1<<10))

//=========================== GPIO macros =====================================

//==== S2 BMODE button read
#define gpio_button_Get(x)        adi_gpio_GetData(ADI_GPIO_PORT1, ADI_GPIO_PIN_1, x)

//==== enable signal to AD5700 modem
#define gpio_ad5700_Off()         adi_gpio_SetLow(ADI_GPIO_PORT1, ADI_GPIO_PIN_11)  
#define gpio_ad5700_On()          adi_gpio_SetHigh(ADI_GPIO_PORT1, ADI_GPIO_PIN_11)

//==== RTS signal to AD5700 modem
#define gpio_ad5700Rts_Tx()       adi_gpio_SetLow(ADI_GPIO_PORT0, ADI_GPIO_PIN_9)  
#define gpio_ad5700Rts_Rx()       adi_gpio_SetHigh(ADI_GPIO_PORT0, ADI_GPIO_PIN_9)
                                  
//==== yellow LED - DS1           
#define gpio_ledYellow_On()       adi_gpio_SetLow(ADI_GPIO_PORT2, ADI_GPIO_PIN_8)
#define gpio_ledYellow_Off()      adi_gpio_SetHigh(ADI_GPIO_PORT2, ADI_GPIO_PIN_8)
                                  
//==== green LED - DS2            
#define gpio_ledGreen_On()        adi_gpio_SetLow(ADI_GPIO_PORT2, ADI_GPIO_PIN_9)
#define gpio_ledGreen_Off()       adi_gpio_SetHigh(ADI_GPIO_PORT2, ADI_GPIO_PIN_9)
                                     
//==== RX_RTSn signal to ltp5901    
#define gpio_moteRxRts_Active()   adi_gpio_SetLow(ADI_GPIO_PORT0, ADI_GPIO_PIN_2)
#define gpio_moteRxRts_Inactive() adi_gpio_SetHigh(ADI_GPIO_PORT0, ADI_GPIO_PIN_2)

//==== TX_CTSn signal to ltp5901
#define gpio_moteTxCts_Active()   adi_gpio_SetLow(ADI_GPIO_PORT1, ADI_GPIO_PIN_10)
#define gpio_moteTxCts_Inactive() adi_gpio_SetHigh(ADI_GPIO_PORT1, ADI_GPIO_PIN_10)

//==== enable signal to acceleromoter
#define gpio_acc_Off()            adi_gpio_SetLow(ADI_GPIO_PORT1, ADI_GPIO_PIN_13)  
#define gpio_acc_On()             adi_gpio_SetHigh(ADI_GPIO_PORT1, ADI_GPIO_PIN_13)

//==== enable signal to AD5700 modem
#define gpio_adc_Off()            adi_gpio_SetLow(ADI_GPIO_PORT0, ADI_GPIO_PIN_12)  
#define gpio_adc_On()             adi_gpio_SetHigh(ADI_GPIO_PORT0, ADI_GPIO_PIN_12)

//==== enable signal to AD5700 modem
#define gpio_ref_Off()            adi_gpio_SetLow(ADI_GPIO_PORT0, ADI_GPIO_PIN_1)  
#define gpio_ref_On()             adi_gpio_SetHigh(ADI_GPIO_PORT0, ADI_GPIO_PIN_1)

#endif
