-
Notifications
You must be signed in to change notification settings - Fork 1
/
MacroOps.h
65 lines (47 loc) · 1.79 KB
/
MacroOps.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
/*
Copyright 2013 Miguel Rodas
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
* MacroOps.h
*
* Useful Macros
* Author: Miguel Rodas
* URL: https://github.com/mwheels/macroOps/
*/
#ifndef MACROOPS_H_
#define MACROOPS_H_
//Byte playing
#define HIGH_2BYTES(x) ( (uint16_t) ( (x) >> 16 ) )
#define LOW_2BYTES(x) ( (uint16_t) ( (x) & 0xFFFF ) )
#define MERGE_2BYTES(H,L) ( (uint32_t) ( ( (uint32_t)(H) << 16 ) | (L) ) )
#define HIGH_BYTE(x) ( (uint8_t) ( (x) >> 8 ) )
#define LOW_BYTE(x) ( (uint8_t) ( (x) & 0x00FF ) )
#define MERGE_BYTES(H,L) ( (uint16_t) ( ( (H) << 8) | (L) ) )
#define HIGH_NIBBLE(x) ( (uint8_t) ( (x) >> 4 ) )
#define LOW_NIBBLE(x) ( (uint8_t) ( (x) & 0x0F ) )
#define MERGE_NIBBLES(H,L) ( (uint8_t) ( ( (H) << 4 ) | ( 0x0F & (L) ) ) )
//Bit playing
#define SET_BIT(x, p) ( (x) | ( 1 << (p) ) )
#define CLEAR_BIT(x, p) ( (x) & ( ~( 1 << (p) ) ) )
#define GET_BIT(x, p) ( ( (x) >> (p) ) & 1)
#define TOGGLE_BIT(x,p) ( (x) ^ ( 1 << (p) ) )
//String playing
#define MERGE_STR(a,b) (a)##(b)
#define STR_EXPAND(s) #s
#define STR(s) STR_EXPAND(s)
//Math
#define MAX(x, y) ( ( (x) > (y) ) ? (x) : (y) )
#define MIN(x, y) ( ( (x) < (y) ) ? (x) : (y) )
#define PI 3.14159265
#define RAD2DEG(x) ( (x) / PI * 180 )
#define DEG2RAD(x) ( (x) * PI / 180 )
#endif /* MACROOPS_H_ */