Files
kunlun/driver/src/hw3/inc/ledc_hw.h
2025-03-27 19:09:12 +08:00

278 lines
8.9 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.

/****************************************************************************
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
be copied by any method or incorporated into another program without
the express written consent of Aerospace C.Power. This Information or any portion
thereof remains the property of Aerospace C.Power. The Information contained herein
is believed to be accurate and Aerospace C.Power assumes no responsibility or
liability for its use in any way and conveys no license or title under
any patent or copyright and makes no representation or warranty that this
Information is free from patent or copyright infringement.
****************************************************************************/
#ifndef _LEDC_HW_H_
#define _LEDC_HW_H_
#define SIG_OUT_LED0 GPIO_MTX_LED0_OUT
#define LEDC_ENA_ENABLE 1
#define LEDC_ENA_DISABLE 0
#define TIMER_CTRL_START 1
#define TIMER_CTRL_PAUSE 0
#define OUT_POL_INVERT 1
#define OUT_POL_ORIGINAL 0
#define IDLE_LEVEL_HIGH 1
#define IDLE_LEVEL_LOW 0
#define DUTY_CNT_COMMON 1
#define DUTY_CNT_OWN 0
#define DUTY_OPT_MODE_NEW 1
#define DUTY_OPT_MODE_OLD 0
#define PHASE_NUM_TWO 1
#define PHASE_NUM_ONE 0
#define PHASE_MODE_FIXED_DUTY 0
#define PHASE_MODE_KEEP_DARK 1
#define PHASE_MODE_INCREASE 2
#define PHASE_MODE_DECREASE 3
typedef enum {
LEDC_PORT_0 = 0,
LEDC_PORT_1,
LEDC_PORT_2,
LEDC_PORT_3,
LEDC_PORT_4,
LEDC_PORT_5,
LEDC_PORT_6,
LEDC_PORT_7,
LEDC_PORT_MAX
} LEDC_PORT;
typedef enum {
COMMON_TIMER_SEL_0 = 0,
COMMON_TIMER_SEL_1,
COMMON_TIMER_SEL_2,
COMMON_TIMER_SEL_3,
COMMON_TIMER_SEL_4,
COMMON_TIMER_SEL_5,
COMMON_TIMER_SEL_6,
COMMON_TIMER_SEL_7,
COMMON_TIMER_SEL_MAX
} COMMON_TIMER_SEL;
typedef void (*ledc_interrrupt_cb_typedef)(uint8_t port);
/**
* @brief ledc_ena_rst() - 复位及使能ledc
*/
void ledc_ena_rst(void);
/**
* @brief ledc_gpio_config() - function used to set ledc gpio
* @param port: led port number
* @param gpio: gpio编号.
*/
void ledc_gpio_config(LEDC_PORT port, uint8_t gpio);
/**
* @brief ledc_timer_rst() - 复位ledc的定时器
* @param port: ledc 通道
*/
void ledc_timer_rst(LEDC_PORT port);
/**
* @brief ledc_timer_init() - 初始化ledc的定时器
* @param port: ledc 通道
* @param div 分频系数范围0-0xffff。输入定时器的时钟频率是24M。
*/
void ledc_timer_init(LEDC_PORT port, uint16_t div);
/**
* @brief ledc_timer_ctrl() - 启动或暂停ledc的定时器
* @param port: ledc 通道
* @param status: TIMER_CTRL_START 定时器开始计时
* TIMER_CTRL_PAUSE 定时器暂停计时
*/
void ledc_timer_ctrl(LEDC_PORT port, uint8_t status);
/**
* @brief ledc_cnt_ena() - ledc启停控制
* @param port: ledc 通道
* @param status: LEDC_ENA_ENABLE 使能
* LEDC_ENA_DISABLE 失能
*/
void ledc_cnt_ena(LEDC_PORT port, uint8_t status);
/**
* @brief ledc_polarity_sel() - ledc输出极性选择
* @param port: ledc 通道
* @param polarity: OUT_POL_ORIGINAL 不反相
* OUT_POL_INVERT 反相
*/
void ledc_polarity_sel(LEDC_PORT port, uint8_t polarity);
/**
* @brief ledc_idle_level_sel() - ledc空闲时电平状态选择
* 空闲是指关闭占空比的情况
* @param port: ledc 通道
* @param level: IDLE_LEVEL_HIGH 空闲时为高电平
* IDLE_LEVEL_LOW 空闲时为低电平
*/
void ledc_idle_level_sel(LEDC_PORT port, uint8_t level);
/**
* @brief ledc_phase1_blink_times_set() - ledc phase1 闪烁次数设置
* @param port: ledc 通道
* @param times: 闪烁次数 范围0-0xffff次特别的如果为0将一直闪烁
*/
void ledc_phase1_blink_times_set(LEDC_PORT port, uint16_t times);
/**
* @brief ledc_phase2_blink_times_set() - ledc phase2 闪烁次数设置
* @param port: ledc 通道
* @param times: 闪烁次数 范围0-0xffff次特别的如果为0将一直闪烁
*/
void ledc_phase2_blink_times_set(LEDC_PORT port, uint16_t times);
/**
* @brief ledc_h2l_point_set() - 设置输出电平从高电平跳变成低电平时的阈值
* @param port: ledc 通道
* @param point: 阈值 范围 0-0xffff
*/
void ledc_h2l_point_set(LEDC_PORT port, uint16_t point);
/**
* @brief ledc_l2h_point_set() - 设置输出电平从低电平跳变成高电平时的阈值
* @param port: ledc 通道
* @param point: 阈值 范围 0-0xffff
*/
void ledc_l2h_point_set(LEDC_PORT port, uint16_t point);
/**
* @brief ledc_duty_cnt_sel() - 选择计数器
* @param port: ledc 通道
* @param point: DUTY_CNT_COMMON 使用共用计数器
* DUTY_CNT_OWN 使用本ledc自己私有的计数器
*/
void ledc_duty_cnt_sel(LEDC_PORT port, uint8_t duty_cnt);
/**
* @brief ledc_thrs_set() - 计数器阈值设置,计数器大于这个值之后会重新开始计数
* @param port: ledc 通道
* @param thrs: 阈值范围0-0xffff
*/
void ledc_thrs_set(LEDC_PORT port, uint16_t thrs);
/**
* @brief ledc_phase_opt_sel() - 工作模式选择
* @param port: ledc 通道
* @param opt: DUTY_OPT_MODE_NEW 使用新模式 ,建议使用该模式
* DUTY_OPT_MODE_OLD 使用旧模式
*/
void ledc_phase_opt_sel(LEDC_PORT port, uint8_t opt);
/**
* @brief ledc_phase_num_sel() - phase个数选择
* @param port: ledc 通道
* @param num: PHASE_NUM_TWO phase1 phase2两个phase都使用
* PHASE_NUM_ONE 仅使用phase1一个phase
*/
void ledc_phase_num_sel(LEDC_PORT port, uint8_t num);
/**
* @brief ledc_phase_num_sel() - phase1工作模式选择
* @param port: ledc 通道
* @param mode: PHASE_MODE_FIXED_DUTY 固定占空比
* PHASE_MODE_KEEP_DARK 一直为暗
* PHASE_MODE_INCREASE 占空比渐变上升(由暗变亮)
* PHASE_MODE_DECREASE 占空比渐变下降(由亮变暗)
*/
void ledc_phase1_mode_sel(LEDC_PORT port, uint8_t mode);
/**
* @brief ledc_phase2_mode_sel() - phase1工作模式选择
* @param port: ledc 通道
* @param mode: PHASE_MODE_FIXED_DUTY 固定占空比
* PHASE_MODE_KEEP_DARK 一直为暗
* PHASE_MODE_INCREASE 占空比渐变上升(由暗变亮)
* PHASE_MODE_DECREASE 占空比渐变下降(由亮变暗)
*/
void ledc_phase2_mode_sel(LEDC_PORT port, uint8_t mode);
/**
* @brief ledc_phase1_scale_set() - phase1的渐变幅度设置scale为一次计数器周期中变化的count数
* @param port: ledc 通道
* @param scale: 范围 0-0xff
*/
void ledc_phase1_scale_set(LEDC_PORT port, uint8_t scale);
/**
* @brief ledc_phase2_scale_set() - phase2的渐变幅度设置scale为一次计数器周期中变化的count数
* @param port: ledc 通道
* @param scale: 范围 0-0xff
*/
void ledc_phase2_scale_set(LEDC_PORT port, uint8_t scale);
/**
* @brief ledc_cycle_times_set() - 设置一个loop里有多少个cycle,
* phase1 blink加上phase2 blink所使用的时间为一个cycle
* @param port: ledc 通道
* @param times: 范围 0-0xff
*/
void ledc_cycle_times_set(LEDC_PORT port, uint8_t times);
/**
* @brief ledc_loop_times_set() - 设置一共多少个loop
* @param port: ledc 通道
* @param times: 范围 0-0xff
*/
void ledc_loop_times_set(LEDC_PORT port, uint8_t times);
/**
* @brief ledc_nop_num_set() - 设置一个loop里有多少个nop计数器周期,这个时候处于空闲状态
* @param port: ledc 通道
* @param times: 范围 0-0xff
*/
void ledc_nop_num_set(LEDC_PORT port, uint16_t num);
/**
* @brief ledc_common_cnt_ena() - 共用计数器启停控制
* @param en: LEDC_ENA_ENABLE 使能
* LEDC_ENA_DISABLE 失能
*/
void ledc_common_cnt_ena(uint8_t en);
/**
* @brief ledc_common_thrs_set() - 共用计数器阈值设置,计数器大于这个值之后会重新开始计数
* @param thrs: 阈值范围0-0xffff
*/
void ledc_common_thrs_set(uint16_t thrs);
/**
* @brief ledc_common_thrs_set() - 共用计数器定时器选择
* @param timer_num: 被选定的定时器枚举序号
*/
void ledc_common_timer_sel(COMMON_TIMER_SEL timer_num);
/**
* @brief ledc_interrupt_init() - 中断初始化,里面只打开了闪烁完成中断,使用请传入
* 中断回调函数 void ledc_interrrupt_cb(uint8_t port)
* @param port:
*/
void ledc_interrupt_init(uint8_t port, ledc_interrrupt_cb_typedef cb);
#endif