Skip to content

Commit 67396b8

Browse files
committed
Split Common.h into separate Wiring headers
1 parent 8ad0c60 commit 67396b8

17 files changed

+276
-176
lines changed

api/ArduinoAPI.h

+15-11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@
2323
// version 1.0.0
2424
#define ARDUINO_API_VERSION 10000
2525

26+
#include "WTypes.h"
27+
28+
#include "WAnalog.h"
29+
#include "WCharacter.h"
30+
#include "WDelay.h"
31+
#include "WDigital.h"
32+
#include "WInterrupts.h"
33+
#include "WMath.h"
34+
#include "WMemory.h"
35+
#include "WPulse.h"
36+
#include "WRandom.h"
37+
#include "WShift.h"
38+
#include "WTime.h"
39+
#include "WTone.h"
40+
2641
#include "Binary.h"
2742

2843
#ifdef __cplusplus
@@ -39,17 +54,6 @@
3954
#include "Stream.h"
4055
#include "Udp.h"
4156
#include "USBAPI.h"
42-
#include "WCharacter.h"
4357
#endif
4458

45-
/* Standard C library includes */
46-
#include <stdlib.h>
47-
#include <stdint.h>
48-
#include <stdbool.h>
49-
#include <string.h>
50-
#include <math.h>
51-
52-
// Misc Arduino core functions
53-
#include "Common.h"
54-
5559
#endif

api/Common.cpp

-10
This file was deleted.

api/Common.h

-153
This file was deleted.

api/Interrupts.h

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <stdlib.h>
66
#include <stdbool.h>
77
#include <stdint.h>
8-
#include "Common.h"
98

109
template <typename T>
1110
using voidTemplateFuncPtrParam = void (*)(T param);

api/Stream.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
findMulti/findUntil routines written by Jim Leonard/Xuth
2323
*/
2424

25-
#include "Common.h"
2625
#include "Stream.h"
2726

27+
#include "WTime.h"
28+
2829
#define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait
2930

3031
// private method to read stream with timeout

api/WAnalog.h

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#include <stdint.h>
4+
5+
#ifdef __cplusplus
6+
extern "C"{
7+
#endif
8+
9+
int analogRead(pin_size_t pinNumber);
10+
void analogReference(uint8_t mode);
11+
void analogWrite(pin_size_t pinNumber, int value);
12+
13+
void analogReadResolution(int bits);
14+
void analogWriteResolution(int bits);
15+
16+
#ifdef __cplusplus
17+
} // extern "C"
18+
#endif

api/WDelay.h

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#ifdef __cplusplus
4+
extern "C"{
5+
#endif
6+
7+
void delay(unsigned long ms);
8+
void delayMicroseconds(unsigned int us);
9+
10+
#ifdef __cplusplus
11+
} // extern "C"
12+
#endif

api/WDigital.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include "WTypes.h"
4+
5+
#ifdef __cplusplus
6+
extern "C"{
7+
#endif
8+
9+
void pinMode(pin_size_t pinNumber, PinMode pinMode);
10+
void digitalWrite(pin_size_t pinNumber, PinStatus status);
11+
PinStatus digitalRead(pin_size_t pinNumber);
12+
13+
#ifdef __cplusplus
14+
} // extern "C"
15+
#endif

api/WInterrupts.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#pragma once
2+
3+
#include "WTypes.h"
4+
5+
#include <stdint.h>
6+
7+
// interrupts() / noInterrupts() must be defined by the core
8+
9+
#ifdef __cplusplus
10+
extern "C"{
11+
#endif
12+
13+
typedef void (*voidFuncPtr)(void);
14+
typedef void (*voidFuncPtrParam)(void*);
15+
16+
void attachInterrupt(pin_size_t interruptNumber, voidFuncPtr callback, PinStatus mode);
17+
void attachInterruptParam(pin_size_t interruptNumber, voidFuncPtrParam callback, PinStatus mode, void* param);
18+
void detachInterrupt(pin_size_t interruptNumber);
19+
20+
#ifdef __cplusplus
21+
} // extern "C"
22+
#endif

api/WMath.h

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#pragma once
2+
3+
#include <math.h>
4+
#include "WTypes.h"
5+
6+
#define PI 3.1415926535897932384626433832795
7+
#define HALF_PI 1.5707963267948966192313216916398
8+
#define TWO_PI 6.283185307179586476925286766559
9+
10+
#define EPSILON (0.0001)
11+
12+
#define DEG_TO_RAD 0.017453292519943295769236907684886
13+
#define RAD_TO_DEG 57.295779513082320876798154814105
14+
15+
#define EULER 2.718281828459045235360287471352
16+
17+
// undefine stdlib's abs if encountered
18+
#ifdef abs
19+
#undef abs
20+
#endif
21+
#define abs(x) ((x)>0?(x):-(x))
22+
23+
#ifndef constrain
24+
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
25+
#endif
26+
27+
long map(long x, long in_min, long in_max, long out_min, long out_max);
28+
29+
#define min(a,b) ((a)<(b)?(a):(b))
30+
#define max(a,b) ((a)>(b)?(a):(b))
31+
32+
#ifndef min
33+
#define min(a,b) \
34+
({ __typeof__ (a) _a = (a); \
35+
__typeof__ (b) _b = (b); \
36+
_a < _b ? _a : _b; })
37+
#endif
38+
39+
#ifndef max
40+
#define max(a,b) \
41+
({ __typeof__ (a) _a = (a); \
42+
__typeof__ (b) _b = (b); \
43+
_a > _b ? _a : _b; })
44+
#endif
45+
46+
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
47+
48+
#ifndef radians
49+
#define radians(deg) ((deg)*DEG_TO_RAD)
50+
#endif
51+
52+
#ifndef degrees
53+
#define degrees(rad) ((rad)*RAD_TO_DEG)
54+
#endif
55+
56+
#ifndef sq
57+
#define sq(x) ((x)*(x))
58+
#endif
59+
60+
#define lowByte(x) ((uint8_t)((x) & 0xff))
61+
#define highByte(x) ((uint8_t)((x) >> 8))
62+
63+
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
64+
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
65+
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
66+
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
67+
68+
#ifndef bit
69+
#define bit(b) (1UL << (b))
70+
#endif
71+
72+
#ifdef __cplusplus
73+
74+
word makeWord(uint16_t w);
75+
word makeWord(byte h, byte l);
76+
77+
#define word(...) makeWord(__VA_ARGS__)
78+
79+
#endif

api/WMemory.h

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#ifdef __cplusplus
4+
#include <stdlib.h>
5+
6+
void *operator new(size_t size);
7+
void operator delete(void *ptr);
8+
void *operator new[](size_t size);
9+
void operator delete[](void *ptr);
10+
11+
#endif

0 commit comments

Comments
 (0)