// I2S接口驱动
// 杭州秒寻科技有限公司
// 周涛
// 2023-09-13

#ifndef DRIVERI2S_H
#define DRIVERI2S_H

#include "sysdef.h"

#define DRIVER_I2S_CPLD_START_GPIO_CLK RCC_AHB1Periph_GPIOD
#define DRIVER_I2S_CPLD_START_GPIO_PORT GPIOD
#define DRIVER_I2S_CPLD_START_GPIO_PIN GPIO_Pin_8

#define DRIVERI2S_SAMPLE_RATIO 48000                                                                                  // 采样率
#define DRIVERI2S_ONE_SECOND_SIGNAL_LEN (DRIVERI2S_SAMPLE_RATIO * 2 * 2)                                              // 一秒信号的长度(2BYTE)
#define DRIVERI2S_BUFFER_LEN 4000                                                                                     // DMA一次发送数量（2byte）
#define DRIVERI2S_ONE_SECOND_SIGNAL_SEND_TIMES (DRIVERI2S_ONE_SECOND_SIGNAL_LEN / DRIVERI2S_BUFFER_LEN)               // 一秒信号的发送次数
#define DRIVERI2S_BASE_ID_LEN 3                                                                                       // 基站ID位宽
#define DRIVERI2S_MINUS_TIMES 2                                                                                       // 每次少发次数
#define DRIVERI2S_SEND_TIMES (DRIVERI2S_ONE_SECOND_SIGNAL_SEND_TIMES * DRIVERI2S_BASE_ID_LEN - DRIVERI2S_MINUS_TIMES) // 一个周期信号的发送次数                                                                   // 每秒信号发送48次，为了同步故意少发2次

// 供外部使用的接口
void driver_i2s_init();
void driver_i2s_start_send_cpld_test_data();
void driver_i2s_cpld_cmd(uint8 byBitValue);
void driver_i2s_start_send_data(uint32 *pdwSingnalSendList);
void driver_i2s_stop_send_data();
uint8 driver_i2s_query_cpld_status();
uint8 driver_i2s_query_send_status();

// 内部使用接口
void driver_i2s_init_cpld();
void driver_i2s_init_i2s();
void driver_i2s_init_dma();
void driver_i2s_init_dma_test();
void driver_i2s_fill_buf_data(uint16 wCounter);

void driver_i2s_send_data_to_gui(uint32 dwAddress);

#endif
