SmartSnippets DA1459x SDK
sys_audio_mgr.h
Go to the documentation of this file.
1 
44 #ifndef SYS_AUDIO_MGR_H_
45 #define SYS_AUDIO_MGR_H_
46 
47 
48 #if dg_configUSE_SYS_AUDIO_MGR
49 
50 #include <stdbool.h>
51 #include <string.h>
52 #include "hw_dma.h"
53 #include "hw_pdm.h"
54 #include "hw_pcm.h"
55 
56 # if dg_configUSE_HW_SDADC
57 #include "hw_sdadc.h"
58 # endif /* dg_configUSE_HW_SDADC */
59 
60 #define MAX_NUM_OF_PATHS 4 // the max number of concurrently supported audio data paths according to device family
61 
65 typedef enum {
66  AUDIO_INVALID = 0,
67  AUDIO_PCM,
68  AUDIO_PDM,
69  AUDIO_MEMORY,
70 # if dg_configUSE_HW_SDADC
71  AUDIO_SDADC,
72 # endif /* dg_configUSE_HW_SDADC */
73  AUDIO_SIZE
74 } SYS_AUDIO_MGR_DEVICE;
75 
79 typedef enum {
80  MODE_SLAVE = 0,
81  MODE_MASTER = 1,
82 } SYS_AUDIO_MGR_MODE;
83 
87 typedef enum {
88  PCM_MODE = 0,
89  I2S_MODE,
90  IOM2_MODE,
91  TDM_MODE
92 } SYS_AUDIO_MGR_PCM_FORMATS;
93 
97 typedef enum {
98  NO_SRC,
99  SRC_1,
100  SRC_2,
101  SRC_AUTO
102 }SYS_AUDIO_MGR_SRC_USE;
103 
107 typedef struct {
108  SYS_AUDIO_MGR_MODE mode;
109  uint32_t clk_frequency;
115  HW_PDM_CHANNEL_CONFIG channel;
116  HW_PDM_DI_DELAY in_delay;
117  HW_PDM_DO_DELAY out_delay;
118  bool swap_channel;
120 } sys_audio_pdm_specific_t;
121 
122 
126 typedef struct {
127  SYS_AUDIO_MGR_MODE mode;
128  SYS_AUDIO_MGR_PCM_FORMATS format;
130  HW_PCM_CLOCK clock;
131  uint32_t sample_rate;
135  uint8_t channel_delay;
136  uint8_t total_channel_num;
139  HW_PCM_DO_OUTPUT_MODE output_mode;
141  uint8_t bit_depth;
143  HW_PCM_CLK_GENERATION clk_generation;
146  HW_PCM_FSC_DELAY fsc_delay;
150  HW_PCM_FSC_POLARITY inverted_fsc_polarity;
153  HW_PCM_CLK_POLARITY inverted_clk_polarity;
156  HW_PCM_CYCLE_PER_BIT cycle_per_bit;
158  uint8_t fsc_length;
161 } sys_audio_pcm_specific_t;
162 
166 typedef struct {
167  uint32_t address;
168  uint32_t buff_len_total;
169  uint32_t buff_len_cb;
170  uint32_t buff_len_pos;
171  uint8_t channel_num;
173  bool stereo;
174 } sys_audio_mgr_buffer_data_block_t;
175 
183 typedef void (*sys_audio_mgr_buffer_ready_cb)(sys_audio_mgr_buffer_data_block_t *buff_data_block, void *app_ud);
184 
185 typedef struct {
186  bool use_prio;
187  HW_DMA_PRIO prio[2];
188 } sys_audio_dma_prio_t;
189 
193 typedef struct {
194  HW_DMA_CHANNEL dma_channel[2];
195  uint32_t buff_addr[2];
196  uint32_t total_buffer_len;
197  uint32_t cb_buffer_len;
198  sys_audio_mgr_buffer_ready_cb cb;
199  void* app_ud;
200  uint32_t sample_rate;
203  bool stereo;
204  uint8_t bit_depth;
205  bool circular;
206  sys_audio_dma_prio_t dma_prio;
207 } sys_audio_memory_specific_t;
208 
209 # if dg_configUSE_HW_SDADC
210 
213 typedef struct {
214  HW_SDADC_PGA_GAIN pga_gain;
215  HW_SDADC_PGA_MODE pga_mode;
216  HW_SDADC_PGA_BIAS pga_bias;
218 } sys_audio_sdadc_specific_t;
219 # endif /* dg_configUSE_HW_SDADC */
220 
224 typedef struct {
225  SYS_AUDIO_MGR_DEVICE device_type;
227  union {
228  sys_audio_pdm_specific_t pdm_param;
229  sys_audio_pcm_specific_t pcm_param;
230  sys_audio_memory_specific_t memory_param;
231 # if dg_configUSE_HW_SDADC
232  sys_audio_sdadc_specific_t sdadc_param;
233 # endif /* dg_configUSE_HW_SDADC */
234  };
235 } sys_audio_device_t;
236 
240 typedef struct {
241  sys_audio_device_t *dev_in;
242  sys_audio_device_t *dev_out;
243 } audio_path_t;
244 
248 typedef struct {
249  audio_path_t audio_path[MAX_NUM_OF_PATHS];
250 } sys_audio_path_t;
251 
263 bool sys_audio_mgr_start(uint8_t idx);
264 
276 bool sys_audio_mgr_stop(uint8_t idx);
277 
291 uint8_t sys_audio_mgr_open_path(sys_audio_device_t *dev_in, sys_audio_device_t *dev_out, SYS_AUDIO_MGR_SRC_USE src);
292 
301 void sys_audio_mgr_close_path(uint8_t idx);
302 
313 DEPRECATED_MSG("API no longer supported, use sys_audio_mgr_open_path() instead.")
314 __STATIC_INLINE void sys_audio_mgr_open(sys_audio_path_t *devs)
315 {
316  for (uint8_t idx = 0; idx < MAX_NUM_OF_PATHS; idx++) {
317  if (devs->audio_path[idx].dev_in != NULL &&
318  devs->audio_path[idx].dev_out != NULL &&
319  devs->audio_path[idx].dev_in->device_type != AUDIO_INVALID &&
320  devs->audio_path[idx].dev_out->device_type != AUDIO_INVALID) {
321  sys_audio_mgr_open_path(devs->audio_path[idx].dev_in,
322  devs->audio_path[idx].dev_out, SRC_AUTO);
323  }
324  }
325 }
326 
334 DEPRECATED_MSG("API no longer supported, use sys_audio_mgr_close_path() instead.")
335 __STATIC_INLINE void sys_audio_mgr_close(void)
336 {
337  for (uint8_t idx = 0; idx < MAX_NUM_OF_PATHS; idx++) {
338  sys_audio_mgr_close_path(idx);
339  }
340 }
341 
342 # endif /* dg_configUSE_SYS_AUDIO_MGR */
343 #endif /* SYS_AUDIO_MGR_H_ */
344 
hw_dma.h
Definition of API for the DMA Low Level Driver.
HW_SDADC_PGA_GAIN
HW_SDADC_PGA_GAIN
PGA gain selection.
Definition: hw_sdadc.h:190
HW_PDM_CHANNEL_CONFIG
HW_PDM_CHANNEL_CONFIG
PDM output channel configuration.
Definition: hw_pdm.h:199
HW_PDM_DO_DELAY
HW_PDM_DO_DELAY
PDM output delay.
Definition: hw_pdm.h:188
HW_PCM_DO_OUTPUT_MODE
HW_PCM_DO_OUTPUT_MODE
PCM DO output mode.
Definition: hw_pcm.h:181
hw_pcm.h
Definition of API for the PCM interface Low Level Driver.
HW_DMA_CHANNEL
HW_DMA_CHANNEL
DMA channel number.
Definition: hw_dma.h:62
HW_PCM_CLK_GENERATION
HW_PCM_CLK_GENERATION
PCM clock generation.
Definition: hw_pcm.h:160
HW_SDADC_PGA_MODE
HW_SDADC_PGA_MODE
PGA mode selection.
Definition: hw_sdadc.h:205
HW_PCM_FSC_DELAY
HW_PCM_FSC_DELAY
PCM FSC delay.
Definition: hw_pcm.h:200
HW_DMA_PRIO
HW_DMA_PRIO
Channel priority.
Definition: hw_dma.h:163
HW_PCM_FSC_POLARITY
HW_PCM_FSC_POLARITY
PCM FSC polarity.
Definition: hw_pcm.h:249
mode
HW_GPIO_MODE mode
Definition: hw_gpio.h:211
HW_PDM_DI_DELAY
HW_PDM_DI_DELAY
PDM input delay.
Definition: hw_pdm.h:177
HW_PCM_CYCLE_PER_BIT
HW_PCM_CYCLE_PER_BIT
PCM clock cycles per bit.
Definition: hw_pcm.h:172
HW_PCM_CLK_POLARITY
HW_PCM_CLK_POLARITY
PCM clock polarity.
Definition: hw_pcm.h:240
hw_pdm.h
Definition of API for the PDM Low Level Driver.
HW_SDADC_PGA_BIAS
HW_SDADC_PGA_BIAS
PGA bias configuration.
Definition: hw_sdadc.h:217
HW_PCM_CLOCK
HW_PCM_CLOCK
PCM system clock source.
Definition: hw_pcm.h:151
hw_sdadc_interrupt_cb
void(* hw_sdadc_interrupt_cb)(void)
SDADC interrupt handler.
Definition: hw_sdadc.h:251
hw_sdadc.h
Definition of API for the SDADC Low Level Driver.