
/// Copyright 2014 MBARI.                                                    
/// MBARI Proprietary Information. All rights reserved.                      

/// @file dig_out.h
/// @brief Control input and output bits as defined by #io_bit_t

#ifndef DIG_OUT_H
#define DIG_OUT_H
#include "cwgsys.h"
#include "pic24.h"

// use direct HW references, so it 
// works as early as possible in the init process
#define BLINK_TOGGLE() (LATDbits.LATD8 = (PORTDbits.RD8?0:1))
#define BLINK_GET()    PORTDbits.RD8 
#define BLINK_SET(x)   (LATDbits.LATD8 = (x==0?0:1)) 
        
// 0: installed 1: not installed
#define SDC_DETECT()   (P24_READ_LATCH_BIT(P24_LATB,P24_BIT15)?false:true)

// parse string to bit field that may be passed to 
// doSetBits.
// may include hex 
return_code_t dio_parse_bits( char *bit_str, unsigned long int *dest);

/// @brief set a bit's state 
/// @param bitnum bit to use
/// @param state 0 to set low/off, otherwise set high/on

void doSetBit(io_bit_t bitnum, int state); 
void doSetBits(unsigned long int bits, int state); 

/// @brief get current state of bit
/// @param bitnum bit to check on
/// @return 0: bit is low/off\n 1: bit is high/on

int doGetBit(io_bit_t bitnum);      

/// @brief turn blinky LED on or off
/// @param state 0 to set low/off, otherwise set high/on

void doSetBlink(int state); 

/// @brief toggle blinky LED
/// @return new state of bit

int doBlinkTog();           

/// @brief is the SD card inserted
/// @return 1: card inserted, otherwise 0

int doIsCardThere();  
#endif