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

151 lines
3.6 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 : CH57x_pwm.h
* Author : WCH
* Version : V1.2
* Date : 2021/11/17
* Description
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/
#ifndef __CH58x_PWM_H__
#define __CH58x_PWM_H__
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief channel of PWM define
*/
#define CH_PWM4 0x01 // PWM4 ͨ<><CDA8>
#define CH_PWM5 0x02 // PWM5 ͨ<><CDA8>
#define CH_PWM6 0x04 // PWM6 ͨ<><CDA8>
#define CH_PWM7 0x08 // PWM7 ͨ<><CDA8>
#define CH_PWM8 0x10 // PWM8 ͨ<><CDA8>
#define CH_PWM9 0x20 // PWM9 ͨ<><CDA8>
#define CH_PWM10 0x40 // PWM10 ͨ<><CDA8>
#define CH_PWM11 0x80 // PWM11 ͨ<><CDA8>
/**
* @brief channel of PWM define
*/
typedef enum
{
High_Level = 0, // Ĭ<>ϵ͵<CFB5>ƽ<EFBFBD><C6BD><EFBFBD>ߵ<EFBFBD>ƽ<EFBFBD><C6BD>Ч
Low_Level, // Ĭ<>ϸߵ<CFB8>ƽ<EFBFBD><C6BD><EFBFBD>͵<EFBFBD>ƽ<EFBFBD><C6BD>Ч
} PWMX_PolarTypeDef;
/**
* @brief Configuration PWM4_11 Cycle size
*/
typedef enum
{
PWMX_Cycle_256 = 0, // 256 <20><>PWMX<4D><58><EFBFBD><EFBFBD>
PWMX_Cycle_255, // 255 <20><>PWMX<4D><58><EFBFBD><EFBFBD>
PWMX_Cycle_128, // 128 <20><>PWMX<4D><58><EFBFBD><EFBFBD>
PWMX_Cycle_127, // 127 <20><>PWMX<4D><58><EFBFBD><EFBFBD>
PWMX_Cycle_64, // 64 <20><>PWMX<4D><58><EFBFBD><EFBFBD>
PWMX_Cycle_63, // 63 <20><>PWMX<4D><58><EFBFBD><EFBFBD>
PWMX_Cycle_32, // 32 <20><>PWMX<4D><58><EFBFBD><EFBFBD>
PWMX_Cycle_31, // 31 <20><>PWMX<4D><58><EFBFBD><EFBFBD>
} PWMX_CycleTypeDef;
/**
* @brief PWM4-PWM11 ͨ<><CDA8><EFBFBD><EFBFBD>׼ʱ<D7BC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param d - ͨ<><CDA8><EFBFBD><EFBFBD>׼ʱ<D7BC><CAB1> = d*Tsys
*/
#define PWMX_CLKCfg(d) (R8_PWM_CLOCK_DIV = d)
/**
* @brief PWM4-PWM11<31><31>׼ʱ<D7BC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param cyc - refer to PWMX_CycleTypeDef
*/
void PWMX_CycleCfg(PWMX_CycleTypeDef cyc);
/**
* @brief <20><><EFBFBD><EFBFBD> PWM4 <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param d - <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
#define PWM4_ActDataWidth(d) (R8_PWM4_DATA = d)
/**
* @brief <20><><EFBFBD><EFBFBD> PWM5 <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param d - <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
#define PWM5_ActDataWidth(d) (R8_PWM5_DATA = d)
/**
* @brief <20><><EFBFBD><EFBFBD> PWM6 <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param d - <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
#define PWM6_ActDataWidth(d) (R8_PWM6_DATA = d)
/**
* @brief <20><><EFBFBD><EFBFBD> PWM7 <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param d - <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
#define PWM7_ActDataWidth(d) (R8_PWM7_DATA = d)
/**
* @brief <20><><EFBFBD><EFBFBD> PWM8 <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param d - <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
#define PWM8_ActDataWidth(d) (R8_PWM8_DATA = d)
/**
* @brief <20><><EFBFBD><EFBFBD> PWM9 <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param d - <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
#define PWM9_ActDataWidth(d) (R8_PWM9_DATA = d)
/**
* @brief <20><><EFBFBD><EFBFBD> PWM10 <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param d - <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
#define PWM10_ActDataWidth(d) (R8_PWM10_DATA = d)
/**
* @brief <20><><EFBFBD><EFBFBD> PWM11 <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param d - <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
#define PWM11_ActDataWidth(d) (R8_PWM11_DATA = d)
/**
* @brief PWM4-PWM11ͨ<31><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param ch - select channel of pwm, refer to channel of PWM define
* @param da - effective pulse width
* @param pr - select wave polar, refer to PWMX_PolarTypeDef
* @param s - control pwmx function, ENABLE or DISABLE
*/
void PWMX_ACTOUT(uint8_t ch, uint8_t da, PWMX_PolarTypeDef pr, FunctionalState s);
/**
* @brief PWM <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD>
*
* @param ch - select group of PWM alternate output
* RB_PWM4_5_STAG_EN - PWM4 <20><> PWM5 ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* RB_PWM6_7_STAG_EN - PWM6 <20><> PWM7 ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* RB_PWM8_9_STAG_EN - PWM8 <20><> PWM9 ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* RB_PWM10_11_STAG_EN - PWM10 <20><> PWM11 ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param s - control pwmx function, ENABLE or DISABLE
*/
void PWMX_AlterOutCfg(uint8_t ch, FunctionalState s);
#ifdef __cplusplus
}
#endif
#endif // __CH58x_PWM_H__