Skip to content

Commit a84634d

Browse files
committed
STM32 I2S
1 parent c01972e commit a84634d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/AudioI2S/I2SSTM32.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class I2SDriverSTM32 {
7676
int availableForWrite() {
7777
if (!active) return 0;
7878
if (use_dma && p_tx_buffer == nullptr) return 0;
79-
return cfg.buffer_size;
79+
return cfg.buffer_size * 2;
8080
}
8181

8282
/// provides the actual configuration
@@ -85,6 +85,7 @@ class I2SDriverSTM32 {
8585
/// blocking writes for the data to the I2S interface
8686
size_t writeBytes(const void *src, size_t size_bytes) {
8787
TRACED();
88+
size_t result = 0;
8889
if (!use_dma) {
8990
result = i2s.write((uint8_t *)src, size_bytes);
9091
} else {
@@ -137,7 +138,6 @@ class I2SDriverSTM32 {
137138
I2SDriverSTM32 *self = (I2SDriverSTM32 *)ref;
138139
static size_t count = 0;
139140
size_t read = 0;
140-
memset(buffer, 0, byteCount);
141141
if (self->p_dma_in != nullptr) {
142142
// stop reading if timout is relevant
143143
if (self->isWriteTimedOut()) {
@@ -153,12 +153,13 @@ class I2SDriverSTM32 {
153153
read = self->p_tx_buffer->readArray(buffer, byteCount);
154154
}
155155
}
156+
memset(buffer+read, 0, byteCount-read);
156157

157158
// check for underflow
158-
// count++;
159-
// if (read != byteCount) {
160-
// LOGW("Buffer undeflow at %lu: %d for %d", count, read, byteCount);
161-
// }
159+
count++;
160+
if (read != byteCount) {
161+
LOGW("Buffer underflow at %lu: %d for %d", count, read, byteCount);
162+
}
162163
}
163164

164165
/// Checks if timout has been activated and if so, if it is timed out
@@ -205,7 +206,7 @@ class I2SDriverSTM32 {
205206
open -= actual_written;
206207
if (open > 0) {
207208
stm32_write_active = true;
208-
delay(1);
209+
//delay(1);
209210
}
210211
}
211212

@@ -404,7 +405,8 @@ class I2SDriverSTM32 {
404405
}
405406

406407
BaseBuffer<uint8_t>* allocateBuffer() {
407-
return new RingBuffer<uint8_t>(cfg.buffer_size * cfg.buffer_count);
408+
//return new RingBuffer<uint8_t>(cfg.buffer_size * cfg.buffer_count);
409+
return new NBuffer<uint8_t>(cfg.buffer_size, cfg.buffer_count);
408410
}
409411
};
410412

0 commit comments

Comments
 (0)