rt-thread-official/bsp/ls1cdev/libraries/ls1c_pwm.h

87 lines
2.3 KiB
C
Raw Normal View History

/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2017-09-06 <EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD> first version
*/
#ifndef __OPENLOONGSON_PWM_H
#define __OPENLOONGSON_PWM_H
// pwm<77><6D><EFBFBD>Ŷ<EFBFBD><C5B6><EFBFBD>
#define LS1C_PWM0_GPIO06 (6) // gpio06<30><36><EFBFBD><EFBFBD>pwm0
#define LS1C_PWM0_GPIO04 (4) // gpio04<30><34><EFBFBD><EFBFBD>Ϊpwm0
#define LS1C_PWM1_GPIO92 (92) // gpio92<39><32><EFBFBD><EFBFBD>pwm1
#define LS1C_PWM1_GPIO05 (5) // gpio05<30><35><EFBFBD><EFBFBD>Ϊpwm1
#define LS1C_PWM2_GPIO52 (52) // gpio52<35><32><EFBFBD><EFBFBD>Ϊpwm2
#define LS1C_PWM2_GPIO46 (46) // gpio46<34><36><EFBFBD><EFBFBD>Ϊpwm2
#define LS1C_PWM3_GPIO47 (47) // gpio47<34><37><EFBFBD><EFBFBD>Ϊpwm3
#define LS1C_PWM3_GPIO53 (53) // gpio53<35><33><EFBFBD><EFBFBD>Ϊpwm3
// ...<2E><><EFBFBD><EFBFBD>һЩgpio<69><6F><EFBFBD>Ը<EFBFBD><D4B8><EFBFBD>Ϊgpio<69>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD>
// pwm<77><6D><EFBFBD>ƼĴ<C6BC><C4B4><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF>bit
#define LS1C_PWM_INT_LRC_EN (11) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
#define LS1C_PWM_INT_HRC_EN (10) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
#define LS1C_PWM_CNTR_RST (7) // ʹ<><CAB9>CNTR<54><52><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define LS1C_PWM_INT_SR (6) // <20>ж<EFBFBD>״̬λ
#define LS1C_PWM_INTEN (5) // <20>ж<EFBFBD>ʹ<EFBFBD><CAB9>λ
#define LS1C_PWM_SINGLE (4) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
#define LS1C_PWM_OE (3) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
#define LS1C_PWM_CNT_EN (0) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
// Ӳ<><D3B2>pwm<77><6D><EFBFBD><EFBFBD>ģʽ
enum
{
// <20><><EFBFBD><EFBFBD>ģʽ--<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pwm<77><6D><EFBFBD><EFBFBD>
PWM_MODE_NORMAL = 0,
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<C4A3><CABD>ÿ<EFBFBD>ε<EFBFBD><CEB5><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E5A3AC><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pwm<77><6D><EFBFBD><EFBFBD>
PWM_MODE_PULSE
};
// Ӳ<><D3B2>pwm<77><6D>Ϣ
typedef struct
{
unsigned int gpio; // PWMn<4D><6E><EFBFBD>ڵ<EFBFBD>gpio
unsigned int mode; // <20><><EFBFBD><EFBFBD>ģʽ(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E5A1A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
float duty; // pwm<77><6D>ռ<EFBFBD>ձ<EFBFBD>
unsigned long period_ns; // pwm<77><6D><EFBFBD><EFBFBD>(<28><>λns)
}pwm_info_t;
/*
* <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>PWMn
* @pwm_info PWMn<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><EFBFBD>Ϣ
*/
void pwm_init(pwm_info_t *pwm_info);
/*
* <EFBFBD><EFBFBD>ֹpwm
* @pwm_info PWMn<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><EFBFBD>Ϣ
*/
void pwm_disable(pwm_info_t *pwm_info);
/*
* ʹ<EFBFBD><EFBFBD>PWM
* @pwm_info PWMn<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><EFBFBD>Ϣ
*/
void pwm_enable(pwm_info_t *pwm_info);
#endif