Skip to content

Commit 5430f70

Browse files
committed
fix compilation issues; closes #40
1 parent 068c0c3 commit 5430f70

File tree

10 files changed

+36
-12
lines changed

10 files changed

+36
-12
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ jobs:
1111
name: ${{ matrix.name }}
1212
runs-on: ubuntu-latest
1313
env:
14-
ESPHOME_VERSION: 2024.9.0
14+
ESPHOME_VERSION: 2025.7.2
1515
PLATFORMIO_LIBDEPS_DIR: ~/.platformio/libdeps
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
python-version: ["3.11"]
19+
python-version: ["3.13"]
2020

2121
steps:
2222
- uses: actions/checkout@v4

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ i2s:
2323
din_pin: 19
2424
sample_rate: 48000 # default: 48000
2525
bits_per_sample: 32 # default: 32
26+
mclk_multiple: 256 # default: 256
2627
dma_buf_count: 8 # default: 8
2728
dma_buf_len: 256 # default: 256
2829
use_apll: true # default: false
@@ -264,9 +265,9 @@ I'm not so familiar with assembler and it is hard to understand and maintain, so
264265
265266
### Supported platforms
266267
267-
Tested with ESPHome version 2024.9.0, platforms:
268-
- [x] ESP32 (Arduino v2.0.6, ESP-IDF v4.4.5)
269-
- [x] ESP32-IDF (ESP-IDF v4.4.7)
268+
Tested with ESPHome version 2025.7.2, platforms:
269+
- [x] ESP32 (Arduino v3.1.3, ESP-IDF v5.3.2)
270+
- [x] ESP32-IDF (ESP-IDF v5.3.2)
270271
271272
### Sending data to sensor.community
272273

components/i2s/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
CONF_DOUT_PIN = "dout_pin"
1919
CONF_SAMPLE_RATE = "sample_rate"
2020
CONF_BITS_PER_SAMPLE = "bits_per_sample"
21+
CONF_MCLK_MULTIPLE = "mclk_multiple"
2122
CONF_DMA_BUF_COUNT = "dma_buf_count"
2223
CONF_DMA_BUF_LEN = "dma_buf_len"
2324
CONF_USE_APLL = "use_apll"
@@ -31,6 +32,15 @@
3132
"right": i2s_channel_fmt_t.I2S_CHANNEL_FMT_ONLY_RIGHT,
3233
}
3334

35+
36+
def validate_mclk_divisible_by_3(config):
37+
if config[CONF_BITS_PER_SAMPLE] == 24 and config[CONF_MCLK_MULTIPLE] % 3 != 0:
38+
raise cv.Invalid(
39+
f"{CONF_MCLK_MULTIPLE} must be divisible by 3 when bits per sample is 24"
40+
)
41+
return config
42+
43+
3444
CONFIG_SCHEMA = cv.All(
3545
cv.Schema(
3646
{
@@ -41,6 +51,8 @@
4151
cv.Optional(CONF_DOUT_PIN): pins.internal_gpio_output_pin_schema,
4252
cv.Optional(CONF_SAMPLE_RATE, 48000): cv.positive_not_null_int,
4353
cv.Optional(CONF_BITS_PER_SAMPLE, 32): cv.one_of(8, 16, 24, 32, int=True),
54+
cv.Optional(CONF_MCLK_MULTIPLE, default=256):
55+
cv.one_of(128, 192, 256, 384, 512, 576, 768, 1024, 1152, int=True),
4456
cv.Optional(CONF_DMA_BUF_COUNT, 8): cv.positive_not_null_int,
4557
cv.Optional(CONF_DMA_BUF_LEN, 256): cv.positive_not_null_int,
4658
cv.Optional(CONF_USE_APLL, False): cv.boolean,
@@ -49,6 +61,7 @@
4961
}
5062
).extend(cv.COMPONENT_SCHEMA),
5163
cv.has_at_least_one_key(CONF_DIN_PIN, CONF_DOUT_PIN),
64+
validate_mclk_divisible_by_3
5265
)
5366

5467

@@ -69,6 +82,7 @@ async def to_code(config):
6982
cg.add(var.set_dout_pin(dout_pin))
7083
cg.add(var.set_sample_rate(config[CONF_SAMPLE_RATE]))
7184
cg.add(var.set_bits_per_sample(config[CONF_BITS_PER_SAMPLE]))
85+
cg.add(var.set_mclk_multiple(config[CONF_MCLK_MULTIPLE]))
7286
cg.add(var.set_dma_buf_count(config[CONF_DMA_BUF_COUNT]))
7387
cg.add(var.set_dma_buf_len(config[CONF_DMA_BUF_LEN]))
7488
cg.add(var.set_use_apll(config[CONF_USE_APLL]))

components/i2s/i2s.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "i2s.h"
2+
#include "esp_timer.h"
23

34
namespace esphome {
45
namespace i2s {
@@ -13,6 +14,8 @@ void I2SComponent::set_sample_rate(uint32_t sample_rate) { this->sample_rate_ =
1314
uint32_t I2SComponent::get_sample_rate() const { return this->sample_rate_; }
1415
void I2SComponent::set_bits_per_sample(uint8_t bits_per_sample) { this->bits_per_sample_ = bits_per_sample; }
1516
uint8_t I2SComponent::get_bits_per_sample() const { return this->bits_per_sample_; }
17+
void I2SComponent::set_mclk_multiple(uint32_t mclk_multiple) { this->mclk_multiple_ = mclk_multiple; }
18+
uint32_t I2SComponent::get_mclk_multiple() const { return this->mclk_multiple_; }
1619
void I2SComponent::set_dma_buf_count(int dma_buf_count) { this->dma_buf_count_ = dma_buf_count; }
1720
int I2SComponent::get_dma_buf_count() const { return this->dma_buf_count_; }
1821
void I2SComponent::set_dma_buf_len(int dma_buf_len) { this->dma_buf_len_ = dma_buf_len; }
@@ -30,8 +33,9 @@ void I2SComponent::dump_config() {
3033
LOG_PIN(" BCK Pin: ", this->bck_pin_);
3134
LOG_PIN(" DIN Pin: ", this->din_pin_);
3235
LOG_PIN(" DOUT Pin: ", this->dout_pin_);
33-
ESP_LOGCONFIG(TAG, " Sample Rate: %u", this->sample_rate_);
36+
ESP_LOGCONFIG(TAG, " Sample Rate: %lu", this->sample_rate_);
3437
ESP_LOGCONFIG(TAG, " Bits Per Sample: %u", this->bits_per_sample_);
38+
ESP_LOGCONFIG(TAG, " MCLK Multiple: %lu", this->mclk_multiple_);
3539
ESP_LOGCONFIG(TAG, " DMA Buf Count: %u", this->dma_buf_count_);
3640
ESP_LOGCONFIG(TAG, " DMA Buf Len: %u", this->dma_buf_len_);
3741
ESP_LOGCONFIG(TAG, " Use APLL: %s", YESNO(this->use_apll_));
@@ -143,7 +147,7 @@ void I2SComponent::setup() {
143147
.use_apll = this->use_apll_,
144148
.tx_desc_auto_clear = false,
145149
.fixed_mclk = 0,
146-
.mclk_multiple = I2S_MCLK_MULTIPLE_DEFAULT,
150+
.mclk_multiple = i2s_mclk_multiple_t(this->mclk_multiple_),
147151
.bits_per_chan = i2s_bits_per_chan_t(0)};
148152

149153
i2s_pin_config_t i2s_pin_config = {

components/i2s/i2s.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class I2SComponent : public Component {
2020
uint32_t get_sample_rate() const;
2121
void set_bits_per_sample(uint8_t bits_per_sample);
2222
uint8_t get_bits_per_sample() const;
23+
void set_mclk_multiple(uint32_t mclk_multiple);
24+
uint32_t get_mclk_multiple() const;
2325
void set_dma_buf_count(int dma_buf_count);
2426
int get_dma_buf_count() const;
2527
void set_dma_buf_len(int dma_buf_len);
@@ -46,6 +48,7 @@ class I2SComponent : public Component {
4648

4749
uint32_t sample_rate_{48000};
4850
uint8_t bits_per_sample_{32};
51+
uint32_t mclk_multiple_{256};
4952
uint8_t port_num_{0};
5053
int dma_buf_count_{8};
5154
int dma_buf_len_{256};

components/sound_level_meter/sound_level_meter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ optional<float> SoundLevelMeter::get_offset() { return this->offset_; }
3737
void SoundLevelMeter::dump_config() {
3838
ESP_LOGCONFIG(TAG, "Sound Level Meter:");
3939
ESP_LOGCONFIG(TAG, " Buffer Size: %u (samples)", this->buffer_size_);
40-
ESP_LOGCONFIG(TAG, " Warmup Interval: %u ms", this->warmup_interval_);
41-
ESP_LOGCONFIG(TAG, " Task Stack Size: %u", this->task_stack_size_);
40+
ESP_LOGCONFIG(TAG, " Warmup Interval: %lu ms", this->warmup_interval_);
41+
ESP_LOGCONFIG(TAG, " Task Stack Size: %lu", this->task_stack_size_);
4242
ESP_LOGCONFIG(TAG, " Task Priority: %u", this->task_priority_);
4343
ESP_LOGCONFIG(TAG, " Task Core: %u", this->task_core_);
4444
LOG_UPDATE_INTERVAL(this);
@@ -117,7 +117,7 @@ void SoundLevelMeter::task(void *param) {
117117
auto sr = this_->get_sample_rate();
118118
if (process_count >= sr * (this_->update_interval_ / 1000.f)) {
119119
auto t = uint32_t(float(process_time) / process_count * (sr / 1000.f));
120-
ESP_LOGD(TAG, "Processing time per 1s of audio data (%u samples): %u ms", sr, t);
120+
ESP_LOGD(TAG, "Processing time per 1s of audio data (%lu samples): %u ms", sr, t);
121121
process_time = process_count = 0;
122122
}
123123
}

components/sound_level_meter/sound_level_meter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include "esp_timer.h"
34
#include <mutex>
45
#include <condition_variable>
56
#include <algorithm>

configs/advanced-example-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ i2s:
2020
din_pin: 19
2121
sample_rate: 48000 # default: 48000
2222
bits_per_sample: 32 # default: 32
23+
mclk_multiple: 256 # default: 256
2324
dma_buf_count: 8 # default: 8
2425
dma_buf_len: 256 # default: 256
2526
use_apll: true # default: false

configs/sensor-community-example-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ i2s:
4040
din_pin: 19
4141
sample_rate: 48000
4242
bits_per_sample: 32
43+
mclk_multiple: 256
4344
dma_buf_count: 8
4445
dma_buf_len: 256
4546
use_apll: true
@@ -87,7 +88,7 @@ interval:
8788
then:
8889
- http_request.post:
8990
url: http://api.sensor.community/v1/push-sensor-data/
90-
headers:
91+
request_headers:
9192
X-Pin: 15
9293
X-Sensor: esp32-... # replace with your sensor ID
9394
Content-Type: application/json

configs/wdt_include.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)