This commit is contained in:
Patrick Moessler 2025-02-15 21:40:57 +01:00
commit 178c8e0803
13 changed files with 315 additions and 0 deletions

13
.devcontainer/Dockerfile Normal file
View file

@ -0,0 +1,13 @@
ARG DOCKER_TAG=latest
FROM espressif/idf:${DOCKER_TAG}
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
RUN apt-get update -y && apt-get install udev -y
RUN echo "source /opt/esp/idf/export.sh > /dev/null 2>&1" >> ~/.bashrc
ENTRYPOINT [ "/opt/esp/entrypoint.sh" ]
CMD ["/bin/bash", "-c"]

View file

@ -0,0 +1,21 @@
{
"name": "ESP-IDF QEMU",
"build": {
"dockerfile": "Dockerfile"
},
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "bash",
"idf.espIdfPath": "/opt/esp/idf",
"idf.toolsPath": "/opt/esp",
"idf.gitPath": "/usr/bin/git"
},
"extensions": [
"espressif.esp-idf-extension",
"espressif.esp-idf-web"
]
}
},
"runArgs": ["--privileged"]
}

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
build/
managed_components/
sdkconfig.old
sdkconfig.ci
sdkconfig

23
.vscode/c_cpp_properties.json vendored Normal file
View file

@ -0,0 +1,23 @@
{
"configurations": [
{
"name": "ESP-IDF",
"compilerPath": "${config:idf.toolsPathWin}\\tools\\xtensa-esp-elf\\esp-14.2.0_20241119\\xtensa-esp-elf\\bin\\xtensa-esp32s3-elf-gcc.exe",
"compileCommands": "${config:idf.buildPath}/compile_commands.json",
"includePath": [
"${config:idf.espIdfPath}/components/**",
"${config:idf.espIdfPathWin}/components/**",
"${workspaceFolder}/**"
],
"browse": {
"path": [
"${config:idf.espIdfPath}/components",
"${config:idf.espIdfPathWin}/components",
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
}

15
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,15 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "gdbtarget",
"request": "attach",
"name": "Eclipse CDT GDB Adapter"
},
{
"type": "espidf",
"name": "Launch",
"request": "launch"
}
]
}

16
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,16 @@
{
"C_Cpp.intelliSenseEngine": "default",
"idf.espIdfPathWin": "c:\\toolchain\\esp32\\v5.4\\esp-idf",
"idf.openOcdConfigs": [
"board/esp32s3-builtin.cfg"
],
"idf.portWin": "COM5",
"idf.toolsPathWin": "c:\\toolchain\\esp32\\tools",
"idf.flashType": "UART",
"files.associations": {
"*.config": "ini",
"freertos.h": "c",
"esp_system.h": "c",
"esp_flash.h": "c"
}
}

6
CMakeLists.txt Normal file
View file

@ -0,0 +1,6 @@
# The following 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(ledstick)

53
README.md Normal file
View file

@ -0,0 +1,53 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 | Linux |
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- | ----- |
# Hello World Example
Starts a FreeRTOS task to print "Hello World".
(See the README.md file in the upper level 'examples' directory for more information about examples.)
## How to use example
Follow detailed instructions provided specifically for this example.
Select the instructions depending on Espressif chip installed on your development board:
- [ESP32 Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/stable/get-started/index.html)
- [ESP32-S2 Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/get-started/index.html)
## Example folder contents
The project **hello_world** contains one source file in C language [hello_world_main.c](main/hello_world_main.c). The file is located in folder [main](main).
ESP-IDF projects are built using CMake. The project build configuration is contained in `CMakeLists.txt` files that provide set of directives and instructions describing the project's source files and targets (executable, library, or both).
Below is short explanation of remaining files in the project folder.
```
├── CMakeLists.txt
├── pytest_hello_world.py Python script used for automated testing
├── main
│ ├── CMakeLists.txt
│ └── hello_world_main.c
└── README.md This is the file you are currently reading
```
For more information on structure and contents of ESP-IDF projects, please refer to Section [Build System](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html) of the ESP-IDF Programming Guide.
## Troubleshooting
* Program upload failure
* Hardware connection is not correct: run `idf.py -p PORT monitor`, and reboot your board to see if there are any output logs.
* The baud rate for downloading is too high: lower your baud rate in the `menuconfig` menu, and try again.
## Technical support and feedback
Please use the following feedback channels:
* For technical queries, go to the [esp32.com](https://esp32.com/) forum
* For a feature request or bug report, create a [GitHub issue](https://github.com/espressif/esp-idf/issues)
We will get back to you as soon as possible.

21
dependencies.lock Normal file
View file

@ -0,0 +1,21 @@
dependencies:
espressif/esp-dsp:
component_hash: fa7fe74305df6da25867437ebcd4213e047cbfc0556cf92067ab657fce537c6e
dependencies:
- name: idf
require: private
version: '>=4.2'
source:
registry_url: https://components.espressif.com/
type: service
version: 1.5.2
idf:
source:
type: idf
version: 5.4.0
direct_dependencies:
- espressif/esp-dsp
- idf
manifest_hash: acb56510805324f107f7c8d502171e5907ed4196d13483775510e84ad86c1969
target: esp32s3
version: 2.0.0

5
main/CMakeLists.txt Normal file
View file

@ -0,0 +1,5 @@
idf_component_register(SRCS "ledstick_main.c"
PRIV_REQUIRES
spi_flash
esp_driver_i2s
INCLUDE_DIRS "")

17
main/idf_component.yml Normal file
View file

@ -0,0 +1,17 @@
## IDF Component Manager Manifest File
dependencies:
## Required IDF version
idf:
version: '>=4.1.0'
# # Put list of dependencies here
# # For components maintained by Espressif:
# component: "~1.0.0"
# # For 3rd party components:
# username/component: ">=1.0.0,<2.0.0"
# username2/component2:
# version: "~1.0.0"
# # For transient dependencies `public` flag can be set.
# # `public` flag doesn't have an effect dependencies of the `main` component.
# # All dependencies of `main` are public by default.
# public: true
espressif/esp-dsp: '*'

115
main/ledstick_main.c Normal file
View file

@ -0,0 +1,115 @@
/* SPDX - FileCopyrightText : 2025 Asaril
** SPDX - License - Identifier : CC0 - 1.0
*/
#include "esp_system.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "sdkconfig.h"
#include <inttypes.h>
#include <stdio.h>
#include "driver/i2s_std.h"
#include "esp_dsp.h"
#define SAMPLE_RATE 24000
#define SAMPLE_COUNT 256
#define BUF_COUNT 4
#define I2S_MIC_SCLK_PIN GPIO_NUM_4
#define I2S_MIC_SD_PIN GPIO_NUM_5
#define I2S_MIC_WS_PIN GPIO_NUM_6
#define SAMPLE_SIZE (2 * SAMPLE_COUNT)
i2s_chan_handle_t rx_handle = NULL;
static int16_t i2s_readraw_buff[SAMPLE_COUNT * 2 * BUF_COUNT]; // 2 channels/complex
void app_init_mic(void)
{
i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_AUTO, I2S_ROLE_MASTER);
ESP_ERROR_CHECK(i2s_new_channel(&chan_cfg, NULL, &rx_handle));
i2s_std_config_t i2s_rx_cfg = {
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(SAMPLE_RATE),
/* The default mono slot is the left slot (whose 'select pin' of the PDM microphone is pulled down) */
.slot_cfg =
{
.data_bit_width = I2S_DATA_BIT_WIDTH_16BIT,
.slot_bit_width = I2S_SLOT_BIT_WIDTH_32BIT,
.slot_mode = I2S_SLOT_MODE_MONO,
.slot_mask = I2S_STD_SLOT_BOTH,
.ws_width = 32,
.ws_pol = false,
.bit_shift = true,
.left_align = true,
.big_endian = false,
.bit_order_lsb = false,
},
.gpio_cfg =
{
.mclk = I2S_GPIO_UNUSED,
.bclk = I2S_MIC_SCLK_PIN,
.din = I2S_MIC_SD_PIN,
.ws = I2S_MIC_WS_PIN,
.invert_flags =
{
.bclk_inv = false,
.mclk_inv = false,
.ws_inv = false,
},
},
};
ESP_ERROR_CHECK(i2s_channel_init_std_mode(rx_handle, &i2s_rx_cfg));
// i2s_event_callbacks_t i2s_cbs = {
// .on_recv = app_i2s_rx_cb,
// .on_recv_q_ovf = NULL,
// .on_send_q_ovf = NULL,
// .on_sent = NULL,
// };
// ESP_ERROR_CHECK(i2s_channel_register_event_callback(rx_handle, &i2s_cbs, NULL));
ESP_ERROR_CHECK(i2s_channel_enable(rx_handle));
}
static void app_process_task(void *args)
{
uint32_t notify_value;
while (1)
{
xTaskNotifyWait(0, 0, &notify_value, portMAX_DELAY);
int16_t *buf = i2s_readraw_buff + notify_value * SAMPLE_COUNT * 2;
printf("%08lx - %08lx - %08lx", (uint32_t)i2s_readraw_buff, (uint32_t)buf, (uint32_t)(buf - i2s_readraw_buff));
dsps_fft2r_sc16(buf, SAMPLE_COUNT);
dsps_bit_rev_sc16_ansi(buf, SAMPLE_COUNT);
dsps_cplx2real_sc16_ansi(buf, SAMPLE_COUNT);
printf("[0] %08x [1] %08x [2] %08x [3]%08x ...\n", (buf[0]), (buf[1]), (buf[2]), (buf[3]));
}
}
void app_main(void)
{
size_t bytes_read = 0;
uint32_t next_rx = 0;
TaskHandle_t proc_task;
app_init_mic();
xTaskCreate(&app_process_task, "app_process_task", 4096, NULL, 5, &proc_task);
while (1)
{
if (i2s_channel_read(rx_handle, (char *)i2s_readraw_buff + (SAMPLE_COUNT * 2 * next_rx), SAMPLE_SIZE * 2,
&bytes_read, 1000) == ESP_OK)
{
xTaskNotify(proc_task, next_rx, eSetValueWithOverwrite);
next_rx = (next_rx + 1) & (BUF_COUNT - 1);
taskYIELD();
}
}
}

5
sdkconfig.defaults Normal file
View file

@ -0,0 +1,5 @@
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration
#
CONFIG_IDF_TARGET="esp32s3"
CONFIG_DSP_MAX_FFT_SIZE_512=y