I am trying to point the DMA buffer to an address in my setup and keep sending the data in an interrupt function (once per execution) without reloading DMA. I know my code works if I put the i2s_write in the interrupt function but that is not my goal. I also tried to find the i2s_write(); definition to define a new function without loading DMA but can only find the declaration in i2s.h and no source code.
here is a summary of my code:
#include "driver/i2s.h"
const i2s_port_t I2S_PORT = I2S_NUM_0;
#define I2S_LRCLK_PIN 15 // 0
#define I2S_BCLK_PIN 27 // 1
#define I2S_TX_PIN 33 // 9
#define I2S_RX_PIN -1 // 2
int32_t waveDMA[WAV_SIZE] = {0}; // scaled waveform
void setup(){
esp_err_t err;
// The I2S config as per the example
const i2s_config_t i2s_config = {
.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_TX), //
.sample_rate = SAMPLERATE_HZ, //
.bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT, //
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, //
.communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
.intr_alloc_flags = 0,//ESP_INTR_FLAG_LEVEL1, // Interrupt level 1
.dma_buf_count = 2, // number of buffers
.dma_buf_len = 32,
.use_apll = false,
.tx_desc_auto_clear=true//
};
// The pin config as per the setup
const i2s_pin_config_t pin_config = {
.bck_io_num = I2S_BCLK_PIN, // Serial Clock (SCK)
.ws_io_num = I2S_LRCLK_PIN , // Word Select (WS)
.data_out_num = I2S_TX_PIN, // not used (only for speakers)
.data_in_num = 32 // Serial Data (SD)
};
// Configuring the I2S driver and pins.
// This function must be called before any I2S driver read/write operations.
err = i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
if (err != ESP_OK) {
Serial.printf("Failed installing driver: %d\n", err);
while (true);
}
err = i2s_set_pin(I2S_PORT, &pin_config);
if (err != ESP_OK) {
Serial.printf("Failed setting pin: %d\n", err);
while (true);
}
Serial.println("I2S driver installed.");
size_t bytesWritten=0;
i2s_write(I2S_PORT, waveDMA, sizeof(waveDMA), &bytesWritten, portMAX_DELAY);
}
void interrupt_function(){
/// how can I just trigger DMA to write to I2S (once) ?
}