• 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_acmp_drv.h"
9 
acmp_channel_config(ACMP_Type * ptr,uint8_t ch,acmp_channel_config_t * config,bool enable)10 hpm_stat_t acmp_channel_config(ACMP_Type *ptr, uint8_t ch, acmp_channel_config_t *config, bool enable)
11 {
12     acmp_channel_enable_cmp(ptr, ch, false);
13     ptr->CHANNEL[ch].CFG = ACMP_CHANNEL_CFG_CMPEN_SET(enable)
14                     | ACMP_CHANNEL_CFG_MINSEL_SET(config->minus_input)
15                     | ACMP_CHANNEL_CFG_PINSEL_SET(config->plus_input)
16                     | ACMP_CHANNEL_CFG_FLTMODE_SET(config->filter_mode)
17                     | ACMP_CHANNEL_CFG_HYST_SET(config->hyst_level)
18                     | ACMP_CHANNEL_CFG_CMPOEN_SET(config->enable_cmp_output)
19                     | ACMP_CHANNEL_CFG_WINEN_SET(config->enable_window_mode)
20                     | ACMP_CHANNEL_CFG_OPOL_SET(config->invert_output)
21                     | ACMP_CHANNEL_CFG_SYNCEN_SET(config->enable_clock_sync)
22                     | ACMP_CHANNEL_CFG_FLTBYPS_SET(config->bypass_filter)
23                     | ACMP_CHANNEL_CFG_DACEN_SET(config->enable_dac)
24                     | ACMP_CHANNEL_CFG_HPMODE_SET(config->enable_hpmode)
25                     | ACMP_CHANNEL_CFG_FLTLEN_SET(config->filter_length);
26     if (enable) {
27         acmp_channel_enable_cmp(ptr, ch, true);
28     }
29     return status_success;
30 }
31 
acmp_channel_get_default_config(ACMP_Type * ptr,acmp_channel_config_t * config)32 void acmp_channel_get_default_config(ACMP_Type *ptr, acmp_channel_config_t *config)
33 {
34     config->plus_input = ACMP_INPUT_DAC_OUT;
35     config->minus_input = ACMP_INPUT_DAC_OUT;
36     config->filter_mode = ACMP_FILTER_MODE_BYPASS;
37     config->hyst_level = ACMP_HYST_LEVEL_0;
38     config->enable_cmp_output = false;
39     config->enable_window_mode = false;
40     config->invert_output = false;
41     config->enable_clock_sync = false;
42     config->bypass_filter = true;
43     config->enable_dac = false;
44     config->enable_hpmode = false;
45     config->filter_length = 0;
46 }
47 
48