From 915de96e80ae44aad9e65d1311d8ed6f94ce32b2 Mon Sep 17 00:00:00 2001 From: pmantoine Date: Wed, 10 Aug 2022 10:45:33 +0800 Subject: [PATCH] DC mode portability for ARM (SAMD21/STM32) --- MotorDriver.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/MotorDriver.h b/MotorDriver.h index 7a155ae..03b5041 100644 --- a/MotorDriver.h +++ b/MotorDriver.h @@ -137,10 +137,12 @@ class MotorDriver { inline byte getSignalPin() { return signalPin; }; virtual void setDCSignal(byte speedByte); inline void detachDCSignal() { -#ifndef ARDUINO_ARCH_ESP32 - setDCSignal(128); -#else +#if defined(__arm__) + pinMode(brakePin, OUTPUT); +#elif defined(ARDUINO_ARCH_ESP32) ledcDetachPin(brakePin); +#else + setDCSignal(128); #endif }; virtual int getCurrentRaw(); @@ -148,7 +150,8 @@ class MotorDriver { virtual unsigned int raw2mA( int raw); virtual unsigned int mA2raw( unsigned int mA); inline bool brakeCanPWM() { -#ifdef ARDUINO_ARCH_ESP32 +#if defined(ARDUINO_ARCH_ESP32) || defined(__arm__) + // TODO: on ARM we can use digitalPinHasPWM, and may wish/need to return true; #else #ifdef digitalPinToTimer @@ -156,7 +159,7 @@ class MotorDriver { #else return (brakePin<14 && brakePin >1); #endif //digitalPinToTimer -#endif //ESP32 +#endif //ESP32/ARM } inline int getRawCurrentTripValue() { return rawCurrentTripValue;