1/*
2  wiring.h - Partial implementation of the Wiring API for the ATmega8.
3  Part of Arduino - http://www.arduino.cc/
4
5  Copyright (c) 2005-2006 David A. Mellis
6
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  Lesser General Public License for more details.
16
17  You should have received a copy of the GNU Lesser General
18  Public License along with this library; if not, write to the
19  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  Boston, MA  02111-1307  USA
21
22  $Id$
23*/
24
25#ifndef Wiring_h
26#define Wiring_h
27
28#include <avr/io.h>
29#include <stdlib.h>
30#include "binary.h"
31
32#ifdef __cplusplus
33extern "C"{
34#endif
35
36#define HIGH 0x1
37#define LOW  0x0
38
39#define INPUT 0x0
40#define OUTPUT 0x1
41
42#define true 0x1
43#define false 0x0
44
45#define PI 3.1415926535897932384626433832795
46#define HALF_PI 1.5707963267948966192313216916398
47#define TWO_PI 6.283185307179586476925286766559
48#define DEG_TO_RAD 0.017453292519943295769236907684886
49#define RAD_TO_DEG 57.295779513082320876798154814105
50
51#define SERIAL  0x0
52#define DISPLAY 0x1
53
54#define LSBFIRST 0
55#define MSBFIRST 1
56
57#define CHANGE 1
58#define FALLING 2
59#define RISING 3
60
61#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
62#define INTERNAL1V1 2
63#define INTERNAL2V56 3
64#else
65#define INTERNAL 3
66#endif
67#define DEFAULT 1
68#define EXTERNAL 0
69
70// undefine stdlib's abs if encountered
71#ifdef abs
72#undef abs
73#endif
74
75#define min(a,b) ((a)<(b)?(a):(b))
76#define max(a,b) ((a)>(b)?(a):(b))
77#define abs(x) ((x)>0?(x):-(x))
78#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
79#if __AVR_LIBC_VERSION__ < 10701UL
80#define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
81#endif
82#define radians(deg) ((deg)*DEG_TO_RAD)
83#define degrees(rad) ((rad)*RAD_TO_DEG)
84#define sq(x) ((x)*(x))
85
86#define interrupts() sei()
87#define noInterrupts() cli()
88
89#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
90#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
91#define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L )
92
93#define lowByte(w) ((uint8_t) ((w) & 0xff))
94#define highByte(w) ((uint8_t) ((w) >> 8))
95
96#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
97#define bitSet(value, bit) ((value) |= (1UL << (bit)))
98#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
99#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
100
101
102typedef unsigned int word;
103
104#define bit(b) (1UL << (b))
105
106typedef uint8_t boolean;
107typedef uint8_t byte;
108
109void init(void);
110
111void pinMode(uint8_t, uint8_t);
112void digitalWrite(uint8_t, uint8_t);
113int digitalRead(uint8_t);
114int analogRead(uint8_t);
115void analogReference(uint8_t mode);
116void analogWrite(uint8_t, int);
117
118unsigned long millis(void);
119unsigned long micros(void);
120void delay(unsigned long);
121void delayMicroseconds(unsigned int us);
122unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
123
124void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
125uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
126
127void attachInterrupt(uint8_t, void (*)(void), int mode);
128void detachInterrupt(uint8_t);
129
130void setup(void);
131void loop(void);
132
133#ifdef __cplusplus
134} // extern "C"
135#endif
136
137#endif
138