From 4fe216f3c77e894136edad7db5cfa4f3e6464795 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Wed, 1 Jul 2020 17:37:32 +0200 Subject: [PATCH 01/12] Support for AC Dimmer --- tasmota/core_esp8266_wiring_pwm.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tasmota/core_esp8266_wiring_pwm.cpp b/tasmota/core_esp8266_wiring_pwm.cpp index f74334e43..95ac7aefc 100644 --- a/tasmota/core_esp8266_wiring_pwm.cpp +++ b/tasmota/core_esp8266_wiring_pwm.cpp @@ -31,6 +31,7 @@ extern "C" { static uint32_t analogMap = 0; static int32_t analogScale = PWMRANGE; static uint16_t analogFreq = 1000; +static uint32_t analogDrift = 10000; extern void __analogWriteRange(uint32_t range) { if (range > 0) { @@ -48,11 +49,19 @@ extern void __analogWriteFreq(uint32_t freq) { } } -extern void __analogWrite(uint8_t pin, int val) { + +extern void __analogWriteCCyPeriod(uint8_t pin, int val, uint32_t period) { if (pin > 16) { return; } - uint32_t analogPeriod = microsecondsToClockCycles(1000000UL) / analogFreq; + uint32_t analogPeriod; + if (period == 0) { + analogPeriod = microsecondsToClockCycles(1000000UL) / analogFreq; + } else { + analogPeriod = period; + } + + //uint32_t analogPeriod = microsecondsToClockCycles(1000000UL) / analogFreq; if (val < 0) { val = 0; } else if (val > analogScale) { @@ -72,12 +81,18 @@ extern void __analogWrite(uint8_t pin, int val) { if (startWaveformClockCycles(pin, high, low, 0, phaseReference, 0, true)) { analogMap |= (1 << pin); } + //Serial.printf("phase: %d, high %d, low %d, drift %d, apr: %u\n", phaseReference,high,low, analogDrift, analogPeriod ); } +extern void __analogWrite(uint8_t pin, int val) { + __analogWriteCCyPeriod( pin, val, 0); +} + +extern void analogWriteCCyPeriod(uint8_t pin, int val, uint32_t priod) __attribute__((weak, alias("__analogWriteCCyPeriod"))); extern void analogWrite(uint8_t pin, int val) __attribute__((weak, alias("__analogWrite"))); extern void analogWriteFreq(uint32_t freq) __attribute__((weak, alias("__analogWriteFreq"))); extern void analogWriteRange(uint32_t range) __attribute__((weak, alias("__analogWriteRange"))); }; -#endif // ESP8266 +#endif // ESP8266 From 2d3d4863b4ef5d6f761e1b9cfa0cf729f446db51 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Wed, 1 Jul 2020 17:38:49 +0200 Subject: [PATCH 02/12] Update core_esp8266_wiring_pwm.cpp --- tasmota/core_esp8266_wiring_pwm.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tasmota/core_esp8266_wiring_pwm.cpp b/tasmota/core_esp8266_wiring_pwm.cpp index 95ac7aefc..1c7704b46 100644 --- a/tasmota/core_esp8266_wiring_pwm.cpp +++ b/tasmota/core_esp8266_wiring_pwm.cpp @@ -31,7 +31,6 @@ extern "C" { static uint32_t analogMap = 0; static int32_t analogScale = PWMRANGE; static uint16_t analogFreq = 1000; -static uint32_t analogDrift = 10000; extern void __analogWriteRange(uint32_t range) { if (range > 0) { From c11e948b81a543dbcbb47cdfbccaad64fbd863f4 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Wed, 1 Jul 2020 17:46:13 +0200 Subject: [PATCH 03/12] Update xsns_01_counter.ino --- tasmota/xsns_01_counter.ino | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tasmota/xsns_01_counter.ino b/tasmota/xsns_01_counter.ino index 3dfbdfaaf..0af9ee8a3 100644 --- a/tasmota/xsns_01_counter.ino +++ b/tasmota/xsns_01_counter.ino @@ -44,6 +44,9 @@ struct COUNTER { bool any_counter = false; } Counter; +uint32_t last_cycle; +uint32_t cycle_time; + #ifndef ARDUINO_ESP8266_RELEASE_2_3_0 // Fix core 2.5.x ISR not in IRAM Exception void CounterUpdate(uint8_t index) ICACHE_RAM_ATTR; void CounterUpdate1(void) ICACHE_RAM_ATTR; @@ -75,7 +78,32 @@ void CounterUpdate(uint8_t index) Counter.timer_low_high[index] = time; Counter.pin_state ^= (1< Date: Wed, 1 Jul 2020 17:46:53 +0200 Subject: [PATCH 04/12] Add files via upload --- tasmota/Arduino.h | 300 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 300 insertions(+) create mode 100644 tasmota/Arduino.h diff --git a/tasmota/Arduino.h b/tasmota/Arduino.h new file mode 100644 index 000000000..d5db76310 --- /dev/null +++ b/tasmota/Arduino.h @@ -0,0 +1,300 @@ +/* + Arduino.h - Main include file for the Arduino SDK + Copyright (c) 2005-2013 Arduino Team. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef Arduino_h +#define Arduino_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "stdlib_noniso.h" +#include "binary.h" +#include "esp8266_peri.h" +#include "twi.h" +#include "core_esp8266_features.h" +#include "core_esp8266_version.h" + +#define HIGH 0x1 +#define LOW 0x0 + +#define PWMRANGE 1023 + +//GPIO FUNCTIONS +#define INPUT 0x00 +#define INPUT_PULLUP 0x02 +#define INPUT_PULLDOWN_16 0x04 // PULLDOWN only possible for pin16 +#define OUTPUT 0x01 +#define OUTPUT_OPEN_DRAIN 0x03 +#define WAKEUP_PULLUP 0x05 +#define WAKEUP_PULLDOWN 0x07 +#define SPECIAL 0xF8 //defaults to the usable BUSes uart0rx/tx uart1tx and hspi +#define FUNCTION_0 0x08 +#define FUNCTION_1 0x18 +#define FUNCTION_2 0x28 +#define FUNCTION_3 0x38 +#define FUNCTION_4 0x48 + +#define PI 3.1415926535897932384626433832795 +#define HALF_PI 1.5707963267948966192313216916398 +#define TWO_PI 6.283185307179586476925286766559 +#define DEG_TO_RAD 0.017453292519943295769236907684886 +#define RAD_TO_DEG 57.295779513082320876798154814105 +#define EULER 2.718281828459045235360287471352 + +#define SERIAL 0x0 +#define DISPLAY 0x1 + +#define LSBFIRST 0 +#define MSBFIRST 1 + +//Interrupt Modes +#define RISING 0x01 +#define FALLING 0x02 +#define CHANGE 0x03 +#define ONLOW 0x04 +#define ONHIGH 0x05 +#define ONLOW_WE 0x0C +#define ONHIGH_WE 0x0D + +#define DEFAULT 1 +#define EXTERNAL 0 + +//timer dividers +enum TIM_DIV_ENUM { + TIM_DIV1 = 0, //80MHz (80 ticks/us - 104857.588 us max) + TIM_DIV16 = 1, //5MHz (5 ticks/us - 1677721.4 us max) + TIM_DIV256 = 3 //312.5Khz (1 tick = 3.2us - 26843542.4 us max) +}; + + +//timer int_types +#define TIM_EDGE 0 +#define TIM_LEVEL 1 +//timer reload values +#define TIM_SINGLE 0 //on interrupt routine you need to write a new value to start the timer again +#define TIM_LOOP 1 //on interrupt the counter will start with the same value again + +#define timer1_read() (T1V) +#define timer1_enabled() ((T1C & (1 << TCTE)) != 0) +#define timer1_interrupted() ((T1C & (1 << TCIS)) != 0) + +typedef void(*timercallback)(void); + +void timer1_isr_init(void); +void timer1_enable(uint8_t divider, uint8_t int_type, uint8_t reload); +void timer1_disable(void); +void timer1_attachInterrupt(timercallback userFunc); +void timer1_detachInterrupt(void); +void timer1_write(uint32_t ticks); //maximum ticks 8388607 + +// timer0 is a special CPU timer that has very high resolution but with +// limited control. +// it uses CCOUNT (ESP.GetCycleCount()) as the non-resetable timer counter +// it does not support divide, type, or reload flags +// it is auto-disabled when the compare value matches CCOUNT +// it is auto-enabled when the compare value changes +#define timer0_interrupted() (ETS_INTR_PENDING() & (_BV(ETS_COMPARE0_INUM))) +#define timer0_read() ((__extension__({uint32_t count;__asm__ __volatile__("esync; rsr %0,ccompare0":"=a" (count));count;}))) +#define timer0_write(count) __asm__ __volatile__("wsr %0,ccompare0; esync"::"a" (count) : "memory") + +void timer0_isr_init(void); +void timer0_attachInterrupt(timercallback userFunc); +void timer0_detachInterrupt(void); + +// Use stdlib abs() and round() to avoid issues with the C++ libraries +#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) +#define radians(deg) ((deg)*DEG_TO_RAD) +#define degrees(rad) ((rad)*RAD_TO_DEG) +#define sq(x) ((x)*(x)) + +void ets_intr_lock(); +void ets_intr_unlock(); + +#define interrupts() xt_rsil(0) +#define noInterrupts() xt_rsil(15) + +#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) +#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) +#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) + +#define lowByte(w) ((uint8_t) ((w) & 0xff)) +#define highByte(w) ((uint8_t) ((w) >> 8)) + +#define bitRead(value, bit) (((value) >> (bit)) & 0x01) +#define bitSet(value, bit) ((value) |= (1UL << (bit))) +#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) +#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) + +// avr-libc defines _NOP() since 1.6.2 +#ifndef _NOP +#define _NOP() do { __asm__ volatile ("nop"); } while (0) +#endif + +typedef uint16_t word; + +#define bit(b) (1UL << (b)) +#define _BV(b) (1UL << (b)) + +typedef bool boolean; +typedef uint8_t byte; + +void init(void); +void initVariant(void); + +int atexit(void (*func)()) __attribute__((weak)); + +void pinMode(uint8_t pin, uint8_t mode); +void digitalWrite(uint8_t pin, uint8_t val); +int digitalRead(uint8_t pin); +int analogRead(uint8_t pin); +void analogReference(uint8_t mode); +void analogWrite(uint8_t pin, int val); +void analogWriteCCyPeriod(uint8_t pin, int val, uint32_t period); +void analogWriteFreq(uint32_t freq); +void analogWriteRange(uint32_t range); + +unsigned long millis(void); +unsigned long micros(void); +uint64_t micros64(void); +void delay(unsigned long); +void delayMicroseconds(unsigned int us); +unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); +unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout); + +void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); +uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); + +void attachInterrupt(uint8_t pin, void (*)(void), int mode); +void detachInterrupt(uint8_t pin); +void attachInterruptArg(uint8_t pin, void (*)(void*), void* arg, int mode); + +void preinit(void); +void setup(void); +void loop(void); + +void yield(void); + +void optimistic_yield(uint32_t interval_us); + +#define _PORT_GPIO16 1 +#define digitalPinToPort(pin) (((pin)==16)?(_PORT_GPIO16):(0)) +#define digitalPinToBitMask(pin) (((pin)==16)?(1):(1UL << (pin))) +#define digitalPinToTimer(pin) (0) +#define portOutputRegister(port) (((port)==_PORT_GPIO16)?((volatile uint32_t*) &GP16O):((volatile uint32_t*) &GPO)) +#define portInputRegister(port) (((port)==_PORT_GPIO16)?((volatile uint32_t*) &GP16I):((volatile uint32_t*) &GPI)) +#define portModeRegister(port) (((port)==_PORT_GPIO16)?((volatile uint32_t*) &GP16E):((volatile uint32_t*) &GPE)) + +#define NOT_A_PIN -1 +#define NOT_A_PORT -1 +#define NOT_AN_INTERRUPT -1 +#define NOT_ON_TIMER 0 + +#ifdef __cplusplus +} // extern "C" +#endif + + +//for compatibility, below 4 lines to be removed in release 3.0.0 +#ifdef __cplusplus +extern "C" +#endif +const int TIM_DIV265 __attribute__((deprecated, weak)) = TIM_DIV256; + + + +#ifdef __cplusplus + +#include +#include +#include + +#include "WCharacter.h" +#include "WString.h" + +#include "HardwareSerial.h" +#include "Esp.h" +#include "Updater.h" +#include "debug.h" + +using std::min; +using std::max; +using std::round; +using std::isinf; +using std::isnan; + +#define _min(a,b) ({ decltype(a) _a = (a); decltype(b) _b = (b); _a < _b? _a : _b; }) +#define _max(a,b) ({ decltype(a) _a = (a); decltype(b) _b = (b); _a > _b? _a : _b; }) + +uint16_t makeWord(uint16_t w); +uint16_t makeWord(byte h, byte l); + +#define word(...) makeWord(__VA_ARGS__) + +unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); +unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); + +void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); +void tone(uint8_t _pin, int frequency, unsigned long duration = 0); +void tone(uint8_t _pin, double frequency, unsigned long duration = 0); +void noTone(uint8_t _pin); + +// WMath prototypes +long random(long); +long random(long, long); +void randomSeed(unsigned long); +long secureRandom(long); +long secureRandom(long, long); +long map(long, long, long, long, long); + +void setTZ(const char* tz); + +void configTime(int timezone, int daylightOffset_sec, const char* server1, + const char* server2 = nullptr, const char* server3 = nullptr); + +void configTime(const char* tz, const char* server1, + const char* server2 = nullptr, const char* server3 = nullptr); + +// esp32 api compatibility +inline void configTzTime(const char* tz, const char* server1, + const char* server2 = nullptr, const char* server3 = nullptr) +{ + configTime(tz, server1, server2, server3); +} + +#endif // __cplusplus + +#include "pins_arduino.h" + +#endif + +#ifdef DEBUG_ESP_OOM +// reinclude *alloc redefinition because of undefining them +// this is mandatory for allowing OOM *alloc definitions in .ino files +#include "umm_malloc/umm_malloc_cfg.h" +#endif From 533f3142776e40dff6d7e3db8207e2eb783b21bd Mon Sep 17 00:00:00 2001 From: stefanbode Date: Wed, 1 Jul 2020 18:45:36 +0200 Subject: [PATCH 05/12] Update Arduino.h --- tasmota/Arduino.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tasmota/Arduino.h b/tasmota/Arduino.h index d5db76310..a4ef77535 100644 --- a/tasmota/Arduino.h +++ b/tasmota/Arduino.h @@ -17,6 +17,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifdef ESP8266 + #ifndef Arduino_h #define Arduino_h @@ -298,3 +300,5 @@ inline void configTzTime(const char* tz, const char* server1, // this is mandatory for allowing OOM *alloc definitions in .ino files #include "umm_malloc/umm_malloc_cfg.h" #endif + +#endif From 862262c34950977c87630537851e7cd83ff45ee8 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Thu, 2 Jul 2020 08:37:32 +0200 Subject: [PATCH 06/12] Update Arduino.h --- tasmota/Arduino.h | 191 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 190 insertions(+), 1 deletion(-) diff --git a/tasmota/Arduino.h b/tasmota/Arduino.h index a4ef77535..2dd8b22e2 100644 --- a/tasmota/Arduino.h +++ b/tasmota/Arduino.h @@ -16,7 +16,6 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - #ifdef ESP8266 #ifndef Arduino_h @@ -301,4 +300,194 @@ inline void configTzTime(const char* tz, const char* server1, #include "umm_malloc/umm_malloc_cfg.h" #endif +#else + +/* + Arduino.h - Main include file for the Arduino SDK + Copyright (c) 2005-2013 Arduino Team. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef Arduino_h +#define Arduino_h + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/semphr.h" +#include "esp32-hal.h" +#include "esp8266-compat.h" +#include "soc/gpio_reg.h" + +#include "stdlib_noniso.h" +#include "binary.h" + +#define PI 3.1415926535897932384626433832795 +#define HALF_PI 1.5707963267948966192313216916398 +#define TWO_PI 6.283185307179586476925286766559 +#define DEG_TO_RAD 0.017453292519943295769236907684886 +#define RAD_TO_DEG 57.295779513082320876798154814105 +#define EULER 2.718281828459045235360287471352 + +#define SERIAL 0x0 +#define DISPLAY 0x1 + +#define LSBFIRST 0 +#define MSBFIRST 1 + +//Interrupt Modes +#define RISING 0x01 +#define FALLING 0x02 +#define CHANGE 0x03 +#define ONLOW 0x04 +#define ONHIGH 0x05 +#define ONLOW_WE 0x0C +#define ONHIGH_WE 0x0D + +#define DEFAULT 1 +#define EXTERNAL 0 + +#ifndef __STRINGIFY +#define __STRINGIFY(a) #a +#endif + +#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) +#define radians(deg) ((deg)*DEG_TO_RAD) +#define degrees(rad) ((rad)*RAD_TO_DEG) +#define sq(x) ((x)*(x)) + +#define sei() +#define cli() +#define interrupts() sei() +#define noInterrupts() cli() + +#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) +#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) +#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) + +#define lowByte(w) ((uint8_t) ((w) & 0xff)) +#define highByte(w) ((uint8_t) ((w) >> 8)) + +#define bitRead(value, bit) (((value) >> (bit)) & 0x01) +#define bitSet(value, bit) ((value) |= (1UL << (bit))) +#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) +#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) + +// avr-libc defines _NOP() since 1.6.2 +#ifndef _NOP +#define _NOP() do { __asm__ volatile ("nop"); } while (0) +#endif + +#define bit(b) (1UL << (b)) +#define _BV(b) (1UL << (b)) + +#define digitalPinToPort(pin) (((pin)>31)?1:0) +#define digitalPinToBitMask(pin) (1UL << (((pin)>31)?((pin)-32):(pin))) +#define digitalPinToTimer(pin) (0) +#define analogInPinToBit(P) (P) +#define portOutputRegister(port) ((volatile uint32_t*)((port)?GPIO_OUT1_REG:GPIO_OUT_REG)) +#define portInputRegister(port) ((volatile uint32_t*)((port)?GPIO_IN1_REG:GPIO_IN_REG)) +#define portModeRegister(port) ((volatile uint32_t*)((port)?GPIO_ENABLE1_REG:GPIO_ENABLE_REG)) + +#define NOT_A_PIN -1 +#define NOT_A_PORT -1 +#define NOT_AN_INTERRUPT -1 +#define NOT_ON_TIMER 0 + +typedef bool boolean; +typedef uint8_t byte; +typedef unsigned int word; + +void setup(void); +void loop(void); + +long random(long, long); +void randomSeed(unsigned long); +long map(long, long, long, long, long); + +#ifdef __cplusplus +extern "C" { +#endif + +void init(void); +void initVariant(void); +void initArduino(void); + +unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); +unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout); + +uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); +void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); + +#ifdef __cplusplus +} + +#include +#include + +#include "WCharacter.h" +#include "WString.h" +#include "Stream.h" +#include "Printable.h" +#include "Print.h" +#include "IPAddress.h" +#include "Client.h" +#include "Server.h" +#include "Udp.h" +#include "HardwareSerial.h" +#include "Esp.h" + +using std::abs; +using std::isinf; +using std::isnan; +using std::max; +using std::min; +using ::round; + +uint16_t makeWord(uint16_t w); +uint16_t makeWord(byte h, byte l); + +#define word(...) makeWord(__VA_ARGS__) + +unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); +unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); + +extern "C" bool getLocalTime(struct tm * info, uint32_t ms = 5000); +extern "C" void configTime(long gmtOffset_sec, int daylightOffset_sec, + const char* server1, const char* server2 = nullptr, const char* server3 = nullptr); +extern "C" void configTzTime(const char* tz, + const char* server1, const char* server2 = nullptr, const char* server3 = nullptr); + +// WMath prototypes +long random(long); +#endif /* __cplusplus */ + +#define _min(a,b) ((a)<(b)?(a):(b)) +#define _max(a,b) ((a)>(b)?(a):(b)) + +#include "pins_arduino.h" + +#endif /* _ESP32_CORE_ARDUINO_H_ */ + #endif From 0509eee6a5da04ce95bd8ff49c7b3c8f56ebaa27 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Thu, 2 Jul 2020 08:42:43 +0200 Subject: [PATCH 07/12] Update xsns_01_counter.ino --- tasmota/xsns_01_counter.ino | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tasmota/xsns_01_counter.ino b/tasmota/xsns_01_counter.ino index 0af9ee8a3..18f1ed461 100644 --- a/tasmota/xsns_01_counter.ino +++ b/tasmota/xsns_01_counter.ino @@ -98,7 +98,11 @@ void CounterUpdate(uint8_t index) // add 100.000 cpu ticks to ensure right step calculation uint32_t steps = (current_cycle-last_cycle+100000)/(clockCyclesPerMicrosecond() * 10000); cycle_time = (current_cycle-last_cycle)/steps; - analogWriteCCyPeriod(Pin(GPIO_PWM1, index), 5, cycle_time ); + #ifdef ESP8266 + analogWriteCCyPeriod(Pin(GPIO_PWM1, index), 5, cycle_time ); + #else + analogWrite(Pin(GPIO_PWM1, index), 5); + #endif } last_cycle = current_cycle; } From fa4680bb616f27f9ab305ea33859922083f39aee Mon Sep 17 00:00:00 2001 From: stefanbode Date: Fri, 3 Jul 2020 08:59:48 +0200 Subject: [PATCH 08/12] Delete Arduino.h --- tasmota/Arduino.h | 493 ---------------------------------------------- 1 file changed, 493 deletions(-) delete mode 100644 tasmota/Arduino.h diff --git a/tasmota/Arduino.h b/tasmota/Arduino.h deleted file mode 100644 index 2dd8b22e2..000000000 --- a/tasmota/Arduino.h +++ /dev/null @@ -1,493 +0,0 @@ -/* - Arduino.h - Main include file for the Arduino SDK - Copyright (c) 2005-2013 Arduino Team. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -#ifdef ESP8266 - -#ifndef Arduino_h -#define Arduino_h - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "stdlib_noniso.h" -#include "binary.h" -#include "esp8266_peri.h" -#include "twi.h" -#include "core_esp8266_features.h" -#include "core_esp8266_version.h" - -#define HIGH 0x1 -#define LOW 0x0 - -#define PWMRANGE 1023 - -//GPIO FUNCTIONS -#define INPUT 0x00 -#define INPUT_PULLUP 0x02 -#define INPUT_PULLDOWN_16 0x04 // PULLDOWN only possible for pin16 -#define OUTPUT 0x01 -#define OUTPUT_OPEN_DRAIN 0x03 -#define WAKEUP_PULLUP 0x05 -#define WAKEUP_PULLDOWN 0x07 -#define SPECIAL 0xF8 //defaults to the usable BUSes uart0rx/tx uart1tx and hspi -#define FUNCTION_0 0x08 -#define FUNCTION_1 0x18 -#define FUNCTION_2 0x28 -#define FUNCTION_3 0x38 -#define FUNCTION_4 0x48 - -#define PI 3.1415926535897932384626433832795 -#define HALF_PI 1.5707963267948966192313216916398 -#define TWO_PI 6.283185307179586476925286766559 -#define DEG_TO_RAD 0.017453292519943295769236907684886 -#define RAD_TO_DEG 57.295779513082320876798154814105 -#define EULER 2.718281828459045235360287471352 - -#define SERIAL 0x0 -#define DISPLAY 0x1 - -#define LSBFIRST 0 -#define MSBFIRST 1 - -//Interrupt Modes -#define RISING 0x01 -#define FALLING 0x02 -#define CHANGE 0x03 -#define ONLOW 0x04 -#define ONHIGH 0x05 -#define ONLOW_WE 0x0C -#define ONHIGH_WE 0x0D - -#define DEFAULT 1 -#define EXTERNAL 0 - -//timer dividers -enum TIM_DIV_ENUM { - TIM_DIV1 = 0, //80MHz (80 ticks/us - 104857.588 us max) - TIM_DIV16 = 1, //5MHz (5 ticks/us - 1677721.4 us max) - TIM_DIV256 = 3 //312.5Khz (1 tick = 3.2us - 26843542.4 us max) -}; - - -//timer int_types -#define TIM_EDGE 0 -#define TIM_LEVEL 1 -//timer reload values -#define TIM_SINGLE 0 //on interrupt routine you need to write a new value to start the timer again -#define TIM_LOOP 1 //on interrupt the counter will start with the same value again - -#define timer1_read() (T1V) -#define timer1_enabled() ((T1C & (1 << TCTE)) != 0) -#define timer1_interrupted() ((T1C & (1 << TCIS)) != 0) - -typedef void(*timercallback)(void); - -void timer1_isr_init(void); -void timer1_enable(uint8_t divider, uint8_t int_type, uint8_t reload); -void timer1_disable(void); -void timer1_attachInterrupt(timercallback userFunc); -void timer1_detachInterrupt(void); -void timer1_write(uint32_t ticks); //maximum ticks 8388607 - -// timer0 is a special CPU timer that has very high resolution but with -// limited control. -// it uses CCOUNT (ESP.GetCycleCount()) as the non-resetable timer counter -// it does not support divide, type, or reload flags -// it is auto-disabled when the compare value matches CCOUNT -// it is auto-enabled when the compare value changes -#define timer0_interrupted() (ETS_INTR_PENDING() & (_BV(ETS_COMPARE0_INUM))) -#define timer0_read() ((__extension__({uint32_t count;__asm__ __volatile__("esync; rsr %0,ccompare0":"=a" (count));count;}))) -#define timer0_write(count) __asm__ __volatile__("wsr %0,ccompare0; esync"::"a" (count) : "memory") - -void timer0_isr_init(void); -void timer0_attachInterrupt(timercallback userFunc); -void timer0_detachInterrupt(void); - -// Use stdlib abs() and round() to avoid issues with the C++ libraries -#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) -#define radians(deg) ((deg)*DEG_TO_RAD) -#define degrees(rad) ((rad)*RAD_TO_DEG) -#define sq(x) ((x)*(x)) - -void ets_intr_lock(); -void ets_intr_unlock(); - -#define interrupts() xt_rsil(0) -#define noInterrupts() xt_rsil(15) - -#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) -#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) -#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) - -#define lowByte(w) ((uint8_t) ((w) & 0xff)) -#define highByte(w) ((uint8_t) ((w) >> 8)) - -#define bitRead(value, bit) (((value) >> (bit)) & 0x01) -#define bitSet(value, bit) ((value) |= (1UL << (bit))) -#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) -#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) - -// avr-libc defines _NOP() since 1.6.2 -#ifndef _NOP -#define _NOP() do { __asm__ volatile ("nop"); } while (0) -#endif - -typedef uint16_t word; - -#define bit(b) (1UL << (b)) -#define _BV(b) (1UL << (b)) - -typedef bool boolean; -typedef uint8_t byte; - -void init(void); -void initVariant(void); - -int atexit(void (*func)()) __attribute__((weak)); - -void pinMode(uint8_t pin, uint8_t mode); -void digitalWrite(uint8_t pin, uint8_t val); -int digitalRead(uint8_t pin); -int analogRead(uint8_t pin); -void analogReference(uint8_t mode); -void analogWrite(uint8_t pin, int val); -void analogWriteCCyPeriod(uint8_t pin, int val, uint32_t period); -void analogWriteFreq(uint32_t freq); -void analogWriteRange(uint32_t range); - -unsigned long millis(void); -unsigned long micros(void); -uint64_t micros64(void); -void delay(unsigned long); -void delayMicroseconds(unsigned int us); -unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); -unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout); - -void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); -uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); - -void attachInterrupt(uint8_t pin, void (*)(void), int mode); -void detachInterrupt(uint8_t pin); -void attachInterruptArg(uint8_t pin, void (*)(void*), void* arg, int mode); - -void preinit(void); -void setup(void); -void loop(void); - -void yield(void); - -void optimistic_yield(uint32_t interval_us); - -#define _PORT_GPIO16 1 -#define digitalPinToPort(pin) (((pin)==16)?(_PORT_GPIO16):(0)) -#define digitalPinToBitMask(pin) (((pin)==16)?(1):(1UL << (pin))) -#define digitalPinToTimer(pin) (0) -#define portOutputRegister(port) (((port)==_PORT_GPIO16)?((volatile uint32_t*) &GP16O):((volatile uint32_t*) &GPO)) -#define portInputRegister(port) (((port)==_PORT_GPIO16)?((volatile uint32_t*) &GP16I):((volatile uint32_t*) &GPI)) -#define portModeRegister(port) (((port)==_PORT_GPIO16)?((volatile uint32_t*) &GP16E):((volatile uint32_t*) &GPE)) - -#define NOT_A_PIN -1 -#define NOT_A_PORT -1 -#define NOT_AN_INTERRUPT -1 -#define NOT_ON_TIMER 0 - -#ifdef __cplusplus -} // extern "C" -#endif - - -//for compatibility, below 4 lines to be removed in release 3.0.0 -#ifdef __cplusplus -extern "C" -#endif -const int TIM_DIV265 __attribute__((deprecated, weak)) = TIM_DIV256; - - - -#ifdef __cplusplus - -#include -#include -#include - -#include "WCharacter.h" -#include "WString.h" - -#include "HardwareSerial.h" -#include "Esp.h" -#include "Updater.h" -#include "debug.h" - -using std::min; -using std::max; -using std::round; -using std::isinf; -using std::isnan; - -#define _min(a,b) ({ decltype(a) _a = (a); decltype(b) _b = (b); _a < _b? _a : _b; }) -#define _max(a,b) ({ decltype(a) _a = (a); decltype(b) _b = (b); _a > _b? _a : _b; }) - -uint16_t makeWord(uint16_t w); -uint16_t makeWord(byte h, byte l); - -#define word(...) makeWord(__VA_ARGS__) - -unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); -unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); - -void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); -void tone(uint8_t _pin, int frequency, unsigned long duration = 0); -void tone(uint8_t _pin, double frequency, unsigned long duration = 0); -void noTone(uint8_t _pin); - -// WMath prototypes -long random(long); -long random(long, long); -void randomSeed(unsigned long); -long secureRandom(long); -long secureRandom(long, long); -long map(long, long, long, long, long); - -void setTZ(const char* tz); - -void configTime(int timezone, int daylightOffset_sec, const char* server1, - const char* server2 = nullptr, const char* server3 = nullptr); - -void configTime(const char* tz, const char* server1, - const char* server2 = nullptr, const char* server3 = nullptr); - -// esp32 api compatibility -inline void configTzTime(const char* tz, const char* server1, - const char* server2 = nullptr, const char* server3 = nullptr) -{ - configTime(tz, server1, server2, server3); -} - -#endif // __cplusplus - -#include "pins_arduino.h" - -#endif - -#ifdef DEBUG_ESP_OOM -// reinclude *alloc redefinition because of undefining them -// this is mandatory for allowing OOM *alloc definitions in .ino files -#include "umm_malloc/umm_malloc_cfg.h" -#endif - -#else - -/* - Arduino.h - Main include file for the Arduino SDK - Copyright (c) 2005-2013 Arduino Team. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef Arduino_h -#define Arduino_h - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/semphr.h" -#include "esp32-hal.h" -#include "esp8266-compat.h" -#include "soc/gpio_reg.h" - -#include "stdlib_noniso.h" -#include "binary.h" - -#define PI 3.1415926535897932384626433832795 -#define HALF_PI 1.5707963267948966192313216916398 -#define TWO_PI 6.283185307179586476925286766559 -#define DEG_TO_RAD 0.017453292519943295769236907684886 -#define RAD_TO_DEG 57.295779513082320876798154814105 -#define EULER 2.718281828459045235360287471352 - -#define SERIAL 0x0 -#define DISPLAY 0x1 - -#define LSBFIRST 0 -#define MSBFIRST 1 - -//Interrupt Modes -#define RISING 0x01 -#define FALLING 0x02 -#define CHANGE 0x03 -#define ONLOW 0x04 -#define ONHIGH 0x05 -#define ONLOW_WE 0x0C -#define ONHIGH_WE 0x0D - -#define DEFAULT 1 -#define EXTERNAL 0 - -#ifndef __STRINGIFY -#define __STRINGIFY(a) #a -#endif - -#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) -#define radians(deg) ((deg)*DEG_TO_RAD) -#define degrees(rad) ((rad)*RAD_TO_DEG) -#define sq(x) ((x)*(x)) - -#define sei() -#define cli() -#define interrupts() sei() -#define noInterrupts() cli() - -#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L ) -#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) -#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) - -#define lowByte(w) ((uint8_t) ((w) & 0xff)) -#define highByte(w) ((uint8_t) ((w) >> 8)) - -#define bitRead(value, bit) (((value) >> (bit)) & 0x01) -#define bitSet(value, bit) ((value) |= (1UL << (bit))) -#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) -#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) - -// avr-libc defines _NOP() since 1.6.2 -#ifndef _NOP -#define _NOP() do { __asm__ volatile ("nop"); } while (0) -#endif - -#define bit(b) (1UL << (b)) -#define _BV(b) (1UL << (b)) - -#define digitalPinToPort(pin) (((pin)>31)?1:0) -#define digitalPinToBitMask(pin) (1UL << (((pin)>31)?((pin)-32):(pin))) -#define digitalPinToTimer(pin) (0) -#define analogInPinToBit(P) (P) -#define portOutputRegister(port) ((volatile uint32_t*)((port)?GPIO_OUT1_REG:GPIO_OUT_REG)) -#define portInputRegister(port) ((volatile uint32_t*)((port)?GPIO_IN1_REG:GPIO_IN_REG)) -#define portModeRegister(port) ((volatile uint32_t*)((port)?GPIO_ENABLE1_REG:GPIO_ENABLE_REG)) - -#define NOT_A_PIN -1 -#define NOT_A_PORT -1 -#define NOT_AN_INTERRUPT -1 -#define NOT_ON_TIMER 0 - -typedef bool boolean; -typedef uint8_t byte; -typedef unsigned int word; - -void setup(void); -void loop(void); - -long random(long, long); -void randomSeed(unsigned long); -long map(long, long, long, long, long); - -#ifdef __cplusplus -extern "C" { -#endif - -void init(void); -void initVariant(void); -void initArduino(void); - -unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout); -unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout); - -uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder); -void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); - -#ifdef __cplusplus -} - -#include -#include - -#include "WCharacter.h" -#include "WString.h" -#include "Stream.h" -#include "Printable.h" -#include "Print.h" -#include "IPAddress.h" -#include "Client.h" -#include "Server.h" -#include "Udp.h" -#include "HardwareSerial.h" -#include "Esp.h" - -using std::abs; -using std::isinf; -using std::isnan; -using std::max; -using std::min; -using ::round; - -uint16_t makeWord(uint16_t w); -uint16_t makeWord(byte h, byte l); - -#define word(...) makeWord(__VA_ARGS__) - -unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); -unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); - -extern "C" bool getLocalTime(struct tm * info, uint32_t ms = 5000); -extern "C" void configTime(long gmtOffset_sec, int daylightOffset_sec, - const char* server1, const char* server2 = nullptr, const char* server3 = nullptr); -extern "C" void configTzTime(const char* tz, - const char* server1, const char* server2 = nullptr, const char* server3 = nullptr); - -// WMath prototypes -long random(long); -#endif /* __cplusplus */ - -#define _min(a,b) ((a)<(b)?(a):(b)) -#define _max(a,b) ((a)>(b)?(a):(b)) - -#include "pins_arduino.h" - -#endif /* _ESP32_CORE_ARDUINO_H_ */ - -#endif From 6bd4edcdae34b57aa349b87b7085b9c7942c6339 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Fri, 3 Jul 2020 09:01:02 +0200 Subject: [PATCH 09/12] Update xsns_01_counter.ino --- tasmota/xsns_01_counter.ino | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tasmota/xsns_01_counter.ino b/tasmota/xsns_01_counter.ino index 18f1ed461..c3584f111 100644 --- a/tasmota/xsns_01_counter.ino +++ b/tasmota/xsns_01_counter.ino @@ -99,7 +99,11 @@ void CounterUpdate(uint8_t index) uint32_t steps = (current_cycle-last_cycle+100000)/(clockCyclesPerMicrosecond() * 10000); cycle_time = (current_cycle-last_cycle)/steps; #ifdef ESP8266 - analogWriteCCyPeriod(Pin(GPIO_PWM1, index), 5, cycle_time ); + pinMode(Pin(GPIO_PWM1, index), OUTPUT); + uint32_t high = (cycle_time * 5) / 1023; + uint32_t low = cycle_time - high; + // Find the first GPIO being generated by checking GCC's find-first-set (returns 1 + the bit of the first 1 in an int32_t + startWaveformClockCycles(Pin(GPIO_PWM1, index), high, low, 0, -1, 0, true); #else analogWrite(Pin(GPIO_PWM1, index), 5); #endif From d3a9413a7c909e8f4d1eaf4f3950fbaf6407c9a1 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Fri, 3 Jul 2020 09:01:53 +0200 Subject: [PATCH 10/12] Update tasmota_globals.h --- tasmota/tasmota_globals.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tasmota/tasmota_globals.h b/tasmota/tasmota_globals.h index 791896ac3..a4df0c4f7 100644 --- a/tasmota/tasmota_globals.h +++ b/tasmota/tasmota_globals.h @@ -42,6 +42,8 @@ void DomoticzTempHumPressureSensor(float temp, float hum, float baro = -1); char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, char inbetween = '\0'); extern "C" void custom_crash_callback(struct rst_info * rst_info, uint32_t stack, uint32_t stack_end); extern "C" void resetPins(); +extern "C" int startWaveformClockCycles(uint8_t pin, uint32_t highCcys, uint32_t lowCcys, + uint32_t runTimeCcys, int8_t alignPhase, uint32_t phaseOffsetCcys, bool autoPwm); #ifdef ESP32 From 041be8882e642edb0cd3c9bc7265fb9f35476df2 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Fri, 3 Jul 2020 09:04:14 +0200 Subject: [PATCH 11/12] Update core_esp8266_wiring_pwm.cpp --- tasmota/core_esp8266_wiring_pwm.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/tasmota/core_esp8266_wiring_pwm.cpp b/tasmota/core_esp8266_wiring_pwm.cpp index 1c7704b46..6141649da 100644 --- a/tasmota/core_esp8266_wiring_pwm.cpp +++ b/tasmota/core_esp8266_wiring_pwm.cpp @@ -49,18 +49,13 @@ extern void __analogWriteFreq(uint32_t freq) { } -extern void __analogWriteCCyPeriod(uint8_t pin, int val, uint32_t period) { +extern void __analogWrite(uint8_t pin, int val) { if (pin > 16) { return; } uint32_t analogPeriod; - if (period == 0) { - analogPeriod = microsecondsToClockCycles(1000000UL) / analogFreq; - } else { - analogPeriod = period; - } - - //uint32_t analogPeriod = microsecondsToClockCycles(1000000UL) / analogFreq; +{ + uint32_t analogPeriod = microsecondsToClockCycles(1000000UL) / analogFreq; if (val < 0) { val = 0; } else if (val > analogScale) { @@ -80,14 +75,8 @@ extern void __analogWriteCCyPeriod(uint8_t pin, int val, uint32_t period) { if (startWaveformClockCycles(pin, high, low, 0, phaseReference, 0, true)) { analogMap |= (1 << pin); } - //Serial.printf("phase: %d, high %d, low %d, drift %d, apr: %u\n", phaseReference,high,low, analogDrift, analogPeriod ); } -extern void __analogWrite(uint8_t pin, int val) { - __analogWriteCCyPeriod( pin, val, 0); -} - -extern void analogWriteCCyPeriod(uint8_t pin, int val, uint32_t priod) __attribute__((weak, alias("__analogWriteCCyPeriod"))); extern void analogWrite(uint8_t pin, int val) __attribute__((weak, alias("__analogWrite"))); extern void analogWriteFreq(uint32_t freq) __attribute__((weak, alias("__analogWriteFreq"))); extern void analogWriteRange(uint32_t range) __attribute__((weak, alias("__analogWriteRange"))); From 22fec3202a911a13ebfd3946dae8568549f60db4 Mon Sep 17 00:00:00 2001 From: stefanbode Date: Fri, 3 Jul 2020 09:07:43 +0200 Subject: [PATCH 12/12] Update core_esp8266_wiring_pwm.cpp --- tasmota/core_esp8266_wiring_pwm.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tasmota/core_esp8266_wiring_pwm.cpp b/tasmota/core_esp8266_wiring_pwm.cpp index 6141649da..d81928a5d 100644 --- a/tasmota/core_esp8266_wiring_pwm.cpp +++ b/tasmota/core_esp8266_wiring_pwm.cpp @@ -53,8 +53,7 @@ extern void __analogWrite(uint8_t pin, int val) { if (pin > 16) { return; } - uint32_t analogPeriod; -{ + uint32_t analogPeriod = microsecondsToClockCycles(1000000UL) / analogFreq; if (val < 0) { val = 0;