#ifndef _ArduWin_h
#define _ArduWin_h

#include "_options.h"

//--------------------------------------------------------------------
// Arduino Console Stub
//--------------------------------------------------------------------

#if _MSC_VER 

#pragma once

#define _CRT_SECURE_NO_WARNINGS

#pragma warning(disable : 4996)

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

//typedef __int8 int8_t;
typedef __int16 int16_t;
typedef __int32 int32_t;
typedef __int64 int64_t;
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;

#define max(a,b)  (((a) > (b)) ? (a) : (b))
#define min(a,b)  (((a) < (b)) ? (a) : (b))
#define Tc int

enum {A0,A1,A2,A3,A4,A5,A6,A7,TC1,A20,A21,A22,A16,A15,A14};

// Add CPU hardware definitions

#define _AVR_IO_H_
#define _SFR_IO8(io_addr) ((io_addr))
//#include "C:\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\avr\iomxx0_1.h"

#define boolean bool

// From "c:\program files\arduino\hardware\cores\arduino\print.h"

#define DEC 10
#define HEX 16
#define OCT 8
#define BIN 2
#define BYTE 0

// From "c:\program files\arduino\hardware\cores\arduino\wiring.h"

#define HIGH 0x1
#define LOW  0x0

#define INPUT 0x0
#define OUTPUT 0x1
#define INPUT_PULLUP 0x3

#define PI 3.14159265
#define HALF_PI 1.57079
#define TWO_PI 6.283185
#define DEG_TO_RAD 0.01745329
#define RAD_TO_DEG 57.2957786

#define SERIAL  0x0
#define DISPLAY 0x1

#define LSBFIRST 0
#define MSBFIRST 1

#define CHANGE 1
#define FALLING 2
#define RISING 3

#define INTERNAL 3
#define DEFAULT 1
#define EXTERNAL 0
#define SERIAL_8N1 0
#define SERIAL_8E1 0
#define SERIAL_8N2 0
#define SERIAL_8E1_RXINV 0
#define SERIAL_8N1_RXINV 0
#define SERIAL_8N2_RXINV 0
#define SERIAL_8N1_RXINV_TXINV 0

#define UART_S1_TDRE 0
#if not defined(_TEENSY4)
extern int UART0_S1;
extern int UART0_D;
extern int UART1_S1;
extern int UART1_D;
extern int UART2_S1;
extern int UART2_D;
extern int UART3_S1;
extern int UART3_D;
#endif
extern int PINC;
extern int PIND;
extern int GPIOC_PDIR;
extern int GPIOD_PDIR;
extern int DDRC;
extern int DDRD;

class CSerial
{
public:
	void begin(long);
	void begin(long,long);

	void print(const char*);

	void println();
	void flush();
	void println(char*);
	void write(void*,int=1);
	void write(int);
	void println(int,int);
	void println(unsigned int,int);
	void println(unsigned long,int);
	int available();
	char read();
	void setTimeout(int timeout);
	int readBytes(char *c,int len);
	int availableForWrite();
	void addMemoryForRead(void *buffer, size_t length);
	void addMemoryForWrite(void *buffer, size_t length);


	// VSPDE
	void _append(char c);
private:
	char buffer[1024];
	int buflen;
};

//extern CSerial Serial;
extern CSerial SerialUSB;
extern CSerial Serial1;
extern CSerial Serial2;
extern CSerial Serial3;
extern CSerial Serial4;
extern CSerial Serial5;
extern CSerial Serial6;
extern unsigned long millis();
extern void pinMode(int,int);
extern void analogWriteFrequency(int,int);
extern void digitalWrite(int,int);
extern void digitalWriteFast(int,int);
extern bool digitalRead(int);
extern bool digitalReadFast(int);
extern void analogWrite(int,int);
extern bool analogRead(int);
extern void analogReadResolution(int);
extern void noInterrupts();
extern void interrupts();

class TimerThree
{
public:
	void initialize(int);
	void attachInterrupt(void *);
};
extern TimerThree Timer3;
extern TimerThree Timer1;


#else
#include <Arduino.h>
#include <TimerOne.h>
#include <TimerThree.h>
#endif
#endif
