Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.20 KB | None | 0 0
  1. Skip to content
  2. Personal Open source Business Explore
  3. Sign upSign inPricingBlogSupport
  4. This repository
  5. Search
  6.  Watch 778  Star 6,289  Fork 5,102 arduino/Arduino
  7.  Code  Issues 739  Pull requests 130  Projects 0  Wiki  Pulse  Graphs
  8. Branch: master Find file Copy pathArduino/hardware/arduino/avr/cores/arduino/Arduino.h
  9. a2a17a0  on 7 Sep 2016
  10. @mischnic mischnic Requested changes to not change code for non ATtinyX5s
  11. 6 contributors @cmaglie @matthijskooijman @mischnic @facchinm @ffissore @Chris--A
  12. RawBlameHistory    
  13. 260 lines (206 sloc)  7.31 KB
  14. /*
  15.   Arduino.h - Main include file for the Arduino SDK
  16.   Copyright (c) 2005-2013 Arduino Team.  All right reserved.
  17.   This library is free software; you can redistribute it and/or
  18.   modify it under the terms of the GNU Lesser General Public
  19.   License as published by the Free Software Foundation; either
  20.   version 2.1 of the License, or (at your option) any later version.
  21.   This library is distributed in the hope that it will be useful,
  22.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  23.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  24.   Lesser General Public License for more details.
  25.   You should have received a copy of the GNU Lesser General Public
  26.   License along with this library; if not, write to the Free Software
  27.   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  28. */
  29.  
  30. #ifndef Arduino_h
  31. #define Arduino_h
  32.  
  33. #include <stdlib.h>
  34. #include <stdbool.h>
  35. #include <string.h>
  36. #include <math.h>
  37.  
  38. #include <avr/pgmspace.h>
  39. #include <avr/io.h>
  40. #include <avr/interrupt.h>
  41.  
  42. #include "binary.h"
  43.  
  44. #ifdef __cplusplus
  45. extern "C"{
  46. #endif
  47.  
  48. void yield(void);
  49.  
  50. #define HIGH 0x1
  51. #define LOW  0x0
  52.  
  53. #define INPUT 0x0
  54. #define OUTPUT 0x1
  55. #define INPUT_PULLUP 0x2
  56.  
  57. #define PI 3.1415926535897932384626433832795
  58. #define HALF_PI 1.5707963267948966192313216916398
  59. #define TWO_PI 6.283185307179586476925286766559
  60. #define DEG_TO_RAD 0.017453292519943295769236907684886
  61. #define RAD_TO_DEG 57.295779513082320876798154814105
  62. #define EULER 2.718281828459045235360287471352
  63.  
  64. #define SERIAL  0x0
  65. #define DISPLAY 0x1
  66.  
  67. #define LSBFIRST 0
  68. #define MSBFIRST 1
  69.  
  70. #define CHANGE 1
  71. #define FALLING 2
  72. #define RISING 3
  73.  
  74. #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
  75.   #define DEFAULT 0
  76.   #define EXTERNAL 1
  77.   #define INTERNAL1V1 2
  78.   #define INTERNAL INTERNAL1V1
  79. #elif defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
  80.   #define DEFAULT 0
  81.   #define EXTERNAL 4
  82.   #define INTERNAL1V1 8
  83.   #define INTERNAL INTERNAL1V1
  84.   #define INTERNAL2V56 9
  85.   #define INTERNAL2V56_EXTCAP 13
  86. #else  
  87. #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)
  88. #define INTERNAL1V1 2
  89. #define INTERNAL2V56 3
  90. #else
  91. #define INTERNAL 3
  92. #endif
  93. #define DEFAULT 1
  94. #define EXTERNAL 0
  95. #endif
  96.  
  97. // undefine stdlib's abs if encountered
  98. #ifdef abs
  99. #undef abs
  100. #endif
  101.  
  102. #define min(a,b) ((a)<(b)?(a):(b))
  103. #define max(a,b) ((a)>(b)?(a):(b))
  104. #define abs(x) ((x)>0?(x):-(x))
  105. #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
  106. #define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
  107. #define radians(deg) ((deg)*DEG_TO_RAD)
  108. #define degrees(rad) ((rad)*RAD_TO_DEG)
  109. #define sq(x) ((x)*(x))
  110.  
  111. #define interrupts() sei()
  112. #define noInterrupts() cli()
  113.  
  114. #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
  115. #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
  116. #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
  117.  
  118. #define lowByte(w) ((uint8_t) ((w) & 0xff))
  119. #define highByte(w) ((uint8_t) ((w) >> 8))
  120.  
  121. #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
  122. #define bitSet(value, bit) ((value) |= (1UL << (bit)))
  123. #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
  124. #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
  125.  
  126. // avr-libc defines _NOP() since 1.6.2
  127. #ifndef _NOP
  128. #define _NOP() do { __asm__ volatile ("nop"); } while (0)
  129. #endif
  130.  
  131. typedef unsigned int word;
  132.  
  133. #define bit(b) (1UL << (b))
  134.  
  135. typedef bool boolean;
  136. typedef uint8_t byte;
  137.  
  138. void init(void);
  139. void initVariant(void);
  140.  
  141. int atexit(void (*func)()) __attribute__((weak));
  142.  
  143. void pinMode(uint8_t, uint8_t);
  144. void digitalWrite(uint8_t, uint8_t);
  145. int digitalRead(uint8_t);
  146. int analogRead(uint8_t);
  147. void analogReference(uint8_t mode);
  148. void analogWrite(uint8_t, int);
  149.  
  150. unsigned long millis(void);
  151. unsigned long micros(void);
  152. void delay(unsigned long);
  153. void delayMicroseconds(unsigned int us);
  154. unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
  155. unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout);
  156.  
  157. void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
  158. uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
  159.  
  160. void attachInterrupt(uint8_t, void (*)(void), int mode);
  161. void detachInterrupt(uint8_t);
  162.  
  163. void setup(void);
  164. void loop(void);
  165.  
  166. // Get the bit location within the hardware port of the given virtual pin.
  167. // This comes from the pins_*.c file for the active board configuration.
  168.  
  169. #define analogInPinToBit(P) (P)
  170.  
  171. // On the ATmega1280, the addresses of some of the port registers are
  172. // greater than 255, so we can't store them in uint8_t's.
  173. extern const uint16_t PROGMEM port_to_mode_PGM[];
  174. extern const uint16_t PROGMEM port_to_input_PGM[];
  175. extern const uint16_t PROGMEM port_to_output_PGM[];
  176.  
  177. extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
  178. // extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
  179. extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
  180. extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
  181.  
  182. // Get the bit location within the hardware port of the given virtual pin.
  183. // This comes from the pins_*.c file for the active board configuration.
  184. //
  185. // These perform slightly better as macros compared to inline functions
  186. //
  187. #define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
  188. #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
  189. #define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
  190. #define analogInPinToBit(P) (P)
  191. #define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
  192. #define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
  193. #define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
  194.  
  195. #define NOT_A_PIN 0
  196. #define NOT_A_PORT 0
  197.  
  198. #define NOT_AN_INTERRUPT -1
  199.  
  200. #ifdef ARDUINO_MAIN
  201. #define PA 1
  202. #define PB 2
  203. #define PC 3
  204. #define PD 4
  205. #define PE 5
  206. #define PF 6
  207. #define PG 7
  208. #define PH 8
  209. #define PJ 10
  210. #define PK 11
  211. #define PL 12
  212. #endif
  213.  
  214. #define NOT_ON_TIMER 0
  215. #define TIMER0A 1
  216. #define TIMER0B 2
  217. #define TIMER1A 3
  218. #define TIMER1B 4
  219. #define TIMER1C 5
  220. #define TIMER2  6
  221. #define TIMER2A 7
  222. #define TIMER2B 8
  223.  
  224. #define TIMER3A 9
  225. #define TIMER3B 10
  226. #define TIMER3C 11
  227. #define TIMER4A 12
  228. #define TIMER4B 13
  229. #define TIMER4C 14
  230. #define TIMER4D 15
  231. #define TIMER5A 16
  232. #define TIMER5B 17
  233. #define TIMER5C 18
  234.  
  235. #ifdef __cplusplus
  236. } // extern "C"
  237. #endif
  238.  
  239. #ifdef __cplusplus
  240. #include "WCharacter.h"
  241. #include "WString.h"
  242. #include "HardwareSerial.h"
  243. #include "USBAPI.h"
  244. #if defined(HAVE_HWSERIAL0) && defined(HAVE_CDCSERIAL)
  245. #error "Targets with both UART0 and CDC serial not supported"
  246. #endif
  247.  
  248. uint16_t makeWord(uint16_t w);
  249. uint16_t makeWord(byte h, byte l);
  250.  
  251. #define word(...) makeWord(__VA_ARGS__)
  252.  
  253. unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
  254. unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
  255.  
  256. void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
  257. void noTone(uint8_t _pin);
  258.  
  259. // WMath prototypes
  260. long random(long);
  261. long random(long, long);
  262. void randomSeed(unsigned long);
  263. long map(long, long, long, long, long);
  264.  
  265. #endif
  266.  
  267. #include "pins_arduino.h"
  268.  
  269. #endif
  270. Contact GitHub API Training Shop Blog About
  271. © 2017 GitHub, Inc. Terms Privacy Security Status Help
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement