Documentation

Documentation

Includes

tuya_driver.h

#include "tuya_driver.h"
#include "tuya_driver.h"

Macros

Marco __TUYA_PWM_H__

#define __TUYA_PWM_H__


      

Marco TUYA_PWM_FREQUENCY(__PWM)

#define TUYA_PWM_FREQUENCY(__PWM)  ((uint32_t)(1000000000 / (__PWM)->cfg.period_ns))


      

Marco TUYA_PWM_PERCENT(__PWM)

#define TUYA_PWM_PERCENT(__PWM)    ((__PWM)->cfg.percent)


      

Marco TUYA_PWM_CFG(__PWM, __PIN, __FREQUENCY, __PERCENT)

#define TUYA_PWM_CFG(__PWM, __PIN, __FREQUENCY, __PERCENT)                     \
   (__PWM)->cfg.pin      = __PIN;                                            \
   (__PWM)->cfg.period_ns = (uint32_t)1000000000 / (__FREQUENCY);             \
   (__PWM)->cfg.percent  = __PERCENT;                                        \
   (__PWM)->cfg.pulse_ns = (uint32_t)((__PWM)->cfg.period_ns * (__PERCENT)); \
   (__PWM)->cfg.polarity = TUYA_PWM_POSITIVE

      

Functions

Func tuya_pwm_frequency_set

int tuya_pwm_frequency_set (tuya_pwm_t *pwm, float frequency);
/**
 * @brief set frequency
 * 
 * @param[in] pwm refer to tuya_pwm_t
 * @param[in] frequency frequency
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Vars

Variable tuya_pwm_init

int tuya_pwm_init    (tuya_pwm_t *pwm);
/**
 * @brief pwm init
 * 
 * @param[in] pwm refer to tuya_pwm_t
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Variable tuya_pwm_start

int tuya_pwm_start    (tuya_pwm_t *pwm);
/**
 * @brief pwm start
 * 
 * @param[in] pwm refer to tuya_pwm_t
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Variable tuya_pwm_stop

int tuya_pwm_stop    (tuya_pwm_t *pwm);
/**
 * @brief pwm stop
 * 
 * @param[in] pwm refer to tuya_pwm_t
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Variable tuya_pwm_control

int tuya_pwm_control     (tuya_pwm_t *pwm, uint8_t cmd, void *arg);
/**
 * @brief pwm control
 * 
 * @param[in] pwm refer to tuya_pwm_t
 * @param[in] cmd control command
 * @param[in] arg command argument
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Variable tuya_pwm_deinit

int tuya_pwm_deinit    (tuya_pwm_t *pwm);
/**
 * @brief pwm deinit
 * 
 * @param[in] pwm refer to tuya_pwm_t
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Variable tuya_pwm_set

int tuya_pwm_set   (tuya_pwm_t *pwm, float frequency, float percent);
/**
 * @brief pwm set
 * 
 * @param[in] pwm refer to tuya_pwm_t
 * @param[in] frequency frequency
 * @param[in] percent percent
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Variable tuya_pwm_duty_set

int tuya_pwm_duty_set     (tuya_pwm_t *pwm, float percent);
/**
 * @brief set duty
 * 
 * @param[in] pwm refer to tuya_pwm_t
 * @param[in] percent percent
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Variable tuya_pwm_polarity_set

int tuya_pwm_polarity_set  (tuya_pwm_t *pwm, tuya_pwm_polarity_t polarity);
/**
 * @brief set polarity
 * 
 * @param[in] pwm refer to tuya_pwm_t
 * @param[in] polarity refer to tuya_pwm_polarity_t
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */

Consts

Types

Typedefs

Typedef tuya_pwm_port_t;

typedef enum {
   TUYA_PWM0 = 0,
   TUYA_PWM1,
   TUYA_PWM2,
   TUYA_PWM3,
   TUYA_PWM4,
   TUYA_PWM5,
   TUYA_PWM6,
   TUYA_PWM7,
   TUYA_PWM8,
} tuya_pwm_port_t;


      

Typedef tuya_pwm_polarity_t;

typedef enum {
   TUYA_PWM_POSITIVE = 0,
   TUYA_PWM_NEGATIVE,
} tuya_pwm_polarity_t;


      

Typedef tuya_pwm_cmd_t;

typedef enum {
   TUYA_PWM_SET_CMD       = TUYA_DRV_CUSTOM_CMD,
   TUYA_PWM_PERIOD_SET_CMD,
   TUYA_PWM_PULSE_SET_CMD,
   TUYA_PWM_POLARIITY_SET_CMD,
} tuya_pwm_cmd_t;


      

Typedef tuya_pwm_cfg_t;

typedef struct {
   uint8_t        pin;
   uint8_t        polarity;
   uint32_t       period_ns;
   uint32_t       pulse_ns;
   float          percent;
} tuya_pwm_cfg_t;


      

Typedef tuya_pwm_t

typedef struct tuya_pwm tuya_pwm_t;


      

Typedef tuya_pwm_ops_t;

typedef struct {
   int (*init)    (tuya_pwm_t *pwm, tuya_pwm_cfg_t *cfg);
   int (*start)   (tuya_pwm_t *pwm);
   int (*stop)    (tuya_pwm_t *pwm);
   int (*control) (tuya_pwm_t *pwm, uint8_t cmd, void *arg);
   int (*deinit)  (tuya_pwm_t *pwm);
} tuya_pwm_ops_t;