数据结构设计
29 May 2024
Read time: 3 minute(s)
HAL 层数据结构
-
hal_i2s.h 的数据结构
struct aic_i2s_buf_info { void *buf; uint32_t buf_len; uint32_t period_len; }; struct aic_i2s_transfer_info { struct aic_dma_chan *dma_chan; struct aic_audio_buf_info buf_info; int transfer_type; }; struct aic_i2s_ctrl { unsigned long reg_base; uint32_t irq_num; uint32_t clk_id; uint32_t idx; struct aic_audio_transfer_info tx_info; //TX buffer 的参数 struct aic_audio_transfer_info rx_info; //RX buffer 的参数 i2s_callback callback; void *arg; };
-
hal_i2s_format.h 的数据结构
typedef enum { I2S_MODE_MASTER, I2S_MODE_SLAVE, } i2s_mode_t; typedef enum { I2S_PROTOCOL_I2S, I2S_PROTOCOL_LEFT_J, I2S_PROTOCOL_RIGHT_J, I2S_PCM_SHORT, I2S_PCM_LONG, } i2s_protocol_t; typedef enum { I2S_LEFT_POLARITY_LOW, I2S_LEFT_POLARITY_HIGH, } i2s_polarity_t; typedef enum { I2S_SAMPLE_RATE_8000 = 8000U, I2S_SAMPLE_RATE_11025 = 11025U, I2S_SAMPLE_RATE_12000 = 12000U, I2S_SAMPLE_RATE_16000 = 16000U, I2S_SAMPLE_RATE_22050 = 22050U, I2S_SAMPLE_RATE_24000 = 24000U, I2S_SAMPLE_RATE_32000 = 32000U, I2S_SAMPLE_RATE_44100 = 44100U, I2S_SAMPLE_RATE_48000 = 48000U, I2S_SAMPLE_RATE_96000 = 96000U, I2S_SAMPLE_RATE_192000 = 192000U, I2S_SAMPLE_RATE_256000 = 256000U, } i2s_sample_rate_t; typedef enum { I2S_SAMPLE_WIDTH_8BIT = 8U, I2S_SAMPLE_WIDTH_12BIT = 12U, I2S_SAMPLE_WIDTH_16BIT = 16U, I2S_SAMPLE_WIDTH_20BIT = 20U, I2S_SAMPLE_WIDTH_24BIT = 24U, I2S_SAMPLE_WIDTH_28BIT = 28U, I2S_SAMPLE_WIDTH_32BIT = 32U, } i2s_sample_width_t; typedef enum { I2S_LEFT_CHANNEL, I2S_RIGHT_CHANNEL, I2S_LEFT_RIGHT_CHANNEL, } i2s_sound_channel_t; typedef enum { I2S_STREAM_PLAYBACK = 0, I2S_STREAM_RECORD = 1, } i2s_stream_t; typedef struct { i2s_mode_t mode; i2s_protocol_t protocol; i2s_polarity_t polarity; i2s_sample_rate_t rate; i2s_sample_width_t width; i2s_sound_channel_t channel; uint32_t sclk_nfs; uint32_t mclk_nfs; i2s_stream_t stream; } i2s_format_t;
Driver 层数据结构
struct aic_i2s_sound
{
struct rt_audio_device audio;
aic_i2s_ctrl i2s;
struct codec *codec;
i2s_format_t format; //i2s 的传输格式
rt_uint8_t volume; //playback 音量
char *name; //设备名
uint32_t i2s_idx;
uint8_t record_idx;
};
static struct aic_i2s_sound snd_dev[] =
{
#ifdef AIC_USING_I2S0
{
.name = "i2s0_sound",
.i2s_idx = 0,
},
#endif
#ifdef AIC_USING_I2S1
{
.name = "i2s1_sound",
.i2s_idx = 1,
},
#endif
};