【XR806开发板试用】2、UDP控制的呼吸灯.
-
上篇文章测试了XR806的UDP通信.
控制PWM控制相关的函数在device/xradio/xr806/adapter/hals/iot_hardware/wifiiot_lite文件夹下的iot_pwm.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);
-
@zthzz
使用udp相关的头文件的时候发现了一堆找不到路径的问题,我是在/demo/hello_demo 文件夹下敲的代码,而用到的文件是在net/lwip-1.4.1/lwip 文件夹里,应该可以通过修改Makefile文件达到但是,小白不会。
Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号