- Muchas notas - Fran Acién

20250331 - Faust and ESP32S3

I modified the project to make it work with ESP32S3:

$ git clone --recursive https://github.com/acien101/faust
$ git checkout feat/esp32s3
$ make
$ sudo make install
$ faust2esp32s3 sawtooth.dsp -lib

That should be it

// faust sawtooth example for PICO_DSP development board with 4MB Flash & PSRAM Enabled
// DSP task and i2s driver running on core 1

#include <Arduino.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "CatEyes.h"
#include "WM8978.h"
#include "UartCli.h"

#if !(USING_DEFAULT_ARDUINO_LOOP_STACK_SIZE)
  uint16_t USER_CONFIG_ARDUINO_LOOP_STACK_SIZE = 8192;
#endif

WM8978 wm8978;

CatEyes* DSP = new CatEyes(48000, 32);


// 1) Define your command functions
void helpCommand(const char* args) {


    Serial.println("Available commands:");
    // This example manually lists commands for demonstration
    // For a large table, you could iterate over it if you store it globally
    Serial.println("  h      : Display help");
    Serial.println("  set      : Set a parameter value");
}

void setParamCommand(const char* args) {
  // Copy the input string so we can safely modify it
  char buffer[64];
  strncpy(buffer, args, sizeof(buffer));
  buffer[sizeof(buffer) - 1] = '\0';  // Ensure null termination

  // Find the first space to split name and value
  char* paramName = strtok(buffer, " ");
  char* paramValueStr = strtok(NULL, " ");

  if (!paramName || !paramValueStr) {
      Serial.println("Usage: set <param> <value>");
      return;
  }

  // Convert value to float
  float value = atof(paramValueStr);

  // Apply the parameter
  DSP->setParamValue(paramName, value);

  Serial.printf("Set param '%s' to value %.3f\r\n", paramName, value);
}

CLICommand commandTable[] = {
    {"h",     helpCommand},
    {"set",  setParamCommand}
};

UartCli cli = UartCli(Serial, commandTable, sizeof(commandTable)/sizeof(commandTable[0]));

TaskHandle_t updateCliTaskHandle = NULL;    // Task handler for the buzer function

void xTaskUpdateCli(void *param){
  while(true){
    cli.handle();
    vTaskDelay(pdMS_TO_TICKS(10));
  }
}

void setup() {

  Serial.begin(115200);
  
  if(psramFound()) {
    Serial.println("PSRAM is enabled and working!");
    Serial.print("Free PSRAM: ");
    Serial.println(ESP.getFreePsram());
  } else {
    Serial.println("PSRAM not found.");
  }

  // Print CPU frequency
  Serial.print("CPU Frequency: ");
  Serial.print(getCpuFrequencyMhz());
  Serial.println(" MHz");

  // Important!
  // It is necessary to unplug and plug again, to reset the board

  delay(10);
  // Init audio codec
  WM8978 wm8978;
  wm8978.init();
  delay(10);
  wm8978.addaCfg(1,1);
  wm8978.inputCfg(0,1,0);
  wm8978.outputCfg(1,0);
  wm8978.sampleRate(0); 
  wm8978.micGain(0);
  wm8978.auxGain(0);
  wm8978.lineinGain(7);     // 7 is max
  wm8978.spkVolSet(0);
  wm8978.hpVolSet(50, 50);      // 63 is max

  wm8978.i2sCfg(2,0);  //format 12S, length 16bit
  wm8978.i2sCfg(2,0);


  cli.begin();

  DSP->start();
  DSP->setParamValue("LowFreq", 10000); 
  DSP->setParamValue("LowQ", 1); 
  DSP->setParamValue("HighFreq", 10); 
  DSP->setParamValue("HighQ", 1); 

  
  xTaskCreatePinnedToCore(
    xTaskUpdateCli,
    "Cli task",
    4096,
    NULL,
    1,
    &updateCliTaskHandle,
    1
  );
} 

void loop() {
	vTaskDelay(pdMS_TO_TICKS(100));
}