Project

General

Profile

Statistics
| Branch: | Revision:

root / arduino-1.0 / hardware / arduino / cores / arduino / Arduino.h @ 58d82c77

History | View | Annotate | Download (5.5 KB)

1
#ifndef Arduino_h
2
#define Arduino_h
3

    
4
#include <stdlib.h>
5
#include <string.h>
6
#include <math.h>
7

    
8
#include <avr/pgmspace.h>
9
#include <avr/io.h>
10
#include <avr/interrupt.h>
11

    
12
#include "binary.h"
13

    
14
#ifdef __cplusplus
15
extern "C"{
16
#endif
17

    
18
#define HIGH 0x1
19
#define LOW  0x0
20

    
21
#define INPUT 0x0
22
#define OUTPUT 0x1
23

    
24
#define true 0x1
25
#define false 0x0
26

    
27
#define PI 3.1415926535897932384626433832795
28
#define HALF_PI 1.5707963267948966192313216916398
29
#define TWO_PI 6.283185307179586476925286766559
30
#define DEG_TO_RAD 0.017453292519943295769236907684886
31
#define RAD_TO_DEG 57.295779513082320876798154814105
32

    
33
#define SERIAL  0x0
34
#define DISPLAY 0x1
35

    
36
#define LSBFIRST 0
37
#define MSBFIRST 1
38

    
39
#define CHANGE 1
40
#define FALLING 2
41
#define RISING 3
42

    
43
#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
44
#define DEFAULT 0
45
#define EXTERNAL 1
46
#define INTERNAL 2
47
#else  
48
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
49
#define INTERNAL1V1 2
50
#define INTERNAL2V56 3
51
#else
52
#define INTERNAL 3
53
#endif
54
#define DEFAULT 1
55
#define EXTERNAL 0
56
#endif
57

    
58
// undefine stdlib's abs if encountered
59
#ifdef abs
60
#undef abs
61
#endif
62

    
63
#define min(a,b) ((a)<(b)?(a):(b))
64
#define max(a,b) ((a)>(b)?(a):(b))
65
#define abs(x) ((x)>0?(x):-(x))
66
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
67
#define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
68
#define radians(deg) ((deg)*DEG_TO_RAD)
69
#define degrees(rad) ((rad)*RAD_TO_DEG)
70
#define sq(x) ((x)*(x))
71

    
72
#define interrupts() sei()
73
#define noInterrupts() cli()
74

    
75
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
76
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
77
#define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L )
78

    
79
#define lowByte(w) ((uint8_t) ((w) & 0xff))
80
#define highByte(w) ((uint8_t) ((w) >> 8))
81

    
82
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
83
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
84
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
85
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
86

    
87

    
88
typedef unsigned int word;
89

    
90
#define bit(b) (1UL << (b))
91

    
92
typedef uint8_t boolean;
93
typedef uint8_t byte;
94

    
95
void init(void);
96

    
97
void pinMode(uint8_t, uint8_t);
98
void digitalWrite(uint8_t, uint8_t);
99
int digitalRead(uint8_t);
100
int analogRead(uint8_t);
101
void analogReference(uint8_t mode);
102
void analogWrite(uint8_t, int);
103

    
104
unsigned long millis(void);
105
unsigned long micros(void);
106
void delay(unsigned long);
107
void delayMicroseconds(unsigned int us);
108
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
109

    
110
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
111
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
112

    
113
void attachInterrupt(uint8_t, void (*)(void), int mode);
114
void detachInterrupt(uint8_t);
115

    
116
void setup(void);
117
void loop(void);
118

    
119
// Get the bit location within the hardware port of the given virtual pin.
120
// This comes from the pins_*.c file for the active board configuration.
121

    
122
#define analogInPinToBit(P) (P)
123

    
124
// On the ATmega1280, the addresses of some of the port registers are
125
// greater than 255, so we can't store them in uint8_t's.
126
extern const uint16_t PROGMEM port_to_mode_PGM[];
127
extern const uint16_t PROGMEM port_to_input_PGM[];
128
extern const uint16_t PROGMEM port_to_output_PGM[];
129

    
130
extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
131
// extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
132
extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
133
extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
134

    
135
// Get the bit location within the hardware port of the given virtual pin.
136
// This comes from the pins_*.c file for the active board configuration.
137
// 
138
// These perform slightly better as macros compared to inline functions
139
//
140
#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
141
#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
142
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
143
#define analogInPinToBit(P) (P)
144
#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
145
#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
146
#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
147

    
148
#define NOT_A_PIN 0
149
#define NOT_A_PORT 0
150

    
151
#ifdef ARDUINO_MAIN
152
#define PA 1
153
#define PB 2
154
#define PC 3
155
#define PD 4
156
#define PE 5
157
#define PF 6
158
#define PG 7
159
#define PH 8
160
#define PJ 10
161
#define PK 11
162
#define PL 12
163
#endif
164

    
165
#define NOT_ON_TIMER 0
166
#define TIMER0A 1
167
#define TIMER0B 2
168
#define TIMER1A 3
169
#define TIMER1B 4
170
#define TIMER2  5
171
#define TIMER2A 6
172
#define TIMER2B 7
173

    
174
#define TIMER3A 8
175
#define TIMER3B 9
176
#define TIMER3C 10
177
#define TIMER4A 11
178
#define TIMER4B 12
179
#define TIMER4C 13
180
#define TIMER4D 14        
181
#define TIMER5A 15
182
#define TIMER5B 16
183
#define TIMER5C 17
184

    
185
#ifdef __cplusplus
186
} // extern "C"
187
#endif
188

    
189
#ifdef __cplusplus
190
#include "WCharacter.h"
191
#include "WString.h"
192
#include "HardwareSerial.h"
193

    
194
uint16_t makeWord(uint16_t w);
195
uint16_t makeWord(byte h, byte l);
196

    
197
#define word(...) makeWord(__VA_ARGS__)
198

    
199
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
200

    
201
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
202
void noTone(uint8_t _pin);
203

    
204
// WMath prototypes
205
long random(long);
206
long random(long, long);
207
void randomSeed(unsigned int);
208
long map(long, long, long, long, long);
209

    
210
#endif
211

    
212
#include "pins_arduino.h"
213

    
214
#endif