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
45 #define OUTPUT 0x01
46 #define OUTPUT_OPEN_DRAIN 0x03
47 #define WAKEUP_PULLUP 0x05
48 #define WAKEUP_PULLDOWN 0x07
49 #define SPECIAL 0xF8 //defaults to the usable BUSes uart0rx/tx uart1tx and hspi
50 #define FUNCTION_0 0x08
51 #define FUNCTION_1 0x18
52 #define FUNCTION_2 0x28
53 #define FUNCTION_3 0x38
54 #define FUNCTION_4 0x48
55 #define ANALOG 0xc0
56 
57 #define CHANGE 32 // to avoid conflict with HIGH value
58 #define FALLING 2
59 #define RISING 3
60 
61 #define LSBFIRST 0x0
62 #define MSBFIRST 0x1
63 
64 #define null NULL
65 
66 #define DEC 10
67 #define HEX 16
68 #define OCT 8
69 #define BIN 2
70 
71 #define PI (3.1415926535897932384626433832795)
72 #define TWO_PI (6.283185307179586476925286766559)
73 #define HALF_PI (1.5707963267948966192313216916398)
74 #define EPSILON (0.0001)
75 #define DEG_TO_RAD (0.017453292519943295769236907684886)
76 #define RAD_TO_DEG (57.295779513082320876798154814105)
77 
78 /*************************************************************
79  * Digital Constants
80  *************************************************************/
81 
82 #define PORT0 0
83 #define PORT1 1
84 #define PORT2 2
85 #define PORT3 3
86 #define PORT4 4
87 #define PORT5 5
88 #define PORT6 6
89 #define PORT7 7
90 #define PORT8 8
91 #define PORT9 9
92 
93 /*************************************************************
94  * Useful macros
95  *************************************************************/
96 
97 #define word(...) makeWord(__VA_ARGS__)
98 
99 #define sq(x) ((x) * (x))
100 #define radians(deg) ((deg)*DEG_TO_RAD)
101 #define degrees(rad) ((rad)*RAD_TO_DEG)
102 #define constrain(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt)))
103 
104 #define lowByte(x) ((uint8_t)((x)&0x00ff))
105 #define highByte(x) ((uint8_t)((x) >> 8))
106 
107 #define clockCyclesPerMicrosecond() (F_CPU / 1000000L)
108 #define clockCyclesToMicroseconds(a) ((a) / clockCyclesPerMicrosecond())
109 #define microsecondsToClockCycles(a) ((a)*clockCyclesPerMicrosecond())
110 
111 /*************************************************************
112  * Typedefs
113  *************************************************************/
114 
115 using word = unsigned int;
116 using byte = uint8_t;
117 using boolean = uint8_t;
118 using voidFuncPtr = void (*)(void);
void(*)(void) voidFuncPtr
Definition: WConstants.h:118
uint8_t byte
Definition: WConstants.h:116