apm32f10x_tmr.c 65.1 KB
Newer Older
A
abbcc 已提交
1
/*!
2
 * @file        apm32f10x_tmr.c
A
abbcc 已提交
3
 *
4
 * @brief       This file provides all the TMR firmware functions.
A
abbcc 已提交
5
 *
6
 * @version     V1.0.2
A
abbcc 已提交
7
 *
8
 * @date        2022-01-05
A
abbcc 已提交
9
 *
10 11 12 13 14 15 16 17 18 19 20 21 22 23
 * @attention
 *
 *  Copyright (C) 2020-2022 Geehy Semiconductor
 *
 *  You may not use this file except in compliance with the
 *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
 *
 *  The program is only for reference, which is distributed in the hope
 *  that it will be usefull and instructional for customers to develop
 *  their software. Unless required by applicable law or agreed to in
 *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
 *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
 *  and limitations under the License.
A
abbcc 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
 */

#include "apm32f10x_tmr.h"
#include "apm32f10x_rcm.h"

/** @addtogroup Peripherals_Library Standard Peripheral Library
  @{
*/

/** @addtogroup TMR_Driver  TMR Driver
  @{
*/

/** @addtogroup  TMR_Fuctions Fuctions
  @{
*/

41 42 43 44
static void TI1Config(TMR_T* tmr, uint16_t ICpolarity, uint16_t ICselection, uint16_t ICfilter);
static void TI2Config(TMR_T* tmr, uint16_t ICpolarity, uint16_t ICselection, uint16_t ICfilter);
static void TI3Config(TMR_T* tmr, uint16_t ICpolarity, uint16_t ICselection, uint16_t ICfilter);
static void TI4Config(TMR_T* tmr, uint16_t ICpolarity, uint16_t ICselection, uint16_t ICfilter);
A
abbcc 已提交
45 46 47 48 49 50 51 52 53

/*!
 * @brief     Deinitializes the TMRx peripheral registers to their default reset values.
 *
 * @param     tmr: Select TMRx peripheral, The x can be 1 to 8
 *
 * @retval    None
 *
 */
54
void TMR_Reset(TMR_T* tmr)
A
abbcc 已提交
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
{
    if (tmr == TMR1)
    {
        RCM_EnableAPB2PeriphReset(RCM_APB2_PERIPH_TMR1);
        RCM_DisableAPB2PeriphReset(RCM_APB2_PERIPH_TMR1);
    }
    else if (tmr == TMR2)
    {
        RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_TMR2);
        RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_TMR2);
    }
    else if (tmr == TMR3)
    {
        RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_TMR3);
        RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_TMR3);
    }
    else if (tmr == TMR4)
    {
        RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_TMR4);
        RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_TMR4);
    }
    else if (tmr == TMR5)
    {
        RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_TMR5);
        RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_TMR5);
    }
    else if (tmr == TMR6)
    {
        RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_TMR6);
        RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_TMR6);
    }
    else if (tmr == TMR7)
    {
        RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_TMR7);
        RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_TMR7);
    }
    else if (tmr == TMR8)
    {
        RCM_EnableAPB2PeriphReset(RCM_APB2_PERIPH_TMR8);
        RCM_DisableAPB2PeriphReset(RCM_APB2_PERIPH_TMR8);
    }
}

/*!
 * @brief     Initializes the base timer through the structure
 *
 * @param     tmr: Select TMRx peripheral, The x can be 1 to 8
 *
 * @param     baseConfig: Pointer to a TMR_BaseConfig_T structure
 *
 * @retval    None
 */
107
void TMR_ConfigTimeBase(TMR_T* tmr, TMR_BaseConfig_T* baseConfig)
A
abbcc 已提交
108 109 110 111
{
    uint16_t temp;

    if ((tmr == TMR1) || (tmr == TMR8) || (tmr == TMR2) || (tmr == TMR3) ||
112
        (tmr == TMR4) || (tmr == TMR5))
A
abbcc 已提交
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
    {
        temp = tmr->CTRL1;
        temp &= 0x038F;
        temp |= baseConfig->countMode;
        tmr->CTRL1 = temp;
    }

    if ((tmr != TMR6) && (tmr != TMR7))
    {
        tmr->CTRL1_B.CLKDIV = baseConfig->clockDivision;
    }

    tmr->AUTORLD = baseConfig->period;
    tmr->PSC = baseConfig->division;

    if ((tmr == TMR1) || (tmr == TMR8))
    {
        tmr->REPCNT = baseConfig->repetitionCounter;
    }
132
    tmr->CEG_B.UEG = 0x01;
A
abbcc 已提交
133 134 135 136 137 138 139
}

/*!
 * @brief     Configure channel 1 according to parameters
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
140
 * @param     OCConfig: Pointer to a TMR_OCConfig_T structure
A
abbcc 已提交
141 142 143
 *
 * @retval    None
 */
144
void TMR_ConfigOC1(TMR_T* tmr, TMR_OCConfig_T* OCConfig)
A
abbcc 已提交
145 146 147 148
{
    tmr->CCEN_B.CC1EN = BIT_RESET;

    tmr->CCM1_COMPARE_B.CC1SEL = BIT_RESET;
149
    tmr->CCM1_COMPARE_B.OC1MOD = OCConfig->mode;
A
abbcc 已提交
150

151 152
    tmr->CCEN_B.CC1POL = OCConfig->polarity;
    tmr->CCEN_B.CC1EN = OCConfig->outputState;
A
abbcc 已提交
153 154 155

    if ((tmr == TMR1) || (tmr == TMR8))
    {
156 157
        tmr->CCEN_B.CC1NPOL = OCConfig->nPolarity;
        tmr->CCEN_B.CC1NEN = OCConfig->outputNState;
A
abbcc 已提交
158 159 160

        tmr->CTRL2_B.OC1OIS = BIT_RESET;
        tmr->CTRL2_B.OC1NOIS = BIT_RESET;
161 162
        tmr->CTRL2_B.OC1OIS = OCConfig->idleState;
        tmr->CTRL2_B.OC1NOIS = OCConfig->nIdleState;
A
abbcc 已提交
163
    }
164
    tmr->CC1 = OCConfig->pulse;
A
abbcc 已提交
165 166 167 168 169 170 171
}

/*!
 * @brief     Configure channel 2 according to parameters
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
172
 * @param     OCConfig: Pointer to a TMR_OCConfig_T structure
A
abbcc 已提交
173 174 175
 *
 * @retval    None
 */
176
void TMR_ConfigOC2(TMR_T* tmr, TMR_OCConfig_T* OCConfig)
A
abbcc 已提交
177 178 179 180 181
{
    tmr->CCEN_B.CC2EN = BIT_RESET;

    tmr->CCM1_COMPARE_B.OC2MOD = BIT_RESET;
    tmr->CCM1_COMPARE_B.CC2SEL = BIT_RESET;
182
    tmr->CCM1_COMPARE_B.OC2MOD = OCConfig->mode;
A
abbcc 已提交
183 184

    tmr->CCEN_B.CC2POL = BIT_RESET;
185 186
    tmr->CCEN_B.CC2POL = OCConfig->polarity;
    tmr->CCEN_B.CC2EN = OCConfig->outputState;
A
abbcc 已提交
187 188 189 190

    if ((tmr == TMR1) || (tmr == TMR8))
    {
        tmr->CCEN_B.CC2NPOL = BIT_RESET;
191
        tmr->CCEN_B.CC2NPOL = OCConfig->nPolarity;
A
abbcc 已提交
192 193

        tmr->CCEN_B.CC2NEN = BIT_RESET;
194
        tmr->CCEN_B.CC2NEN = OCConfig->outputNState;
A
abbcc 已提交
195 196 197

        tmr->CTRL2_B.OC2OIS = BIT_RESET;
        tmr->CTRL2_B.OC2NOIS = BIT_RESET;
198 199
        tmr->CTRL2_B.OC2OIS = OCConfig->idleState;
        tmr->CTRL2_B.OC2NOIS = OCConfig->nIdleState;
A
abbcc 已提交
200
    }
201
    tmr->CC2 = OCConfig->pulse;
A
abbcc 已提交
202 203 204 205 206 207 208
}

/*!
 * @brief     Configure channel 3 according to parameters
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
209
 * @param     OCConfig: Pointer to a TMR_OCConfig_T structure
A
abbcc 已提交
210 211 212
 *
 * @retval    None
 */
213
void TMR_ConfigOC3(TMR_T* tmr, TMR_OCConfig_T* OCConfig)
A
abbcc 已提交
214 215 216
{
    tmr->CCEN_B.CC3EN = BIT_RESET;

217
    tmr->CCM2_COMPARE_B.OC3MOD = BIT_RESET;
A
abbcc 已提交
218
    tmr->CCM2_COMPARE_B.CC3SEL = BIT_RESET;
219
    tmr->CCM2_COMPARE_B.OC3MOD = OCConfig->mode;
A
abbcc 已提交
220 221

    tmr->CCEN_B.CC3POL = BIT_RESET;
222 223
    tmr->CCEN_B.CC3POL = OCConfig->polarity;
    tmr->CCEN_B.CC3EN = OCConfig->outputState;
A
abbcc 已提交
224 225 226 227

    if ((tmr == TMR1) || (tmr == TMR8))
    {
        tmr->CCEN_B.CC3NPOL = BIT_RESET;
228
        tmr->CCEN_B.CC3NPOL = OCConfig->nPolarity;
A
abbcc 已提交
229
        tmr->CCEN_B.CC3NEN = BIT_RESET;
230
        tmr->CCEN_B.CC3NEN = OCConfig->outputNState;
A
abbcc 已提交
231 232 233

        tmr->CTRL2_B.OC3OIS = BIT_RESET;
        tmr->CTRL2_B.OC3NOIS = BIT_RESET;
234 235
        tmr->CTRL2_B.OC3OIS = OCConfig->idleState;
        tmr->CTRL2_B.OC3NOIS = OCConfig->nIdleState;
A
abbcc 已提交
236
    }
237
    tmr->CC3 = OCConfig->pulse;
A
abbcc 已提交
238 239 240 241 242 243 244
}

/*!
 * @brief     Configure channel 4 according to parameters
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
245
 * @param     OCConfig: Pointer to a TMR_OCConfig_T structure
A
abbcc 已提交
246 247 248
 *
 * @retval    None
 */
249
void TMR_ConfigOC4(TMR_T* tmr, TMR_OCConfig_T* OCConfig)
A
abbcc 已提交
250 251 252
{
    tmr->CCEN_B.CC4EN = BIT_RESET;

253
    tmr->CCM2_COMPARE_B.OC4MOD = BIT_RESET;
A
abbcc 已提交
254
    tmr->CCM2_COMPARE_B.CC4SEL = BIT_RESET;
255
    tmr->CCM2_COMPARE_B.OC4MOD = OCConfig->mode;
A
abbcc 已提交
256 257

    tmr->CCEN_B.CC4POL = BIT_RESET;
258 259
    tmr->CCEN_B.CC4POL = OCConfig->polarity;
    tmr->CCEN_B.CC4EN = OCConfig->outputState;
A
abbcc 已提交
260 261 262 263

    if ((tmr == TMR1) || (tmr == TMR8))
    {
        tmr->CTRL2_B.OC4OIS = BIT_RESET;
264
        tmr->CTRL2_B.OC4OIS = OCConfig->idleState;
A
abbcc 已提交
265
    }
266
    tmr->CC4 = OCConfig->pulse;
A
abbcc 已提交
267 268 269 270 271 272 273 274 275 276 277
}

/*!
 * @brief     Configure Peripheral equipment
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     ICConfig: Pointer to a TMR_ICConfig_T structure
 *
 * @retval    None
 */
278
void TMR_ConfigIC(TMR_T* tmr, TMR_ICConfig_T* ICConfig)
A
abbcc 已提交
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
{
    if (ICConfig->channel == TMR_CHANNEL_1)
    {
        TI1Config(tmr, ICConfig->polarity, ICConfig->selection, ICConfig->filter);
        TMR_ConfigIC1Prescal(tmr, ICConfig->prescaler);
    }
    else if (ICConfig->channel == TMR_CHANNEL_2)
    {
        TI2Config(tmr, ICConfig->polarity, ICConfig->selection, ICConfig->filter);
        TMR_ConfigIC2Prescal(tmr, ICConfig->prescaler);
    }
    else if (ICConfig->channel == TMR_CHANNEL_3)
    {
        TI3Config(tmr, ICConfig->polarity, ICConfig->selection, ICConfig->filter);
        TMR_ConfigIC3Prescal(tmr, ICConfig->prescaler);
    }
    else if (ICConfig->channel == TMR_CHANNEL_4)
    {
        TI4Config(tmr, ICConfig->polarity, ICConfig->selection, ICConfig->filter);
        TMR_ConfigIC4Prescal(tmr, ICConfig->prescaler);
    }
}

/*!
 * @brief     Configures the: Break feature, dead time, Lock level, the IMOS
 *
 * @param     tmr: The TMRx it can be TMR1 and TMR8
 *
 * @param     BDTConfig: Pointer to a TMR_BDTConfig_T structure
 *
 * @retval    None
 */
311
void TMR_ConfigBDT(TMR_T* tmr, TMR_BDTConfig_T* BDTConfig)
A
abbcc 已提交
312
{
313 314 315 316 317 318 319
    tmr->BDT = (BDTConfig->IMOS)<<10 |\
               (BDTConfig->RMOS)<<11 |\
               (BDTConfig->lockLevel)<<8 |\
               (BDTConfig->deadTime) |\
               (BDTConfig->BRKState)<<12 |\
               (BDTConfig->BRKPolarity)<<13 |\
               (BDTConfig->automaticOutput)<<14;
A
abbcc 已提交
320 321 322 323 324 325 326 327 328
}

/*!
 * @brief     Initialize the Base timer with its default value.
 *
 * @param     baseConfig: pointer to a TMR_BaseConfig_T
 *
 * @retval    None
 */
329
void TMR_ConfigTimeBaseStructInit(TMR_BaseConfig_T* baseConfig)
A
abbcc 已提交
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
{
    baseConfig->period = 0xFFFF;
    baseConfig->division = 0x0000;
    baseConfig->clockDivision = TMR_CLOCK_DIV_1;
    baseConfig->countMode = TMR_COUNTER_MODE_UP;
    baseConfig->repetitionCounter = 0x0000;
}

/*!
 * @brief     Initialize the OC timer with its default value.
 *
 * @param     OCConfig: pointer to a TMR_OCConfig_T
 *
 * @retval    None
 */
345
void TMR_ConfigOCStructInit(TMR_OCConfig_T* OCConfig)
A
abbcc 已提交
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
{
    OCConfig->mode = TMR_OC_MODE_TMRING;
    OCConfig->outputState = TMR_OC_STATE_DISABLE;
    OCConfig->outputNState = TMR_OC_NSTATE_DISABLE;
    OCConfig->pulse = 0x0000;
    OCConfig->polarity = TMR_OC_POLARITY_HIGH;
    OCConfig->nPolarity = TMR_OC_NPOLARITY_HIGH;
    OCConfig->idleState = TMR_OC_IDLE_STATE_RESET;
    OCConfig->nIdleState = TMR_OC_NIDLE_STATE_RESET;
}

/*!
 * @brief     Initialize the IC timer with its default value.
 *
 * @param     ICConfig: pointer to a TMR_ICConfig_T
 *
 * @retval    None
 */
364
void TMR_ConfigICStructInit(TMR_ICConfig_T* ICConfig)
A
abbcc 已提交
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
{
    ICConfig->channel = TMR_CHANNEL_1;
    ICConfig->polarity = TMR_IC_POLARITY_RISING;
    ICConfig->selection = TMR_IC_SELECTION_DIRECT_TI;
    ICConfig->prescaler = TMR_IC_PSC_1;
    ICConfig->filter = 0x00;
}

/*!
 * @brief     Initialize the BDT timer with its default value.
 *
 * @param     BDTConfig: pointer to a TMR_BDTConfig_T
 *
 * @retval    None
 */
380
void TMR_ConfigBDTStructInit( TMR_BDTConfig_T* BDTConfig)
A
abbcc 已提交
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
{
    BDTConfig->RMOS = TMR_RMOS_STATE_DISABLE;
    BDTConfig->IMOS = TMR_IMOS_STATE_DISABLE;
    BDTConfig->lockLevel = TMR_LOCK_LEVEL_OFF;
    BDTConfig->deadTime = 0x00;
    BDTConfig->BRKState = TMR_BRK_STATE_DISABLE;
    BDTConfig->BRKPolarity = TMR_BRK_POLARITY_LOW;
    BDTConfig->automaticOutput = TMR_AUTOMATIC_OUTPUT_DISABLE;
}

/*!
 * @brief     Enable the specified TMR peripheral
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @retval    None
 */
398
void TMR_Enable(TMR_T* tmr)
A
abbcc 已提交
399 400 401 402 403 404 405 406 407 408 409
{
    tmr->CTRL1_B.CNTEN = ENABLE;
}

/*!
 * @brief     Disable the specified TMR peripheral
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @retval    None
 */
410
void TMR_Disable(TMR_T* tmr)
A
abbcc 已提交
411 412 413 414 415 416 417 418 419 420 421 422 423
{
    tmr->CTRL1_B.CNTEN = DISABLE;
}

/*!
 * @brief     Config of TMR to PWM
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     PWMConfig: pointer to a TMR_ICConfig_T
 *
 * @retval    None
 */
424
void TMR_ConfigPWM(TMR_T* tmr, TMR_ICConfig_T* PWMConfig)
A
abbcc 已提交
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
{
    uint16_t icpolarity = TMR_IC_POLARITY_RISING;
    uint16_t icselection = TMR_IC_SELECTION_DIRECT_TI;

    if (PWMConfig->polarity == TMR_IC_POLARITY_RISING)
    {
        icpolarity = TMR_IC_POLARITY_FALLING;
    }
    else
    {
        icpolarity = TMR_IC_POLARITY_RISING;
    }

    if (PWMConfig->selection == TMR_IC_SELECTION_DIRECT_TI)
    {
        icselection = TMR_IC_SELECTION_INDIRECT_TI;
    }
    else
    {
        icselection = TMR_IC_SELECTION_DIRECT_TI;
    }

    if (PWMConfig->channel == TMR_CHANNEL_1)
    {
        TI1Config(tmr, PWMConfig->polarity, PWMConfig->selection, PWMConfig->filter);
        TMR_ConfigIC1Prescal(tmr, PWMConfig->prescaler);
        TI2Config(tmr, icpolarity, icselection, PWMConfig->filter);
        TMR_ConfigIC2Prescal(tmr, PWMConfig->prescaler);
    }
    else
    {
        TI2Config(tmr, PWMConfig->polarity, PWMConfig->selection, PWMConfig->filter);
        TMR_ConfigIC2Prescal(tmr, PWMConfig->prescaler);
        TI1Config(tmr, icpolarity, icselection, PWMConfig->filter);
        TMR_ConfigIC1Prescal(tmr, PWMConfig->prescaler);
    }
}

/*!
 * @brief     Enable TMRx PWM output
 *
 * @param     tmr: The TMRx it can be TMR1 and TMR8
 *
 * @retval    None
 */
470
void TMR_EnablePWMOutputs(TMR_T* tmr)
A
abbcc 已提交
471 472 473 474 475 476 477 478 479 480 481
{
    tmr->BDT_B.MOEN = ENABLE;
}

/*!
 * @brief     Disable TMRx PWM output.
 *
 * @param     tmr: The TMRx it can be TMR1 and TMR8
 *
 * @retval    None
 */
482
void TMR_DisablePWMOutputs(TMR_T* tmr)
A
abbcc 已提交
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
{
    tmr->BDT_B.MOEN = DISABLE;
}

/*!
 * @brief     Configures the TMRx's DMA interface.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     baseAddress: pointer to a TMR_DMA_BASE_T
 *
 * @param     burstLength: pointer to a TMR_DMA_BURSTLENGTH_T
 *
 * @retval    None
 */
498
void TMR_ConfigDMA(TMR_T* tmr, TMR_DMA_BASE_T baseAddress, TMR_DMA_BURSTLENGTH_T burstLength)
A
abbcc 已提交
499
{
500
    tmr->DCTRL = (uint32_t)baseAddress | (uint32_t)burstLength;
A
abbcc 已提交
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
}

/*!
 * @brief     Enable TMRx Requests.
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @param     souces: specifies the TMR DMA souces
 *                    The parameter can be any combination of following values:
 *                    @arg TMR_DMA_SOURCE_UPDATE: TMR update DMA souces
 *                    @arg TMR_DMA_SOURCE_CC1:    TMR Capture Compare 1 DMA souces
 *                    @arg TMR_DMA_SOURCE_CC2:    TMR Capture Compare 2 DMA souces
 *                    @arg TMR_DMA_SOURCE_CC3:    TMR Capture Compare 3 DMA souces
 *                    @arg TMR_DMA_SOURCE_CC4:    TMR Capture Compare 4 DMA souces
 *                    @arg TMR_DMA_SOURCE_COM:    TMR Commutation DMA souces
 *                    @arg TMR_DMA_SOURCE_TRG:    TMR Trigger DMA souces
 * @retval    None
 *
 */
520
void TMR_EnableDMASoure(TMR_T* tmr, uint16_t dmaSource)
A
abbcc 已提交
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
{
    tmr->DIEN |= dmaSource;
}

/*!
 * @brief     Disable TMRx Requests.
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @param     souces: specifies the TMR DMA souces
 *                    The parameter can be any combination of following values:
 *                    @arg TMR_DMA_SOURCE_UPDATE: TMR update DMA souces
 *                    @arg TMR_DMA_SOURCE_CC1:    TMR Capture Compare 1 DMA souces
 *                    @arg TMR_DMA_SOURCE_CC2:    TMR Capture Compare 2 DMA souces
 *                    @arg TMR_DMA_SOURCE_CC3:    TMR Capture Compare 3 DMA souces
 *                    @arg TMR_DMA_SOURCE_CC4:    TMR Capture Compare 4 DMA souces
 *                    @arg TMR_DMA_SOURCE_COM:    TMR Commutation DMA souces
 *                    @arg TMR_DMA_SOURCE_TRG:    TMR Trigger DMA souces
 * @retval    None
 *
 */
542
void TMR_DisableDMASoure(TMR_T* tmr, uint16_t dmaSource)
A
abbcc 已提交
543 544 545 546 547 548 549 550 551 552 553
{
    tmr->DIEN &= ~dmaSource;
}

/*!
 * @brief     Configures the TMRx internal Clock
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @retval    None
 */
554
void TMR_ConfigInternalClock(TMR_T* tmr)
A
abbcc 已提交
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
{
    tmr->SMCTRL_B.SMFSEL = DISABLE;
}

/*!
 * @brief     Configures the TMRx Internal Trigger as External Clock
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     triggerSource: specifies the TMR trigger souces
 *                   The parameter can be one of following values:
 *                   @arg TMR_TRIGGER_SOURCE_ITR0: TMR Internal Trigger 0
 *                   @arg TMR_TRIGGER_SOURCE_ITR1: TMR Internal Trigger 1
 *                   @arg TMR_TRIGGER_SOURCE_ITR2: TMR Internal Trigger 2
 *                   @arg TMR_TRIGGER_SOURCE_ITR3: TMR Internal Trigger 3
 * @retval    None
 */
572
void TMR_ConfigIntTrigExternalClock(TMR_T* tmr, TMR_TRIGGER_SOURCE_T triggerSource)
A
abbcc 已提交
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
{
    TMR_SelectInputTrigger(tmr, triggerSource);
    tmr->SMCTRL_B.SMFSEL = 0x07;
}

/*!
 * @brief     Configures the TMRx  Trigger as External Clock
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     triggerSource: specifies the TMR trigger souces
 *                     The parameter can be one of following values:
 *                     @arg TMR_TRIGGER_SOURCE_TI1F_ED:  TI1 Edge Detector
 *                     @arg TMR_TRIGGER_SOURCE_TI1FP1:   Filtered Timer Input 1
 *                     @arg TMR_TRIGGER_SOURCE_TI2FP2:   Filtered Timer Input 2
 *
 * @param     ICpolarity: specifies the TMR IC polarity
 *                     The parameter can be one of following values:
 *                     @arg TMR_IC_POLARITY_RISING:  TMR IC polarity rising
 *                     @arg TMR_IC_POLARITY_FALLING: TMR IC polarity falling
 *
 * @param     ICfilter: This parameter must be a value between 0x00 and 0x0F.
 *
 * @retval    None
 */
598 599
void TMR_ConfigTrigExternalClock(TMR_T* tmr, TMR_TRIGGER_SOURCE_T triggerSource,
                                TMR_IC_POLARITY_T ICpolarity, uint16_t ICfilter)
A
abbcc 已提交
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
{
    if (triggerSource == 0x06)
    {
        TI2Config(tmr, ICpolarity, TMR_IC_SELECTION_DIRECT_TI, ICfilter);
    }
    else
    {
        TI1Config(tmr, ICpolarity, TMR_IC_SELECTION_DIRECT_TI, ICfilter);
    }

    TMR_SelectInputTrigger(tmr, triggerSource);
    tmr->SMCTRL_B.SMFSEL = 0x07;
}

/*!
 * @brief     Configures the External clock Mode1
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     prescaler: specifies the external Trigger Prescaler
 *                     The parameter can be one of following values:
 *                     @arg TMR_EXTTRG_PSC_OFF:  ETRP Prescaler OFF
 *                     @arg TMR_EXTTRG_PSC_DIV2: ETRP frequency divided by 2
 *                     @arg TMR_EXTTRG_PSC_DIV4: ETRP frequency divided by 4
 *                     @arg TMR_EXTTRG_PSC_DIV8: ETRP frequency divided by 8
 *
 * @param     polarity: specifies the TMR IC polarity
 *                     The parameter can be one of following values:
 *                     @arg TMR_EXTTRG_POL_INVERTED:  Active low or falling edge active
 *                     @arg TMR_EXTTGR_POL_NONINVERTED: Active high or rising edge active
 *
 * @param     filter: This parameter must be a value between 0x00 and 0x0F.
 *
 * @retval    None
 */
635
void TMR_ConfigETRClockMode1(TMR_T* tmr, TMR_EXTTRG_PSC_T prescaler,
A
abbcc 已提交
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664
                             TMR_EXTTRG_POL_T polarity, uint16_t filter)
{
    TMR_ConfigETR(tmr, prescaler, polarity, filter);
    tmr->SMCTRL_B.SMFSEL = BIT_RESET;
    tmr->SMCTRL_B.SMFSEL = 0x07;
    tmr->SMCTRL_B.TRGSEL = 0x07;
}

/*!
 * @brief     Configures the External clock Mode2
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     prescaler: specifies the external Trigger Prescaler
 *                     The parameter can be one of following values:
 *                     @arg TMR_EXTTRG_PSC_OFF:  ETRP Prescaler OFF
 *                     @arg TMR_EXTTRG_PSC_DIV2: ETRP frequency divided by 2
 *                     @arg TMR_EXTTRG_PSC_DIV4: ETRP frequency divided by 4
 *                     @arg TMR_EXTTRG_PSC_DIV8: ETRP frequency divided by 8
 *
 * @param     polarity: specifies the TMR IC polarity
 *                     The parameter can be one of following values:
 *                     @arg TMR_EXTTRG_POL_INVERTED:  Active low or falling edge active
 *                     @arg TMR_EXTTGR_POL_NONINVERTED: Active high or rising edge active
 *
 * @param     filter: This parameter must be a value between 0x00 and 0x0F.
 *
 * @retval    None
 */
665
void TMR_ConfigETRClockMode2(TMR_T* tmr, TMR_EXTTRG_PSC_T prescaler,
A
abbcc 已提交
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
                             TMR_EXTTRG_POL_T polarity, uint16_t filter)
{
    TMR_ConfigETR(tmr, prescaler, polarity, filter);
    tmr->SMCTRL_B.ECEN = ENABLE;
}
/*!
 * @brief     Configures the TMRx External Trigger (ETR).
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     prescaler: specifies the external Trigger Prescaler
 *                     The parameter can be one of following values:
 *                     @arg TMR_EXTTRG_PSC_OFF:  ETRP Prescaler OFF
 *                     @arg TMR_EXTTRG_PSC_DIV2: ETRP frequency divided by 2
 *                     @arg TMR_EXTTRG_PSC_DIV4: ETRP frequency divided by 4
 *                     @arg TMR_EXTTRG_PSC_DIV8: ETRP frequency divided by 8
 *
 * @param     polarity: specifies the TMR IC polarity
 *                     The parameter can be one of following values:
 *                     @arg TMR_EXTTRG_POL_INVERTED:  Active low or falling edge active
 *                     @arg TMR_EXTTGR_POL_NONINVERTED: Active high or rising edge active
 *
 * @param     filter: This parameter must be a value between 0x00 and 0x0F.
 *
 * @retval    None
 */
692
void TMR_ConfigETR(TMR_T* tmr, TMR_EXTTRG_PSC_T prescaler,
A
abbcc 已提交
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
                   TMR_EXTTRG_POL_T polarity, uint16_t filter)
{
    tmr->SMCTRL &= 0x00FF;
    tmr->SMCTRL_B.ETPCFG = prescaler;
    tmr->SMCTRL_B.ETPOL = polarity;
    tmr->SMCTRL_B.ETFCFG = filter;
}

/*!
 * @brief     Configures the TMRx prescaler.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     prescaler: specifies the prescaler Register value
 *
 * @param     pscReloadMode: specifies the TMR prescaler Reload mode
 *                     The parameter can be one of following values:
710 711
 *                     @arg TMR_PSC_RELOAD_UPDATE:  The Prescaler is loaded at the update event
 *                     @arg TMR_PSC_RELOAD_IMMEDIATE: The Prescaler is loaded immediately
A
abbcc 已提交
712 713
 * @retval    None
 */
714
void TMR_ConfigPrescaler(TMR_T* tmr, uint16_t prescaler, TMR_PSC_RELOAD_T pscReloadMode)
A
abbcc 已提交
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
{
    tmr->PSC = prescaler;
    tmr->CEG_B.UEG = pscReloadMode;
}

/*!
 * @brief     Config counter mode
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     countMode:specifies the Counter Mode to be used
 *                     The parameter can be one of following values:
 *                     @arg TMR_COUNTER_MODE_UP:   Timer Up Counting Mode
 *                     @arg TMR_COUNTER_MODE_DOWN: Timer Down Counting Mode
 *                     @arg TMR_COUNTER_MODE_CENTERALIGNED1: Timer Center Aligned Mode1
 *                     @arg TMR_COUNTER_MODE_CENTERALIGNED2: Timer Center Aligned Mode2
 *                     @arg TMR_COUNTER_MODE_CENTERALIGNED3: Timer Center Aligned Mode3
 * @retval   None
 */
734
void TMR_ConfigCounterMode(TMR_T* tmr, TMR_COUNTER_MODE_T countMode)
A
abbcc 已提交
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
{
    tmr->CTRL1_B.CNTDIR = BIT_RESET;
    tmr->CTRL1_B.CAMSEL = BIT_RESET;
    tmr->CTRL1 |= countMode;
}

/*!
 * @brief     Selects the Input Trigger source
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     triggerSource: specifies the Input Trigger source
 *                     The parameter can be one of following values:
 *                     @arg TMR_TRIGGER_SOURCE_ITR0: Internal Trigger 0
 *                     @arg TMR_TRIGGER_SOURCE_ITR1: Internal Trigger 1
 *                     @arg TMR_TRIGGER_SOURCE_ITR2: Internal Trigger 2
 *                     @arg TMR_TRIGGER_SOURCE_ITR3: Internal Trigger 3
 *                     @arg TMR_TRIGGER_SOURCE_TI1F_ED: TI1 Edge Detector
 *                     @arg TMR_TRIGGER_SOURCE_TI1FP1: Filtered Timer Input 1
 *                     @arg TMR_TRIGGER_SOURCE_TI2FP2: Filtered Timer Input 2
 *                     @arg TMR_TRIGGER_SOURCE_ETRF: External Trigger input
 *
 * @retval    None
 */
759
void TMR_SelectInputTrigger(TMR_T* tmr, TMR_TRIGGER_SOURCE_T triggerSource)
A
abbcc 已提交
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
{
    tmr->SMCTRL_B.TRGSEL = BIT_RESET;
    tmr->SMCTRL_B.TRGSEL = triggerSource;
}

/*!
 * @brief     Configures the Encoder Interface.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     encodeMode: specifies the Encoder Mode
 *                     The parameter can be one of following values:
 *                     @arg TMR_ENCODER_MODE_TI1:  Counter counts on TI1FP1 edge depending on TI2FP2 level
 *                     @arg TMR_ENCODER_MODE_TI2:  Counter counts on TI2FP2 edge depending on TI1FP1 level
 *                     @arg TMR_ENCODER_MODE_TI12: Counter counts on both TI1FP1 and TI2FP2 edges depending
 *                                                 on the level of the other input
 *
 * @param     IC1Polarity: specifies the TMR IC1 polarity
 *                     The parameter can be one of following values:
 *                     @arg TMR_IC_POLARITY_RISING:  TMR IC polarity rising
 *                     @arg TMR_IC_POLARITY_FALLING: TMR IC polarity falling
 *
 * @param     IC2Polarity: specifies the TMR IC2 polarity
 *                     The parameter can be one of following values:
 *                     @arg TMR_IC_POLARITY_RISING:  TMR IC polarity rising
 *                     @arg TMR_IC_POLARITY_FALLING: TMR IC polarity falling
 * @retval    None
 */
788
void TMR_ConfigEncodeInterface(TMR_T* tmr, TMR_ENCODER_MODE_T encodeMode, TMR_IC_POLARITY_T IC1Polarity,
A
abbcc 已提交
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814
                               TMR_IC_POLARITY_T IC2Polarity)
{
    tmr->SMCTRL_B.SMFSEL = BIT_RESET;
    tmr->SMCTRL_B.SMFSEL = encodeMode;

    tmr->CCM1_CAPTURE_B.CC1SEL = BIT_RESET ;
    tmr->CCM1_CAPTURE_B.CC2SEL = BIT_RESET ;
    tmr->CCM1_CAPTURE_B.CC1SEL = 0x01 ;
    tmr->CCM1_CAPTURE_B.CC2SEL = 0x01 ;

    tmr->CCEN_B.CC1POL = BIT_RESET;
    tmr->CCEN_B.CC2POL = BIT_RESET;
    tmr->CCEN |= ((IC1Polarity | (IC2Polarity << 4)));
}

/*!
 * @brief     Forces the output 1 waveform to active or inactive level.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     forcesAction: specifies the forced Action to be set to the output waveform
 *                     The parameter can be one of following values:
 *                     @arg TMR_FORCED_ACTION_ACTIVE:  Force active level on OC1REF
 *                     @arg TMR_FORCED_ACTION_INACTIVE: Force inactive level on OC1REF
 * @retval    None
 */
815
void TMR_ConfigForcedOC1(TMR_T* tmr, TMR_FORCED_ACTION_T forcesAction)
A
abbcc 已提交
816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
{
    tmr->CCM1_COMPARE_B.OC1MOD = BIT_RESET;
    tmr->CCM1_COMPARE_B.OC1MOD = forcesAction;
}

/*!
 * @brief     Forces the output 2 waveform to active or inactive level.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     forcesAction: specifies the forced Action to be set to the output waveform
 *                     The parameter can be one of following values:
 *                     @arg TMR_FORCED_ACTION_ACTIVE:  Force active level on OC1REF
 *                     @arg TMR_FORCED_ACTION_INACTIVE: Force inactive level on OC1REF
 * @retval    None
 */
832
void TMR_ConfigForcedOC2(TMR_T* tmr, TMR_FORCED_ACTION_T forcesAction)
A
abbcc 已提交
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849
{
    tmr->CCM1_COMPARE_B.OC2MOD = BIT_RESET;
    tmr->CCM1_COMPARE_B.OC2MOD = forcesAction;
}

/*!
 * @brief     Forces the output 3 waveform to active or inactive level.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     forcesAction: specifies the forced Action to be set to the output waveform
 *                     The parameter can be one of following values:
 *                     @arg TMR_FORCED_ACTION_ACTIVE:  Force active level on OC1REF
 *                     @arg TMR_FORCED_ACTION_INACTIVE: Force inactive level on OC1REF
 *
 * @retval    None
 */
850
void TMR_ConfigForcedOC3(TMR_T* tmr, TMR_FORCED_ACTION_T forcesAction)
A
abbcc 已提交
851
{
852 853
    tmr->CCM2_COMPARE_B.OC3MOD = BIT_RESET;
    tmr->CCM2_COMPARE_B.OC3MOD = forcesAction;
A
abbcc 已提交
854 855 856 857 858 859 860 861 862 863 864 865 866 867
}

/*!
 * @brief     Forces the output 4 waveform to active or inactive level.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     forcesAction: specifies the forced Action to be set to the output waveform
 *                     The parameter can be one of following values:
 *                     @arg TMR_FORCED_ACTION_ACTIVE:  Force active level on OC1REF
 *                     @arg TMR_FORCED_ACTION_INACTIVE: Force inactive level on OC1REF
 *
 * @retval    None
 */
868
void TMR_ConfigForcedOC4(TMR_T* tmr, TMR_FORCED_ACTION_T forcesAction)
A
abbcc 已提交
869
{
870 871
    tmr->CCM2_COMPARE_B.OC4MOD = BIT_RESET;
    tmr->CCM2_COMPARE_B.OC4MOD = forcesAction;
A
abbcc 已提交
872 873 874 875 876 877 878 879 880
}

/*!
 * @brief     Enables peripheral Preload register on AUTORLD.
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @retval    None
 */
881
void TMR_EnableAutoReload(TMR_T* tmr)
A
abbcc 已提交
882 883 884 885 886 887 888 889 890 891 892
{
    tmr->CTRL1_B.ARPEN = ENABLE;
}

/*!
 * @brief     Disable peripheral Preload register on AUTORLD.
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @retval    None
 */
893
void TMR_DisableAutoReload(TMR_T* tmr)
A
abbcc 已提交
894 895 896 897 898 899 900 901 902 903 904
{
    tmr->CTRL1_B.ARPEN = DISABLE;
}

/*!
 * @brief     Enable Selects the TMR peripheral Commutation event.
 *
 * @param     tmr: The TMRx it can be TMR1 and TMR8
 *
 * @retval    None
 */
905
void TMR_EnableSelectCOM(TMR_T* tmr)
A
abbcc 已提交
906 907 908 909 910 911 912 913 914 915
{
    tmr->CTRL2_B.CCUSEL = ENABLE;
}
/*!
 * @brief     Disable Selects the TMR peripheral Commutation event.
 *
 * @param     tmr: The TMRx it can be TMR1 and TMR8
 *
 * @retval    None
 */
916
void TMR_DisableSelectCOM(TMR_T* tmr)
A
abbcc 已提交
917 918 919 920 921 922 923 924 925 926 927
{
    tmr->CTRL2_B.CCUSEL = DISABLE;
}

/*!
 * @brief     Enable Capture Compare DMA source.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @retval    None
 */
928
void TMR_EnableCCDMA(TMR_T* tmr)
A
abbcc 已提交
929 930 931 932 933 934 935 936 937 938 939
{
    tmr->CTRL2_B.CCDSEL = ENABLE;
}

/*!
 * @brief     Disable Capture Compare DMA source.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @retval    None
 */
940
void TMR_DisableCCDMA(TMR_T* tmr)
A
abbcc 已提交
941 942 943 944 945 946 947 948 949 950 951
{
    tmr->CTRL2_B.CCDSEL = DISABLE;
}

/*!
 * @brief     Enable Capture Compare Preload Control bit.
 *
 * @param     tmr: The TMRx it can be TMR1 and TMR8
 *
 * @retval    None
 */
952
void TMR_EnableCCPreload(TMR_T* tmr)
A
abbcc 已提交
953 954 955 956 957 958 959 960 961 962 963
{
    tmr->CTRL2_B.CCPEN = ENABLE;
}

/*!
 * @brief     Disable Capture Compare Preload Control bit.
 *
 * @param     tmr: The TMRx it can be TMR1 and TMR8
 *
 * @retval    None
 */
964
void TMR_DisableCCPreload(TMR_T* tmr)
A
abbcc 已提交
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979
{
    tmr->CTRL2_B.CCPEN = DISABLE;
}

/*!
 * @brief     Enables or disables the peripheral Preload register on CCM1.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     OCPreload: specifies the Output Compare Channel Preload
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_PRELOAD_DISABLE
 *                     @arg TMR_OC_PRELOAD_ENABLE
 * @retval    None
 */
980
void TMR_ConfigOC1Preload(TMR_T* tmr, TMR_OC_PRELOAD_T OCPreload)
A
abbcc 已提交
981 982 983 984 985 986 987 988 989 990 991 992 993 994 995
{
    tmr->CCM1_COMPARE_B.OC1PEN = OCPreload;
}

/*!
 * @brief     Enables or disables the peripheral Preload register on CCM2.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     OCPreload: specifies the Output Compare Channel Preload
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_PRELOAD_DISABLE
 *                     @arg TMR_OC_PRELOAD_ENABLE
 * @retval    None
 */
996
void TMR_ConfigOC2Preload(TMR_T* tmr, TMR_OC_PRELOAD_T OCPreload)
A
abbcc 已提交
997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
{
    tmr->CCM1_COMPARE_B.OC2PEN = OCPreload;
}

/*!
 * @brief     Enables or disables the peripheral Preload register on CCM3.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     OCPreload: specifies the Output Compare Channel Preload
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_PRELOAD_DISABLE
 *                     @arg TMR_OC_PRELOAD_ENABLE
 * @retval    None
 */
1012
void TMR_ConfigOC3Preload(TMR_T* tmr, TMR_OC_PRELOAD_T OCPreload)
A
abbcc 已提交
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
{
    tmr->CCM2_COMPARE_B.OC3PEN = OCPreload;
}

/*!
 * @brief     Enables or disables the peripheral Preload register on CCM4.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     OCPreload: specifies the Output Compare Channel Preload
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_PRELOAD_DISABLE
 *                     @arg TMR_OC_PRELOAD_ENABLE
 * @retval    Nonee
 */
1028
void TMR_ConfigOC4Preload(TMR_T* tmr, TMR_OC_PRELOAD_T OCPreload)
A
abbcc 已提交
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043
{
    tmr->CCM2_COMPARE_B.OC4PEN = OCPreload;
}

/*!
 * @brief     Configures the Output Compare 1 Fast feature.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     OCFast: specifies the Output Compare Channel Fast
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_FAST_DISABLE
 *                     @arg TMR_OC_FAST_ENABLE
 * @retval    None
 */
1044
void TMR_ConfigOC1Fast(TMR_T* tmr, TMR_OC_FAST_T OCFast)
A
abbcc 已提交
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059
{
    tmr->CCM1_COMPARE_B.OC1FEN = OCFast;
}

/*!
 * @brief     Configures the Output Compare 2 Fast feature.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     OCFast: specifies the Output Compare Channel Fast
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_FAST_DISABLE
 *                     @arg TMR_OC_FAST_ENABLE
 * @retval    None
 */
1060
void TMR_ConfigOC2Fast(TMR_T* tmr, TMR_OC_FAST_T OCFast)
A
abbcc 已提交
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
{
    tmr->CCM1_COMPARE_B.OC2FEN = OCFast;
}

/*!
 * @brief     Configures the Output Compare 2 Fast feature.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     OCFast: specifies the Output Compare Channel Fast
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_FAST_DISABLE
 *                     @arg TMR_OC_FAST_ENABLE
 * @retval    None
 */
1076
void TMR_ConfigOC3Fast(TMR_T* tmr, TMR_OC_FAST_T OCFast)
A
abbcc 已提交
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
{
    tmr->CCM2_COMPARE_B.OC3FEN = OCFast;
}

/*!
 * @brief     Configures the Output Compare 4 Fast feature.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     OCFast: specifies the Output Compare Channel Fast
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_FAST_DISABLE
 *                     @arg TMR_OC_FAST_ENABLE
 * @retval    None
 */
1092
void TMR_ConfigOC4Fast(TMR_T* tmr, TMR_OC_FAST_T OCFast)
A
abbcc 已提交
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
{
    tmr->CCM2_COMPARE_B.OC4FEN = OCFast;
}

/*!
 * @brief     Clears or safeguards the OCREF1 signal on an external event
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     OCClear: specifies the Output Compare Channel1 Clear
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_CLEAR_DISABLE
 *                     @arg TMR_OC_CLEAR_ENABLE
 * @retval    None
 */
1108
void TMR_ClearOC1Ref(TMR_T* tmr, TMR_OC_CLEAR_T OCClear)
A
abbcc 已提交
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123
{
    tmr->CCM1_COMPARE_B.OC1CEN = OCClear;
}

/*!
 * @brief     Clears or safeguards the OCREF2 signal on an external event
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     OCClear: specifies the Output Compare Channel1 Clear
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_CLEAR_DISABLE
 *                     @arg TMR_OC_CLEAR_ENABLE
 * @retval    None
 */
1124
void TMR_ClearOC2Ref(TMR_T* tmr, TMR_OC_CLEAR_T OCClear)
A
abbcc 已提交
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139
{
    tmr->CCM1_COMPARE_B.OC2CEN = OCClear;
}

/*!
 * @brief     Clears or safeguards the OCREF3 signal on an external event
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     OCClear: specifies the Output Compare Channel1 Clear
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_CLEAR_DISABLE
 *                     @arg TMR_OC_CLEAR_ENABLE
 * @retval    None
 */
1140
void TMR_ClearOC3Ref(TMR_T* tmr, TMR_OC_CLEAR_T OCClear)
A
abbcc 已提交
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155
{
    tmr->CCM2_COMPARE_B.OC3CEN = OCClear;
}

/*!
 * @brief     Clears or safeguards the OCREF4 signal on an external event
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     OCClear: specifies the Output Compare Channel1 Clear
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_CLEAR_DISABLE
 *                     @arg TMR_OC_CLEAR_ENABLE
 * @retval    None
 */
1156
void TMR_ClearOC4Ref(TMR_T* tmr, TMR_OC_CLEAR_T OCClear)
A
abbcc 已提交
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171
{
    tmr->CCM2_COMPARE_B.OC4CEN = OCClear;
}

/*!
 * @brief     Configures the channel 1 polarity.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     polarity: specifies the OC1 Polarity
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_POLARITY_HIGH: Output Compare active high
 *                     @arg TMR_OC_POLARITY_LOW: Output Compare active low
 * @retval    Nonee
 */
1172
void TMR_ConfigOC1Polarity(TMR_T* tmr, TMR_OC_POLARITY_T polarity)
A
abbcc 已提交
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187
{
    tmr->CCEN_B.CC1POL = polarity;
}

/*!
 * @brief     Configures the  channel 1 nPolarity.
 *
 * @param     tmr: The TMRx it can be TMR1 and TMR8
 *
 * @param     nPolarity: specifies the OC1 nPolarity
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_NPOLARITY_HIGH: Output Compare active high
 *                     @arg TMR_OC_NPOLARITY_LOW: Output Compare active low
 * @retval    None
 */
1188
void TMR_ConfigOC1NPolarity(TMR_T* tmr, TMR_OC_NPOLARITY_T nPolarity)
A
abbcc 已提交
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203
{
    tmr->CCEN_B.CC1NPOL = nPolarity;
}

/*!
 * @brief     Configures the channel 2 polarity.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     polarity: specifies the OC2 Polarity
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_POLARITY_HIGH: Output Compare active high
 *                     @arg TMR_OC_POLARITY_LOW: Output Compare active low
 * @retval    None
 */
1204
void TMR_ConfigOC2Polarity(TMR_T* tmr, TMR_OC_POLARITY_T polarity)
A
abbcc 已提交
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219
{
    tmr->CCEN_B.CC2POL = polarity;
}

/*!
 * @brief     Configures the  channel 2 nPolarity.
 *
 * @param     tmr: The TMRx it can be TMR1 and TMR8
 *
 * @param     nPolarity: specifies the OC2 nPolarity
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_NPOLARITY_HIGH: Output Compare active high
 *                     @arg TMR_OC_NPOLARITY_LOW: Output Compare active low
 * @retval    None
 */
1220
void TMR_ConfigOC2NPolarity(TMR_T* tmr, TMR_OC_NPOLARITY_T nPolarity)
A
abbcc 已提交
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235
{
    tmr->CCEN_B.CC2NPOL = nPolarity;
}

/*!
 * @brief     Configures the channel 3 polarity.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     polarity: specifies the OC3 Polarity
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_POLARITY_HIGH: Output Compare active high
 *                     @arg TMR_OC_POLARITY_LOW: Output Compare active low
 * @retval    None
 */
1236
void TMR_ConfigOC3Polarity(TMR_T* tmr, TMR_OC_POLARITY_T polarity)
A
abbcc 已提交
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
{
    tmr->CCEN_B.CC3POL = polarity;
}

/*!
 * @brief     Configures the  channel 3 nPolarity.
 *
 * @param     tmr: The TMRx it can be TMR1 and TMR8
 *
 * @param     nPolarity: specifies the OC3 nPolarity
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_NPOLARITY_HIGH: Output Compare active high
 *                     @arg TMR_OC_NPOLARITY_LOW: Output Compare active low
 * @retval    None
 */
1252
void TMR_ConfigOC3NPolarity(TMR_T* tmr, TMR_OC_NPOLARITY_T nPolarity)
A
abbcc 已提交
1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267
{
    tmr->CCEN_B.CC3NPOL = nPolarity;
}

/*!
 * @brief     Configures the channel 4 polarity.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     polarity: specifies the OC4 Polarity
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_POLARITY_HIGH: Output Compare active high
 *                     @arg TMR_OC_POLARITY_LOW: Output Compare active low
 * @retval    None
 */
1268
void TMR_ConfigOC4Polarity(TMR_T* tmr, TMR_OC_POLARITY_T polarity)
A
abbcc 已提交
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285
{
    tmr->CCEN_B.CC4POL = polarity;
}

/*!
 * @brief     Enables the Capture Compare Channel x.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     channel: specifies the Channel
 *                     The parameter can be one of following values:
 *                     @arg TMR_CHANNEL_1: Timer Channel 1
 *                     @arg TMR_CHANNEL_2: Timer Channel 2
 *                     @arg TMR_CHANNEL_3: Timer Channel 3
 *                     @arg TMR_CHANNEL_4: Timer Channel 4
 * @retval    None
 */
1286
void TMR_EnableCCxChannel(TMR_T* tmr, TMR_CHANNEL_T channel)
A
abbcc 已提交
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
{
    tmr->CCEN |= BIT_SET << channel;
}

/*!
 * @brief     Disables the Capture Compare Channel x.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     channel: specifies the Channel
 *                     The parameter can be one of following values:
 *                     @arg TMR_CHANNEL_1: Timer Channel 1
 *                     @arg TMR_CHANNEL_2: Timer Channel 2
 *                     @arg TMR_CHANNEL_3: Timer Channel 3
 *                     @arg TMR_CHANNEL_4: Timer Channel 4
 * @retval    None
 */
1304
void TMR_DisableCCxChannel(TMR_T* tmr, TMR_CHANNEL_T channel)
A
abbcc 已提交
1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320
{
    tmr->CCEN &= BIT_RESET << channel;
}

/*!
 * @brief     Enables the Capture Compare Channelx N.
 *
 * @param     tmr: The TMRx it can be TMR1 and TMR8
 *
 * @param     channel: specifies the Channel
 *                     The parameter can be one of following values:
 *                     @arg TMR_CHANNEL_1: Timer Channel 1
 *                     @arg TMR_CHANNEL_2: Timer Channel 2
 *                     @arg TMR_CHANNEL_3: Timer Channel 3
 * @retval    None
 */
1321
void TMR_EnableCCxNChannel(TMR_T* tmr, TMR_CHANNEL_T channel)
A
abbcc 已提交
1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337
{
    tmr->CCEN |= 0x04 << channel;
}

/*!
 * @brief     Disables the Capture Compare Channelx N.
 *
 * @param     tmr: The TMRx it can be TMR1 and TMR8
 *
 * @param     channel: specifies the Channel
 *                     The parameter can be one of following values:
 *                     @arg TMR_CHANNEL_1: Timer Channel 1
 *                     @arg TMR_CHANNEL_2: Timer Channel 2
 *                     @arg TMR_CHANNEL_3: Timer Channel 3
 * @retval    None
 */
1338
void TMR_DisableCCxNChannel(TMR_T* tmr, TMR_CHANNEL_T channel)
A
abbcc 已提交
1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366
{
    tmr->CCEN &= BIT_RESET << channel;
}

/*!
 * @brief     Selects the Output Compare Mode.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     channel: specifies the Channel
 *                     The parameter can be one of following values:
 *                     @arg TMR_CHANNEL_1: Timer Channel 1
 *                     @arg TMR_CHANNEL_2: Timer Channel 2
 *                     @arg TMR_CHANNEL_3: Timer Channel 3
 *                     @arg TMR_CHANNEL_4: Timer Channel 4
 *
 * @param     mode: specifies the Output Compare Mode
 *                     The parameter can be one of following values:
 *                     @arg TMR_OC_MODE_TMRING
 *                     @arg TMR_OC_MODE_ACTIVE
 *                     @arg TMR_OC_MODE_INACTIVE
 *                     @arg TMR_OC_MODE_TOGGEL
 *                     @arg TMR_OC_MODE_LOWLEVEL
 *                     @arg TMR_OC_MODE_HIGHLEVEL
 *                     @arg TMR_OC_MODE_PWM1
 *                     @arg TMR_OC_MODE_PWM2
 * @retval    None
 */
1367
void TMR_SelectOCxMode(TMR_T* tmr, TMR_CHANNEL_T channel, TMR_OC_MODE_T mode)
A
abbcc 已提交
1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380
{
    tmr->CCEN &= BIT_RESET << channel;

    if (channel == TMR_CHANNEL_1)
    {
        tmr->CCM1_COMPARE_B.OC1MOD = mode;
    }
    else if (channel == TMR_CHANNEL_2)
    {
        tmr->CCM1_COMPARE_B.OC2MOD = mode;
    }
    else if (channel == TMR_CHANNEL_3)
    {
1381
        tmr->CCM2_COMPARE_B.OC3MOD = mode;
A
abbcc 已提交
1382 1383 1384
    }
    else if (channel == TMR_CHANNEL_4)
    {
1385
        tmr->CCM2_COMPARE_B.OC4MOD = mode;
A
abbcc 已提交
1386 1387 1388 1389 1390 1391 1392 1393 1394 1395
    }
}

/*!
 * @brief     Enable the TMRx update event
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @retval    None
 */
1396
void TMR_EnableUpdate(TMR_T* tmr)
A
abbcc 已提交
1397
{
1398
    tmr->CTRL1_B.UD = DISABLE;
A
abbcc 已提交
1399 1400 1401 1402 1403 1404 1405 1406 1407
}

/*!
 * @brief     Disable the TMRx update event
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @retval    None
 */
1408
void TMR_DisableUpdate(TMR_T* tmr)
A
abbcc 已提交
1409
{
1410
    tmr->CTRL1_B.UD = ENABLE;
A
abbcc 已提交
1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423
}

/*!
 * @brief     Configures the Update Request Interrupt source
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @param     updateSource: Config the Update source
 *                     The parameter can be one of following values:
 *                     @arg TMR_UPDATE_SOURCE_GLOBAL
 *                     @arg TMR_UPDATE_SOURCE_REGULAR
 * @retval    None
 */
1424
void TMR_ConfigUpdateRequest(TMR_T* tmr, TMR_UPDATE_SOURCE_T updateSource)
A
abbcc 已提交
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442
{
    if (updateSource != TMR_UPDATE_SOURCE_GLOBAL)
    {
        tmr->CTRL1_B.URSSEL = BIT_SET;
    }
    else
    {
        tmr->CTRL1_B.URSSEL = BIT_RESET;
    }
}

/*!
 * @brief     Enables Hall sensor interface.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @retval    None
 */
1443
void TMR_EnableHallSensor(TMR_T* tmr)
A
abbcc 已提交
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454
{
    tmr->CTRL2_B.TI1SEL = ENABLE;
}

/*!
 * @brief     Disable Hall sensor interface.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @retval    None
 */
1455
void TMR_DisableHallSensor(TMR_T* tmr)
A
abbcc 已提交
1456 1457 1458 1459 1460
{
    tmr->CTRL2_B.TI1SEL = DISABLE;
}

/*!
1461
 * @brief     Config the Sing pulse Mode.
A
abbcc 已提交
1462 1463 1464 1465 1466 1467 1468 1469 1470
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @param     singlePulseMode: specifies the Single Pulse Mode
 *                     The parameter can be one of following values:
 *                     @arg TMR_SPM_REPETITIVE
 *                     @arg TMR_SPM_SINGLE
 * @retval    None
 */
1471
void TMR_ConfigSinglePulseMode(TMR_T* tmr, TMR_SPM_T singlePulseMode)
A
abbcc 已提交
1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493
{
    tmr->CTRL1_B.SPMEN = singlePulseMode;
}

/*!
 * @brief     Selects the Trigger Output Mode.
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @param     TRGOSource: specifies the Trigger Output source
 *                     The parameter can be one of following values:
 *                     @arg TMR_TRGO_SOURCE_RESET
 *                     @arg TMR_TRGO_SOURCE_ENABLE
 *                     @arg TMR_TRGO_SOURCE_UPDATE
 *                     The under is not for TMR6 and TMR7
 *                     @arg TMR_TRGO_SOURCE_OC1
 *                     @arg TMR_TRGO_SOURCE_OC1REF
 *                     @arg TMR_TRGO_SOURCE_OC2REF
 *                     @arg TMR_TRGO_SOURCE_OC3REF
 *                     @arg TMR_TRGO_SOURCE_OC4REF
 * @retval    None
 */
1494
void TMR_SelectOutputTrigger(TMR_T* tmr, TMR_TRGO_SOURCE_T TRGOSource)
A
abbcc 已提交
1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508
{
    tmr->CTRL2_B.MMSEL = TRGOSource;
}

/*!
 * @brief     Selects the Slave Mode.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     slaveMode: specifies the Timer Slave Mode.
 *                     The parameter can be one of following values:
 *                     @arg TMR_SLAVE_MODE_RESET
 *                     @arg TMR_SLAVE_MODE_GATED
 *                     @arg TMR_SLAVE_MODE_TRIGGER
1509
 *                     @arg TMR_SLAVE_MODE_EXTERNAL1
A
abbcc 已提交
1510 1511
 * @retval    None
 */
1512
void TMR_SelectSlaveMode(TMR_T* tmr, TMR_SLAVE_MODE_T slaveMode)
A
abbcc 已提交
1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523
{
    tmr->SMCTRL_B.SMFSEL = slaveMode;
}

/*!
 * @brief     Enable the Master Slave Mode
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @retval    None
 */
1524
void TMR_EnableMasterSlaveMode(TMR_T* tmr)
A
abbcc 已提交
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535
{
    tmr->SMCTRL_B.MSMEN = ENABLE;
}

/*!
 * @brief     Disable the Master Slave Mode
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @retval    None
 */
1536
void TMR_DisableMasterSlaveMode(TMR_T* tmr)
A
abbcc 已提交
1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549
{
    tmr->SMCTRL_B.MSMEN = DISABLE;
}

/*!
 * @brief     Configs the Counter Register value
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @param     counter: Counter register new value
 *
 * @retval    None
 */
1550
void TMR_ConfigCounter(TMR_T* tmr, uint16_t counter)
A
abbcc 已提交
1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563
{
    tmr->CNT = counter;
}

/*!
 * @brief     Configs the AutoReload Register value
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @param     autoReload: autoReload register new value
 *
 * @retval    None
 */
1564
void TMR_ConfigAutoreload(TMR_T* tmr, uint16_t autoReload)
A
abbcc 已提交
1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577
{
    tmr->AUTORLD = autoReload;
}

/*!
 * @brief     Configs the Capture Compare1 Register value
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     compare1: specifies the Capture Compare1 value.
 *
 * @retval    None
 */
1578
void TMR_ConfigCompare1(TMR_T* tmr, uint16_t compare1)
A
abbcc 已提交
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591
{
    tmr->CC1 = compare1;
}

/*!
 * @brief     Configs the Capture Compare2 Register value
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     compare2: specifies the Capture Compare1 value.
 *
 * @retval    None
 */
1592
void TMR_ConfigCompare2(TMR_T* tmr, uint16_t compare2)
A
abbcc 已提交
1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605
{
    tmr->CC2 = compare2;
}

/*!
 * @brief     Configs the Capture Compare3 Register value
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     compare3: specifies the Capture Compare1 value.
 *
 * @retval    None
 */
1606
void TMR_ConfigCompare3(TMR_T* tmr, uint16_t compare3)
A
abbcc 已提交
1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619
{
    tmr->CC3 = compare3;
}

/*!
 * @brief     Configs the Capture Compare4 Register value
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     compare4: specifies the Capture Compare1 value.
 *
 * @retval    None
 */
1620
void TMR_ConfigCompare4(TMR_T* tmr, uint16_t compare4)
A
abbcc 已提交
1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637
{
    tmr->CC4 = compare4;
}

/*!
 * @brief     Configs the TMRx Input Capture 1 prescaler.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     prescaler: specifies the Input Capture Channel1 Perscaler
 *                     The parameter can be one of following values:
 *                     @arg TMR_IC_PSC_1: no prescaler
 *                     @arg TMR_IC_PSC_2: capture is done once every 2 events
 *                     @arg TMR_IC_PSC_4: capture is done once every 4 events
 *                     @arg TMR_IC_PSC_8: capture is done once every 8 events
 * @retval    None
 */
1638
void TMR_ConfigIC1Prescal(TMR_T* tmr, TMR_IC_PSC_T prescaler)
A
abbcc 已提交
1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655
{
    tmr->CCM1_CAPTURE_B.IC1PSC = BIT_RESET;
    tmr->CCM1_CAPTURE_B.IC1PSC = prescaler;
}
/*!
 * @brief     Sets the TMRx Input Capture 2 prescaler.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     prescaler: specifies the Input Capture Channel2 Perscaler
 *                     The parameter can be one of following values:
 *                     @arg TMR_IC_PSC_1: no prescaler
 *                     @arg TMR_IC_PSC_2: capture is done once every 2 events
 *                     @arg TMR_IC_PSC_4: capture is done once every 4 events
 *                     @arg TMR_IC_PSC_8: capture is done once every 8 events
 * @retval    None
 */
1656
void TMR_ConfigIC2Prescal(TMR_T* tmr, TMR_IC_PSC_T prescaler)
A
abbcc 已提交
1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674
{
    tmr->CCM1_CAPTURE_B.IC2PSC = BIT_RESET;
    tmr->CCM1_CAPTURE_B.IC2PSC = prescaler;
}

/*!
 * @brief     Configs the TMRx Input Capture 3 prescaler.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     prescaler: specifies the Input Capture Channel3 Perscaler
 *                     The parameter can be one of following values:
 *                     @arg TMR_IC_PSC_1: no prescaler
 *                     @arg TMR_IC_PSC_2: capture is done once every 2 events
 *                     @arg TMR_IC_PSC_4: capture is done once every 4 events
 *                     @arg TMR_IC_PSC_8: capture is done once every 8 events
 * @retval    None
 */
1675
void TMR_ConfigIC3Prescal(TMR_T* tmr, TMR_IC_PSC_T prescaler)
A
abbcc 已提交
1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693
{
    tmr->CCM2_CAPTURE_B.IC3PSC = BIT_RESET;
    tmr->CCM2_CAPTURE_B.IC3PSC = prescaler;
}

/*!
 * @brief     Configs the TMRx Input Capture 4 prescaler.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     prescaler: specifies the Input Capture Channel4 Perscaler
 *                     The parameter can be one of following values:
 *                     @arg TMR_IC_PSC_1: no prescaler
 *                     @arg TMR_IC_PSC_2: capture is done once every 2 events
 *                     @arg TMR_IC_PSC_4: capture is done once every 4 events
 *                     @arg TMR_IC_PSC_8: capture is done once every 8 events
 * @retval    None
 */
1694
void TMR_ConfigIC4Prescal(TMR_T* tmr, TMR_IC_PSC_T prescaler)
A
abbcc 已提交
1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711
{
    tmr->CCM2_CAPTURE_B.IC4PSC = BIT_RESET;
    tmr->CCM2_CAPTURE_B.IC4PSC = prescaler;
}

/*!
 * @brief     Configs the Clock Division value
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     clockDivision: specifies the clock division value.
 *                     The parameter can be one of following values:
 *                     @arg TMR_CLOCK_DIV_1: TDTS = Tck_tim
 *                     @arg TMR_CLOCK_DIV_2: TDTS = 2*Tck_tim
 *                     @arg TMR_CLOCK_DIV_4: TDTS = 4*Tck_tim
 * @retval    None
 */
1712
void TMR_ConfigClockDivision(TMR_T* tmr, TMR_CLOCK_DIV_T clockDivision)
A
abbcc 已提交
1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723
{
    tmr->CTRL1_B.CLKDIV = clockDivision;
}

/*!
 * @brief     Read Input Capture 1 value.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @retval    Capture Compare 1 Register value.
 */
1724
uint16_t TMR_ReadCaputer1(TMR_T* tmr)
A
abbcc 已提交
1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735
{
    return tmr->CC1;
}

/*!
 * @brief     Read Input Capture 2 value.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @retval    Capture Compare 2 Register value.
 */
1736
uint16_t TMR_ReadCaputer2(TMR_T* tmr)
A
abbcc 已提交
1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747
{
    return tmr->CC2;
}

/*!
 * @brief     Read Input Capture 3 value.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @retval    Capture Compare 3 Register value.
 */
1748
uint16_t TMR_ReadCaputer3(TMR_T* tmr)
A
abbcc 已提交
1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759
{
    return tmr->CC3;
}

/*!
 * @brief     Read Input Capture 4 value.
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @retval    Capture Compare 4 Register value.
 */
1760
uint16_t TMR_ReadCaputer4(TMR_T* tmr)
A
abbcc 已提交
1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771
{
    return tmr->CC4;
}

/*!
 * @brief     Read the TMRx Counter value.
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @retval    Counter Register value.
 */
1772
uint16_t TMR_ReadCounter(TMR_T* tmr)
A
abbcc 已提交
1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783
{
    return tmr->CNT;
}

/*!
 * @brief     Read the TMRx  Prescaler value.
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @retval    Prescaler Register value.
 */
1784
uint16_t TMR_ReadPrescaler(TMR_T* tmr)
A
abbcc 已提交
1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807
{
    return tmr->PSC;
}

/*!
 * @brief     Enable intterupts
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @param     interrupt: specifies the TMR interrupts sources
 *                     The parameter can be any combination of following values:
 *                     @arg TMR_INT_UPDATE: Timer update Interrupt source
 *                     @arg TMR_INT_CC1: Timer Capture Compare 1 Interrupt source
 *                     @arg TMR_INT_CC2: Timer Capture Compare 1 Interrupt source
 *                     @arg TMR_INT_CC3: Timer Capture Compare 3 Interrupt source
 *                     @arg TMR_INT_CC4: Timer Capture Compare 4 Interrupt source
 *                     @arg TMR_INT_COM: Timer Commutation Interrupt source (Only for TMR1 and TMR8)
 *                     @arg TMR_INT_TRG: Timer Trigger Interrupt source
 *                     @arg TMR_INT_BRK: Timer Break Interrupt source (Only for TMR1 and TMR8)
 * @retval    None
 *
 * @note      TMR6 and TMR7 can only generate an TMR_INT_UPDATE.
 */
1808
void TMR_EnableInterrupt(TMR_T* tmr, uint16_t interrupt)
A
abbcc 已提交
1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831
{
    tmr->DIEN |= interrupt;
}

/*!
 * @brief     Disable intterupts
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @param     interrupt: specifies the TMR interrupts sources
 *                     The parameter can be any combination of following values:
 *                     @arg TMR_INT_UPDATE: Timer update Interrupt source
 *                     @arg TMR_INT_CC1: Timer Capture Compare 1 Interrupt source
 *                     @arg TMR_INT_CC2: Timer Capture Compare 1 Interrupt source
 *                     @arg TMR_INT_CC3: Timer Capture Compare 3 Interrupt source
 *                     @arg TMR_INT_CC4: Timer Capture Compare 4 Interrupt source
 *                     @arg TMR_INT_COM: Timer Commutation Interrupt source (Only for TMR1 and TMR8)
 *                     @arg TMR_INT_TRG: Timer Trigger Interrupt source
 *                     @arg TMR_INT_BRK: Timer Break Interrupt source (Only for TMR1 and TMR8)
 * @retval    None
 *
 * @note      TMR6 and TMR7 can only generate an TMR_INT_UPDATE.
 */
1832
void TMR_DisableInterrupt(TMR_T* tmr, uint16_t interrupt)
A
abbcc 已提交
1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855
{
    tmr->DIEN &= ~interrupt;
}

/*!
 * @brief     Configures the TMRx event to be generate by software.
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @param     eventSources: specifies the TMR event sources
 *                     The parameter can be any combination of following values:
 *                     @arg TMR_EVENT_UPDATE: Timer update Interrupt source
 *                     @arg TMR_EVENT_CC1: Timer Capture Compare 1 Event source
 *                     @arg TMR_EVENT_CC2: Timer Capture Compare 1 Event source
 *                     @arg TMR_EVENT_CC3: Timer Capture Compare 3 Event source
 *                     @arg TMR_EVENT_CC4: Timer Capture Compare 4 Event source
 *                     @arg TMR_EVENT_COM: Timer Commutation Event source (Only for TMR1 and TMR8)
 *                     @arg TMR_EVENT_TRG: Timer Trigger Event source
 *                     @arg TMR_EVENT_BRK: Timer Break Event source (Only for TMR1 and TMR8)
 * @retval    None
 *
 * @note      TMR6 and TMR7 can only generate an TMR_EVENT_UPDATE.
 */
1856
void TMR_GenerateEvent(TMR_T* tmr, uint16_t eventSources)
A
abbcc 已提交
1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883
{
    tmr->CEG = eventSources;
}

/*!
 * @brief     Check whether the flag is set or reset
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @param     interrupt: specifies the TMR interrupts sources
 *                     The parameter can be any combination of following values:
 *                     @arg TMR_FLAG_UPDATE: Timer update Flag
 *                     @arg TMR_FLAG_CC1: Timer Capture Compare 1 Flag
 *                     @arg TMR_FLAG_CC2: Timer Capture Compare 2 Flag
 *                     @arg TMR_FLAG_CC3: Timer Capture Compare 3 Flag
 *                     @arg TMR_FLAG_CC4: Timer Capture Compare 4 Flag
 *                     @arg TMR_FLAG_COM: Timer Commutation Flag (Only for TMR1 and TMR8)
 *                     @arg TMR_FLAG_TRG: Timer Trigger Flag
 *                     @arg TMR_FLAG_BRK: Timer Break Flag (Only for TMR1 and TMR8)
 *                     @arg TMR_FLAG_CC1RC: Timer Capture Compare 1 Repetition Flag
 *                     @arg TMR_FLAG_CC2RC: Timer Capture Compare 2 Repetition Flag
 *                     @arg TMR_FLAG_CC3RC: Timer Capture Compare 3 Repetition Flag
 *                     @arg TMR_FLAG_CC4RC: Timer Capture Compare 4 Repetition Flag
 * @retval    None
 *
 * @note      TMR6 and TMR7 can only generate an TMR_FLAG_UPDATE.
 */
1884
uint16_t TMR_ReadStatusFlag(TMR_T* tmr, TMR_FLAG_T flag)
A
abbcc 已提交
1885
{
1886
    return (tmr->STS & flag) ? SET : RESET;
A
abbcc 已提交
1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911
}

/*!
 * @brief     Clears the TMR's pending flags.
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @param     interrupt: specifies the TMR interrupts sources
 *                     The parameter can be any combination of following values:
 *                     @arg TMR_FLAG_UPDATE: Timer update Flag
 *                     @arg TMR_FLAG_CC1: Timer Capture Compare 1 Flag
 *                     @arg TMR_FLAG_CC2: Timer Capture Compare 2 Flag
 *                     @arg TMR_FLAG_CC3: Timer Capture Compare 3 Flag
 *                     @arg TMR_FLAG_CC4: Timer Capture Compare 4 Flag
 *                     @arg TMR_FLAG_COM: Timer Commutation Flag (Only for TMR1 and TMR8)
 *                     @arg TMR_FLAG_TRG: Timer Trigger Flag
 *                     @arg TMR_FLAG_BRK: Timer Break Flag (Only for TMR1 and TMR8)
 *                     @arg TMR_FLAG_CC1RC: Timer Capture Compare 1 Repetition Flag
 *                     @arg TMR_FLAG_CC2RC: Timer Capture Compare 2 Repetition Flag
 *                     @arg TMR_FLAG_CC3RC: Timer Capture Compare 3 Repetition Flag
 *                     @arg TMR_FLAG_CC4RC: Timer Capture Compare 4 Repetition Flag
 * @retval    None
 *
 * @note      TMR6 and TMR7 can only generate an TMR_FLAG_UPDATE.
 */
1912
void TMR_ClearStatusFlag(TMR_T* tmr, uint16_t flag)
A
abbcc 已提交
1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935
{
    tmr->STS = ~flag;
}

/*!
 * @brief     Check whether the ITflag is set or reset
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @param     interrupt: specifies the TMR interrupts sources
 *                     The parameter can be one of following values:
 *                     @arg TMR_INT_UPDATE: Timer update Interrupt source
 *                     @arg TMR_INT_CC1: Timer Capture Compare 1 Interrupt source
 *                     @arg TMR_INT_CC2: Timer Capture Compare 1 Interrupt source
 *                     @arg TMR_INT_CC3: Timer Capture Compare 3 Interrupt source
 *                     @arg TMR_INT_CC4: Timer Capture Compare 4 Interrupt source
 *                     @arg TMR_INT_COM: Timer Commutation Interrupt source (Only for TMR1 and TMR8)
 *                     @arg TMR_INT_TRG: Timer Trigger Interrupt source
 *                     @arg TMR_INT_BRK: Timer Break Interrupt source (Only for TMR1 and TMR8)
 * @retval    None
 *
 * @note      TMR6 and TMR7 can only generate an TMR_INT_UPDATE.
 */
1936
uint16_t TMR_ReadIntFlag(TMR_T* tmr, TMR_INT_T flag)
A
abbcc 已提交
1937
{
1938
    if (((tmr->STS & flag) != RESET ) && ((tmr->DIEN & flag) != RESET))
A
abbcc 已提交
1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966
    {
        return SET;
    }
    else
    {
        return RESET;
    }
}

/*!
 * @brief     Clears the TMR's interrupt pending bits.
 *
 * @param     tmr: The TMRx can be 1 to 8
 *
 * @param     interrupt: specifies the TMR interrupts sources
 *                     The parameter can be any combination following values:
 *                     @arg TMR_INT_UPDATE: Timer update Interrupt source
 *                     @arg TMR_INT_CC1: Timer Capture Compare 1 Interrupt source
 *                     @arg TMR_INT_CC2: Timer Capture Compare 1 Interrupt source
 *                     @arg TMR_INT_CC3: Timer Capture Compare 3 Interrupt source
 *                     @arg TMR_INT_CC4: Timer Capture Compare 4 Interrupt source
 *                     @arg TMR_INT_COM: Timer Commutation Interrupt source (Only for TMR1 and TMR8)
 *                     @arg TMR_INT_TRG: Timer Trigger Interrupt source
 *                     @arg TMR_INT_BRK: Timer Break Interrupt source (Only for TMR1 and TMR8)
 * @retval    None
 *
 * @note      TMR6 and TMR7 can only generate an TMR_INT_UPDATE.
 */
1967
void TMR_ClearIntFlag(TMR_T* tmr,  uint16_t flag)
A
abbcc 已提交
1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984
{
    tmr->STS = ~flag;
}

/*!
 * @brief     Configure the TI1 as Input
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     ICpolarity: pointer to a TMR_IC_POLARITY_T
 *
 * @param     ICselection: pointer to a TMR_IC_SELECTION_T
 *
 * @param     ICfilter: This parameter must be a value between 0x00 and 0x0F
 *
 * @retval    None
 */
1985
static void TI1Config(TMR_T* tmr, uint16_t ICpolarity, uint16_t ICselection, uint16_t ICfilter)
A
abbcc 已提交
1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996
{
    uint16_t tmpchctrl = 0;

    tmr->CCEN_B.CC1EN = BIT_RESET;

    tmr->CCM1_CAPTURE_B.CC1SEL = BIT_RESET;
    tmr->CCM1_CAPTURE_B.IC1F   = BIT_RESET;
    tmr->CCM1_CAPTURE_B.CC1SEL = ICselection;
    tmr->CCM1_CAPTURE_B.IC1F   = ICfilter;

    if ((tmr == TMR1) || (tmr == TMR8) || (tmr == TMR2) || (tmr == TMR3) ||
1997
        (tmr == TMR4) || (tmr == TMR5))
A
abbcc 已提交
1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028
    {
        tmr->CCEN_B.CC1POL = BIT_RESET;
        tmr->CCEN_B.CC1EN  = BIT_SET;
        tmpchctrl = tmr->CCEN;
        tmpchctrl |= ICpolarity;
        tmr->CCEN = tmpchctrl;
    }
    else
    {
        tmr->CCEN_B.CC1POL  = BIT_RESET;
        tmr->CCEN_B.CC1NPOL = BIT_RESET;
        tmr->CCEN_B.CC1EN   = BIT_SET;
        tmpchctrl = tmr->CCEN;
        tmpchctrl |= ICpolarity;
        tmr->CCEN = tmpchctrl;
    }
}

/*!
 * @brief     Configure the TI2 as Input
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     ICpolarity: pointer to a TMR_IC_POLARITY_T
 *
 * @param     ICselection: pointer to a TMR_IC_SELECTION_T
 *
 * @param     ICfilter: This parameter must be a value between 0x00 and 0x0F
 *
 * @retval    None
 */
2029
static void TI2Config(TMR_T* tmr, uint16_t ICpolarity, uint16_t ICselection, uint16_t ICfilter)
A
abbcc 已提交
2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040
{
    uint16_t tmpchctrl = 0;

    tmr->CCEN_B.CC2EN = BIT_RESET;

    tmr->CCM1_CAPTURE_B.CC2SEL = BIT_RESET;
    tmr->CCM1_CAPTURE_B.IC2F   = BIT_RESET;
    tmr->CCM1_CAPTURE_B.CC2SEL = ICselection;
    tmr->CCM1_CAPTURE_B.IC2F   = ICfilter;

    if ((tmr == TMR1) || (tmr == TMR8) || (tmr == TMR2) || (tmr == TMR3) ||
2041
        (tmr == TMR4) || (tmr == TMR5))
A
abbcc 已提交
2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072
    {
        tmr->CCEN_B.CC2POL = BIT_RESET;
        tmr->CCEN_B.CC2EN  = BIT_SET;
        tmpchctrl = tmr->CCEN;
        tmpchctrl |= (ICpolarity << 4);
        tmr->CCEN = tmpchctrl;
    }
    else
    {
        tmr->CCEN_B.CC2POL  = BIT_RESET;
        tmr->CCEN_B.CC2NPOL = BIT_RESET;
        tmr->CCEN_B.CC2EN   = BIT_SET;
        tmpchctrl = tmr->CCEN;
        tmpchctrl |= (ICpolarity << 4);
        tmr->CCEN = tmpchctrl;
    }
}

/*!
 * @brief     Configure the TI3 as Input
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     ICpolarity: pointer to a TMR_IC_POLARITY_T
 *
 * @param     ICselection: pointer to a TMR_IC_SELECTION_T
 *
 * @param     ICfilter: This parameter must be a value between 0x00 and 0x0F
 *
 * @retval    None
 */
2073
static void TI3Config(TMR_T* tmr, uint16_t ICpolarity, uint16_t ICselection, uint16_t ICfilter)
A
abbcc 已提交
2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084
{
    uint16_t tmpchctrl = 0;

    tmr->CCEN_B.CC3EN = BIT_RESET;

    tmr->CCM2_CAPTURE_B.CC3SEL = BIT_RESET;
    tmr->CCM2_CAPTURE_B.IC3F   = BIT_RESET;
    tmr->CCM2_CAPTURE_B.CC3SEL = ICselection;
    tmr->CCM2_CAPTURE_B.IC3F   = ICfilter;

    if ((tmr == TMR1) || (tmr == TMR8) || (tmr == TMR2) || (tmr == TMR3) ||
2085
        (tmr == TMR4) || (tmr == TMR5))
A
abbcc 已提交
2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116
    {
        tmr->CCEN_B.CC3POL = BIT_RESET;
        tmr->CCEN_B.CC3EN  = BIT_SET;
        tmpchctrl = tmr->CCEN;
        tmpchctrl |= (ICpolarity << 8);
        tmr->CCEN = tmpchctrl;
    }
    else
    {
        tmr->CCEN_B.CC3POL  = BIT_RESET;
        tmr->CCEN_B.CC3NPOL = BIT_RESET;
        tmr->CCEN_B.CC3EN   = BIT_SET;
        tmpchctrl = tmr->CCEN;
        tmpchctrl |= (ICpolarity << 8);
        tmr->CCEN = tmpchctrl;
    }
}

/*!
 * @brief     Configure the TI4 as Input
 *
 * @param     tmr: The TMRx can be 1 to 8 except 6 and 7
 *
 * @param     ICpolarity: pointer to a TMR_IC_POLARITY_T
 *
 * @param     ICselection: pointer to a TMR_IC_SELECTION_T
 *
 * @param     ICfilter: This parameter must be a value between 0x00 and 0x0F
 *
 * @retval    None
 */
2117
static void TI4Config(TMR_T* tmr, uint16_t ICpolarity, uint16_t ICselection, uint16_t ICfilter)
A
abbcc 已提交
2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137
{
    uint16_t tmpchctrl = 0;

    tmr->CCEN_B.CC4EN = BIT_RESET;

    tmr->CCM2_CAPTURE_B.CC4SEL = BIT_RESET;
    tmr->CCM2_CAPTURE_B.IC4F   = BIT_RESET;
    tmr->CCM2_CAPTURE_B.CC4SEL = ICselection;
    tmr->CCM2_CAPTURE_B.IC4F   = ICfilter;

    tmr->CCEN_B.CC4POL = BIT_RESET;
    tmr->CCEN_B.CC4EN  = BIT_SET;
    tmpchctrl = tmr->CCEN;
    tmpchctrl |= (ICpolarity << 12);
    tmr->CCEN = tmpchctrl;
}

/**@} end of group TMR_Fuctions*/
/**@} end of group TMR_Driver*/
/**@} end of group Peripherals_Library*/