RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
dev_pwm.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2006-2024 RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2018-05-07 aozima the first version
9 * 2022-09-24 yuqi add phase and dead time configuration
10 */
11
12#ifndef __DEV_PWM_H__
13#define __DEV_PWM_H__
14
15#include <rtthread.h>
83
88#define PWM_CMD_ENABLE (RT_DEVICE_CTRL_BASE(PWM) + 0)
89#define PWM_CMD_DISABLE (RT_DEVICE_CTRL_BASE(PWM) + 1)
90#define PWM_CMD_SET (RT_DEVICE_CTRL_BASE(PWM) + 2)
91#define PWM_CMD_GET (RT_DEVICE_CTRL_BASE(PWM) + 3)
92#define PWMN_CMD_ENABLE (RT_DEVICE_CTRL_BASE(PWM) + 4)
93#define PWMN_CMD_DISABLE (RT_DEVICE_CTRL_BASE(PWM) + 5)
94#define PWM_CMD_SET_PERIOD (RT_DEVICE_CTRL_BASE(PWM) + 6)
95#define PWM_CMD_SET_PULSE (RT_DEVICE_CTRL_BASE(PWM) + 7)
96#define PWM_CMD_SET_DEAD_TIME (RT_DEVICE_CTRL_BASE(PWM) + 8)
97#define PWM_CMD_SET_PHASE (RT_DEVICE_CTRL_BASE(PWM) + 9)
98#define PWM_CMD_ENABLE_IRQ (RT_DEVICE_CTRL_BASE(PWM) + 10)
99#define PWM_CMD_DISABLE_IRQ (RT_DEVICE_CTRL_BASE(PWM) + 11)
100
105{
106 rt_uint32_t channel; /* 0 ~ n or 0 ~ -n, which depends on specific MCU requirements */
107 rt_uint32_t period; /* unit:ns 1ns~4.29s:1Ghz~0.23hz */
108 rt_uint32_t pulse; /* unit:ns (pulse<=period) */
109 rt_uint32_t dead_time; /* unit:ns */
110 rt_uint32_t phase; /*unit: degree, 0~360, which is the phase of pwm output, */
111 /*
112 * RT_TRUE : The channel of pwm is complememtary.
113 * RT_FALSE : The channel of pwm is nomal.
114 */
116};
117
118struct rt_device_pwm;
123{
124 rt_err_t (*control)(struct rt_device_pwm *device, int cmd, void *arg);
125};
126
131{
133 const struct rt_pwm_ops *ops;
134};
135
143rt_err_t rt_device_pwm_register(struct rt_device_pwm *device, const char *name, const struct rt_pwm_ops *ops, const void *user_data);
144
151rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel);
152
159rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel);
160
169rt_err_t rt_pwm_set(struct rt_device_pwm *device, int channel, rt_uint32_t period, rt_uint32_t pulse);
170
178rt_err_t rt_pwm_set_period(struct rt_device_pwm *device, int channel, rt_uint32_t period);
179
187rt_err_t rt_pwm_set_pulse(struct rt_device_pwm *device, int channel, rt_uint32_t pulse);
188
196rt_err_t rt_pwm_set_dead_time(struct rt_device_pwm *device, int channel, rt_uint32_t dead_time);
197
205rt_err_t rt_pwm_set_phase(struct rt_device_pwm *device, int channel, rt_uint32_t phase);
206
208
209#endif /* __DEV_PWM_H__ */
rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel)
enable the PWM channel
rt_err_t rt_pwm_set(struct rt_device_pwm *device, int channel, rt_uint32_t period, rt_uint32_t pulse)
set the PWM channel
rt_err_t rt_pwm_set_pulse(struct rt_device_pwm *device, int channel, rt_uint32_t pulse)
set the PWM channel pulse
rt_err_t rt_pwm_set_period(struct rt_device_pwm *device, int channel, rt_uint32_t period)
set the PWM channel period
rt_err_t rt_pwm_set_phase(struct rt_device_pwm *device, int channel, rt_uint32_t phase)
set the phase of PWM
rt_err_t rt_pwm_set_dead_time(struct rt_device_pwm *device, int channel, rt_uint32_t dead_time)
set the dead zone time of PWM
rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel)
disable the PWM channel
rt_err_t rt_device_pwm_register(struct rt_device_pwm *device, const char *name, const struct rt_pwm_ops *ops, const void *user_data)
register a PWM device
int rt_bool_t
rt_base_t rt_err_t
unsigned int rt_uint32_t
struct rt_device parent
const struct rt_pwm_ops * ops
PWM configuration
PWM operations
rt_err_t(* control)(struct rt_device_pwm *device, int cmd, void *arg)