-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use maximum ADC resolution, Array bounds checks
- Loading branch information
Showing
17 changed files
with
145 additions
and
60 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
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,68 @@ | ||
#pragma once | ||
|
||
/** | ||
* @file | ||
* @brief This file contains the platform-specific ADC resolutions. | ||
* By default, the library automatically selects the maximum supported | ||
* resolution for known boards, otherwise, it falls back to 10 bits. | ||
* @see ADC_BITS | ||
*/ | ||
|
||
#include <Arduino.h> | ||
|
||
#if defined(ADC_RESOLUTION) | ||
#define HAS_ANALOG_READ_RESOLUTION 1 | ||
|
||
// Teensy | ||
//------------------------------------------------------------------------------ | ||
#elif defined(TEENSYDUINO) && !defined(DOXYGEN) | ||
|
||
#if defined(__AVR__) // Teensy 2.x | ||
#define ADC_RESOLUTION 10 | ||
#define HAS_ANALOG_READ_RESOLUTION 0 | ||
|
||
#elif defined(__MK20DX128__) // Teensy 3.0 | ||
#define ADC_RESOLUTION 13 | ||
#define HAS_ANALOG_READ_RESOLUTION 1 | ||
|
||
#elif defined(__MK20DX256__) // Teensy 3.1/3.2 | ||
#define ADC_RESOLUTION 13 | ||
#define HAS_ANALOG_READ_RESOLUTION 1 | ||
|
||
#elif defined(__MKL26Z64__) // Teensy LC | ||
#define ADC_RESOLUTION 12 | ||
#define HAS_ANALOG_READ_RESOLUTION 1 | ||
|
||
#elif defined(__MK64FX512__) // Teensy 3.5 | ||
#define ADC_RESOLUTION 13 | ||
#define HAS_ANALOG_READ_RESOLUTION 1 | ||
|
||
#elif defined(__MK66FX1M0__) // Teensy 3.6 | ||
#define ADC_RESOLUTION 13 | ||
#define HAS_ANALOG_READ_RESOLUTION 1 | ||
|
||
#elif defined(__IMXRT1062__) || defined(__IMXRT1052__) // Teensy 4.0 | ||
#define ADC_RESOLUTION 12 | ||
#define HAS_ANALOG_READ_RESOLUTION 1 | ||
|
||
#else | ||
#warning "Unknown Teensy board, please open an issue on GitHub" \ | ||
"https://github.com/tttapa/Control-Surface" | ||
#endif | ||
|
||
// ESP32 | ||
//------------------------------------------------------------------------------ | ||
#elif defined(ESP32) | ||
|
||
#define ADC_RESOLUTION 12 | ||
#define HAS_ANALOG_READ_RESOLUTION 1 | ||
|
||
// Unknown/Default | ||
//------------------------------------------------------------------------------ | ||
#else | ||
/// The actual maximum resolution of the built-in ADC. | ||
#define ADC_RESOLUTION 10 | ||
/// Whether the platform supports the `analogReadResolution` function. | ||
#define HAS_ANALOG_READ_RESOLUTION 0 | ||
|
||
#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
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,19 +1,22 @@ | ||
#pragma once | ||
|
||
#include <Arduino.h> | ||
#include <Settings/NamespaceSettings.hpp> | ||
|
||
BEGIN_CS_NAMESPACE | ||
#ifdef min | ||
#undef min | ||
#endif | ||
template <class T, class U> | ||
auto min(const T &a, const U &b) -> decltype(b < a ? b : a) { | ||
constexpr auto min(const T &a, const U &b) -> decltype(b < a ? b : a) { | ||
return b < a ? b : a; | ||
} | ||
#endif | ||
|
||
#ifdef max | ||
#undef max | ||
#endif | ||
template <class T, class U> | ||
auto max(const T &a, const U &b) -> decltype(b < a ? b : a) { | ||
constexpr auto max(const T &a, const U &b) -> decltype(b < a ? b : a) { | ||
return a < b ? b : a; | ||
} | ||
#endif | ||
END_CS_NAMESPACE |
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
Oops, something went wrong.