1 /* 2 * Copyright (C) 2021 Alibaba Group Holding Limited 3 */ 4 5 #ifndef _AOS_PWM_CORE_H 6 #define _AOS_PWM_CORE_H 7 8 #include <stdint.h> 9 #include <aos/kernel.h> 10 #include <aos/device_core.h> 11 #include <aos/pwm.h> 12 13 /** @defgroup driver_api driver 14 * @ingroup aos_components 15 * @{ 16 */ 17 18 /** @} */ 19 20 /** 21 * @defgroup aos_pwm_driver PWM驱动操作 22 * @ingroup driver_api 23 * 给PWM驱动提供PWM设备注册/注销操作. 24 * 25 * @{ 26 */ 27 28 struct aos_pwm_ops; 29 30 typedef struct aos_pwm { 31 aos_dev_t dev; 32 33 const struct aos_pwm_ops *ops; /**< PWM设备的底层操作, 设备注册前必须赋值 */ 34 uint32_t period; /**< PWM设备周期(单位:ns) */ 35 uint32_t duty_cycle; /**< PWM设备占空比(单位:ns) */ 36 uint32_t polarity; 37 bool enabled; 38 void *priv; /**< 私有数据 */ 39 } aos_pwm_t; 40 41 typedef struct aos_pwm_ops { 42 /**< PWM设备的注销操作(可选) */ 43 void (*unregister)(aos_pwm_t *pwm); 44 /**< PWM设备的前期准备 */ 45 aos_status_t (*startup)(aos_pwm_t *pwm); 46 /**< PWM设备的停止波形输出 */ 47 void (*shutdown)(aos_pwm_t *pwm); 48 /**< 设置PWM设备的频率 */ 49 aos_status_t (*apply)(aos_pwm_t *pwm, aos_pwm_attr_t const *attr); 50 } aos_pwm_ops_t; 51 52 #ifdef __cplusplus 53 extern "C" { 54 #endif 55 56 /** 57 * 注册一个PWM设备 58 * 59 * @param[in] pwm 要注册的PWM设备,调用者应该分配内存并初始化设置它的ID 60 * 61 * @return 0: 成功; <0: 失败 62 */ 63 aos_status_t aos_pwm_register(aos_pwm_t *pwm); 64 65 /** 66 * 注销一个PWM设备 67 * 68 * @param[in] id PWM设备的ID 69 * 70 * @return 0: 成功; <0: 失败 71 */ 72 aos_status_t aos_pwm_unregister(uint32_t id); 73 74 /** @} */ 75 #ifdef __cplusplus 76 } 77 #endif 78 79 #endif /* _AOS_PWM_CORE_H */ 80