叒宇 · 2022年01月08日

【XR806开发板试用】2、UDP控制的呼吸灯.

【XR806开发板试用】1、UDP通信测试
上篇文章测试了XR806的UDP通信.
控制PWM控制相关的函数在device/xradio/xr806/adapter/hals/iot\_hardware/wifiiot\_lite文件夹下的iot\_pwm.c
.
├── BUILD.gn
├── iot\_flash.c
├── iot\_gpio.c
├── iot\_i2c.c
├── iot\_pwm.c
├── iot\_uart.c
├── iot\_watchdog.c
├── lowpower.c
└── reset.c

//port 指定输出引脚
//duty 指定输出PWM占空比 范围1-99
//freq 指定PWM输出频率
unsigned int IoTPwmInit(unsigned int port);
unsigned int IoTPwmDeinit(unsigned int port);
unsigned int IoTPwmStart(unsigned int port, unsigned short duty,unsigned int freq);
unsigned int IoTPwmStop(unsigned int port);

#include "iot_pwm.h"


#define pwm_channl1         0U
#define pwm_channl2         1U
#define pwm_channl3         2U
#define pwm_channl4         3U

void udp_echoserver_init(void)
{
//略
//在udp初始化结束后初始化PWM输出引脚.
        IoTPwmInit(pwm_channl1);
        IoTPwmInit(pwm_channl2);
        IoTPwmInit(pwm_channl3);
        IoTPwmInit(pwm_channl4);
}

void udp_echoserver_receive_callback(void *arg, struct udp_pcb *upcb,struct pbuf *p, const ip_addr_t *addr, u16_t port)
{
    udp_connect(upcb, addr, UDP_CLIENT_PORT);
    udp_send(upcb, p);
    udpReceiveCallback(p->payload, p->len);        //recave call 
    udp_disconnect(upcb);
    pbuf_free(p);
}
//udp接收回调函数中根据接收到的数据控制PWM占空比.

void udpReceiveCallback(char *p, int len)        //recave call 
{
    if(len<42+5)
        return;
    p+=42;
    //p[0]留作开关量控制.
    if(p[1]<5||p[1]>99)
        IoTPwmStop(pwm_channl1);
    else
        IoTPwmStart(pwm_channl1, p[1], 2000);

    if(p[2]<5||p[2]>99)
        IoTPwmStop(pwm_channl2);
    else
        IoTPwmStart(pwm_channl2, p[2], 2000);

    if(p[3]<5||p[3]>99)
        IoTPwmStop(pwm_channl3);
    else
        IoTPwmStart(pwm_channl3, p[3], 2000);

    if(p[4]<5||p[4]>99)
        IoTPwmStop(pwm_channl4);
    else
        IoTPwmStart(pwm_channl4, p[4], 2000);

 title=
 title=

推荐阅读
关注数
13823
内容数
139
全志XR806开发板相关的知识介绍以及应用专栏。
目录
极术微信服务号
关注极术微信号
实时接收点赞提醒和评论通知
安谋科技学堂公众号
关注安谋科技学堂
实时获取安谋科技及 Arm 教学资源
安谋科技招聘公众号
关注安谋科技招聘
实时获取安谋科技中国职位信息