1 /* 2 * Copyright (C) 2021 Alibaba Group Holding Limited 3 */ 4 5 #ifndef _AOS_PWM_H 6 #define _AOS_PWM_H 7 8 #include <stdint.h> 9 #include <aos/kernel.h> 10 #include <aos/device.h> 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 /** @defgroup driver_api driver 17 * @ingroup aos_components 18 * @{ 19 */ 20 21 /** @} */ 22 typedef enum { 23 AOS_PWM_POLARITY_NORMAL, 24 AOS_PWM_POLARITY_INVERSE, 25 } aos_pwm_polarity_t; 26 27 /** @} */ 28 29 typedef struct { 30 uint32_t period; /*in ns*/ 31 uint32_t duty_cycle; /*in ns*/ 32 aos_pwm_polarity_t polarity; 33 bool enabled; 34 } aos_pwm_attr_t; 35 /** 36 * @defgroup aos_pwm_app PWM应用操作 37 * @ingroup driver_api 38 * 给应用提供PWM操作的AOS PWM API. 39 * 40 * @{ 41 */ 42 43 typedef aos_dev_ref_t aos_pwm_ref_t; /**< PWM设备的引用 */ 44 45 /** 46 * 获取一个PWM设备的引用 47 * 48 * @param[out/in] ref PWM设备的引用 49 * @param[in] id PWM设备ID 50 * 51 * @return 0: 成功 <0: 失败 52 */ 53 aos_status_t aos_pwm_get(aos_pwm_ref_t *ref, uint32_t id); 54 55 /** 56 * 释放一个PWM设备的引用 57 * 58 * @param[out/in] ref PWM设备的引用 59 * 60 * @return 无 61 */ 62 void aos_pwm_put(aos_pwm_ref_t *ref); 63 64 /** 65 * 应用pwm参数到pwm设备 66 * 67 * @param[in] ref PWM设备的引用 68 * @param[in] pwm参数 aos_pwm_attr_t 69 * 70 * @return 0: 成功 <0: 失败 71 */ 72 aos_status_t aos_pwm_set_attr(aos_pwm_ref_t *ref, aos_pwm_attr_t const *attr); 73 74 /** 75 *获取当前pwm参数 76 * 77 * @param[in] ref PWM设备的引用 78 * @param[in] pwm参数 aos_pwm_attr_t 79 * 80 * @return 0: 成功 <0:失败 81 */ 82 aos_status_t aos_pwm_get_attr(aos_pwm_ref_t *ref, aos_pwm_attr_t *attr); 83 84 #ifdef __cplusplus 85 } 86 #endif 87 88 #endif /* _AOS_PWM_H */ 89