-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibarduino.h
98 lines (81 loc) · 3.42 KB
/
libarduino.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* ***********************************************************************
** libarduino - a GNU library for using GNU toolchain with Arduino
** Copyright (C) 2009 Michael Spiceland
*************************************************************************
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software Foundation,
** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
*************************************************************************/
#ifndef LIBARDUINO_H
#define LIBARDUINO_H
#include <inttypes.h>
#define ENABLE_PWMSERVO /* servo control (conflicts with regular pwm) */
#define ENABLE_PWM /* motor or led control (conflicts with pwmservo) */
#define ENABLE_IR /* infrared receiver */
#define ENABLE_ADC /* analog to digital convertor */
#define ENABLE_SERIAL /* uart0 interface */
#define ENABLE_ONEWIRE /* enable the onewire interface */
#define ENABLE_DS18X20 /* enable the DS18x20 temperature sensor driver */
#define ENABLE_ARDUINO_COMPAT /* subset of arduino functions */
#define IR_DEBOUNCE /* uncomment to debounce IR with a delay */
#include "uart.h"
#include "gpio.h"
#include "ir.h"
#include "pwm.h"
#include "adc.h"
#include "crc8.h"
#include "onewire.h"
#include "ds18x20.h"
#if !((F_CPU == 16000000) || (F_CPU == 8000000))
#error "Processor speed not supported in libarduino.c !"
#endif
#if (F_CPU == 8000000)
#error "Processor speed only partically supported by libarduino.c. Some things may not work !"
#endif
#define true 0x1
#define false 0x0
#define PI 3.1415926535897932384626433832795
#define HALF_PI 1.5707963267948966192313216916398
#define TWO_PI 6.283185307179586476925286766559
#define DEG_TO_RAD 0.017453292519943295769236907684886
#define RAD_TO_DEG 57.295779513082320876798154814105
// undefine stdlib's abs if encountered
#ifdef abs
#undef abs
#endif
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(x) ((x)>0?(x):-(x))
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
#define radians(deg) ((deg)*DEG_TO_RAD)
#define degrees(rad) ((rad)*RAD_TO_DEG)
#define sq(x) ((x)*(x))
#define interrupts() sei()
#define noInterrupts() cli()
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
#define lowByte(w) ((uint8_t) ((w) & 0xff))
#define highByte(w) ((uint8_t) ((w) >> 8))
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
typedef unsigned int word;
#define bit(b) (1UL << (b))
typedef uint8_t boolean;
typedef uint8_t byte;
#endif