#define DIO_NOT_PRESENT 0
#define DIO_CAN_INPUT 1
#define DIO_CAN_DRIVE_HIGH 2
#define DIO_CAN_DRIVE_LOW 4
#define DIO_INPUT_ONLY DIO_CAN_INPUT
#define DIO_OUTPUT_ONLY (DIO_CAN_DRIVE_HIGH | DIO_CAN_DRIVE_LOW)
#define DIO_NORMAL (DIO_CAN_DRIVE_HIGH | DIO_CAN_DRIVE_LOW | DIO_CAN_INPUT)


typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned uint32;

extern uint8 TotalDioCount;
extern uint8 DioCapabilities[256];

extern void (*SetDioDir)(int dionum,int asOutput);
extern void (*SetDio)(int dionum,int asHigh);
extern int (*GetDioDir)(int dionum);
extern int (*GetDio)(int dionum);
extern void (*CommitDio)(int);

/*
int getCNfromDIO(int *diocn,int dio);
int getDioNumFromName(char *name);
*/
extern int *arch_dio;

typedef struct dioName dioName;
// API
typedef struct dio_connection {
	FILE *conn;
	struct Map *dioNameCache;
	struct Map *nameIterator;
	int groupPins[16][16];
	int groupsInUse;
	int pinsInGroup[16];
          // a value of 0 means group was previously used, then freed
          // a negative value means pins have been defined locally, but 
          // group has not yet been defined on the server.  this lets
          // add pins, and then when we try to actually use the group
          // it gets defined on the server
	int pinInGroup[256];
	int lastPinRead[256];
	int nextPinWrite[256];
	struct timeval *lastEvent;
} dio_connection;

void dio_group_finalize(dio_connection *conn,int group);

#include "dioctl_api.h"
/*
  Author: Michael Schmidt (michael@embeddedARM.com)
 */
