feat : Added .gitignore, README files, partitions, build options, dependencies, and configuration for ESP32-S3 development board using Arduino.

- Added `.gitignore` file to exclude unnecessary build and system files.
- Summary: Added a README file for project headers, improving organization and management of header files in the source codebase.
- Added a README file in the lib directory for project-specific libraries.
- Added new partitions to `partitions.csv`.
- The `git diff` output updates the `platformio.ini` file to include new build and upload options, dependencies, and configuration for an ESP32-S3 development board using Arduino.
- The user has added a new `main.cpp` file, added I2S and FFT functionality to it, and defined a function to calculate the frequency and convert it to a MIDI note number.
- Added a new README file in the `test` directory for PlatformIO Unit Testing.
This commit is contained in:
2025-04-18 18:23:25 +02:00
parent 9af74aa4bc
commit 83a594cdd9
7 changed files with 257 additions and 0 deletions

34
.gitignore vendored Normal file
View File

@@ -0,0 +1,34 @@
# PlatformIO build files
.pio/
.pioenvs/
.piolibdeps/
# VS Code settings
.vscode/
# PlatformIO package cache
.platformio/
# Python virtual environment
venv/
env/
# macOS system files
.DS_Store
# Windows system files
Thumbs.db
# Compiled object files
*.o
*.obj
# Compiled Dynamic libraries
*.dll
*.so
*.dylib
# Firmware binaries
*.bin
*.elf
*.hex

37
include/README Normal file
View File

@@ -0,0 +1,37 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the convention is to give header files names that end with `.h'.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

46
lib/README Normal file
View File

@@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into the executable file.
The source code of each library should be placed in a separate directory
("lib/your_library_name/[Code]").
For example, see the structure of the following example libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
Example contents of `src/main.c` using Foo and Bar:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
The PlatformIO Library Dependency Finder will find automatically dependent
libraries by scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

5
partitions.csv Normal file
View File

@@ -0,0 +1,5 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x2F0000,
spiffs, data, spiffs, 0x300000,0x100000
1 # Name, Type, SubType, Offset, Size, Flags
2 nvs, data, nvs, 0x9000, 0x5000,
3 otadata, data, ota, 0xe000, 0x2000,
4 app0, app, ota_0, 0x10000, 0x2F0000,
5 spiffs, data, spiffs, 0x300000,0x100000

36
platformio.ini Normal file
View File

@@ -0,0 +1,36 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp32-s3-devkitm-1]
platform = espressif32
board = esp32-s3-devkitm-1
framework = arduino ;, espidf
board_build.arduino.memory_type = qio_qspi
board_build.flash_mode = qio
board_build.psram_type = qio
board_upload.flash_size = 4MB
board_upload.maximum_size = 4194304
board_build.partitions = partitions.csv # Use custom partition table
build_flags = -DARDUINO_USB_CDC_ON_BOOT=1
-DBOARD_HAS_PSRAM
-DARDUINO_ESP32S3_DEV
-DBOARD_HAS_TEMP_SENSOR
; -DCONFIG_FREERTOS_HZ=1000
; -DESP_PLATFORM
; -DARDUINO_RUNNING
board_build.filesystem = spiffs
monitor_speed = 115200
upload_speed = 921600
monitor_filters = esp32_exception_decoder
lib_deps =
https://github.com/pschatzmann/arduino-audio-tools.git
https://github.com/pschatzmann/arduino-audio-driver.git

88
src/main.cpp Normal file
View File

@@ -0,0 +1,88 @@
#include "AudioTools.h"
// #include "AudioTools/AudioLibs/AudioI2SStream.h"
#include "AudioTools/AudioLibs/AudioRealFFT.h" // or AudioKissFFT
I2SStream i2sStream; // I2S input stream for INMP441
AudioRealFFT fft; // FFT analyzer
StreamCopy copier(fft, i2sStream); // copy I2S mic to FFT
int channels = 1; // INMP441 is mono
int samples_per_second = 11025;
int bits_per_sample = 32; // INMP441 sends 24-bit data in 32-bit words
const char* solfegeName(uint8_t midiNote) {
static const char* solfegeNames[] = {
"Do", "Do#", "Re", "Re#", "Mi", "Fa", "Fa#", "Sol", "Sol#", "La", "La#", "Si"
};
return solfegeNames[midiNote % 12];
}
void fftResult(AudioFFTBase &fft) {
float diff;
auto result = fft.result();
if (result.magnitude > 100) { // avoid noise floor
float magnitude_dB = 20.0 * log10(result.magnitude);
float freq = result.frequency;
// MIDI note number
int midiNote = round(69 + 12.0 * log2(freq / 440.0));
const char* solfege = solfegeName(midiNote);
int octave = (midiNote / 12) - 1;
Serial.print(freq, 2);
Serial.print(" Hz | ");
Serial.print("MIDI ");
Serial.print(midiNote);
Serial.print(" | ");
Serial.print("Note: ");
Serial.print(result.frequencyAsNote(diff));
Serial.print(" | ");
Serial.print("Solfège: ");
Serial.print(solfege);
Serial.print(octave);
Serial.print(" | dB: ");
Serial.print(magnitude_dB, 2);
Serial.print(" | Diff: ");
Serial.println(diff, 2);
}
}
void setup() {
Serial.begin(115200);
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
// Configure I2SStream for INMP441
auto cfg = i2sStream.defaultConfig(RX_MODE);
cfg.i2s_format = I2S_STD_FORMAT;
cfg.bits_per_sample = bits_per_sample;
cfg.channels = channels;
cfg.sample_rate = samples_per_second;
cfg.is_master = true;
cfg.pin_bck = 8; // SCK
cfg.pin_ws = 9; // WS
cfg.pin_data = 10; // SD
i2sStream.begin(cfg);
// Configure FFT
auto tcfg = fft.defaultConfig();
tcfg.length = 8192; // 186ms @ 11kHz minimun C2 theoretical
tcfg.channels = channels;
tcfg.sample_rate = samples_per_second;
tcfg.bits_per_sample = bits_per_sample;
tcfg.callback = &fftResult;
fft.begin(tcfg);
Serial.println("Setup complete. Listening...");
}
void loop() {
copier.copy(); // Stream mic data into FFT processor
}

11
test/README Normal file
View File

@@ -0,0 +1,11 @@
This directory is intended for PlatformIO Test Runner and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html