Skip to content

Commit

Permalink
fix espidf compatibility. using matrix in actions
Browse files Browse the repository at this point in the history
  • Loading branch information
gin66 committed Aug 18, 2024
1 parent db8a02b commit 85859bd
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 9 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build_examples_esp32_matrix.yml
Original file line number Diff line number Diff line change
@@ -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 }}
21 changes: 21 additions & 0 deletions .github/workflows/build_examples_esp32_tasmota_2_0_15.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 17 additions & 1 deletion extras/ci/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
84 changes: 84 additions & 0 deletions extras/idf_examples/UsageExample/UsageExample.cpp
Original file line number Diff line number Diff line change
@@ -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.
}
9 changes: 5 additions & 4 deletions extras/scripts/build-pio-dirs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ../../..
Expand All @@ -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_*

2 changes: 1 addition & 1 deletion src/FastAccelStepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/StepperISR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
18 changes: 17 additions & 1 deletion src/fas_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <driver/gpio.h>
#include <driver/mcpwm.h>
#include <driver/pcnt.h>
#include <driver/rmt.h>
#include <esp_task_wdt.h>
#include <math.h>
#include <soc/mcpwm_reg.h>
#include <soc/mcpwm_struct.h>
#include <soc/pcnt_reg.h>
#include <soc/pcnt_struct.h>
#include <soc/rmt_periph.h>
#include <soc/rmt_reg.h>
#include <soc/rmt_struct.h>

// on espidf need to use portDISABLE/ENABLE_INTERRUPTS
//
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#define fasDisableInterrupts portDISABLE_INTERRUPTS
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 85859bd

Please sign in to comment.