i2s function to seperate file
This commit is contained in:
@@ -1,74 +1,71 @@
|
||||
// #include <stdint.h>
|
||||
// #include <string.h>
|
||||
// #include <stdbool.h>
|
||||
// #include "freertos/xtensa_api.h"
|
||||
// #include "freertos/FreeRTOSConfig.h"
|
||||
// #include "freertos/FreeRTOS.h"
|
||||
// #include "freertos/queue.h"
|
||||
// #include "freertos/task.h"
|
||||
// #include "esp_log.h"
|
||||
// //#include "bt_app_core.h"
|
||||
// #include "driver/i2s.h"
|
||||
// #include "freertos/ringbuf.h"
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include "freertos/xtensa_api.h"
|
||||
#include "freertos/FreeRTOSConfig.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include "driver/i2s.h"
|
||||
#include "freertos/ringbuf.h"
|
||||
|
||||
// #include "H2201_i2s.h"
|
||||
static xTaskHandle h2201_i2s_task_handle = NULL;
|
||||
static RingbufHandle_t h2201_i2s_ringbuffer_handle = NULL;
|
||||
|
||||
// static xTaskHandle h2201_i2s_task_handle = NULL;
|
||||
// static RingbufHandle_t s_ringbuf_i2s = NULL;
|
||||
static void h2201_i2s_task(void *arg)
|
||||
{
|
||||
uint8_t *data = NULL;
|
||||
size_t item_size = 0;
|
||||
size_t bytes_written = 0;
|
||||
|
||||
// static void h2201_i2s_task(void *arg)
|
||||
// {
|
||||
// uint8_t *data = NULL;
|
||||
// size_t item_size = 0;
|
||||
// size_t bytes_written = 0;
|
||||
for (;;)
|
||||
{
|
||||
data = (uint8_t *)xRingbufferReceive(h2201_i2s_ringbuffer_handle, &item_size, (portTickType)portMAX_DELAY);
|
||||
if (item_size != 0)
|
||||
{
|
||||
i2s_write(0, data, item_size, &bytes_written, portMAX_DELAY);
|
||||
vRingbufferReturnItem(h2201_i2s_ringbuffer_handle, (void *)data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for (;;)
|
||||
// {
|
||||
// data = (uint8_t *)xRingbufferReceive(s_ringbuf_i2s, &item_size, (portTickType)portMAX_DELAY);
|
||||
// if (item_size != 0)
|
||||
// {
|
||||
// i2s_write(0, data, item_size, &bytes_written, portMAX_DELAY);
|
||||
// vRingbufferReturnItem(s_ringbuf_i2s, (void *)data);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
void h2201_i2s_task_start_up(void)
|
||||
{
|
||||
h2201_i2s_ringbuffer_handle = xRingbufferCreate(8 * 1024, RINGBUF_TYPE_BYTEBUF);
|
||||
if (h2201_i2s_ringbuffer_handle == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// void h2201_i2s_task_start_up(void)
|
||||
// {
|
||||
// s_ringbuf_i2s = xRingbufferCreate(8 * 1024, RINGBUF_TYPE_BYTEBUF);
|
||||
// if (s_ringbuf_i2s == NULL)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
xTaskCreate(h2201_i2s_task, "BtI2ST", 1024, NULL, configMAX_PRIORITIES - 3, &h2201_i2s_task_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
// xTaskCreate(h2201_i2s_task, "BtI2ST", 1024, NULL, configMAX_PRIORITIES - 3, &h2201_i2s_task_handle);
|
||||
// return;
|
||||
// }
|
||||
void h2201_i2s_task_shut_down(void)
|
||||
{
|
||||
if (h2201_i2s_task_handle)
|
||||
{
|
||||
vTaskDelete(h2201_i2s_task_handle);
|
||||
h2201_i2s_task_handle = NULL;
|
||||
}
|
||||
|
||||
// void h2201_i2s_task_shut_down(void)
|
||||
// {
|
||||
// if (h2201_i2s_task_handle)
|
||||
// {
|
||||
// vTaskDelete(h2201_i2s_task_handle);
|
||||
// h2201_i2s_task_handle = NULL;
|
||||
// }
|
||||
if (h2201_i2s_ringbuffer_handle)
|
||||
{
|
||||
vRingbufferDelete(h2201_i2s_ringbuffer_handle);
|
||||
h2201_i2s_ringbuffer_handle = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// if (s_ringbuf_i2s)
|
||||
// {
|
||||
// vRingbufferDelete(s_ringbuf_i2s);
|
||||
// s_ringbuf_i2s = NULL;
|
||||
// }
|
||||
// }
|
||||
|
||||
// size_t h2201_i2s_write_ringbuf(const uint8_t *data, size_t size)
|
||||
// {
|
||||
// BaseType_t done = xRingbufferSend(s_ringbuf_i2s, (void *)data, size, (portTickType)portMAX_DELAY);
|
||||
// if (done)
|
||||
// {
|
||||
// return size;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return 0;
|
||||
// }
|
||||
// }
|
||||
size_t h2201_i2s_write_ringbuf(const uint8_t *data, size_t size)
|
||||
{
|
||||
BaseType_t done = xRingbufferSend(h2201_i2s_ringbuffer_handle, (void *)data, size, (portTickType)portMAX_DELAY);
|
||||
if (done)
|
||||
{
|
||||
return size;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
// #ifndef __H2201_I2S_H__
|
||||
// #define __H2201_I2S_H__
|
||||
#ifndef __H2201_I2S_H__
|
||||
#define __H2201_I2S_H__
|
||||
|
||||
// void h2201_i2s_task_start_up(void);
|
||||
void h2201_i2s_task_start_up(void);
|
||||
|
||||
// void h2201_i2s_task_shut_down(void);
|
||||
void h2201_i2s_task_shut_down(void);
|
||||
|
||||
// size_t h2201_i2s_write_ringbuf(const uint8_t *data, size_t size);
|
||||
size_t h2201_i2s_write_ringbuf(const uint8_t *data, size_t size);
|
||||
|
||||
// #endif /* __H2201_I2S_H__ */
|
||||
#endif /* __H2201_I2S_H__ */
|
||||
@@ -27,6 +27,8 @@
|
||||
|
||||
#include "sys/lock.h"
|
||||
|
||||
#include "H2201_i2s.h"
|
||||
|
||||
// AVRCP used transaction label
|
||||
#define APP_RC_CT_TL_GET_CAPS (0)
|
||||
#define APP_RC_CT_TL_GET_META_DATA (1)
|
||||
|
||||
@@ -25,8 +25,6 @@ static void bt_app_work_dispatched(bt_app_msg_t *msg);
|
||||
|
||||
static xQueueHandle s_bt_app_task_queue = NULL;
|
||||
static xTaskHandle s_bt_app_task_handle = NULL;
|
||||
static xTaskHandle s_bt_i2s_task_handle = NULL;
|
||||
static RingbufHandle_t s_ringbuf_i2s = NULL;
|
||||
|
||||
bool bt_app_work_dispatch(bt_app_cb_t p_cback, uint16_t event, void *p_params, int param_len, bt_app_copy_cb_t p_copy_cback)
|
||||
{
|
||||
@@ -128,61 +126,4 @@ void bt_app_task_shut_down(void)
|
||||
vQueueDelete(s_bt_app_task_queue);
|
||||
s_bt_app_task_queue = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void h2201_i2s_task(void *arg)
|
||||
{
|
||||
uint8_t *data = NULL;
|
||||
size_t item_size = 0;
|
||||
size_t bytes_written = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
data = (uint8_t *)xRingbufferReceive(s_ringbuf_i2s, &item_size, (portTickType)portMAX_DELAY);
|
||||
if (item_size != 0)
|
||||
{
|
||||
i2s_write(0, data, item_size, &bytes_written, portMAX_DELAY);
|
||||
vRingbufferReturnItem(s_ringbuf_i2s, (void *)data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void h2201_i2s_task_start_up(void)
|
||||
{
|
||||
s_ringbuf_i2s = xRingbufferCreate(8 * 1024, RINGBUF_TYPE_BYTEBUF);
|
||||
if (s_ringbuf_i2s == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
xTaskCreate(h2201_i2s_task, "BtI2ST", 1024, NULL, configMAX_PRIORITIES - 3, &s_bt_i2s_task_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
void h2201_i2s_task_shut_down(void)
|
||||
{
|
||||
if (s_bt_i2s_task_handle)
|
||||
{
|
||||
vTaskDelete(s_bt_i2s_task_handle);
|
||||
s_bt_i2s_task_handle = NULL;
|
||||
}
|
||||
|
||||
if (s_ringbuf_i2s)
|
||||
{
|
||||
vRingbufferDelete(s_ringbuf_i2s);
|
||||
s_ringbuf_i2s = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
size_t h2201_i2s_write_ringbuf(const uint8_t *data, size_t size)
|
||||
{
|
||||
BaseType_t done = xRingbufferSend(s_ringbuf_i2s, (void *)data, size, (portTickType)portMAX_DELAY);
|
||||
if (done)
|
||||
{
|
||||
return size;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,10 +45,4 @@ void bt_app_task_start_up(void);
|
||||
|
||||
void bt_app_task_shut_down(void);
|
||||
|
||||
void h2201_i2s_task_start_up(void);
|
||||
|
||||
void h2201_i2s_task_shut_down(void);
|
||||
|
||||
size_t h2201_i2s_write_ringbuf(const uint8_t *data, size_t size);
|
||||
|
||||
#endif /* __BT_APP_CORE_H__ */
|
||||
|
||||
@@ -58,14 +58,16 @@ void app_main(void)
|
||||
i2s_config_t i2s_config = {
|
||||
.mode = I2S_MODE_MASTER | I2S_MODE_TX, // Only TX
|
||||
.sample_rate = 48000,
|
||||
.bits_per_sample = 16,
|
||||
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
|
||||
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, // 2-channels
|
||||
//.channel_format = I2S_CHANNEL_FMT_MULTIPLE, // multi channel
|
||||
.communication_format = I2S_COMM_FORMAT_STAND_I2S,
|
||||
.dma_buf_count = 8,
|
||||
.dma_buf_len = 64,
|
||||
.intr_alloc_flags = 0, // Default interrupt priority
|
||||
.use_apll = true,
|
||||
.tx_desc_auto_clear = true // Auto clear tx descriptor on underflow
|
||||
//.chan_mask = I2S_TDM_ACTIVE_CH0 | I2S_TDM_ACTIVE_CH1
|
||||
};
|
||||
i2s_driver_install(i2s_num, &i2s_config, 0, NULL);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user