|
| 1 | +/* |
| 2 | + Arduino.h - Main include file for the Arduino SDK |
| 3 | + Copyright (c) 2014 Arduino LLC. 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 <stdbool.h> |
| 24 | +#include <stdint.h> |
| 25 | +#include <stdlib.h> |
| 26 | +#include <string.h> |
| 27 | +#include <math.h> |
| 28 | + |
| 29 | +#define CORE_HAS_LIBB64 |
| 30 | + |
| 31 | +typedef bool boolean; |
| 32 | +typedef uint8_t byte; |
| 33 | +typedef uint16_t word; |
| 34 | + |
| 35 | +// some libraries and sketches depend on this AVR stuff, |
| 36 | +// assuming Arduino.h or WProgram.h automatically includes it... |
| 37 | +// |
| 38 | +#include "avr/pgmspace.h" |
| 39 | +#include "avr/interrupt.h" |
| 40 | +#include "avr/dtostrf.h" |
| 41 | +#include "avr/io.h" |
| 42 | + |
| 43 | +#include "binary.h" |
| 44 | +#include "itoa.h" |
| 45 | + |
| 46 | +#ifdef __cplusplus |
| 47 | +extern "C"{ |
| 48 | +#endif // __cplusplus |
| 49 | + |
| 50 | +// Include Atmel headers |
| 51 | +#include "sam.h" |
| 52 | + |
| 53 | +#include "wiring_constants.h" |
| 54 | + |
| 55 | +#define clockCyclesPerMicrosecond() ( SystemCoreClock / 1000000L ) |
| 56 | +#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (SystemCoreClock / 1000L) ) |
| 57 | +#define microsecondsToClockCycles(a) ( (a) * (SystemCoreClock / 1000000L) ) |
| 58 | + |
| 59 | +void yield( void ) ; |
| 60 | + |
| 61 | +/* system functions */ |
| 62 | +int main( void ); |
| 63 | +void init( void ); |
| 64 | + |
| 65 | +/* sketch */ |
| 66 | +void setup( void ) ; |
| 67 | +void loop( void ) ; |
| 68 | + |
| 69 | +int __debug_buf(const char* head, char* buf, int len); |
| 70 | + |
| 71 | +#include "WVariant.h" |
| 72 | + |
| 73 | +#ifdef __cplusplus |
| 74 | +} // extern "C" |
| 75 | +#endif |
| 76 | + |
| 77 | +// The following headers are for C++ only compilation |
| 78 | +#ifdef __cplusplus |
| 79 | + #include "WCharacter.h" |
| 80 | + #include "WString.h" |
| 81 | + #include "Tone.h" |
| 82 | + #include "WMath.h" |
| 83 | + #include "HardwareSerial.h" |
| 84 | + #include "pulse.h" |
| 85 | +#endif |
| 86 | +#include "delay.h" |
| 87 | +#ifdef __cplusplus |
| 88 | + #include "Uart.h" |
| 89 | +#endif |
| 90 | + |
| 91 | +// Include board variant |
| 92 | +#include "variant.h" |
| 93 | + |
| 94 | +#include "wiring.h" |
| 95 | +#include "wiring_digital.h" |
| 96 | +#include "wiring_analog.h" |
| 97 | +#include "wiring_shift.h" |
| 98 | +#include "wiring_pwm.h" |
| 99 | +#include "WInterrupts.h" |
| 100 | + |
| 101 | +// undefine stdlib's abs if encountered |
| 102 | +#ifdef abs |
| 103 | +#undef abs |
| 104 | +#endif // abs |
| 105 | +// undefine stdlib's abs if encountered |
| 106 | +#ifdef abs |
| 107 | +#undef abs |
| 108 | +#endif // abs |
| 109 | + |
| 110 | +#ifdef __cplusplus |
| 111 | + template<class T, class L> |
| 112 | + auto min(const T& a, const L& b) -> decltype((b < a) ? b : a) |
| 113 | + { |
| 114 | + return (b < a) ? b : a; |
| 115 | + } |
| 116 | + |
| 117 | + template<class T, class L> |
| 118 | + auto max(const T& a, const L& b) -> decltype((b < a) ? b : a) |
| 119 | + { |
| 120 | + return (a < b) ? b : a; |
| 121 | + } |
| 122 | +#else |
| 123 | +#ifndef min |
| 124 | +#define min(a,b) \ |
| 125 | + ({ __typeof__ (a) _a = (a); \ |
| 126 | + __typeof__ (b) _b = (b); \ |
| 127 | + _a < _b ? _a : _b; }) |
| 128 | +#endif |
| 129 | +#ifndef max |
| 130 | +#define max(a,b) \ |
| 131 | + ({ __typeof__ (a) _a = (a); \ |
| 132 | + __typeof__ (b) _b = (b); \ |
| 133 | + _a > _b ? _a : _b; }) |
| 134 | +#endif |
| 135 | +#endif |
| 136 | + |
| 137 | +#define abs(x) ((x)>0?(x):-(x)) |
| 138 | +#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) |
| 139 | +#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) |
| 140 | +#define radians(deg) ((deg)*DEG_TO_RAD) |
| 141 | +#define degrees(rad) ((rad)*RAD_TO_DEG) |
| 142 | +#define sq(x) ((x)*(x)) |
| 143 | + |
| 144 | +#define interrupts() __enable_irq() |
| 145 | +#define noInterrupts() __disable_irq() |
| 146 | +#ifndef interruptsStatus |
| 147 | +static inline unsigned char __interruptsStatus(void) __attribute__((always_inline, unused)); |
| 148 | +static inline unsigned char __interruptsStatus(void) |
| 149 | +{ |
| 150 | + // See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/CHDBIBGJ.html |
| 151 | + return (__get_PRIMASK() ? 0 : 1); |
| 152 | +} |
| 153 | +#define interruptsStatus() __interruptsStatus() |
| 154 | +#endif |
| 155 | + |
| 156 | +#define lowByte(w) ((uint8_t) ((w) & 0xff)) |
| 157 | +#define highByte(w) ((uint8_t) ((w) >> 8)) |
| 158 | + |
| 159 | +#define bitRead(value, bit) (((value) >> (bit)) & 0x01) |
| 160 | +#define bitSet(value, bit) ((value) |= (1UL << (bit))) |
| 161 | +#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) |
| 162 | +#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) |
| 163 | + |
| 164 | +#define bit(b) (1UL << (b)) |
| 165 | + |
| 166 | +#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606) |
| 167 | +// Interrupts |
| 168 | +#define digitalPinToInterrupt(P) ( P ) |
| 169 | +#endif |
| 170 | + |
| 171 | +// USB |
| 172 | +#ifdef USE_TINYUSB |
| 173 | +#include "Adafruit_TinyUSB_Core.h" |
| 174 | +#else |
| 175 | +#include "USB/USBDesc.h" |
| 176 | +#include "USB/USBCore.h" |
| 177 | +#include "USB/USBAPI.h" |
| 178 | +#include "USB/USB_host.h" |
| 179 | +#endif |
| 180 | + |
| 181 | +#endif // Arduino_h |
0 commit comments