wifiiot_pwm.h接口简介
初始化PWM unsigned int PwmInit(WifiIotPwmPort port); 取消初始化PWM unsigned int PwmDeinit(WifiIotPwmPort port); 根据输入参数输出PWM unsigned int PwmStart(WifiIotPwmPort port, unsigned short duty, unsigned short freq); 停止PWM输出 unsigned int PwmStop(WifiIotPwmPort port);
PWM驱动LED灯代码
# include <stdio.h>
# include <unistd.h>
# include "ohos_init.h"
# include <string.h>
# include "cmsis_os2.h"
# include "wifiiot_gpio.h"
# include "wifiiot_gpio_ex.h"
# include "wifiiot_pwm.h"
static void pwm2_func ( void )
{
GpioInit ( ) ;
IoSetFunc ( WIFI_IOT_IO_NAME_GPIO_2, WIFI_IOT_IO_FUNC_GPIO_2_PWM2_OUT) ;
GpioSetDir ( WIFI_IOT_IO_NAME_GPIO_2, WIFI_IOT_GPIO_DIR_OUT) ;
int i;
PwmInit ( WIFI_IOT_PWM_PORT_PWM2) ;
while ( 1 )
{
for ( i = 0 ; i < 40000 ; i += 200 )
{
PwmStart ( WIFI_IOT_PWM_PORT_PWM2, i, 40000 ) ;
usleep ( 10 ) ;
}
}
}
static void my_led_example ( void )
{
osThreadAttr_t attr;
attr. attr_bits = 0 ;
attr. name = "pwm2" ;
attr. cb_mem = NULL ;
attr. cb_size = 0 ;
attr. priority = 24 ;
attr. stack_size = 512 ;
if ( osThreadNew ( ( osThreadFunc_t ) pwm2_func, NULL , & attr) == NULL )
{
printf ( "Falied to create PWMTask!\n" ) ;
}
}
SYS_RUN ( my_led_example) ;
运行效果