From 8990c57fab95bf5c28c64d8fc1c04d857e50555b Mon Sep 17 00:00:00 2001 From: Owen L - SFE Date: Fri, 15 Nov 2019 09:24:37 -0700 Subject: [PATCH 1/3] perform conditional setup of the adc this should be pretty uncontroversial - instead of always initializing the ADC it will only happen the first time analogRead gets called. This prevents surprises when runnin bare-HAL code --- cores/arduino/ard_sup/analog/ap3_analog.cpp | 6 ++++++ cores/arduino/ard_sup/main.cpp | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cores/arduino/ard_sup/analog/ap3_analog.cpp b/cores/arduino/ard_sup/analog/ap3_analog.cpp index a940677c..95936671 100644 --- a/cores/arduino/ard_sup/analog/ap3_analog.cpp +++ b/cores/arduino/ard_sup/analog/ap3_analog.cpp @@ -125,6 +125,12 @@ uint8_t _servoWriteBits = 8; // 8-bit by default for writes uint16_t analogRead(uint8_t pinNumber) { + static bool ap3_adc_initialized = false; + if(!ap3_adc_initialized){ + ap3_adc_setup(); + ap3_adc_initialized = true; + } + uint32_t ui32IntMask; am_hal_adc_sample_t Sample; uint32_t ui32NumSamples = 1; diff --git a/cores/arduino/ard_sup/main.cpp b/cores/arduino/ard_sup/main.cpp index 869f9088..1464324d 100644 --- a/cores/arduino/ard_sup/main.cpp +++ b/cores/arduino/ard_sup/main.cpp @@ -21,7 +21,7 @@ extern "C" int main(void) ap3_variant_init(); - ap3_adc_setup(); + // ap3_adc_setup(); setup(); for (;;) From 16a2bcd0d5eca0d6c47bc8ab48c01308a2d984be Mon Sep 17 00:00:00 2001 From: Owen L - SFE Date: Fri, 15 Nov 2019 09:27:25 -0700 Subject: [PATCH 2/3] remove min/max macros This is more controversial. We need to figure out how this plays with examples and such. The reason for removing these is that they seem to conflict with the STL library, and that is used in TFLM. --- cores/arduino/ard_sup/Arduino_defines.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/arduino/ard_sup/Arduino_defines.h b/cores/arduino/ard_sup/Arduino_defines.h index dc8e72c1..65057adb 100644 --- a/cores/arduino/ard_sup/Arduino_defines.h +++ b/cores/arduino/ard_sup/Arduino_defines.h @@ -28,8 +28,8 @@ #undef abs #endif // abs -#define min(a, b) ((a) < (b) ? (a) : (b)) -#define max(a, b) ((a) > (b) ? (a) : (b)) +// #define min(a, b) ((a) < (b) ? (a) : (b)) +// #define max(a, b) ((a) > (b) ? (a) : (b)) #define abs(x) ((x) > 0 ? (x) : -(x)) #define constrain(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt))) #define round(x) ((x) >= 0 ? (long)((x) + 0.5) : (long)((x)-0.5)) From 979698529c171d30f0b2f0dea128f3638e67f247 Mon Sep 17 00:00:00 2001 From: Owen L - SFE Date: Fri, 15 Nov 2019 12:51:50 -0700 Subject: [PATCH 3/3] re-instate Arduino macros for min/max After discussion with Kirk we agreed that ```that's just the way it is``` in Arduino. Solved the TFLM example support by simply placing this at the top of the example ``` c++ #ifdef min #undef min #endif #ifdef max #undef max #endif ``` --- cores/arduino/ard_sup/Arduino_defines.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/arduino/ard_sup/Arduino_defines.h b/cores/arduino/ard_sup/Arduino_defines.h index 65057adb..dc8e72c1 100644 --- a/cores/arduino/ard_sup/Arduino_defines.h +++ b/cores/arduino/ard_sup/Arduino_defines.h @@ -28,8 +28,8 @@ #undef abs #endif // abs -// #define min(a, b) ((a) < (b) ? (a) : (b)) -// #define max(a, b) ((a) > (b) ? (a) : (b)) +#define min(a, b) ((a) < (b) ? (a) : (b)) +#define max(a, b) ((a) > (b) ? (a) : (b)) #define abs(x) ((x) > 0 ? (x) : -(x)) #define constrain(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt))) #define round(x) ((x) >= 0 ? (long)((x) + 0.5) : (long)((x)-0.5))