Files
player/Project/Src/Drive/Include/dac.h
2025-07-05 19:47:28 +08:00

71 lines
1.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef DAC_H__
#define DAC_H__
#include "stm32f4xx.h"
//定义采样率对应的定时器周期
//定时器频率是90Mhz时
#define RATE11025 8163
#define RATE22050 4081
#define RATE44100 2041
#define RATE48000 1875 //这个是整数
// dac 最大音量等级
#define DAC_VOL_MAX 10
//定义使用的定时器
#define DAC_TIMER TIM4
#define DAC_TIMER_RCC RCC_APB1Periph_TIM4
typedef struct _DAC_UserStruct
{
u32 *buff1; //buff的高16位声道1低16位声道2
u32 *buff2;
int buff_size;
int buff_useing;// 当前正在使用哪个buff
int buff_Invalid;// 1,有空闲buff0无空闲buff
int rate; //采样率对应的定时器周期
void (*call_back)(struct _DAC_UserStruct *u);
}DAC_UserStruct;
// 以双缓冲方式初始化返回0成功
int DAC_NormalInit (DAC_UserStruct *dac);
void DAC_NormalDeInit (DAC_UserStruct *dac);
//获取DAC句柄
DAC_UserStruct *DAC_GetDacHander (void);
//根据采样率求得定时器频率
u16 DAC_GetRate (u16 rate);
// 填充缓冲区,返回0成功-1失败
int DAC_FillBuff(int16_t *buf,int size,int nch);
// 以fifo方式初始化,返回0成功
int DAC_FifolInit (void);
void DAC_FifoDeInit (void);
// 设置获取数据函数
int DAC_SetSetValuwFun(int (*fun)(uint16_t *));
// 保存数据,返回0成功
int DAC_SaveValue(uint16_t value);
#endif