|
| 1 | +/* |
| 2 | + Arduino.h - Main include file for the Arduino SDK |
| 3 | + Copyright (c) 2005-2013 Arduino Team. All right reserved. |
| 4 | +
|
| 5 | + This library is free software; you can redistribute it and/or |
| 6 | + modify it under the terms of the GNU Lesser General Public |
| 7 | + License as published by the Free Software Foundation; either |
| 8 | + version 2.1 of the License, or (at your option) any later version. |
| 9 | +
|
| 10 | + This library is distributed in the hope that it will be useful, |
| 11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + Lesser General Public License for more details. |
| 14 | +
|
| 15 | + You should have received a copy of the GNU Lesser General Public |
| 16 | + License along with this library; if not, write to the Free Software |
| 17 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | +*/ |
| 19 | + |
| 20 | +#ifndef Arduino_h |
| 21 | +#define Arduino_h |
| 22 | + |
| 23 | +#include <stdlib.h> |
| 24 | +#include <stdint.h> |
| 25 | +#include <stdbool.h> |
| 26 | +#include <string.h> |
| 27 | +#include <math.h> |
| 28 | + |
| 29 | +#include "binary.h" |
| 30 | + |
| 31 | +#ifdef __cplusplus |
| 32 | +extern "C"{ |
| 33 | +#endif |
| 34 | + |
| 35 | +void yield(void); |
| 36 | + |
| 37 | +#define HIGH 0x1 |
| 38 | +#define LOW 0x0 |
| 39 | + |
| 40 | +#define INPUT 0x0 |
| 41 | +#define OUTPUT 0x1 |
| 42 | +#define INPUT_PULLUP 0x2 |
| 43 | + |
| 44 | +#define PI 3.1415926535897932384626433832795 |
| 45 | +#define HALF_PI 1.5707963267948966192313216916398 |
| 46 | +#define TWO_PI 6.283185307179586476925286766559 |
| 47 | +#define DEG_TO_RAD 0.017453292519943295769236907684886 |
| 48 | +#define RAD_TO_DEG 57.295779513082320876798154814105 |
| 49 | +#define EULER 2.718281828459045235360287471352 |
| 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 | +#define DEFAULT 1 |
| 62 | +#define EXTERNAL 0 |
| 63 | + |
| 64 | +// undefine stdlib's abs if encountered |
| 65 | +#ifdef abs |
| 66 | +#undef abs |
| 67 | +#endif |
| 68 | + |
| 69 | +#define min(a,b) ((a)<(b)?(a):(b)) |
| 70 | +#define max(a,b) ((a)>(b)?(a):(b)) |
| 71 | +#define abs(x) ((x)>0?(x):-(x)) |
| 72 | +#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) |
| 73 | +#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) |
| 74 | +#define radians(deg) ((deg)*DEG_TO_RAD) |
| 75 | +#define degrees(rad) ((rad)*RAD_TO_DEG) |
| 76 | +#define sq(x) ((x)*(x)) |
| 77 | + |
| 78 | +#define interrupts() sei() |
| 79 | +#define noInterrupts() cli() |
| 80 | + |
| 81 | +#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) |
| 82 | +#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) |
| 83 | +#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) |
| 84 | + |
| 85 | +#define lowByte(w) ((uint8_t) ((w) & 0xff)) |
| 86 | +#define highByte(w) ((uint8_t) ((w) >> 8)) |
| 87 | + |
| 88 | +#define bitRead(value, bit) (((value) >> (bit)) & 0x01) |
| 89 | +#define bitSet(value, bit) ((value) |= (1UL << (bit))) |
| 90 | +#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) |
| 91 | +#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) |
| 92 | + |
| 93 | +// avr-libc defines _NOP() since 1.6.2 |
| 94 | +#ifndef _NOP |
| 95 | +#define _NOP() do { __asm__ volatile ("nop"); } while (0) |
| 96 | +#endif |
| 97 | + |
| 98 | +typedef unsigned int word; |
| 99 | + |
| 100 | +#define bit(b) (1UL << (b)) |
| 101 | + |
| 102 | +typedef uint8_t boolean; |
| 103 | +typedef uint8_t byte; |
| 104 | + |
| 105 | +void init(void); |
| 106 | +void initVariant(void); |
| 107 | + |
| 108 | +int atexit(void (*func)()) __attribute__((weak)); |
| 109 | + |
| 110 | +void pinMode(uint8_t, uint8_t); |
| 111 | +void digitalWrite(uint8_t, uint8_t); |
| 112 | +int digitalRead(uint8_t); |
| 113 | +int analogRead(uint8_t); |
| 114 | +void analogReference(uint8_t mode); |
| 115 | +void analogWrite(uint8_t, int); |
| 116 | + |
| 117 | +unsigned long millis(void); |
| 118 | +unsigned long micros(void); |
| 119 | +void delay(unsigned long); |
| 120 | +void delayMicroseconds(unsigned int us); |
| 121 | +unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); |
| 122 | + |
| 123 | +void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); |
| 124 | +uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); |
| 125 | + |
| 126 | +void attachInterrupt(uint8_t, void (*)(void), int mode); |
| 127 | +void detachInterrupt(uint8_t); |
| 128 | + |
| 129 | +void setup(void); |
| 130 | +void loop(void); |
| 131 | + |
| 132 | +// Get the bit location within the hardware port of the given virtual pin. |
| 133 | +// This comes from the pins_*.c file for the active board configuration. |
| 134 | + |
| 135 | +#define analogInPinToBit(P) (P) |
| 136 | + |
| 137 | +// On the ATmega1280, the addresses of some of the port registers are |
| 138 | +// greater than 255, so we can't store them in uint8_t's. |
| 139 | +#define PROGMEM |
| 140 | + |
| 141 | +extern const uint16_t PROGMEM port_to_mode_PGM[]; |
| 142 | +extern const uint16_t PROGMEM port_to_input_PGM[]; |
| 143 | +extern const uint16_t PROGMEM port_to_output_PGM[]; |
| 144 | + |
| 145 | +extern const uint8_t PROGMEM digital_pin_to_port_PGM[]; |
| 146 | +// extern const uint8_t PROGMEM digital_pin_to_bit_PGM[]; |
| 147 | +extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[]; |
| 148 | +extern const uint8_t PROGMEM digital_pin_to_timer_PGM[]; |
| 149 | + |
| 150 | +// Get the bit location within the hardware port of the given virtual pin. |
| 151 | +// This comes from the pins_*.c file for the active board configuration. |
| 152 | +// |
| 153 | +// These perform slightly better as macros compared to inline functions |
| 154 | +// |
| 155 | +#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) ) |
| 156 | +#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) ) |
| 157 | +#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) ) |
| 158 | +#define analogInPinToBit(P) (P) |
| 159 | +#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) ) |
| 160 | +#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) ) |
| 161 | +#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) ) |
| 162 | + |
| 163 | +#define NOT_A_PIN 0 |
| 164 | +#define NOT_A_PORT 0 |
| 165 | + |
| 166 | +#define NOT_AN_INTERRUPT -1 |
| 167 | + |
| 168 | +#ifdef ARDUINO_MAIN |
| 169 | +#define PA 1 |
| 170 | +#define PB 2 |
| 171 | +#define PC 3 |
| 172 | +#define PD 4 |
| 173 | +#define PE 5 |
| 174 | +#define PF 6 |
| 175 | +#define PG 7 |
| 176 | +#define PH 8 |
| 177 | +#define PJ 10 |
| 178 | +#define PK 11 |
| 179 | +#define PL 12 |
| 180 | +#endif |
| 181 | + |
| 182 | +#define NOT_ON_TIMER 0 |
| 183 | +#define TIMER0A 1 |
| 184 | +#define TIMER0B 2 |
| 185 | +#define TIMER1A 3 |
| 186 | +#define TIMER1B 4 |
| 187 | +#define TIMER1C 5 |
| 188 | +#define TIMER2 6 |
| 189 | +#define TIMER2A 7 |
| 190 | +#define TIMER2B 8 |
| 191 | + |
| 192 | +#define TIMER3A 9 |
| 193 | +#define TIMER3B 10 |
| 194 | +#define TIMER3C 11 |
| 195 | +#define TIMER4A 12 |
| 196 | +#define TIMER4B 13 |
| 197 | +#define TIMER4C 14 |
| 198 | +#define TIMER4D 15 |
| 199 | +#define TIMER5A 16 |
| 200 | +#define TIMER5B 17 |
| 201 | +#define TIMER5C 18 |
| 202 | + |
| 203 | +#ifdef __cplusplus |
| 204 | +} // extern "C" |
| 205 | +#endif |
| 206 | + |
| 207 | +#ifdef __cplusplus |
| 208 | + |
| 209 | +#include "WCharacter.h" |
| 210 | +#include "WString.h" |
| 211 | +/* |
| 212 | +#include "HardwareSerial.h" |
| 213 | +
|
| 214 | +#include "USBAPI.h" |
| 215 | +#if defined(HAVE_HWSERIAL0) && defined(HAVE_CDCSERIAL) |
| 216 | +#error "Targets with both UART0 and CDC serial not supported" |
| 217 | +#endif |
| 218 | +*/ |
| 219 | + |
| 220 | +uint16_t makeWord(uint16_t w); |
| 221 | +uint16_t makeWord(byte h, byte l); |
| 222 | + |
| 223 | +#define word(...) makeWord(__VA_ARGS__) |
| 224 | + |
| 225 | +unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); |
| 226 | + |
| 227 | +void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); |
| 228 | +void noTone(uint8_t _pin); |
| 229 | + |
| 230 | +// WMath prototypes |
| 231 | +long random(long); |
| 232 | +long random(long, long); |
| 233 | +void randomSeed(unsigned int); |
| 234 | +long map(long, long, long, long, long); |
| 235 | + |
| 236 | +#endif |
| 237 | + |
| 238 | +#include "pins_arduino.h" |
| 239 | + |
| 240 | +#endif |
0 commit comments