Skip to content

Commit 6ba9921

Browse files
Add Arduino SAMD Packages_Patches
To fix Arduino SAMD compiler error when using STL
1 parent 7eef460 commit 6ba9921

File tree

3 files changed

+411
-61
lines changed

3 files changed

+411
-61
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/*
2+
Arduino.h - Main include file for the Arduino SDK
3+
Copyright (c) 2014 Arduino LLC. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
// KH, This is the fix according to https://github.com/arduino/ArduinoCore-samd/pull/399
21+
// to avoid notorious compiler error while uing STL (min and max macro error)
22+
// It's terrible Arduino has just released new core and still don't merge the PR
23+
24+
#ifndef Arduino_h
25+
#define Arduino_h
26+
27+
#include <stdbool.h>
28+
#include <stdint.h>
29+
#include <stdlib.h>
30+
#include <string.h>
31+
#include <math.h>
32+
33+
typedef bool boolean;
34+
typedef uint8_t byte;
35+
typedef uint16_t word;
36+
37+
// some libraries and sketches depend on this AVR stuff,
38+
// assuming Arduino.h or WProgram.h automatically includes it...
39+
//
40+
#include "avr/pgmspace.h"
41+
#include "avr/interrupt.h"
42+
#include "avr/io.h"
43+
#include "binary.h"
44+
#include "itoa.h"
45+
46+
#ifdef __cplusplus
47+
extern "C"{
48+
#endif // __cplusplus
49+
50+
// Include Atmel headers
51+
#include "sam.h"
52+
#include "wiring_constants.h"
53+
54+
#define clockCyclesPerMicrosecond() ( SystemCoreClock / 1000000L )
55+
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (SystemCoreClock / 1000L) )
56+
#define microsecondsToClockCycles(a) ( (a) * (SystemCoreClock / 1000000L) )
57+
void yield( void ) ;
58+
/* system functions */
59+
int main( void );
60+
void init( void );
61+
/* sketch */
62+
void setup( void ) ;
63+
void loop( void ) ;
64+
#include "WVariant.h"
65+
66+
#ifdef __cplusplus
67+
} // extern "C"
68+
#endif
69+
70+
71+
// The following headers are for C++ only compilation
72+
#ifdef __cplusplus
73+
#include "WCharacter.h"
74+
#include "WString.h"
75+
#include "Tone.h"
76+
#include "WMath.h"
77+
#include "HardwareSerial.h"
78+
#include "pulse.h"
79+
#include <bits/stl_algobase.h>
80+
#endif
81+
82+
#include "delay.h"
83+
84+
#ifdef __cplusplus
85+
#include "Uart.h"
86+
#endif
87+
88+
// Include board variant
89+
#include "variant.h"
90+
#include "wiring.h"
91+
#include "wiring_digital.h"
92+
#include "wiring_analog.h"
93+
#include "wiring_shift.h"
94+
#include "WInterrupts.h"
95+
96+
#ifndef __cplusplus
97+
// undefine stdlib's abs if encountered
98+
#ifdef abs
99+
#undef abs
100+
#endif // abs
101+
102+
#define min(a,b) ((a)<(b)?(a):(b))
103+
#define max(a,b) ((a)>(b)?(a):(b))
104+
#define abs(x) ((x)>0?(x):-(x))
105+
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
106+
107+
#else
108+
//using std::min;
109+
//using std::max;
110+
template<class T, class L>
111+
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
112+
{
113+
return (b < a) ? b : a;
114+
}
115+
116+
template<class T, class L>
117+
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
118+
{
119+
return (a < b) ? b : a;
120+
}
121+
#endif
122+
123+
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
124+
#define radians(deg) ((deg)*DEG_TO_RAD)
125+
#define degrees(rad) ((rad)*RAD_TO_DEG)
126+
#define sq(x) ((x)*(x))
127+
128+
#define interrupts() __enable_irq()
129+
#define noInterrupts() __disable_irq()
130+
131+
#define lowByte(w) ((uint8_t) ((w) & 0xff))
132+
#define highByte(w) ((uint8_t) ((w) >> 8))
133+
134+
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
135+
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
136+
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
137+
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
138+
#define bit(b) (1UL << (b))
139+
140+
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
141+
// Interrupts
142+
#define digitalPinToInterrupt(P) ( P )
143+
#endif
144+
145+
// Allows publishing the Beta core under samd-beta / arduino organization
146+
#ifndef ARDUINO_ARCH_SAMD
147+
#define ARDUINO_ARCH_SAMD
148+
#endif
149+
150+
// USB Device
151+
#include "USB/USBDesc.h"
152+
#include "USB/USBCore.h"
153+
#include "USB/USBAPI.h"
154+
#include "USB/USB_host.h"
155+
156+
#ifdef __cplusplus
157+
#include "USB/CDC.h"
158+
#endif
159+
160+
#endif // Arduino_h
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/*
2+
Arduino.h - Main include file for the Arduino SDK
3+
Copyright (c) 2014 Arduino LLC. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
// KH, This is the fix according to https://github.com/arduino/ArduinoCore-samd/pull/399
21+
// to avoid notorious compiler error while uing STL (min and max macro error)
22+
// It's terrible Arduino has just released new core and still don't merge the PR
23+
24+
#ifndef Arduino_h
25+
#define Arduino_h
26+
27+
#include <stdbool.h>
28+
#include <stdint.h>
29+
#include <stdlib.h>
30+
#include <string.h>
31+
#include <math.h>
32+
33+
typedef bool boolean;
34+
typedef uint8_t byte;
35+
typedef uint16_t word;
36+
37+
// some libraries and sketches depend on this AVR stuff,
38+
// assuming Arduino.h or WProgram.h automatically includes it...
39+
//
40+
#include "avr/pgmspace.h"
41+
#include "avr/interrupt.h"
42+
#include "avr/io.h"
43+
#include "binary.h"
44+
#include "itoa.h"
45+
46+
#ifdef __cplusplus
47+
extern "C"{
48+
#endif // __cplusplus
49+
50+
// Include Atmel headers
51+
#include "sam.h"
52+
#include "wiring_constants.h"
53+
54+
#define clockCyclesPerMicrosecond() ( SystemCoreClock / 1000000L )
55+
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (SystemCoreClock / 1000L) )
56+
#define microsecondsToClockCycles(a) ( (a) * (SystemCoreClock / 1000000L) )
57+
void yield( void ) ;
58+
/* system functions */
59+
int main( void );
60+
void init( void );
61+
/* sketch */
62+
void setup( void ) ;
63+
void loop( void ) ;
64+
#include "WVariant.h"
65+
66+
#ifdef __cplusplus
67+
} // extern "C"
68+
#endif
69+
70+
71+
// The following headers are for C++ only compilation
72+
#ifdef __cplusplus
73+
#include "WCharacter.h"
74+
#include "WString.h"
75+
#include "Tone.h"
76+
#include "WMath.h"
77+
#include "HardwareSerial.h"
78+
#include "pulse.h"
79+
#include <bits/stl_algobase.h>
80+
#endif
81+
82+
#include "delay.h"
83+
84+
#ifdef __cplusplus
85+
#include "Uart.h"
86+
#endif
87+
88+
// Include board variant
89+
#include "variant.h"
90+
#include "wiring.h"
91+
#include "wiring_digital.h"
92+
#include "wiring_analog.h"
93+
#include "wiring_shift.h"
94+
#include "WInterrupts.h"
95+
96+
#ifndef __cplusplus
97+
// undefine stdlib's abs if encountered
98+
#ifdef abs
99+
#undef abs
100+
#endif // abs
101+
102+
#define min(a,b) ((a)<(b)?(a):(b))
103+
#define max(a,b) ((a)>(b)?(a):(b))
104+
#define abs(x) ((x)>0?(x):-(x))
105+
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
106+
107+
#else
108+
//using std::min;
109+
//using std::max;
110+
template<class T, class L>
111+
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
112+
{
113+
return (b < a) ? b : a;
114+
}
115+
116+
template<class T, class L>
117+
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
118+
{
119+
return (a < b) ? b : a;
120+
}
121+
#endif
122+
123+
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
124+
#define radians(deg) ((deg)*DEG_TO_RAD)
125+
#define degrees(rad) ((rad)*RAD_TO_DEG)
126+
#define sq(x) ((x)*(x))
127+
128+
#define interrupts() __enable_irq()
129+
#define noInterrupts() __disable_irq()
130+
131+
#define lowByte(w) ((uint8_t) ((w) & 0xff))
132+
#define highByte(w) ((uint8_t) ((w) >> 8))
133+
134+
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
135+
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
136+
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
137+
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
138+
#define bit(b) (1UL << (b))
139+
140+
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
141+
// Interrupts
142+
#define digitalPinToInterrupt(P) ( P )
143+
#endif
144+
145+
// Allows publishing the Beta core under samd-beta / arduino organization
146+
#ifndef ARDUINO_ARCH_SAMD
147+
#define ARDUINO_ARCH_SAMD
148+
#endif
149+
150+
// USB Device
151+
#include "USB/USBDesc.h"
152+
#include "USB/USBCore.h"
153+
#include "USB/USBAPI.h"
154+
#include "USB/USB_host.h"
155+
156+
#ifdef __cplusplus
157+
#include "USB/CDC.h"
158+
#endif
159+
160+
#endif // Arduino_h

0 commit comments

Comments
 (0)