WConstants.h
Go to the documentation of this file.
1 /* $Id: WConstants.h 1156 2011-06-07 04:01:16Z bhagman $
2 ||
3 || @author Hernando Barragan <b@wiring.org.co>
4 || @url http://wiring.org.co/
5 || @contribution Brett Hagman <bhagman@wiring.org.co>
6 || @contribution Alexander Brevig <abrevig@wiring.org.co>
7 ||
8 || @description
9 || | Main constant and macro definitions for Wiring.
10 || |
11 || | Wiring Common API
12 || #
13 ||
14 || @license Please see cores/Common/License.txt.
15 ||
16 */
17 
18 #pragma once
19 
20 #include <cstdint>
21 
22 // Wiring API version for libraries
23 // this is passed in at compile-time
24 #ifndef WIRING
25 #define WIRING 101
26 #endif
27 
28 // passed in at compile-time
29 #ifndef F_CPU
30 #define F_CPU 80000000L
31 #endif
32 
33 /*************************************************************
34  * Constants
35  *************************************************************/
36 
37 #define LOW 0x0
38 #define HIGH 0x1
39 //#define HIGH 0xFF
40 
41 //GPIO FUNCTIONS
42 #define INPUT 0x00
43 #define INPUT_PULLUP 0x02
44 #define INPUT_PULLDOWN_16 0x04 // PULLDOWN only possible for pin16 on ESP8266
45 #define INPUT_PULLDOWN 0x04
46 #define OUTPUT 0x01
47 #define OUTPUT_OPEN_DRAIN 0x03
48 #define WAKEUP_PULLUP 0x05
49 #define WAKEUP_PULLDOWN 0x07
50 #define SPECIAL 0xF8 //defaults to the usable BUSes uart0rx/tx uart1tx and hspi
51 #define FUNCTION_0 0x08
52 #define FUNCTION_1 0x18
53 #define FUNCTION_2 0x28
54 #define FUNCTION_3 0x38
55 #define FUNCTION_4 0x48
56 #define ANALOG 0xc0
57 
58 #define CHANGE 32 // to avoid conflict with HIGH value
59 #define FALLING 2
60 #define RISING 3
61 
62 #define LSBFIRST 0x0
63 #define MSBFIRST 0x1
64 
65 #define null NULL
66 
67 #define DEC 10
68 #define HEX 16
69 #define OCT 8
70 #define BIN 2
71 
72 #define PI (3.1415926535897932384626433832795)
73 #define TWO_PI (6.283185307179586476925286766559)
74 #define HALF_PI (1.5707963267948966192313216916398)
75 #define EPSILON (0.0001)
76 #define DEG_TO_RAD (0.017453292519943295769236907684886)
77 #define RAD_TO_DEG (57.295779513082320876798154814105)
78 
79 /*************************************************************
80  * Digital Constants
81  *************************************************************/
82 
83 #define PORT0 0
84 #define PORT1 1
85 #define PORT2 2
86 #define PORT3 3
87 #define PORT4 4
88 #define PORT5 5
89 #define PORT6 6
90 #define PORT7 7
91 #define PORT8 8
92 #define PORT9 9
93 
94 /*************************************************************
95  * Useful macros
96  *************************************************************/
97 
98 #define word(...) makeWord(__VA_ARGS__)
99 
100 #define sq(x) ((x) * (x))
101 #define radians(deg) ((deg)*DEG_TO_RAD)
102 #define degrees(rad) ((rad)*RAD_TO_DEG)
103 #define constrain(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt)))
104 
105 #define lowByte(x) ((uint8_t)((x)&0x00ff))
106 #define highByte(x) ((uint8_t)((x) >> 8))
107 
108 #define clockCyclesPerMicrosecond() (F_CPU / 1000000L)
109 #define clockCyclesToMicroseconds(a) ((a) / clockCyclesPerMicrosecond())
110 #define microsecondsToClockCycles(a) ((a)*clockCyclesPerMicrosecond())
111 
112 /*************************************************************
113  * Typedefs
114  *************************************************************/
115 
116 using word = unsigned int;
117 using byte = uint8_t;
118 using boolean = uint8_t;
119 using voidFuncPtr = void (*)(void);
void(*)(void) voidFuncPtr
Definition: WConstants.h:119