• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
33 extern "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 #define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
80 #define radians(deg) ((deg)*DEG_TO_RAD)
81 #define degrees(rad) ((rad)*RAD_TO_DEG)
82 #define sq(x) ((x)*(x))
83 
84 #define interrupts() sei()
85 #define noInterrupts() cli()
86 
87 #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
88 #define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
89 #define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L )
90 
91 #define lowByte(w) ((uint8_t) ((w) & 0xff))
92 #define highByte(w) ((uint8_t) ((w) >> 8))
93 
94 #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
95 #define bitSet(value, bit) ((value) |= (1UL << (bit)))
96 #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
97 #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
98 
99 
100 typedef unsigned int word;
101 
102 #define bit(b) (1UL << (b))
103 
104 typedef uint8_t boolean;
105 typedef uint8_t byte;
106 
107 void init(void);
108 
109 void pinMode(uint8_t, uint8_t);
110 void digitalWrite(uint8_t, uint8_t);
111 int digitalRead(uint8_t);
112 int analogRead(uint8_t);
113 void analogReference(uint8_t mode);
114 void analogWrite(uint8_t, int);
115 
116 unsigned long millis(void);
117 unsigned long micros(void);
118 void delay(unsigned long);
119 void delayMicroseconds(unsigned int us);
120 unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
121 
122 void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
123 uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
124 
125 void attachInterrupt(uint8_t, void (*)(void), int mode);
126 void detachInterrupt(uint8_t);
127 
128 void setup(void);
129 void loop(void);
130 
131 #ifdef __cplusplus
132 } // extern "C"
133 #endif
134 
135 #endif
136