wiring.h

Sat, 07 Nov 2015 13:24:46 +0100

author
mbayer
date
Sat, 07 Nov 2015 13:24:46 +0100
changeset 1
b584642d4f58
parent 0
2c8ba1964db7
permissions
-rw-r--r--

several modifications to support laser enable - still needs cleanup

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

mercurial