Skip to content

Commit 436bbc6

Browse files
committed
libraries/SPI: remove pointless abs(...) call
SPI library code erroneously assumed that: - abs() is a C function, so include stdlib.h is required. what happens instead is Arduino.h shadows `abs()` with it's own macro - uint32_t() - int32_t() promotes to int32_t, thus needing abs() Fix both issues, leaving existing calculations as-is.
1 parent 83523c0 commit 436bbc6

File tree

2 files changed

+1
-2
lines changed

2 files changed

+1
-2
lines changed

libraries/SPI/SPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ void SPIClass::setFrequency(uint32_t freq) {
260260
break;
261261
} else if(calFreq < (int32_t) freq) {
262262
// never go over the requested frequency
263-
if(abs(freq - calFreq) < abs(freq - bestFreq)) {
263+
if((freq - calFreq) < (freq - bestFreq)) {
264264
bestFreq = calFreq;
265265
memcpy(&bestReg, &reg, sizeof(bestReg));
266266
}

libraries/SPI/SPI.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#define _SPI_H_INCLUDED
2323

2424
#include <Arduino.h>
25-
#include <stdlib.h>
2625

2726
#define SPI_HAS_TRANSACTION 1
2827

0 commit comments

Comments
 (0)