接口设计
7.7.5.5. Driver 层接口设计
以下接口是 PWM 设备驱动框架需要的标准接口。
struct rt_pwm_ops
{
rt_err_t (*control)(struct rt_device_pwm *device, int cmd, void *arg);
};| 函数原型 | rt_err_t drv_pwm_control(struct rt_device_pwm *device, int cmd, void *arg) |
|---|---|
| 功能说明 | (类似 ioctl 的接口方式)配置一个 PWM 通道 |
| 参数定义 | device - 指向 PWM 设备的指针 ioctl 命令码 arg - 命令参数,指向 configuration 结构的指针 |
| 返回值 | 0,成功; < 0,失败 |
| 注意事项 | - |
HAL 层接口设计
HAL 层的函数接口声明存放在 hal_pwm.h
中,主要接口有:
void hal_pwm_ch_init(u32 ch, enum aic_pwm_mode mode, u32 default_level,
struct aic_pwm_action *a0, struct aic_pwm_action *a1);
int hal_pwm_set(u32 ch, u32 duty_ns, u32 period_ns);
int hal_pwm_get(u32 ch, u32 *duty_ns, u32 *period_ns);
int hal_pwm_set_polarity(u32 ch, enum pwm_polarity polarity);
int hal_pwm_enable(u32 ch);
int hal_pwm_disable(u32 ch);
int hal_pwm_init(void);
int hal_pwm_deinit(void);
void hal_pwm_status_show(void);