2022-03-26 20:51:40 +08:00

103 lines
2.7 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/********************************** (C) COPYRIGHT *******************************
* File Name : CH58x_timer1.c
* Author : WCH
* Version : V1.2
* Date : 2021/11/17
* Description
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/
#include "CH58x_common.h"
/*********************************************************************
* @fn TMR1_TimerInit
*
* @brief <20><>ʱ<EFBFBD><CAB1><EFBFBD>ܳ<EFBFBD>ʼ<EFBFBD><CABC>
*
* @param t - <20><>ʱʱ<CAB1><EFBFBD><E4A3AC><EFBFBD>ڵ<EFBFBD>ǰϵͳʱ<CDB3><CAB1>Tsys, <20><EFBFBD><EEB3A4>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> 67108864
*
* @return none
*/
void TMR1_TimerInit(uint32_t t)
{
R32_TMR1_CNT_END = t;
R8_TMR1_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR1_CTRL_MOD = RB_TMR_COUNT_EN;
}
/*********************************************************************
* @fn TMR1_EXTSingleCounterInit
*
* @brief <20><><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܳ<EFBFBD>ʼ<EFBFBD><CABC>
*
* @param cap - <20>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @return none
*/
void TMR1_EXTSingleCounterInit(CapModeTypeDef cap)
{
R8_TMR1_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR1_CTRL_MOD = RB_TMR_COUNT_EN | RB_TMR_CAP_COUNT | RB_TMR_MODE_IN | (cap << 6);
}
/*********************************************************************
* @fn TMR1_PWMInit
*
* @brief PWM <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
*
* @param pr - select wave polar, refer to PWMX_PolarTypeDef
* @param ts - set pwm repeat times, refer to PWM_RepeatTsTypeDef
*
* @return none
*/
void TMR1_PWMInit(PWMX_PolarTypeDef pr, PWM_RepeatTsTypeDef ts)
{
// R8_TMR1_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR1_CTRL_MOD = RB_TMR_COUNT_EN | RB_TMR_OUT_EN | (pr << 4) | (ts << 6);
}
/*********************************************************************
* @fn TMR1_CapInit
*
* @brief <20>ⲿ<EFBFBD>źŲ<C5BA>׽<EFBFBD><D7BD><EFBFBD>ܳ<EFBFBD>ʼ<EFBFBD><CABC>
*
* @param cap - select capture mode, refer to CapModeTypeDef
*
* @return none
*/
void TMR1_CapInit(CapModeTypeDef cap)
{
R8_TMR1_CTRL_MOD = RB_TMR_ALL_CLEAR;
R8_TMR1_CTRL_MOD = RB_TMR_COUNT_EN | RB_TMR_MODE_IN | (cap << 6);
}
/*********************************************************************
* @fn TMR1_DMACfg
*
* @brief <20><><EFBFBD><EFBFBD>DMA<4D><41><EFBFBD><EFBFBD>
*
* @param s - <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>DMA<4D><41><EFBFBD><EFBFBD>
* @param startAddr - DMA <20><>ʼ<EFBFBD><CABC>ַ
* @param endAddr - DMA <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
* @param m - <20><><EFBFBD><EFBFBD>DMAģʽ
*
* @return none
*/
void TMR1_DMACfg(uint8_t s, uint16_t startAddr, uint16_t endAddr, DMAModeTypeDef m)
{
if(s == DISABLE)
{
R8_TMR1_CTRL_DMA = 0;
}
else
{
R16_TMR1_DMA_BEG = startAddr;
R16_TMR1_DMA_END = endAddr;
if(m)
R8_TMR1_CTRL_DMA = RB_TMR_DMA_LOOP | RB_TMR_DMA_ENABLE;
else
R8_TMR1_CTRL_DMA = RB_TMR_DMA_ENABLE;
}
}