-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwiring_constants.h
263 lines (230 loc) · 7.74 KB
/
wiring_constants.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/*
Copyright (c) 2011 Arduino. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 20 Aug 2014 by MediaTek Inc.
*/
#ifndef _WIRING_CONSTANTS_
#define _WIRING_CONSTANTS_
#ifdef __cplusplus
extern "C"{
#endif // __cplusplus
/* DOM-NOT_FOR_SDK-BEGIN */
#define HIGH 0x1
#define LOW 0x0
#define INPUT 0x0
#define OUTPUT 0x1
#define INPUT_PULLUP 0x2
#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 //褒僅蛌說僅
#define EULER 2.718281828459045235360287471352
#define SERIAL 0x0
#define DISPLAY 0x1
enum BitOrder {
LSBFIRST = 0,
MSBFIRST = 1
};
// LOW 0
// HIGH 1
#define CHANGE 2
#define FALLING 3
#define RISING 4
#define DEFAULT 1
#define EXTERNAL 0
// undefine stdlib's abs if encountered
#ifdef abs
#undef abs
#endif // abs
/* DOM-NOT_FOR_SDK-END */
#ifndef min
/*****************************************************************************
* <GROUP Core_Math>
* FUNCTION
* min
* DESCRIPTION
* Calculates the minimum of two numbers.
* PARAMETERS
* x: the first number, any data type
* y: the second number, any data type
* RETURNS
* The smaller of the two numbers.
* RETURN VALUES
* depend on input value
*****************************************************************************/
#define min(a,b) ((a)<(b)?(a):(b))
#endif // min
#ifndef max
/*****************************************************************************
* <GROUP Core_Math>
* FUNCTION
* max
* DESCRIPTION
* Calculates the maximum of two numbers.
* PARAMETERS
* x: the first number, any data type
* y: the second number, any data type
* RETURNS
* The larger of the two numbers.
* RETURN VALUES
* depend on input value
*****************************************************************************/
#define max(a,b) ((a)>(b)?(a):(b))
#endif // max
/*****************************************************************************
* <GROUP Core_Math>
* FUNCTION
* abs
* DESCRIPTION
* Computes the absolute value of a number.
* PARAMETERS
* x: the number
* RETURNS
* x: if x is greater than or equal to 0.
* -x: if x is less than 0.
* RETURN VALUES
* depend on input value
*****************************************************************************/
#define abs(x) ((x)>0?(x):-(x))
/*****************************************************************************
* <GROUP Core_Math>
* FUNCTION
* constrain
* DESCRIPTION
* Constrains a number to be within a range.
* PARAMETERS
* x: the number to constrain, all data types
* a: the lower end of the range, all data types
* b: the upper end of the range, all data types
* RETURNS
* x: if x is between a and b
* a: if x is less than a
* b: if x is greater than b
* RETURN VALUES
* depend on input value
*****************************************************************************/
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
/* DOM-NOT_FOR_SDK-BEGIN */
#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)) //源
/* DOM-NOT_FOR_SDK-END */
/*****************************************************************************
* FUNCTION
* lowByte
* DESCRIPTION
* Extracts the high-order (leftmost) byte of a word (or the second lowest byte of a larger data type).
* PARAMETERS
* x: a value of any type
* RETURNS
* byte
* RETURN VALUES
* depend on input value
*****************************************************************************/
#define lowByte(w) ((uint8_t) ((w) & 0xff))
/*****************************************************************************
* FUNCTION
* highByte
* DESCRIPTION
* Extracts the high-order (leftmost) byte of a word (or the second lowest byte of a larger data type).
* PARAMETERS
* x: a value of any type
* RETURNS
* byte
* RETURN VALUES
* depend on input value
*****************************************************************************/
#define highByte(w) ((uint8_t) ((w) >> 8))
/*****************************************************************************
* FUNCTION
* bitRead
* DESCRIPTION
* Reads a bit of a number.
* PARAMETERS
* x: the number from which to read
* n: which bit to read, starting at 0 for the least-significant (rightmost) bit
* RETURNS
* the value of the bit (0 or 1).
* RETURN VALUES
* depend on input value
*****************************************************************************/
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
/*****************************************************************************
* FUNCTION
* bitSet
* DESCRIPTION
* Sets (writes a 1 to) a bit of a numeric variable.
* PARAMETERS
* x: the numeric variable whose bit to set
* n: which bit to set, starting at 0 for the least-significant (rightmost) bit
* RETURNS
* none
*****************************************************************************/
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
/*****************************************************************************
* FUNCTION
* bitClear
* DESCRIPTION
* Clears (writes a 0 to) a bit of a numeric variable.
* PARAMETERS
* x: the numeric variable whose bit to clear
* n: which bit to clear, starting at 0 for the least-significant (rightmost) bit
* RETURNS
* none
*****************************************************************************/
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
/*****************************************************************************
* FUNCTION
* bitWrite
* DESCRIPTION
* Writes a bit of a numeric variable.
* PARAMETERS
* x: the numeric variable to which to write
* n: which bit of the number to write, starting at 0 for the least-significant (rightmost) bit
* b: the value to write to the bit (0 or 1)
* RETURNS
* the value of the bit
* RETURN VALUES
* depend on input value
*****************************************************************************/
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
/* DOM-NOT_FOR_SDK-BEGIN */
typedef unsigned int word;
/* DOM-NOT_FOR_SDK-END */
/*****************************************************************************
* FUNCTION
* bit
* DESCRIPTION
* Computes the value of the specified bit (bit 0 is 1, bit 1 is 2, bit 2 is 4, etc.).
* PARAMETERS
* b: the bit whose value to compute
* RETURNS
* the value of the bit
* RETURN VALUES
* depend on input value
*****************************************************************************/
#define bit(b) (1UL << (b))
#define _BV(bit) (1 << (bit))
/* DOM-NOT_FOR_SDK-BEGIN */
// TODO: to be checked
typedef uint8_t boolean ;
typedef uint8_t byte ;
/* DOM-NOT_FOR_SDK-END */
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif /* _WIRING_CONSTANTS_ */