Skip to content

Commit a546da2

Browse files
committed
Fixed min/max definition and other macros as well
It seems that #include <stdint.h> is able to undef "min" and "max" previously defined. With this commit we make sure that they are defined as last. Fix #10
1 parent 74e68be commit a546da2

File tree

3 files changed

+28
-41
lines changed

3 files changed

+28
-41
lines changed

cores/arduino/Arduino.h

+27
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,33 @@ void loop( void ) ;
8585
#include "wiring_shift.h"
8686
#include "WInterrupts.h"
8787

88+
// undefine stdlib's abs if encountered
89+
#ifdef abs
90+
#undef abs
91+
#endif // abs
92+
93+
#define min(a,b) ((a)<(b)?(a):(b))
94+
#define max(a,b) ((a)>(b)?(a):(b))
95+
#define abs(x) ((x)>0?(x):-(x))
96+
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
97+
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
98+
#define radians(deg) ((deg)*DEG_TO_RAD)
99+
#define degrees(rad) ((rad)*RAD_TO_DEG)
100+
#define sq(x) ((x)*(x))
101+
102+
#define interrupts() __enable_irq()
103+
#define noInterrupts() __disable_irq()
104+
105+
#define lowByte(w) ((uint8_t) ((w) & 0xff))
106+
#define highByte(w) ((uint8_t) ((w) >> 8))
107+
108+
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
109+
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
110+
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
111+
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
112+
113+
#define bit(b) (1UL << (b))
114+
88115
// USB Device
89116
#include "USB/USBDesc.h"
90117
#include "USB/USBCore.h"

cores/arduino/USB/USBCore.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@
1616
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1717
*/
1818

19-
#include <stdlib.h>
20-
#include <stdio.h>
21-
#include <stdint.h>
22-
23-
#include "sam.h"
24-
#include "wiring_constants.h"
19+
#include "../Arduino.h"
2520
#include "USBCore.h"
2621
#include "USB/USB_device.h" // needed for USB PID define
2722
#include "USBDesc.h"

cores/arduino/wiring_constants.h

-35
Original file line numberDiff line numberDiff line change
@@ -56,41 +56,6 @@ enum BitOrder {
5656
//#define DEFAULT 1
5757
//#define EXTERNAL 0
5858

59-
// undefine stdlib's abs if encountered
60-
61-
//#ifdef abs
62-
//#undef abs
63-
//#endif // abs
64-
65-
66-
#ifndef min
67-
#define min(a,b) ((a)<(b)?(a):(b))
68-
#endif // min
69-
70-
#ifndef max
71-
#define max(a,b) ((a)>(b)?(a):(b))
72-
#endif // max
73-
74-
//#define abs(x) ((x)>0?(x):-(x))
75-
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
76-
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
77-
#define radians(deg) ((deg)*DEG_TO_RAD)
78-
#define degrees(rad) ((rad)*RAD_TO_DEG)
79-
#define sq(x) ((x)*(x))
80-
81-
#define interrupts() __enable_irq()
82-
#define noInterrupts() __disable_irq()
83-
84-
#define lowByte(w) ((uint8_t) ((w) & 0xff))
85-
#define highByte(w) ((uint8_t) ((w) >> 8))
86-
87-
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
88-
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
89-
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
90-
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
91-
92-
#define bit(b) (1UL << (b))
93-
9459
#ifdef __cplusplus
9560
} // extern "C"
9661
#endif // __cplusplus

0 commit comments

Comments
 (0)