ald_acmp.h 11.6 KB
Newer Older
W
wangyq2018 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
/**
  *********************************************************************************
  *
  * @file    ald_acmp.h
  * @brief   Header file of ACMP module driver.
  *
  * @version V1.0
  * @date    13 Dec 2017
  * @author  AE Team
  * @note
  *
  * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
  *
  *********************************************************************************
  */

#ifndef __ALD_ACMP_H__
#define __ALD_ACMP_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "utils.h"

/** @addtogroup ES32FXXX_ALD
  * @{
  */

/** @addtogroup ACMP
  * @{
  */

/** @defgroup ACMP_Public_Types ACMP Public Types
  * @{
  */

/**
  * @brief Acmp interrupt
  */
typedef enum
{
    ACMP_IT_EDGE   = (1U << 0), /**< Edge interrupt bit */
    ACMP_IT_WARMUP = (1U << 1), /**< Warm up interrupt bit */
} acmp_it_t;

/**
  * @brief Acmp interrupt
  */
typedef enum
{
    ACMP_FLAG_EDGE   = (1U << 0),   /**< Edge interrupt flag */
    ACMP_FLAG_WARMUP = (1U << 1),   /**< Warm up interrupt flag */
} acmp_flag_t;

/**
  * @brief Acmp interrupt flag
  */
typedef enum
{
    ACMP_STATUS_EDGE    = (1U << 0),    /**< Edge interrupt flag */
    ACMP_STATUS_WARMUP  = (1U << 1),    /**< Warm up interrupt flag */
} acmp_status_t;

/**
  * @brief Acmp positive input
  */
typedef enum
{
    ACMP_POS_CH0 = 0,   /**< Channel 0 as positive input */
    ACMP_POS_CH1 = 1,   /**< Channel 1 as positive input */
    ACMP_POS_CH2 = 2,   /**< Channel 2 as positive input */
    ACMP_POS_CH3 = 3,   /**< Channel 3 as positive input */
    ACMP_POS_CH4 = 4,   /**< Channel 4 as positive input */
    ACMP_POS_CH5 = 5,   /**< Channel 5 as positive input */
    ACMP_POS_CH6 = 6,   /**< Channel 6 as positive input */
    ACMP_POS_CH7 = 7,   /**< Channel 7 as positive input */
} acmp_pos_input_t;

/**
  * @brief Acmp negative input
  */
typedef enum
{
    ACMP_NEG_CH0      = 0,  /**< Channel 0 as negative input */
    ACMP_NEG_CH1      = 1,  /**< Channel 1 as negative input */
    ACMP_NEG_CH2      = 2,  /**< Channel 2 as negative input */
    ACMP_NEG_CH3      = 3,  /**< Channel 3 as negative input */
    ACMP_NEG_CH4      = 4,  /**< Channel 4 as negative input */
    ACMP_NEG_CH5      = 5,  /**< Channel 5 as negative input */
    ACMP_NEG_CH6      = 6,  /**< Channel 6 as negative input */
    ACMP_NEG_CH7      = 7,  /**< Channel 7 as negative input */
    ACMP_NEG_1V25     = 8,  /**< 1.25v as negative input */
    ACMP_NEG_2V5      = 9,  /**< 2.5v as negative input */
    ACMP_NEG_VDD      = 10, /**< VDD as negative input */
    ACMP_NEG_CAP      = 11, /**< Capacitive as negative input */
    ACMP_NEG_DAC0_CH0 = 12, /**< DAC0 channel 0 as negative input */
    ACMP_NEG_DAC0_CH1 = 13, /**< DAC0 channel 1 as negative input */
} acmp_neg_input_t;

/**
  * @brief Acmp mode
  */
typedef enum
{
    ACMP_ULTRA_LOW_POWER = 0,   /**< Ultra low power mode */
    ACMP_LOW_POWER       = 1,   /**< Low power mode */
    ACMP_MIDDLE_POWER    = 2,   /**< Middle power mode */
    ACMP_HIGH_POWER      = 3,   /**< High power mode */
} acmp_mode_t;

/**
  * @brief Acmp warm-up time
  */
typedef enum
{
    ACMP_4_PCLK   = 0,  /**< 4 hfperclk cycles */
    ACMP_8_PCLK   = 1,  /**< 4 hfperclk cycles */
    ACMP_16_PCLK  = 2,  /**< 4 hfperclk cycles */
    ACMP_32_PCLK  = 3,  /**< 4 hfperclk cycles */
    ACMP_64_PCLK  = 4,  /**< 4 hfperclk cycles */
    ACMP_128_PCLK = 5,  /**< 4 hfperclk cycles */
    ACMP_256_PCLK = 6,  /**< 4 hfperclk cycles */
    ACMP_512_PCLK = 7,  /**< 4 hfperclk cycles */
} acmp_warm_time_t;

/**
  * @brief Acmp hysteresis level
  */
typedef enum
{
    ACMP_HYST_0  = 0,   /**< No hysteresis */
    ACMP_HYST_15 = 1,   /**< 15mV hysteresis */
    ACMP_HYST_22 = 2,   /**< 22mV hysteresis */
    ACMP_HYST_29 = 3,   /**< 29mV hysteresis */
    ACMP_HYST_36 = 4,   /**< 36mV hysteresis */
    ACMP_HYST_43 = 5,   /**< 43mV hysteresis */
    ACMP_HYST_50 = 6,   /**< 50mV hysteresis */
    ACMP_HYST_57 = 7,   /**< 57mV hysteresis */
} acmp_hystsel_t;

/**
  * @brief Acmp inactive state
  */
typedef enum
{
    ACMP_INACTVAL_LOW  = 0, /**< The inactive value is 0 */
    ACMP_INACTVAL_HIGH = 1, /**< The inactive value is 1 */
} acmp_inactval_t;

/**
  * @brief which edges set up interrupt
  */
typedef enum
{
    ACMP_EDGE_NONE = 0, /**< Disable EDGE interrupt */
    ACMP_EDGE_FALL = 1, /**< Falling edges set EDGE interrupt */
    ACMP_EDGE_RISE = 2, /**< rise edges set EDGE interrupt */
    ACMP_EDGE_ALL  = 3, /**< Falling edges and rise edges set EDGE interrupt */
} acmp_edge_t;

/**
  * @brief Acmp output function
  */
typedef enum
{
    ACMP_OUT_DISABLE = 0,   /**< Disable acmp output */
    ACMP_OUT_ENABLE  = 1,   /**< Enable acmp output */
} acmp_out_func_t;

/**
  * @brief Acmp warm-up interrupt function
  */
typedef enum
{
    ACMP_WARM_DISABLE = 0,  /**< Disable acmp warm-up interrupt */
    ACMP_WARM_ENABLE  = 1,  /**< Enable acmp warm-up interrupt */
} acmp_warm_it_func;

/**
  * @brief Acmp gpio output invert
  */
typedef enum
{
    ACMP_GPIO_NO_INV = 0,   /**< Acmp output to gpio is not inverted */
    ACMP_GPIO_INV    = 1,   /**< Acmp output to gpio is inverted */
} acmp_invert_t;

/**
  * @brief The location of the acmp i/o pin
  */
typedef enum
{
    ACMP_LOCATION_O = 0,    /**< Location 0 */
    ACMP_LOCATION_1 = 1,    /**< Location 1 */
    ACMP_LOCATION_2 = 2,    /**< Location 2 */
} acmp_location_t;

/**
  * @brief Acmp output config structure definition
  */
typedef struct
{
    acmp_out_func_t out_func;   /**< Acmp output function */
    acmp_invert_t gpio_inv;     /**< If invert gpio output */
    acmp_location_t location;   /**< The location of acmp I/0 pin */
} acmp_output_config_t;

/**
  * @brief Acmp init structure definition
  */
typedef struct
{
    acmp_mode_t mode;               /**< Acmp operation mode */
    acmp_warm_time_t warm_time;     /**< Acmp warm up time */
    acmp_hystsel_t hystsel;         /**< Acmp hysteresis level */
    acmp_warm_it_func warm_func;    /**< Acmp warm-up interrupt enable/disable */
    acmp_pos_input_t pos_port;      /**< Acmp positive port select */
    acmp_neg_input_t neg_port;      /**< Acmp negative port select */
    acmp_inactval_t inactval;       /**< Acmp inavtive output value */
    acmp_edge_t edge;               /** Select edges to set interrupt flag */
    uint8_t vdd_level;              /** Select scaling factor for CDD reference level, MAX is 63 */
} acmp_init_t;

/**
  * @brief  ACMP Handle Structure definition
  */
typedef struct acmp_handle_s
{
    ACMP_TypeDef *perh; /**< Register base address */
    acmp_init_t init;   /**< ACMP required parameters */
    lock_state_t lock;  /**< Locking object */

    void (*acmp_warmup_cplt_cbk)(struct acmp_handle_s *arg);    /**< Acmp warm-up complete callback */
    void (*acmp_edge_cplt_cbk)(struct acmp_handle_s *arg);      /**< Acmp edge trigger callback */
} acmp_handle_t;
/**
  * @}
  */

/** @defgroup ACMP_Public_Macros ACMP Public Macros
  * @{
  */
#define ACMP_ENABLE(handle)     (SET_BIT((handle)->perh->CON, ACMP_CON_EN_MSK))
#define ACMP_DISABLE(handle)    (CLEAR_BIT((handle)->perh->CON, ACMP_CON_EN_MSK))
/**
  * @}
  */

/** @defgroup ACMP_Private_Macros   ACMP Private Macros
  * @{
  */
#define IS_ACMP_TYPE(x)         (((x) == ACMP0) || \
                         ((x) == ACMP1))
#define IS_ACMP_MODE_TYPE(x)        (((x) == ACMP_ULTRA_LOW_POWER) || \
                     ((x) == ACMP_LOW_POWER)       || \
                     ((x) == ACMP_MIDDLE_POWER)    || \
                     ((x) == ACMP_HIGH_POWER))
#define IS_ACMP_IT_TYPE(x)      (((x) == ACMP_IT_EDGE)  || \
                         ((x) == ACMP_IT_WARMUP))
#define IS_ACMP_FLAG_TYPE(x)        (((x) == ACMP_FLAG_EDGE)  || \
                         ((x) == ACMP_FLAG_WARMUP))
#define IS_ACMP_STATUS_TYPE(x)          (((x) == ACMP_STATUS_EDGE)  || \
                         ((x) == ACMP_STATUS_WARMUP))
#define IS_ACMP_POS_INPUT_TYPE(x)   (((x) == ACMP_POS_CH0) || \
                         ((x) == ACMP_POS_CH1) || \
                         ((x) == ACMP_POS_CH2) || \
                         ((x) == ACMP_POS_CH3) || \
                         ((x) == ACMP_POS_CH4) || \
                         ((x) == ACMP_POS_CH5) || \
                         ((x) == ACMP_POS_CH6) || \
                         ((x) == ACMP_POS_CH7))
#define IS_ACMP_NEG_INPUT_TYPE(x)   (((x) == ACMP_NEG_CH0)      || \
                         ((x) == ACMP_NEG_CH1)      || \
                         ((x) == ACMP_NEG_CH2)      || \
                         ((x) == ACMP_NEG_CH3)      || \
                         ((x) == ACMP_NEG_CH4)      || \
                         ((x) == ACMP_NEG_CH5)      || \
                         ((x) == ACMP_NEG_CH6)      || \
                         ((x) == ACMP_NEG_CH7)      || \
                         ((x) == ACMP_NEG_1V25)     || \
                         ((x) == ACMP_NEG_2V5)      || \
                         ((x) == ACMP_NEG_VDD)      || \
                         ((x) == ACMP_NEG_CAP)      || \
                         ((x) == ACMP_NEG_DAC0_CH0) || \
                         ((x) == ACMP_NEG_DAC0_CH1))
#define IS_ACMP_WARM_UP_TIME_TYPE(x)    (((x) == ACMP_4_PCLK)   || \
                         ((x) == ACMP_8_PCLK)   || \
                         ((x) == ACMP_16_PCLK)  || \
                         ((x) == ACMP_32_PCLK)  || \
                         ((x) == ACMP_64_PCLK)  || \
                         ((x) == ACMP_128_PCLK) || \
                         ((x) == ACMP_256_PCLK) || \
                         ((x) == ACMP_512_PCLK))
#define IS_ACMP_HYSTSEL_TYPE(x)         (((x) == ACMP_HYST_0)  || \
                         ((x) == ACMP_HYST_15) || \
                         ((x) == ACMP_HYST_22) || \
                         ((x) == ACMP_HYST_29) || \
                         ((x) == ACMP_HYST_36) || \
                         ((x) == ACMP_HYST_43) || \
                         ((x) == ACMP_HYST_50) || \
                         ((x) == ACMP_HYST_57))
#define IS_ACMP_INACTVAL_TYPE(x)    (((x) == ACMP_INACTVAL_LOW) || \
                         ((x) == ACMP_INACTVAL_HIGH))
#define IS_ACMP_EDGE_TYPE(x)            (((x) == ACMP_EDGE_NONE) || \
                     ((x) == ACMP_EDGE_FALL) || \
                         ((x) == ACMP_EDGE_RISE) || \
                     ((x) == ACMP_EDGE_ALL))
#define IS_ACMP_OUT_FUNC_TYPE(x)    (((x) == ACMP_OUT_DISABLE) || \
                     ((x) == ACMP_OUT_ENABLE))
#define IS_ACMP_INVERT_TYPE(x)      (((x) == ACMP_GPIO_NO_INV) || \
                     ((x) == ACMP_GPIO_INV))
#define IS_ACMP_LOCATION_TYPE(x)    (((x) == ACMP_LOCATION_O) || \
                     ((x) == ACMP_LOCATION_1) || \
                     ((x) == ACMP_LOCATION_2))
#define IS_ACMP_WARM_FUNC_TYPE(x)   (((x) == ACMP_WARM_DISABLE) || \
                     ((x) == ACMP_WARM_ENABLE))
/**
  * @}
  */

/** @addtogroup ACMP_Public_Functions
  * @{
  */

/** @addtogroup ACMP_Public_Functions_Group1
  * @{
  */
ald_status_t acmp_init(acmp_handle_t *hperh);

/**
  * @}
  */

/** @addtogroup ACMP_Public_Functions_Group2
  * @{
  */
ald_status_t acmp_interrupt_config(acmp_handle_t *hperh, acmp_it_t it, type_func_t state);
ald_status_t acmp_set_interrupt_mask(acmp_handle_t *hperh, acmp_it_t it);
it_status_t acmp_get_flag_status(acmp_handle_t *hperh, acmp_flag_t it);
ald_status_t acmp_clear_flag_status(acmp_handle_t *hperh, acmp_flag_t it);
flag_status_t acmp_get_status(acmp_handle_t *hperh, acmp_status_t flag);

/**
  * @}
  */

/** @addtogroup ACMP_Public_Functions_Group3
  * @{
  */
void acmp_irq_handle(acmp_handle_t *hperh);
ald_status_t acmp_out_config(acmp_handle_t *hperh, acmp_output_config_t *config);
uint8_t acmp_out_result(acmp_handle_t *hperh);
/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */
#ifdef __cplusplus
extern "C"
}
#endif

#endif