P17
PWM的API
查看LED对应的GPIO引脚
输出PWM改变LED亮度
PWM扩展实验
static void PWMTask(void)
{
unsigned int i;
GpioInit();
IoSetFunc(WIFI_IOT_IO_NAME_GPIO_2, WIFI_IOT_IO_FUNC_GPIO_2_PWM2_OUT);
GpioSetDir(WIFI_IOT_GPIO_IDX_2, WIFI_IOT_GPIO_DIR_OUT);
PwmInit(WIFI_IOT_PWM_PORT_PWM2);
uint8_t j = 0;
while (1)
{
for (i = 0; i < 40000; i += 100)
{
PwmStart(WIFI_IOT_PWM_PORT_PWM2, i, 40000);
usleep(10);
}
i = 0;
j++;
if(j == 5)
{
PwmDeinit(WIFI_IOT_PWM_PORT_PWM2);
}
}
}
P20
UART API介绍
查看UART1对应的GPIO引脚
static void UART_Task(void)
{
uint8_t uart_buff[UART_BUFF_SIZE] = {0};
uint8_t *uart_buff_ptr = uart_buff;
uint32_t ret;
WifiIotUartAttribute uart_attr = {
.baudRate = 9600,
.dataBits = 8,
.stopBits = 1,
.parity = 0,
};
ret = UartInit(WIFI_IOT_UART_IDX_1, &uart_attr, NULL);
if (ret != WIFI_IOT_SUCCESS)
{
printf("Failed to init uart! Err code = %d\n", ret);
return;
}
printf("UART Test Start\n");
while (1)
{
printf("=======================================\r\n");
printf("*************UART_example**************\r\n");
printf("=======================================\r\n");
UartWrite(WIFI_IOT_UART_IDX_1, (unsigned char *)data, strlen(data));
UartRead(WIFI_IOT_UART_IDX_1, uart_buff_ptr, UART_BUFF_SIZE);
printf("Uart1 read data:%s", uart_buff_ptr);
usleep(1000000);
}
}
结果
在这里插入图片描述
|