TcMenu / TaskManagerIO

A task, event, scheduling, and interrupt marshalling library for Arduino and mbed boards.
Apache License 2.0
124 stars 14 forks source link

TcMenu with VSCode + ESP-IDF v5.1.3 for ESP32 an ST7735 1,8" TFT display #59

Open ONik93 opened 2 months ago

ONik93 commented 2 months ago

Hi,

I've build TcMenu with VSCode + ESP-IDF v5.1.3 for ESP32 an ST7735 1,8" TFT display.

To achieve it i changed this lines in TaskManagerIO and SimpleCollections lib

#include "Utils.h"

inline bool casAtomic(position_ptr_t ptr, position_t expected, position_t newVal) {
    uint32_t exp32 = expected;
    uint32_t new32 = newVal;
    // uxPortCompareSet(ptr, exp32, &new32);
    uxPortCompareSetCustom(ptr, exp32, &new32);
    return new32 == expected;
}
// Utils.h
#include <stdint.h>

void uxPortCompareSetCustom(volatile uint32_t *addr, uint32_t compare, uint32_t *set);
// Utils.cpp
#include "Utils.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

void uxPortCompareSetCustom(volatile uint32_t *addr, uint32_t compare, uint32_t *set) {
    uint32_t prev;
    //BaseType_t taskState;
    int taskState;

    // Enter critical section to ensure atomicity
    taskState = taskENTER_CRITICAL_FROM_ISR();

    prev = *addr;
    if (prev == compare) {
        *addr = *set;  // Update memory location with the new value
    }
    *set = prev;  // Update the 'set' pointer with the previous value

    // Exit critical section
    taskEXIT_CRITICAL_FROM_ISR(taskState);
}

And IoAbstraction library required following modification


#include <Arduino.h>

void EspAnalogOutputMode::pinSetup() {
    if(!isDac()) {
        // for other than the dac ports, we need to set up PWM
        ledcSetup(pwmChannel, pwmWidth, 8);
        ledcAttachPin(pin, pwmChannel);
        // ledcSetup(pwmChannel, pwmWidth, 8);
        // ledcAttachPin(pin, pwmChannel);
        ledcAttach(pin, pwmWidth, 8);
    }

I hope you can implement this fixes to your project.

davetcc commented 1 month ago

I'm not sure why the port macro uxPortCompareSet from freertos/portmacro.h doesn't work to be honest, it should really be there as it's part of their core rtos implementation.

I think the ledc functions may be part of Arduino to be honest and they may need to be fully moved to use IDF functions instead.

We do plan to fully support IDF, but for now, you should be able to get uxPortCompareSet working with IDF, and you could just comment out the ledc functions if Arduino library is not there.