diff --git a/.github/workflows/build_examples_esp32_matrix.yml b/.github/workflows/build_examples_esp32_matrix.yml new file mode 100644 index 00000000..3263e6b6 --- /dev/null +++ b/.github/workflows/build_examples_esp32_matrix.yml @@ -0,0 +1,41 @@ + +name: Build esp32 + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + strategy: + matrix: + version: + - esp32_V3_5_0 + - esp32_V4_1_0 + - esp32_V4_2_0 + - esp32_V4_3_0 + - esp32_V4_4_0 + - esp32_V5_0_0 + - esp32_V5_1_1 + - esp32_V5_2_0 + - esp32_V5_3_0 + - esp32_V6_0_1 + - esp32_V6_2_0 + - esp32_V6_3_2 + - esp32_V6_4_0 + - esp32_V6_5_0 + - esp32_V6_6_0 + - esp32_V6_7_0 + - esp32_V6_8_1 + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Make directories + run: bash extras/scripts/build-pio-dirs.sh + - name: Build on PlatformIO + run: bash extras/scripts/build-platformio.sh {{ matrix.versionĀ }} diff --git a/.github/workflows/build_examples_esp32_tasmota_2_0_15.yml b/.github/workflows/build_examples_esp32_tasmota_2_0_15.yml new file mode 100644 index 00000000..cfd36747 --- /dev/null +++ b/.github/workflows/build_examples_esp32_tasmota_2_0_15.yml @@ -0,0 +1,21 @@ + +name: Build examples for esp32 @ esp32_tasmota 2.0.15 + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Make directories + run: bash extras/scripts/build-pio-dirs.sh + - name: Build on PlatformIO + run: bash extras/scripts/build-platformio.sh esp32_tasmota_2_0_15 diff --git a/CHANGELOG.md b/CHANGELOG.md index 292a744a..5adc7fe3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ pre-0.30.16: - Fix missing parenthesis in preprocessor macro (#271) - Position parameter for `forceStopAndNewPosition()` changed from `uint32_t` to `int32_t` (#268) - Add `stepsToStop()` to predict motor stop position +- espidf compatibility: `pio run -e esp32idf` in `pio_espidf` works. 0.30.15: - Fix missing initialization in `getCurrentSpeedInTicks()` (#262) diff --git a/README.md b/README.md index 3a6d402f..a38d2fad 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,10 @@ Build examples for different versions of espressif-arduino platform: [![`V6_6_0`](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_esp32c3_V6_6_0.yml/badge.svg)](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_esp32c3_V6_6_0.yml) [![`V6_5_0`](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_esp32c3_V6_5_0.yml/badge.svg)](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_esp32c3_V6_5_0.yml) +### esp32 tasmota +[![`V3_0_0`](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_esp32_tasmota_3_0_0.yml/badge.svg)](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_esp32_tasmota_3_0_0.yml) +[![`V2_0_15`](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_esp32_tasmota_2_0_15.yml/badge.svg)](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_esp32_tasmota_2_0_15.yml) + ## Build for avr-platform [![Build examples for Atmega2560](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_atmega2560.yml/badge.svg)](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_atmega2560.yml) [![Build examples for Atmel SAM](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_atmelsam.yml/badge.svg)](https://github.com/gin66/FastAccelStepper/actions/workflows/build_examples_atmelsam.yml) diff --git a/extras/ci/platformio.ini b/extras/ci/platformio.ini index 1e3d8038..b361c7a8 100644 --- a/extras/ci/platformio.ini +++ b/extras/ci/platformio.ini @@ -13,6 +13,22 @@ ; [platformio] +[env:esp32_tasmota_3_0_0] +platform = https://github.com/tasmota/platform-espressif32/releases/download/2024.05.12/platform-espressif32.zip +board = esp32dev +framework = arduino +build_flags = -Wall +board_build.f_cpu = 240000000L +lib_extra_dirs = ../../.. + +[env:esp32_tasmota_2_0_15] +platform = https://github.com/tasmota/platform-espressif32/releases/download/2024.04.00/platform-espressif32.zip +board = esp32dev +framework = arduino +build_flags = -Wall +board_build.f_cpu = 240000000L +lib_extra_dirs = ../../.. + [env:esp32] platform = espressif32 board = esp32dev @@ -302,7 +318,7 @@ board_build.f_cpu = 240000000L lib_extra_dirs = ../../.. [env:esp32idf] -platform = espressif32 +platform = espressif32 @ 4.4.0 board = esp32dev framework = espidf build_flags = -Werror -Wall -Wno-deprecated-declarations -Wno-error=incompatible-pointer-types -Wno-unused-function -Wno-error=attributes diff --git a/extras/idf_examples/UsageExample/UsageExample.cpp b/extras/idf_examples/UsageExample/UsageExample.cpp new file mode 100644 index 00000000..98e140a4 --- /dev/null +++ b/extras/idf_examples/UsageExample/UsageExample.cpp @@ -0,0 +1,84 @@ +#include "FastAccelStepper.h" + +// As in StepperDemo for Motor 1 on AVR +//#define dirPinStepper 5 +//#define enablePinStepper 6 +//#define stepPinStepper 9 // OC1A in case of AVR + +// As in StepperDemo for Motor 1 on ESP32 +#define dirPinStepper 18 +#define enablePinStepper 26 +#define stepPinStepper 17 + +FastAccelStepperEngine engine = FastAccelStepperEngine(); +FastAccelStepper *stepper = NULL; + + +void setup() { + printf("START\n"); + for (uint8_t i = 0;i < 10;i++) { + printf("LOOP %d\n",i); + vTaskDelay(pdMS_TO_TICKS(500)); + esp_task_wdt_reset(); + } + + engine.init(0); + + printf("Engine initialized\n"); + for (uint8_t i = 0;i < 10;i++) { + printf("LOOP %d\n",i); + vTaskDelay(pdMS_TO_TICKS(500)); + esp_task_wdt_reset(); + } + + stepper = engine.stepperConnectToPin(stepPinStepper); + + printf("Stepper connected\n"); + for (uint8_t i = 0;i < 10;i++) { + printf("LOOP %d\n",i); + vTaskDelay(pdMS_TO_TICKS(500)); + esp_task_wdt_reset(); + } + + if (stepper) { +// stepper->setDirectionPin(dirPinStepper); +// stepper->setEnablePin(enablePinStepper); +// stepper->setAutoEnable(true); + + // If auto enable/disable need delays, just add (one or both): + // stepper->setDelayToEnable(50); + // stepper->setDelayToDisable(1000); + + stepper->setSpeedInUs(1000); // the parameter is us/step !!! + stepper->setAcceleration(100); + stepper->move(1000); + printf("Stepper initialized\n"); + } + else { + printf("No stepper\n"); + } + + for (uint8_t i = 0;i < 10;i++) { + printf("LOOP %d\n",i); + vTaskDelay(pdMS_TO_TICKS(500)); + esp_task_wdt_reset(); + } +} + +void loop() { + while(stepper->isRunning()) { + esp_task_wdt_reset(); + printf("pos=%d\n", stepper->getCurrentPosition()); + vTaskDelay(pdMS_TO_TICKS(500)); + } + stepper->move(1000); +} + +extern "C" void app_main() +{ + setup(); + while(true) { + loop(); + } + // WARNING: if program reaches end of function app_main() the MCU will restart. +} diff --git a/extras/scripts/build-pio-dirs.sh b/extras/scripts/build-pio-dirs.sh index a40270e5..3a2ed4c3 100755 --- a/extras/scripts/build-pio-dirs.sh +++ b/extras/scripts/build-pio-dirs.sh @@ -31,14 +31,14 @@ done # for espidf as of now, the src/* files need to be linked into the example build directory rm -fR pio_espidf mkdir pio_espidf -for i in `ls examples` +for i in `cd extras;ls idf_examples` do mkdir -p pio_espidf/$i/src cd pio_espidf/$i ln -s ../../extras/ci/platformio.ini . cd src - FILES=`cd ../../../examples/$i;find . -type f` - for f in $FILES;do ln -s ../../../examples/$i/$f .;done + FILES=`cd ../../../extras/idf_examples/$i;find . -type f` + for f in $FILES;do ln -s ../../../extras/idf_examples/$i/$f .;done FILES=`cd ../../../src/.;find . -type f` for f in $FILES;do ln -s ../../../src/$f .;done cd ../../.. @@ -55,4 +55,5 @@ ln -s ../../../extras/tests/pc_based/test_03.h . ln -s ../../../extras/tests/pc_based/PMF_test.ino PMF_test.ino cd ../../.. -ls -al pio* +ls -al pio_* + diff --git a/src/FastAccelStepper.cpp b/src/FastAccelStepper.cpp index ac758366..fb2aeafa 100644 --- a/src/FastAccelStepper.cpp +++ b/src/FastAccelStepper.cpp @@ -850,7 +850,7 @@ void FastAccelStepper::setCurrentPosition(int32_t new_pos) { if (delta != 0) { struct queue_end_s* queue_end = &fas_queue[_queue_num].queue_end; fasDisableInterrupts(); - queue_end->pos += delta; + queue_end->pos = queue_end->pos + delta; _rg.advanceTargetPosition(delta, queue_end); fasEnableInterrupts(); } diff --git a/src/StepperISR.cpp b/src/StepperISR.cpp index dddcde9d..872089e9 100644 --- a/src/StepperISR.cpp +++ b/src/StepperISR.cpp @@ -112,7 +112,7 @@ int8_t StepperQueue::addQueueEntry(const struct stepper_command_s* cmd, #if defined(SUPPORT_QUEUE_ENTRY_START_POS_U16) e->start_pos_last16 = (uint32_t)next_queue_end.pos & 0xffff; #endif - next_queue_end.pos += cmd->count_up ? steps : -steps; + next_queue_end.pos = next_queue_end.pos + (cmd->count_up ? steps : -steps); #if defined(SUPPORT_QUEUE_ENTRY_END_POS_U16) e->end_pos_last16 = (uint32_t)next_queue_end.pos & 0xffff; #endif @@ -123,7 +123,7 @@ int8_t StepperQueue::addQueueEntry(const struct stepper_command_s* cmd, fasDisableInterrupts(); if (!ignore_commands) { if (isReadyForCommands()) { - next_write_idx++; + next_write_idx = next_write_idx + 1; queue_end = next_queue_end; } else { fasEnableInterrupts(); diff --git a/src/fas_common.h b/src/fas_common.h index 00350460..d454f242 100644 --- a/src/fas_common.h +++ b/src/fas_common.h @@ -273,19 +273,25 @@ struct queue_end_s { #define SUPPORT_ESP32 #define SUPPORT_UNSAFE_ABS_SPEED_LIMIT_SETTING 1 +#define SUPPORT_ESP32_RMT +#define SUPPORT_ESP32_MCPWM_PCNT + // esp32 specific includes #include #include #include +#include #include #include #include #include #include #include +#include +#include +#include // on espidf need to use portDISABLE/ENABLE_INTERRUPTS -// #include #include #define fasDisableInterrupts portDISABLE_INTERRUPTS @@ -300,7 +306,10 @@ struct queue_end_s { // Esp32 queue definitions #define MAX_STEPPER 6 #define NUM_QUEUES 6 +#define QUEUES_MCPWM_PCNT 6 +#define QUEUES_RMT 8 #define QUEUE_LEN 32 +#define SUPPORT_EXTERNAL_DIRECTION_PIN // Esp32 timing definition #define TICKS_PER_S 16000000L @@ -329,6 +338,13 @@ struct queue_end_s { // have more than one core #define SUPPORT_CPU_AFFINITY +#if defined(ARDUINO_ESP32_RELEASE_3_0_0) +#else +// have support for pulse counter +#define SUPPORT_ESP32_PULSE_COUNTER +#define FAS_RMT_MEM(channel) ((uint32_t *)RMT_CHANNEL_MEM(channel)) +#endif + //========================================================================== // // This for SAM-architecture