-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
582 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <ArduinoUnitTests.h> | ||
#include <Arduino.h> | ||
|
||
// added to fix https://github.com/Arduino-CI/arduino_ci/issues/193 | ||
// https://github.com/arduino-libraries/Ethernet/blob/master/src/utility/w5100.h#L337 | ||
|
||
#if defined(__AVR__) | ||
unittest(portOutputRegister) | ||
{ | ||
uint8_t ss_pin = 12; | ||
uint8_t ss_port = digitalPinToPort(ss_pin); | ||
assertEqual(12, ss_port); | ||
uint8_t *ss_pin_reg = portOutputRegister(ss_port); | ||
assertEqual(GODMODE()->pMmapPort(ss_port), ss_pin_reg); | ||
uint8_t ss_pin_mask = digitalPinToBitMask(ss_pin); | ||
assertEqual(1, ss_pin_mask); | ||
|
||
assertEqual((int) 1, (int) *ss_pin_reg); // verify initial value | ||
*(ss_pin_reg) &= ~ss_pin_mask; // set SS | ||
assertEqual((int) 0, (int) *ss_pin_reg); // verify value | ||
*(ss_pin_reg) |= ss_pin_mask; // clear SS | ||
assertEqual((int) 1, (int) *ss_pin_reg); // verify value | ||
} | ||
#endif | ||
|
||
unittest_main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,126 @@ | ||
#pragma once | ||
#include "ArduinoDefines.h" | ||
#include <math.h> | ||
|
||
#define constrain(x,l,h) ((x)<(l)?(l):((x)>(h)?(h):(x))) | ||
#define map(x,inMin,inMax,outMin,outMax) (((x)-(inMin))*((outMax)-(outMin))/((inMax)-(inMin))+outMin) | ||
#ifdef __cplusplus | ||
|
||
#define sq(x) ((x)*(x)) | ||
template <class Amt, class Low, class High> | ||
auto constrain(const Amt &amt, const Low &low, const High &high) | ||
-> decltype(amt < low ? low : (amt > high ? high : amt)) { | ||
return (amt < low ? low : (amt > high ? high : amt)); | ||
} | ||
|
||
#define radians(deg) ((deg)*DEG_TO_RAD) | ||
#define degrees(rad) ((rad)*RAD_TO_DEG) | ||
template <class X, class InMin, class InMax, class OutMin, class OutMax> | ||
auto map(const X &x, const InMin &inMin, const InMax &inMax, | ||
const OutMin &outMin, const OutMax &outMax) | ||
-> decltype((x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin) { | ||
return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin; | ||
} | ||
|
||
#ifdef abs | ||
#undef abs | ||
#endif | ||
#define abs(x) ((x)>0?(x):-(x)) | ||
template <class T> auto radians(const T °) -> decltype(deg * DEG_TO_RAD) { | ||
return deg * DEG_TO_RAD; | ||
} | ||
|
||
#ifdef max | ||
#undef max | ||
#endif | ||
#define max(a,b) ((a)>(b)?(a):(b)) | ||
template <class T> auto degrees(const T &rad) -> decltype(rad * RAD_TO_DEG) { | ||
return rad * RAD_TO_DEG; | ||
} | ||
|
||
#ifdef min | ||
#undef min | ||
#endif | ||
#define min(a,b) ((a)<(b)?(a):(b)) | ||
template <class T> auto sq(const T &x) -> decltype(x * x) { return x * x; } | ||
|
||
template <class T> auto abs(const T &x) -> decltype(x > 0 ? x : -x) { | ||
return x > 0 ? x : -x; | ||
} | ||
|
||
template <class T, class L> | ||
auto min(const T &a, const L &b) -> decltype((b < a) ? b : a) { | ||
return (b < a) ? b : a; | ||
} | ||
|
||
template <class T, class L> | ||
auto max(const T &a, const L &b) -> decltype((b < a) ? b : a) { | ||
return (a < b) ? b : a; | ||
} | ||
|
||
#else // __cplusplus | ||
|
||
#ifdef constrain | ||
#undef constrain | ||
#endif | ||
#define constrain(amt, low, high) \ | ||
({ \ | ||
__typeof__(amt) _amt = (amt); \ | ||
__typeof__(low) _low = (low); \ | ||
__typeof__(high) _high = (high); \ | ||
(amt < low ? low : (amt > high ? high : amt)); \ | ||
}) | ||
|
||
#ifdef map | ||
#undef map | ||
#endif | ||
#define map(x, inMin, inMax, outMin, outMax) \ | ||
({ \ | ||
__typeof__(x) _x = (x); \ | ||
__typeof__(inMin) _inMin = (inMin); \ | ||
__typeof__(inMax) _inMax = (inMax); \ | ||
__typeof__(outMin) _outMin = (outMin); \ | ||
__typeof__(outMax) _outMax = (outMax); \ | ||
(_x - _inMin) * (_outMax - _outMin) / (_inMax - _inMin) + _outMin; \ | ||
}) | ||
|
||
#ifdef radians | ||
#undef radians | ||
#endif | ||
#define radians(deg) \ | ||
({ \ | ||
__typeof__(deg) _deg = (deg); \ | ||
_deg *DEG_TO_RAD; \ | ||
}) | ||
|
||
#ifdef degrees | ||
#undef degrees | ||
#endif | ||
#define degrees(rad) \ | ||
({ \ | ||
__typeof__(rad) _rad = (rad); \ | ||
_rad *RAD_TO_DEG; \ | ||
}) | ||
|
||
#ifdef sq | ||
#undef sq | ||
#endif | ||
#define sq(x) \ | ||
({ \ | ||
__typeof__(x) _x = (x); \ | ||
_x *_x; \ | ||
}) | ||
|
||
#ifdef abs | ||
#undef abs | ||
#endif | ||
#define abs(x) \ | ||
({ \ | ||
__typeof__(x) _x = (x); \ | ||
_x > 0 ? _x : -_x; \ | ||
}) | ||
|
||
#ifdef min | ||
#undef min | ||
#endif | ||
#define min(a, b) \ | ||
({ \ | ||
__typeof__(a) _a = (a); \ | ||
__typeof__(b) _b = (b); \ | ||
_a < _b ? _a : _b; \ | ||
}) | ||
|
||
#ifdef max | ||
#undef max | ||
#endif | ||
#define max(a, b) \ | ||
({ \ | ||
__typeof__(a) _a = (a); \ | ||
__typeof__(b) _b = (b); \ | ||
_a > _b ? _a : _b; \ | ||
}) | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.