Koduino
wiring_constants.h
1 
19 #ifndef _WIRING_CONSTANTS_
20 #define _WIRING_CONSTANTS_
21 
22 #include <stdint.h>
23 
24 #ifdef __cplusplus
25 extern "C"{
26 #endif // __cplusplus
27 
28 
29 
30 // cldoc:begin-category(Pins)
31 
32 // This is commented
33 // #define HIGH 0x1
34 // #define LOW 0x0
35 // #define TOGGLE 0x2
36 
37 // Types of pin modes
38 //
39 // This is Arduino compatible, except there are some extra options
40 // typedef enum PinMode {
41 // OUTPUT, OUTPUT_OPEN_DRAIN, INPUT, INPUT_ANALOG, INPUT_PULLUP, INPUT_PULLDOWN, ALTERNATE_FUNCTION, PWM_IN
42 // } PinMode;
43 
44 // cldoc:end-category()
45 
46 // typedef enum {
47 // LOW = 0, HIGH = 1, TOGGLE = 2
48 // } LogicValue;
49 
50 // #define INPUT 0x0
51 // #define OUTPUT 0x1
52 // #define INPUT_PULLUP 0x2
53 
54 // #define true 0x1
55 // #define false 0x0
56 
57 #ifndef PI
58 #define PI 3.1415926535897932384626433832795f
59 #endif
60 #define HALF_PI 1.5707963267948966192313216916398f
61 #define TWO_PI 6.283185307179586476925286766559f
62 #define DEG_TO_RAD 0.017453292519943295769236907684886f
63 #define RAD_TO_DEG 57.295779513082320876798154814105f
64 #define EULER 2.718281828459045235360287471352f
65 
66 #define SERIAL 0x0
67 #define DISPLAY 0x1
68 
69 enum BitOrder {
70  LSBFIRST = 0,
71  MSBFIRST = 1
72 };
73 
74 
75 // LOW 0
76 // HIGH 1
77 // #define CHANGE 2
78 // #define FALLING 3
79 // #define RISING 4
80 
81 // #define DEFAULT 1
82 // #define EXTERNAL 0
83 
84 // undefine stdlib's abs if encountered
85 #ifdef abs
86 #undef abs
87 #endif // abs
88 
89 #ifndef min
90 #define min(a,b) ((a)<(b)?(a):(b))
91 #endif // min
92 
93 #ifndef max
94 #define max(a,b) ((a)>(b)?(a):(b))
95 #endif // max
96 
97 #define abs(x) ((x)>0?(x):-(x))
98 #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
99 #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
100 #define radians(deg) ((deg)*DEG_TO_RAD)
101 #define degrees(rad) ((rad)*RAD_TO_DEG)
102 #define sq(x) ((x)*(x))
103 
104 // #define interrupts() __enable_irq()
105 // #define noInterrupts() __disable_irq()
106 
107 #define lowByte(w) ((uint8_t) ((w) & 0xff))
108 #define highByte(w) ((uint8_t) ((w) >> 8))
109 
110 #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
111 #define bitSet(value, bit) ((value) |= (1UL << (bit)))
112 #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
113 #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
114 
115 typedef unsigned int word;
116 
117 #define bit(b) (1UL << (b))
118 
119 // TODO: to be checked
120 typedef uint8_t boolean;
121 typedef uint8_t byte;
122 
123 
124 #ifdef __cplusplus
125 } // extern "C"
126 #endif // __cplusplus
127 
128 #endif /* _WIRING_CONSTANTS_ */