Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
WConstants.h
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 #ifndef WCONSTANTS_H
19 #define WCONSTANTS_H
20 
21 #include "../include/user_config.h"
22 
23 // Wiring API version for libraries
24 // this is passed in at compile-time
25 #ifndef WIRING
26 #define WIRING 101
27 #endif
28 
29 // passed in at compile-time
30 #ifndef F_CPU
31 #define F_CPU 80000000L
32 #warning "F_CPU was not defined. Default to 80 MHz."
33 #endif
34 
35 /*************************************************************
36  * Constants
37  *************************************************************/
38 
39 #define LOW 0x0
40 #define HIGH 0x1
41 //#define HIGH 0xFF
42 
43 //GPIO FUNCTIONS
44 #define INPUT 0x00
45 #define INPUT_PULLUP 0x02
46 #define INPUT_PULLDOWN_16 0x04 // PULLDOWN only possible for pin16
47 #define OUTPUT 0x01
48 #define OUTPUT_OPEN_DRAIN 0x03
49 #define WAKEUP_PULLUP 0x05
50 #define WAKEUP_PULLDOWN 0x07
51 #define SPECIAL 0xF8 //defaults to the usable BUSes uart0rx/tx uart1tx and hspi
52 #define FUNCTION_0 0x08
53 #define FUNCTION_1 0x18
54 #define FUNCTION_2 0x28
55 #define FUNCTION_3 0x38
56 #define FUNCTION_4 0x48
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 // Defined in ctypes
66 //#define true 0x1
67 //#define false 0x0
68 //#define TRUE 0x1
69 //#define FALSE 0x0
70 #define null NULL
71 
72 #define DEC 10
73 #define HEX 16
74 #define OCT 8
75 #define BIN 2
76 
77 #define PI (3.1415926535897932384626433832795)
78 #define TWO_PI (6.283185307179586476925286766559)
79 #define HALF_PI (1.5707963267948966192313216916398)
80 #define EPSILON (0.0001)
81 #define DEG_TO_RAD (0.017453292519943295769236907684886)
82 #define RAD_TO_DEG (57.295779513082320876798154814105)
83 
84 
85 /*************************************************************
86  * Digital Constants
87  *************************************************************/
88 
89 #define PORT0 0
90 #define PORT1 1
91 #define PORT2 2
92 #define PORT3 3
93 #define PORT4 4
94 #define PORT5 5
95 #define PORT6 6
96 #define PORT7 7
97 #define PORT8 8
98 #define PORT9 9
99 
100 
101 /*************************************************************
102  * Useful macros
103  *************************************************************/
104 
105 /*#define int(x) ((int)(x))
106 #define char(x) ((char)(x))
107 #define long(x) ((long)(x))
108 #define byte(x) ((uint8_t)(x))
109 #define float(x) ((float)(x))
110 #define boolean(x) ((uint8_t)((x)==0?false:true))
111 */
112 
113 #define word(...) makeWord(__VA_ARGS__)
114 
115 #define sq(x) ((x)*(x))
116 //#define abs(x) ((x)>0?(x):-(x))
117 //#ifndef min
118 //#define min(a,b) ((a)<(b)?(a):(b))
119 //#endif
120 //#ifndef max
121 //#define max(a,b) ((a)>(b)?(a):(b))
122 //#endif
123 //#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
124 #define radians(deg) ((deg)*DEG_TO_RAD)
125 #define degrees(rad) ((rad)*RAD_TO_DEG)
126 #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
127 
128 #define lowByte(x) ((uint8_t) ((x) & 0x00ff))
129 #define highByte(x) ((uint8_t) ((x)>>8))
130 
131 
132 #define clockCyclesPerMicrosecond() (F_CPU / 1000000L)
133 #define clockCyclesToMicroseconds(a) ((a) / clockCyclesPerMicrosecond())
134 #define microsecondsToClockCycles(a) ((a) * clockCyclesPerMicrosecond())
135 
136 
137 
138 /*************************************************************
139  * Typedefs
140  *************************************************************/
141 
142 typedef unsigned int word;
143 typedef uint8_t byte;
144 typedef uint8_t boolean;
145 typedef void (*voidFuncPtr)(void);
146 
147 #endif
148 // WCONSTANTS_H