summaryrefslogtreecommitdiff
path: root/fw/esp32/components/eos/cell_pcm.c
diff options
context:
space:
mode:
Diffstat (limited to 'fw/esp32/components/eos/cell_pcm.c')
-rw-r--r--fw/esp32/components/eos/cell_pcm.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/fw/esp32/components/eos/cell_pcm.c b/fw/esp32/components/eos/cell_pcm.c
index 0648be7..b993021 100644
--- a/fw/esp32/components/eos/cell_pcm.c
+++ b/fw/esp32/components/eos/cell_pcm.c
@@ -59,23 +59,42 @@ static void i2s_event_task(void *pvParameters) {
unsigned char _type;
unsigned char *buf;
+ if (!pcm_active) {
+ if (hold_buf) {
+ eos_net_free(hold_buf);
+ hold_buf = NULL;
+ }
+ break;
+ }
+
// Event of I2S receiving data
if (!hold_cnt) {
-
buf = eos_net_alloc();
buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_PCM;
bytes_r = eos_cell_pcm_read(buf + 1, PCM_MIC_WM);
+ if (bytes_r < 0) {
+ ESP_LOGE(TAG, "*** I2S READ ERROR ***");
+ eos_net_free(buf);
+ break;
+ }
eos_net_send(EOS_NET_MTYPE_CELL, buf, bytes_r + 1);
} else {
- hold_cnt--;
if (hold_buf == NULL) {
hold_buf = eos_net_alloc();
hold_buf[0] = EOS_CELL_MTYPE_VOICE | EOS_CELL_MTYPE_VOICE_PCM;
+ hold_bytes_r = 0;
+ }
+ if (1 + hold_bytes_r + PCM_MIC_WM <= EOS_NET_SIZE_BUF) {
+ bytes_r = eos_cell_pcm_read(hold_buf + 1 + hold_bytes_r, PCM_MIC_WM);
+ if (bytes_r < 0) {
+ ESP_LOGE(TAG, "*** I2S READ ERROR ***");
+ break;
+ }
+ hold_bytes_r += bytes_r;
}
- if (1 + hold_bytes_r + PCM_MIC_WM <= EOS_NET_MTU) hold_bytes_r += eos_cell_pcm_read(hold_buf + 1 + hold_bytes_r, PCM_MIC_WM);
+ hold_cnt--;
if (hold_cnt == 0) {
eos_net_send(EOS_NET_MTYPE_CELL, hold_buf, hold_bytes_r + 1);
- hold_bytes_r = 0;
hold_buf = NULL;
}
}
@@ -87,10 +106,16 @@ static void i2s_event_task(void *pvParameters) {
xSemaphoreGive(mutex);
if (buf) {
- i2s_write(I2S_NUM_0, (const void *)buf, bytes_e, &bytes_w, portMAX_DELAY);
+ esp_err_t ret;
+
+ ret = i2s_write(I2S_NUM_0, (const void *)buf, bytes_e, &bytes_w, 1000 / portTICK_RATE_MS);
xSemaphoreTake(mutex, portMAX_DELAY);
eos_bufq_push(&pcm_buf_q, buf);
xSemaphoreGive(mutex);
+ if (ret != ESP_OK) {
+ ESP_LOGE(TAG, "*** I2S WRITE ERROR ***");
+ break;
+ }
}
break;
}
@@ -172,11 +197,12 @@ void eos_cell_pcm_init(void) {
ssize_t eos_cell_pcm_read(unsigned char *data, size_t size) {
static unsigned char buf[PCM_SIZE_BUF];
size_t bytes_r;
+ esp_err_t ret;
int i;
if (size > PCM_MIC_WM) return EOS_ERR;
- esp_err_t ret = i2s_read(I2S_NUM_0, (void *)buf, size * 4, &bytes_r, portMAX_DELAY);
+ ret = i2s_read(I2S_NUM_0, (void *)buf, size * 4, &bytes_r, 1000 / portTICK_RATE_MS);
if (ret != ESP_OK) return EOS_ERR;
for (i=0; i<size/2; i++) {