Skip to content

Commit

Permalink
Merge pull request #302 from pvginkel/esp-idf-github-action
Browse files Browse the repository at this point in the history
Created ESP-IDF sample project and a GitHub action to test build it
  • Loading branch information
gin66 authored Dec 25, 2024
2 parents bcf472b + dadcb16 commit 27df201
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/build_examples_esp_idf_project.yml
Original file line number Diff line number Diff line change
@@ -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

5 changes: 5 additions & 0 deletions extras/idf_project_example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/build
/.vscode
/managed_components
/sdkconfig
/dependencies.lock
10 changes: 10 additions & 0 deletions extras/idf_project_example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 8 additions & 0 deletions extras/idf_project_example/README.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 6 additions & 0 deletions extras/idf_project_example/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 "."
)
5 changes: 5 additions & 0 deletions extras/idf_project_example/main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dependencies:
FastAccelStepper:
path: ../../..
# Alternatively you can point this directly at the GitHub repository:
# git: https://github.com/gin66/FastAccelStepper.git
78 changes: 78 additions & 0 deletions extras/idf_project_example/main/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include "FastAccelStepper.h"

#include <cinttypes>

// 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.
}
2 changes: 2 additions & 0 deletions extras/idf_project_example/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Required by the android-esp32 component.
CONFIG_FREERTOS_HZ=1000
3 changes: 3 additions & 0 deletions idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies:
espressif/arduino-esp32:
version: "*"

0 comments on commit 27df201

Please sign in to comment.