/* 
 * File:   DigitalIO_Chaletduino.h
 * Author: JF
 *
 * Created on November 24, 2018, 3:20 PM
 */

#ifndef DIGITALIO_CHALETDUINO_H
#define	DIGITALIO_CHALETDUINO_H


#ifdef	__cplusplus
extern "C" {
#endif
    
    
    /* ************************************************************************** */
    /* Includes */
#include "define.h"
    /* ************************************************************************** */
    /* Defines */
    //#include <plib.h>
#define SYS_FREQ 			(80000000L)		//Clock period = 12.5 ns
#define PERIPHERAL_FREQ		(80000000L)
    
    
    
    //Output pins hardware definitions
    //
#define HEARTBEAT_LED_2_PIN_DIR		TRISEbits.TRISE6
#define HEARTBEAT_LED_2_PIN			LATEbits.LATE6
#define HEARTBEAT_LED_2_TOGGLE_REG  LATEINV
#define HEARTBEAT_LED_2_SET_REG  	LATESET
#define HEARTBEAT_LED_2_CLEAR_REG   LATECLR
#define HEARTBEAT_LED_2_TOGGLE_MASK _LATG_LATE6_MASK
	
#define HEARTBEAT_LED_1_PIN_DIR		TRISEbits.TRISE5
#define HEARTBEAT_LED_1_PIN			LATEbits.LATE5
#define HEARTBEAT_LED_1_TOGGLE_REG  LATEINV
#define HEARTBEAT_LED_1_SET_REG  	LATESET
#define HEARTBEAT_LED_1_CLEAR_REG   LATECLR
#define HEARTBEAT_LED_1_TOGGLE_MASK _LATE_LATE5_MASK
    
    
    
    //    #define GP_DEBUG_1_PIN_DIR  TRISEbits.TRISE5
    //    #define GP_DEBUG_1_PIN      LATEbits.LATE5
    //    #define GP_DEBUG_2_PIN_DIR  TRISEbits.TRISE6
    //    #define GP_DEBUG_2_PIN      LATEbits.LATE6
    
    
    //	#define SD_CARD_DETECT_PIN_DIR		TRISDbits.TRISD8
    //	#define SD_CARD_DETECT_PIN			LATDbits.LATD8
    
    //SPI port defs
#define SPI_SDO_PIN_DIR		TRISGbits.TRISG8
#define SPI_SDI_PIN_DIR		TRISGbits.TRISG7
#define SPI_SCK_PIN_DIR		TRISGbits.TRISG6
    
    
    
    
    //SD Card 
#define SD_SPI_SS_PIN_DIR		TRISBbits.TRISB13
#define SD_SPI_SS_PIN   		LATBbits.LATB13
    
    //SPI Flash
#define FLASH_SS_PIN_DIR   	TRISEbits.TRISE3
#define FLASH_SS_PIN       	LATEbits.LATE3
    
    
    //Wifi (WINC3400 module)
#define WIFI_SPI_SS_PIN_DIR		TRISEbits.TRISE0
#define WIFI_SPI_SS_PIN   		LATEbits.LATE0
#define WIFI_IRQ_PIN_DIR   		TRISDbits.TRISD0
#define WIFI_IRQ_PIN       		PORTDbits.RD0
    
    // #define WIFI_SPI_CFG_PIN_DIR   	TRISEbits.TRISE1
    // #define WIFI_SPI_CFG_PIN       	LATEbits.LATE1
#define WIFI_CHP_EN_PIN_DIR   	TRISEbits.TRISE2
#define WIFI_CHP_EN_PIN       	LATEbits.LATE2
#define WIFI_CHP_RST_PIN_DIR   	TRISEbits.TRISE4
#define WIFI_CHP_RST_PIN       	LATEbits.LATE4
    
    
    
#define ONBOARD_LED1_PIN_DIR    TRISGbits.TRISG9
#define ONBOARD_LED1_PIN        LATGbits.LATG9
#define ONBOARD_LED2_PIN_DIR    TRISDbits.TRISD3
#define ONBOARD_LED2_PIN        LATDbits.LATD3
#define ONBOARD_LED3_PIN_DIR    TRISFbits.TRISF0
#define ONBOARD_LED3_PIN        LATFbits.LATF0
#define ONBOARD_LED7_PIN_DIR    TRISBbits.TRISB14
#define ONBOARD_LED7_PIN        LATBbits.LATB14
    
    
#define PUSH_BUTTON_LED1_PIN_DIR TRISBbits.TRISB8
#define PUSH_BUTTON_LED1_PIN     LATBbits.LATB8
#define PUSH_BUTTON_LED2_PIN_DIR TRISBbits.TRISB9
#define PUSH_BUTTON_LED2_PIN     LATBbits.LATB9
#define PUSH_BUTTON_LED3_PIN_DIR TRISBbits.TRISB10
#define PUSH_BUTTON_LED3_PIN     LATBbits.LATB10
#define PUSH_BUTTON_LED4_PIN_DIR TRISBbits.TRISB11
#define PUSH_BUTTON_LED4_PIN     LATBbits.LATB11
#define PUSH_BUTTON_LED5_PIN_DIR TRISBbits.TRISB12
#define PUSH_BUTTON_LED5_PIN     LATBbits.LATB12
#define PUSH_BUTTON_LED6_PIN_DIR TRISBbits.TRISB13
#define PUSH_BUTTON_LED6_PIN     LATBbits.LATB13
#define PUSH_BUTTON_LED7_PIN_DIR TRISBbits.TRISB1
#define PUSH_BUTTON_LED7_PIN     LATBbits.LATB1  
    
#define  PUSH_BUTTON_INPUT1_PIN_DIR TRISDbits.TRISD4
#define  PUSH_BUTTON_INPUT1_PIN     PORTDbits.RD4
#define  PUSH_BUTTON_INPUT2_PIN_DIR TRISDbits.TRISD5
#define  PUSH_BUTTON_INPUT2_PIN     PORTDbits.RD5
#define  PUSH_BUTTON_INPUT3_PIN_DIR TRISDbits.TRISD6
#define  PUSH_BUTTON_INPUT3_PIN     PORTDbits.RD6
#define  PUSH_BUTTON_INPUT4_PIN_DIR TRISDbits.TRISD7
#define  PUSH_BUTTON_INPUT4_PIN     PORTDbits.RD7
#define  PUSH_BUTTON_INPUT5_PIN_DIR TRISCbits.TRISC13
#define  PUSH_BUTTON_INPUT5_PIN     PORTCbits.RC13
#define  PUSH_BUTTON_INPUT6_PIN_DIR TRISCbits.TRISC14
#define  PUSH_BUTTON_INPUT6_PIN     PORTCbits.RC14
#define  PUSH_BUTTON_INPUT7_PIN_DIR TRISBbits.TRISB15
#define  PUSH_BUTTON_INPUT7_PIN     PORTBbits.RB15
    
    
#define VU1_DAC_SYNC_PIN_DIR        TRISFbits.TRISF1
#define VU1_DAC_SYNC_PIN            LATFbits.LATF1
#define VU1_BACKLIGHT_PIN_DIR       TRISDbits.TRISD2
#define VU1_BACKLIGHT_PIN           LATDbits.LATD2
#define VU1_ANALOG_FEEDBACK_PIN_DIR TRISBbits.TRISB0

    
#define VU2_DAC_SYNC_PIN_DIR        TRISEbits.TRISE7
#define VU2_DAC_SYNC_PIN            LATEbits.LATE7
#define VU2_BACKLIGHT_PIN_DIR       TRISDbits.TRISD1
#define VU2_BACKLIGHT_PIN           LATDbits.LATD1  
#define VU2_ANALOG_FEEDBACK_PIN_DIR TRISBbits.TRISB2    
    
#define BUREAU_VOL_POT_CW_PIN_DIR   TRISDbits.TRISD9    
#define BUREAU_VOL_POT_CW_PIN       PORTDbits.RD9       //INT2
#define BUREAU_VOL_POT_CCW_PIN_DIR   TRISDbits.TRISD8    
#define BUREAU_VOL_POT_CCW_PIN       PORTDbits.RD8      //INT1
    
#define CUISINE_VOL_POT_CW_PIN_DIR   TRISDbits.TRISD11  
#define CUISINE_VOL_POT_CW_PIN       PORTDbits.RD11     //INT4
#define CUISINE_VOL_POT_CCW_PIN_DIR   TRISDbits.TRISD10    
#define CUISINE_VOL_POT_CCW_PIN       PORTDbits.RD10    //INT3
    
    /* ************************************************************************** */
    /* Prototypes */
    void InitDigitalIO(void);
    
    
#ifdef	__cplusplus
}
#endif

#endif	/* DIGITALIO_PINGUINO_H */

