forked from Makuna/NeoPixelBus
@@ -142,7 +142,7 @@ bool i2sInitDmaItems(uint8_t bus_num) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
I2S[bus_num].tx_queue = xQueueCreate(I2S[bus_num].dma_count, sizeof(i2s_dma_item_t*));
|
I2S[bus_num].tx_queue = xQueueCreate(I2S[bus_num].dma_count - 3, sizeof(i2s_dma_item_t*));
|
||||||
if (I2S[bus_num].tx_queue == NULL) {// memory error
|
if (I2S[bus_num].tx_queue == NULL) {// memory error
|
||||||
log_e("MEM ERROR!");
|
log_e("MEM ERROR!");
|
||||||
free(I2S[bus_num].dma_items);
|
free(I2S[bus_num].dma_items);
|
||||||
@@ -434,21 +434,13 @@ void IRAM_ATTR i2sDmaISR(void* arg)
|
|||||||
i2s_bus_t* dev = (i2s_bus_t*)arg;
|
i2s_bus_t* dev = (i2s_bus_t*)arg;
|
||||||
portBASE_TYPE hpTaskAwoken = 0;
|
portBASE_TYPE hpTaskAwoken = 0;
|
||||||
|
|
||||||
if (dev->bus->int_st.out_dscr_err) {
|
if (dev->bus->int_st.out_eof) {
|
||||||
ets_printf("out_dscr_err\n");
|
|
||||||
}
|
|
||||||
while (dev->bus->int_st.out_eof) {
|
|
||||||
i2s_dma_item_t* item = (i2s_dma_item_t*)dev->bus->out_eof_des_addr;
|
i2s_dma_item_t* item = (i2s_dma_item_t*)dev->bus->out_eof_des_addr;
|
||||||
dev->bus->int_clr.out_eof = 1;
|
|
||||||
|
|
||||||
if (item->data != dev->silence_buf) {
|
|
||||||
item->data = dev->silence_buf;
|
item->data = dev->silence_buf;
|
||||||
item->blocksize = dev->silence_len;
|
item->blocksize = dev->silence_len;
|
||||||
item->datalen = dev->silence_len;
|
item->datalen = dev->silence_len;
|
||||||
}
|
if (xQueueIsQueueFullFromISR(dev->tx_queue) == pdTRUE) {
|
||||||
if (xQueueIsQueueFullFromISR(dev->tx_queue) == pdTRUE && xQueueReceiveFromISR(dev->tx_queue, &dummy, &hpTaskAwoken) == pdTRUE && dummy->free_ptr) {
|
xQueueReceiveFromISR(dev->tx_queue, &dummy, &hpTaskAwoken);
|
||||||
free(dummy->free_ptr);
|
|
||||||
dummy->free_ptr = NULL;
|
|
||||||
}
|
}
|
||||||
xQueueSendFromISR(dev->tx_queue, (void*)&item, &hpTaskAwoken);
|
xQueueSendFromISR(dev->tx_queue, (void*)&item, &hpTaskAwoken);
|
||||||
}
|
}
|
||||||
@@ -467,58 +459,26 @@ size_t i2sWrite(uint8_t bus_num, uint8_t* data, size_t len, bool copy, bool free
|
|||||||
size_t limit = I2S_DMA_MAX_DATA_LEN;
|
size_t limit = I2S_DMA_MAX_DATA_LEN;
|
||||||
i2s_dma_item_t* item = NULL;
|
i2s_dma_item_t* item = NULL;
|
||||||
|
|
||||||
if (I2S[bus_num].dma_buf_len) {
|
|
||||||
limit = I2S[bus_num].dma_buf_len;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (len) {
|
while (len) {
|
||||||
if (xQueueReceive(I2S[bus_num].tx_queue, &item, portMAX_DELAY) == pdFALSE) {
|
|
||||||
log_e("xQueueReceive failed\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (item->free_ptr) {
|
|
||||||
free(item->free_ptr);
|
|
||||||
item->free_ptr = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
toSend = len;
|
toSend = len;
|
||||||
|
|
||||||
if (toSend > limit) {
|
if (toSend > limit) {
|
||||||
toSend = limit;
|
toSend = limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!copy) {
|
if (xQueueReceive(I2S[bus_num].tx_queue, &item, portMAX_DELAY) == pdFALSE) {
|
||||||
|
log_e("xQueueReceive failed\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
// data is constant. no need to copy
|
// data is constant. no need to copy
|
||||||
item->data = data + index;
|
item->data = data + index;
|
||||||
item->blocksize = toSend;
|
item->blocksize = toSend;
|
||||||
item->datalen = toSend;
|
item->datalen = toSend;
|
||||||
if (free_when_sent && (toSend == len)) {
|
|
||||||
// free the full data when done
|
|
||||||
item->free_ptr = data;
|
|
||||||
}
|
|
||||||
} else if (item->buf) {
|
|
||||||
// dma buffers are preallocated
|
|
||||||
memcpy(item->buf, data+index, toSend);
|
|
||||||
item->data = item->buf;
|
|
||||||
item->blocksize = toSend;
|
|
||||||
item->datalen = toSend;
|
|
||||||
} else {
|
|
||||||
// copy data to a new buffer (dma buffers are NULL)
|
|
||||||
uint8_t* buf = (uint8_t*)malloc(toSend);
|
|
||||||
if (!buf) {
|
|
||||||
log_e("buf = NULL; %u/%u (%u/%u)\n", index, len, toSend, esp_get_free_heap_size());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
memcpy(buf, data+index, toSend);
|
|
||||||
item->free_ptr = buf;
|
|
||||||
item->data = buf;
|
|
||||||
item->blocksize = toSend;
|
|
||||||
item->datalen = toSend;
|
|
||||||
}
|
|
||||||
len -= toSend;
|
len -= toSend;
|
||||||
index += toSend;
|
index += toSend;
|
||||||
}
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -117,7 +117,7 @@ public:
|
|||||||
|
|
||||||
void Initialize()
|
void Initialize()
|
||||||
{
|
{
|
||||||
i2sInit(T_BUS::I2sBusNumber, 16, c_dmaI2sSampleRate / T_SPEED::I2sSampleRateDiv, I2S_CHAN_STEREO, I2S_FIFO_16BIT_DUAL, 2, 0);
|
i2sInit(T_BUS::I2sBusNumber, 16, c_dmaI2sSampleRate / T_SPEED::I2sSampleRateDiv, I2S_CHAN_STEREO, I2S_FIFO_16BIT_DUAL, 4, 0);
|
||||||
i2sSetPins(T_BUS::I2sBusNumber, _pin, -1, -1, -1);
|
i2sSetPins(T_BUS::I2sBusNumber, _pin, -1, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user