summaryrefslogtreecommitdiff
path: root/bsp/tae32f5300/libraries/TAE32F53xx_StdPeriph_Driver/src/tae32f53xx_ll_cmp.c
blob: 4a31133b57db2b4471f88d38ec2adec26d9ae23a (plain)
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
/**
  ******************************************************************************
  * @file    tae32f53xx_ll_cmp.c
  * @author  MCD Application Team
  * @brief   Source file for CMP Moudle
  *
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2020 Tai-Action.
  * All rights reserved.</center></h2>
  *
  * This software is licensed by Tai-Action under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "tae32f53xx_ll.h"


#define DBG_TAG             "CMP LL"
#define DBG_LVL             DBG_ERROR
#include "dbg/tae32f53xx_dbg.h"


/** @addtogroup TAE32F53xx_LL_Driver
  * @{
  */

/** @defgroup CMP_LL CMP LL
  * @brief    CMP LL module driver.
  * @{
  */

#ifdef LL_CMP_MODULE_ENABLED

/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @defgroup CMP_LL_Exported_Functions CMP LL Exported Functions
  * @brief    CMP LL Exported Functions
  * @{
  */

/** @defgroup CMP_LL_Exported_Functions_Group1 Initialization and De-Initialization functions
  * @brief    Initialization and De-Initialization functions
@verbatim
  ==============================================================================
              ##### Initialization and De-Initialization functions #####
  ==============================================================================
  [..]
    This section provides functions allowing to:
    (+) Initialize the CMP peripheral.
    (+) De-initialize the CMP peripheral.
@endverbatim
  * @{
  */

/**
  * @brief  Initialize the CMP peripheral
  * @param  Instance CMP peripheral instance
  * @return status of the initialization
  */
LL_StatusETypeDef LL_CMP_Init(CMP_TypeDef *Instance)
{
    /* Check the parameters */
    assert_param(IS_CMP_ALL_INSTANCE(Instance));

    /* Init the low level hardware */
    LL_CMP_MspInit(Instance);

    /* Clear interrupt pending flags */
    __LL_CMP_PENDING_FLAG_CLEAR(Instance, CMP_FLAG_ALLIF);

    /* Return function status */
    return LL_OK;
}

/**
  * @brief  Deinitialize the CMP peripheral
  * @param  Instance CMP peripheral instance
  * @return status of the initialization
  */
LL_StatusETypeDef LL_CMP_DeInit(CMP_TypeDef *Instance)
{
    /* Check the parameters */
    assert_param(IS_CMP_ALL_INSTANCE(Instance));

    for (uint8_t chnnum = 0; chnnum < CMP_CHN_NB; ++chnnum) {
        /* Disable CMP channel FALIE/RISIE interrupts */
        __LL_CMP_IT_DISABLE(Instance, chnnum, CMP_IT_FALIE | CMP_IT_RISIE);

        /* Disable CMP channel */
        __LL_CMP_DISABLE(Instance, chnnum);
    }

    /* DeInit the low level hardware */
    LL_CMP_MspDeInit(Instance);

    /* Return function status */
    return LL_OK;
}

/**
  * @brief  Initializes the CMP MSP.
  * @param  Instance CMP peripheral
  * @return None
  */
__WEAK void LL_CMP_MspInit(CMP_TypeDef *Instance)
{
    /* Prevent unused argument(s) compilation warning */
    LL_UNUSED(Instance);

    /* NOTE : This function should not be modified, when the callback is needed,
              the LL_CMP_MspInit could be implemented in the user file
     */
}

/**
  * @brief  DeInitializes the CMP MSP
  * @param  Instance CMP peripheral
  * @return None
  */
__WEAK void LL_CMP_MspDeInit(CMP_TypeDef *Instance)
{
    /* Prevent unused argument(s) compilation warning */
    LL_UNUSED(Instance);

    /* NOTE: This function should not be modified, when the callback is needed,
             the LL_CMP_MspDeInit could be implemented in the user file
     */
}

/**
  * @}
  */


/** @defgroup CMP_LL_Exported_Functions_Group2 CMP Peripheral Control functions
  * @brief    CMP Peripheral Control functions
@verbatim
  ===============================================================================
                       ##### Peripheral Control functions #####
  ===============================================================================
  [..] This section provides functions allowing to:
    (+) Configure CMP channels.

@endverbatim
  * @{
  */

/**
  * @brief  Configures the selected CMP channel.
  * @param  Instance CMP peripheral
  * @param  Channel The selected CMP channel.
  *         This parameter can be one of the following values:
  *            @arg CMP_CHANNEL_0: CMP Channel0 selected
  *            @arg CMP_CHANNEL_1: CMP Channel1 selected
  *            @arg CMP_CHANNEL_2: CMP Channel2 selected
  *            @arg CMP_CHANNEL_3: CMP Channel3 selected
  * @param  sConfig CMP configuration structure.
  * @return LL Status
  */
LL_StatusETypeDef LL_CMP_ChannelConfig(CMP_TypeDef *Instance, uint32_t Channel, CMP_ChannelConfTypeDef *sConfig)
{
    /* Get the channel number */
    uint8_t chnnum = POSITION_VAL(Channel);

    /* Check the parameters */
    assert_param(IS_CMP_ALL_INSTANCE(Instance));
    assert_param(IS_CMP_CHANNEL(Channel));
    assert_param(IS_CMP_NUMBER(chnnum));
    assert_param(sConfig != NULL);
    assert_param(IS_CMP_INPUT_MINUS(sConfig->InputMinus));
    assert_param(IS_CMP_HYSTERESIS(sConfig->Hysteresis));
    assert_param(IS_CMP_BLANKING_SOURCE(Channel, sConfig->BlankingSource));
    assert_param(IS_CMP_OUTPUT_DEBOUNCE(sConfig->OutputDebounce));
    assert_param(IS_CMP_OUTPUT_DEBOUNCE_VAL(sConfig->OutputDebounceValue));
    assert_param(IS_CMP_OUTPUT_POLARITY(sConfig->OutputPolarity));
    assert_param(IS_CMP_TRIGGER_IT(sConfig->TriggerInterrupt));

    /* Set Debounce Vaule */
    if (sConfig->OutputDebounceValue == CMP_OUTPUT_DEBOUNCE_ENABLE) {
        __LL_CMP_DEBOUNCE_VALUE_SET(Instance, chnnum, sConfig->OutputDebounceValue);
    }

    /* Reset and Calculate CR register value depending on sConfig */
    MODIFY_REG(Instance->CR[chnnum],
               (CMP_CR_OPOL_Msk
                | CMP_CR_ODEB_Msk
                | CMP_CR_BLANKING_Msk
                | CMP_CR_INM_Msk
                | CMP_CR_HYST_Msk
                | CMP_CR_FALIE_Msk
                | CMP_CR_RISIE_Msk
               ),
               (sConfig->OutputPolarity
                | sConfig->OutputDebounce
                | sConfig->BlankingSource
                | sConfig->InputMinus
                | sConfig->Hysteresis
                | sConfig->TriggerInterrupt));

    /* Return function status */
    return LL_OK;
}

/**
  * @}
  */


/** @defgroup CMP_LL_Exported_Functions_Group3 CMP IO operation functions
  * @brief    CMP IO operation functions
  *
@verbatim
  ==============================================================================
             ##### IO operation functions #####
  ==============================================================================
    [..]  This section provides functions allowing to:
      (+) Start/Stop CMP.

@endverbatim
  * @{
  */

/**
  * @brief  Enables CMP Channel conversion
  * @param  Instance CMP peripheral instance
  * @param  Channel The selected CMP channel.
  *         This parameter can be one of the following values:
  *            @arg CMP_CHANNEL_0: CMP Channel0 selected
  *            @arg CMP_CHANNEL_1: CMP Channel1 selected
  *            @arg CMP_CHANNEL_2: CMP Channel2 selected
  *            @arg CMP_CHANNEL_3: CMP Channel3 selected
  * @return LL Status
  */
LL_StatusETypeDef LL_CMP_Start(CMP_TypeDef *Instance, uint32_t Channel)
{
    /* Get the channel number */
    uint8_t chnnum = POSITION_VAL(Channel);

    /* Check the parameters */
    assert_param(IS_CMP_ALL_INSTANCE(Instance));
    assert_param(IS_CMP_CHANNEL(Channel));
    assert_param(IS_CMP_NUMBER(chnnum));

    /* Enable the CMP channel */
    __LL_CMP_ENABLE(Instance, chnnum);

    /* Return function status */
    return LL_OK;
}

/**
  * @brief  Disable CMP Channel conversion
  * @param  Instance CMP peripheral instance
  * @param  Channel The selected CMP channel.
  *         This parameter can be one of the following values:
  *            @arg CMP_CHANNEL_0: CMP Channel0 selected
  *            @arg CMP_CHANNEL_1: CMP Channel1 selected
  *            @arg CMP_CHANNEL_2: CMP Channel2 selected
  *            @arg CMP_CHANNEL_3: CMP Channel3 selected
  * @return LL Status
  */
LL_StatusETypeDef LL_CMP_Stop(CMP_TypeDef *Instance, uint32_t Channel)
{
    /* Get the channel number */
    uint8_t chnnum = POSITION_VAL(Channel);

    /* Check the CMP parameters */
    assert_param(IS_CMP_ALL_INSTANCE(Instance));
    assert_param(IS_CMP_CHANNEL(Channel));
    assert_param(IS_CMP_NUMBER(chnnum));

    /* Enable CMP Channel */
    __LL_CMP_DISABLE(Instance, chnnum);

    /* Return function status */
    return LL_OK;
}

/**
  * @}
  */


/** @defgroup CMP_LL_Exported_Functions_Interrupt CMP Interrupt management
  * @brief    CMP Interrupt management
@verbatim
  ===============================================================================
                          ##### Initerrupt management #####
  ===============================================================================
  [..]
      This section provides CMP interrupt handler and callback functions.

@endverbatim
  * @{
  */

/**
  * @brief   This function handles CMP interrupts requests.
  * @param   Instance CMP peripheral
  * @return  None
  */
void LL_CMP_IRQHandler(CMP_TypeDef *Instance)
{
    uint32_t irqtemp = READ_REG(Instance->SR);

    /* Check the CMP parameters */
    assert_param(IS_CMP_ALL_INSTANCE(Instance));

    for (uint8_t chnnum = 0; chnnum < CMP_CHN_NB; ++chnnum) {
        if ((__LL_CMP_IT_CHECK_SOURCE(Instance, chnnum, CMP_IT_FALIE) != RESET) &&
            ((irqtemp & (CMP_SR_FALIF_0 << chnnum)) != RESET)) {
            /* Chear the CMP_CHx FALIF pending flag */
            __LL_CMP_PENDING_FLAG_CLEAR(Instance, (CMP_SR_FALIF_0 << chnnum));

            /* CMP falling edge trigger user callback */
            LL_CMP_FailingEdgeTrigCallback(Instance, (0x1UL << chnnum));
        }

        if ((__LL_CMP_IT_CHECK_SOURCE(Instance, chnnum, CMP_IT_RISIE) != RESET) &&
            ((irqtemp & (CMP_SR_RISIF_0 << chnnum)) != RESET)) {
            /* Chear the CMP_CHx RISIF pending flag */
            __LL_CMP_PENDING_FLAG_CLEAR(Instance, (CMP_SR_RISIF_0 << chnnum));

            /* CMP rising edge trigger user callback */
            LL_CMP_RisingEdgeTrigCallback(Instance, (0x1UL << chnnum));
        }
    }
}

/**
  * @brief  CMP_CHx failing edge interrupt callback function
  * @param  Instance CMP peripheral
  * @param  Channel The handling CMP channel
  * @return None
  */
__WEAK void LL_CMP_FailingEdgeTrigCallback(CMP_TypeDef *Instance, uint32_t Channel)
{
    /* Prevent unused argument(s) compilation warning */
    LL_UNUSED(Instance);
    LL_UNUSED(Channel);

    /* NOTE: This function should not be modified, when the callback is needed,
             the LL_CMP_FailingEdgeTrigCallback could be implemented in the user file
     */
}

/**
  * @brief  CMP_CHx rising edge interrupt callback function
  * @param  Instance CMP peripheral
  * @param  Channel The handling CMP channel
  * @return None
  */
__WEAK void LL_CMP_RisingEdgeTrigCallback(CMP_TypeDef *Instance, uint32_t Channel)
{
    /* Prevent unused argument(s) compilation warning */
    LL_UNUSED(Instance);
    LL_UNUSED(Channel);

    /* NOTE: This function should not be modified, when the callback is needed,
             the LL_CMP_RisingEdgeTrigCallback could be implemented in the user file
     */
}

/**
  * @}
  */

/**
  * @}
  */

/* Private functions ---------------------------------------------------------*/

#endif /* LL_CMP_MODULE_ENABLED */

/**
  * @}
  */

/**
  * @}
  */

/************************* (C) COPYRIGHT Tai-Action *****END OF FILE***********/