@@ -76,7 +76,7 @@ class I2SDriverSTM32 {
76
76
int availableForWrite () {
77
77
if (!active) return 0 ;
78
78
if (use_dma && p_tx_buffer == nullptr ) return 0 ;
79
- return cfg.buffer_size ;
79
+ return cfg.buffer_size * 2 ;
80
80
}
81
81
82
82
// / provides the actual configuration
@@ -85,6 +85,7 @@ class I2SDriverSTM32 {
85
85
// / blocking writes for the data to the I2S interface
86
86
size_t writeBytes (const void *src, size_t size_bytes) {
87
87
TRACED ();
88
+ size_t result = 0 ;
88
89
if (!use_dma) {
89
90
result = i2s.write ((uint8_t *)src, size_bytes);
90
91
} else {
@@ -137,7 +138,6 @@ class I2SDriverSTM32 {
137
138
I2SDriverSTM32 *self = (I2SDriverSTM32 *)ref;
138
139
static size_t count = 0 ;
139
140
size_t read = 0 ;
140
- memset (buffer, 0 , byteCount);
141
141
if (self->p_dma_in != nullptr ) {
142
142
// stop reading if timout is relevant
143
143
if (self->isWriteTimedOut ()) {
@@ -153,12 +153,13 @@ class I2SDriverSTM32 {
153
153
read = self->p_tx_buffer ->readArray (buffer, byteCount);
154
154
}
155
155
}
156
+ memset (buffer+read, 0 , byteCount-read);
156
157
157
158
// 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
+ }
162
163
}
163
164
164
165
// / Checks if timout has been activated and if so, if it is timed out
@@ -205,7 +206,7 @@ class I2SDriverSTM32 {
205
206
open -= actual_written;
206
207
if (open > 0 ) {
207
208
stm32_write_active = true ;
208
- delay (1 );
209
+ // delay(1);
209
210
}
210
211
}
211
212
@@ -404,7 +405,8 @@ class I2SDriverSTM32 {
404
405
}
405
406
406
407
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 );
408
410
}
409
411
};
410
412
0 commit comments