• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 #include "hpm_pdm_drv.h"
8 #define PDM_WORKING_CLOCK_FREQ_IN_HZ (48000UL)
9 
pdm_get_default_config(PDM_Type * ptr,pdm_config_t * config)10 void pdm_get_default_config(PDM_Type *ptr, pdm_config_t *config)
11 {
12     (void) ptr;
13     config->sof_at_ref_clk_falling_edge = true;
14     config->bypass_pdm_clk_div = false;
15     config->enable_pdm_clk_out = true;
16     config->pdm_clk_div = 3;
17     config->capture_delay = 1;
18     config->dec_after_cic = 3;
19     config->post_scale = 12;
20     config->sigma_delta_order = PDM_CIC_SIGMA_DELTA_ORDER_6;
21     config->cic_dec_ratio = 64;
22     config->enable_hpf = true;
23 }
24 
pdm_init(PDM_Type * ptr,pdm_config_t * config)25 hpm_stat_t pdm_init(PDM_Type *ptr, pdm_config_t *config)
26 {
27     if (pdm_is_running(ptr)) {
28         pdm_stop(ptr);
29     }
30     /* pdm_software_reset(ptr); */
31 
32     /* ptr->CTRL = PDM_CTRL_DIS_CLK_GATE_MASK; */
33     ptr->CTRL = PDM_CTRL_SOF_FEDGE_SET(config->sof_at_ref_clk_falling_edge)
34         | PDM_CTRL_DEC_AFT_CIC_SET(config->dec_after_cic)
35         | PDM_CTRL_CAPT_DLY_SET(config->capture_delay)
36         | PDM_CTRL_PDM_CLK_HFDIV_SET(config->pdm_clk_div)
37         | PDM_CTRL_PDM_CLK_DIV_BYPASS_SET(config->bypass_pdm_clk_div)
38         | PDM_CTRL_PDM_CLK_OE_SET(config->enable_pdm_clk_out)
39         | PDM_CTRL_HPF_EN_SET(config->enable_hpf);
40 
41     ptr->CH_CTRL = 0xF000FF;
42     ptr->CH_CFG = 0x50000;
43     ptr->CIC_CFG = PDM_CIC_CFG_POST_SCALE_SET(config->post_scale)
44         | PDM_CIC_CFG_SGD_SET(config->sigma_delta_order)
45         | PDM_CIC_CFG_CIC_DEC_RATIO_SET(config->cic_dec_ratio);
46 
47     return status_success;
48 }
49