/****************************************************************************/
/* Copyright 2015-2018 MBARI                                                */
/****************************************************************************/
/* Summary  : Digital I/O Support for BEDS2 on PIC32MX470F512L				*/
/* Filename : dig_io.c                                                      */
/* Author   : Robert Herlien (rah)                                          */
/* Project  : OASIS Mooring Replacement (OASIS5)                            */
/* Revision: 1.0                                                            */
/* Created  : 02/13/2018 from Oasis5 dig_io.c                               */
/*                                                                          */
/* MBARI provides this documentation and code "as is", with no warranty,    */
/* express or implied, of its quality or consistency. It is provided without*/
/* support and without obligation on the part of the Monterey Bay Aquarium  */
/* Research Institute to assist in its use, correction, modification, or    */
/* enhancement. This information should not be published or distributed to  */
/* third parties without specific written permission from MBARI.            */
/*                                                                          */
/****************************************************************************/
/* Modification History:                                                    */
/* 13jul2015 rah - created for Oasis5                                       */
/* 13feb2018 rah - created for BEDS2										*/
/****************************************************************************/

#include <xc.h>
#include <mbariTypes.h>					/* MBARI type definitions			*/
#include <beds.h>						/* BEDS controller definitions		*/
#include <dig_io.h>
#include <clock.h>						/* Timers							*/


/********************************/
/*  Module Local Data           */
/********************************/


/************************************************************************/
/* Function    : digInit                                                */
/* Purpose     : Initialize digital I/O ports on PIC32MX                */
/* Inputs      : None                                                   */
/* Outputs     : None                                                   */
/************************************************************************/
void digInit()
{
    ANSELA = 0;
    ANSELB = 0;
    ANSELC = 0;
    ANSELD = 0;
    ANSELE = 0;
    ANSELF = 0;
    ANSELG = 0;

    TRISA = 0x8600;
    TRISB = 0;
    TRISC = 0x2014;
    TRISD = 0x0903;
    TRISE = 0x0200;
    TRISF = 0x0118;
    TRISG = 0x0100;

    LATA = 0x0001;				/* Deselect ADC			*/
    LATB = 0x0008;				/* Enable serial port	*/
    LATC = 0x4008;				/* Deselect SD and RTC	*/
    LATD = 0x0004;				/* Deselect IMU			*/
    LATE = 0;
    LATF = 0;
    LATG = 0x0200;				/* Enable ADC			*/

    CNPUC = 0x2014;
    CNPUD = 0x0803;
}
