diff --git a/.github/workflows/build_examples_esp_idf_project.yml b/.github/workflows/build_examples_esp_idf_project.yml new file mode 100644 index 00000000..e29a61c5 --- /dev/null +++ b/.github/workflows/build_examples_esp_idf_project.yml @@ -0,0 +1,23 @@ +name: Build examples for an ESP-IDF project + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: esp-idf build + uses: espressif/esp-idf-ci-action@v1 + with: + esp_idf_version: v5.3.2 + target: esp32 + path: extras/idf_project_example + \ No newline at end of file diff --git a/extras/idf_project_example/.gitignore b/extras/idf_project_example/.gitignore new file mode 100644 index 00000000..bbab53b9 --- /dev/null +++ b/extras/idf_project_example/.gitignore @@ -0,0 +1,5 @@ +/build +/.vscode +/managed_components +/sdkconfig +/dependencies.lock diff --git a/extras/idf_project_example/CMakeLists.txt b/extras/idf_project_example/CMakeLists.txt new file mode 100644 index 00000000..e0254bfe --- /dev/null +++ b/extras/idf_project_example/CMakeLists.txt @@ -0,0 +1,10 @@ +# For more information about build system see +# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html +# The following five lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly + +cmake_minimum_required(VERSION 3.16) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) + +project(idf_project_example) diff --git a/extras/idf_project_example/README.md b/extras/idf_project_example/README.md new file mode 100644 index 00000000..7152e9bd --- /dev/null +++ b/extras/idf_project_example/README.md @@ -0,0 +1,8 @@ +This folder contains a bare bones functional ESP-IDF project. + +You can create one using the **ESP-IDF: New Project** command in +Visual Studio code, or use this one as a basis. If you do use this one +as a basis for your own project, review the `.gitignore` file as it +excludes files you would not want to exclude in a normal project. +Normally only the `managed_components` and `build` folders would be +excluded from version control. diff --git a/extras/idf_project_example/main/CMakeLists.txt b/extras/idf_project_example/main/CMakeLists.txt new file mode 100644 index 00000000..0125dc2e --- /dev/null +++ b/extras/idf_project_example/main/CMakeLists.txt @@ -0,0 +1,6 @@ +FILE(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.c ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) + +idf_component_register( + SRCS ${SOURCES} + INCLUDE_DIRS "." +) diff --git a/extras/idf_project_example/main/idf_component.yml b/extras/idf_project_example/main/idf_component.yml new file mode 100644 index 00000000..d0a9c3c5 --- /dev/null +++ b/extras/idf_project_example/main/idf_component.yml @@ -0,0 +1,5 @@ +dependencies: + FastAccelStepper: + path: ../../.. + # Alternatively you can point this directly at the GitHub repository: + # git: https://github.com/gin66/FastAccelStepper.git diff --git a/extras/idf_project_example/main/main.cpp b/extras/idf_project_example/main/main.cpp new file mode 100644 index 00000000..13de17a7 --- /dev/null +++ b/extras/idf_project_example/main/main.cpp @@ -0,0 +1,78 @@ +#include "FastAccelStepper.h" + +#include + +// 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"); + + 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); + +#ifdef SUPPORT_ESP32_PULSE_COUNTER + stepper->attachToPulseCounter(7); +#endif + + printf("Stepper initialized\n"); + } else { + printf("No stepper\n"); + } +} + +extern "C" void app_main() { + setup(); + int32_t target = 0; + while (true) { + while (stepper->isRunning()) { + // esp_task_wdt_reset(); + printf("pos=%" PRId32, stepper->getCurrentPosition()); +#ifdef SUPPORT_ESP32_PULSE_COUNTER + int16_t pcnt = stepper->readPulseCounter(); + printf(" pcnt=%d", pcnt); +#endif + printf("\n"); + vTaskDelay(pdMS_TO_TICKS(500)); + } + printf("done\n"); + vTaskDelay(pdMS_TO_TICKS(500)); + printf("move\n"); + target = 1000 - target; + stepper->moveTo(target); + } + // WARNING: if program reaches end of function app_main() the MCU will + // restart. +} diff --git a/extras/idf_project_example/sdkconfig.defaults b/extras/idf_project_example/sdkconfig.defaults new file mode 100644 index 00000000..f1e9f313 --- /dev/null +++ b/extras/idf_project_example/sdkconfig.defaults @@ -0,0 +1,2 @@ +# Required by the android-esp32 component. +CONFIG_FREERTOS_HZ=1000 diff --git a/idf_component.yml b/idf_component.yml new file mode 100644 index 00000000..0b4136f8 --- /dev/null +++ b/idf_component.yml @@ -0,0 +1,3 @@ +dependencies: + espressif/arduino-esp32: + version: "*"