• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include "hpm_vad_drv.h"
9 
vad_get_default_config(VAD_Type * ptr,vad_config_t * config)10 void vad_get_default_config(VAD_Type *ptr, vad_config_t *config)
11 {
12     (void) ptr;
13     config->enable_buffer = true;
14     config->enable_pdm_clock_out = true;
15     config->enable_two_channels = true;
16     config->capture_delay = 1;
17     config->pdm_half_div = 3;
18     config->fifo_threshold = 4;
19     config->channel_polarity_high[0] = false;
20     config->channel_polarity_high[1] = true;
21     config->post_scale = 20;
22 }
23 
vad_init(VAD_Type * ptr,vad_config_t * config)24 void vad_init(VAD_Type *ptr, vad_config_t *config)
25 {
26     vad_reset(ptr);
27     ptr->CTRL = VAD_CTRL_PDM_CLK_HFDIV_SET(config->pdm_half_div)
28         | VAD_CTRL_PDM_CLK_OE_SET(config->enable_pdm_clock_out)
29         | VAD_CTRL_MEMBUF_DISABLE_SET(!config->enable_buffer)
30         | VAD_CTRL_FIFO_THRSH_SET(config->fifo_threshold)
31         | VAD_CTRL_CAPT_DLY_SET(config->capture_delay)
32         | VAD_CTRL_CHNUM_SET(config->enable_two_channels)
33         | VAD_CTRL_CH_POL_SET((config->channel_polarity_high[1] << 1)
34                 | config->channel_polarity_high[0]);
35     ptr->FILTCTRL = VAD_FILTCTRL_DECRATIO_SET(2)
36         | VAD_FILTCTRL_IIR_SLOT_EN_SET(0xff);
37     ptr->CIC_CFG = (ptr->CIC_CFG & ~VAD_CIC_CFG_POST_SCALE_MASK)
38         | VAD_CIC_CFG_POST_SCALE_SET(config->post_scale);
39 
40     vad_enable_fifo(ptr);
41 }
42 
vad_reset(VAD_Type * ptr)43 void vad_reset(VAD_Type *ptr)
44 {
45     if (vad_is_running(ptr)) {
46         vad_stop(ptr);
47     }
48     vad_software_reset(ptr);
49 }
50 
51