代码拉取完成,页面将自动刷新
同步操作将从 异想天开/openwrt_mt7688_ctest 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/*------------------------------------------------------------------
Author: qianrushizaixian
refer to: blog.csdn.net/qianrushizaixian/article/details/46536005
------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <math.h> //-- -lm
#include <stdbool.h> //bool
#include "/home/midas/ctest/kmods/soopwm/sooall_pwm.h"
#define PWM_DEV "/dev/sooall_pwm"
int main(int argc, char *argv)
{
int ret = -1;
int pwm_fd;
int pwmno;
struct pwm_cfg cfg;
int tmp;
pwm_fd = open(PWM_DEV, O_RDWR);
if (pwm_fd < 0) {
printf("open pwm fd failed\n");
return -1;
}
cfg.no = 0; /* pwm0 */
cfg.clksrc = PWM_CLK_40MHZ; //40MHZ or 100KHZ;
cfg.clkdiv = PWM_CLK_DIV2; //DIV2 40/2=20MHZ
cfg.old_pwm_mode =false; /* true=old mode --- false=new mode */
cfg.lduration = 2-1; //(duration 2)for NEW MODE !!!!!! set N as N-1
cfg.hduration = 2-1; //(duration 2)for NEW MODE !!!!!! set N as N-1
cfg.senddata0 = 0xf000f000;//1101110111011101;//0xAAAA; for NEW MODE
cfg.senddata1 = 0xf0f0f0f0;//1101110111011101;//0xAAAA; FOR NEW MODE
cfg.stop_bitpos = 63; // stop position of send data 0-63
cfg.idelval = 0;
cfg.guardval = 0; //
cfg.guarddur = 0; //
cfg.wavenum = 0; /* forever loop */
cfg.datawidth = 100;//781;//--limit 2^13-1=8191
cfg.threshold = 50; //500;
//---period=1000/100(KHZ)*(DIV(1-128))*datawidth (us)
//---period=1000/40(MHz)*(DIV)*datawidth (ns)
if(cfg.old_pwm_mode == true)
{
if(cfg.clksrc == PWM_CLK_100KHZ)
{
tmp=pow(2.0,(float)(cfg.clkdiv));
printf("tmp=%d,set PWM period=%d us\n",tmp,(int)(1000.0/100.0*tmp*(int)(cfg.datawidth))); // div by integer is dangerous!!!
}
else if(cfg.clksrc == PWM_CLK_40MHZ)
{
tmp=pow(2.0,(float)(cfg.clkdiv));
printf("tmp=%d,set PWM period=%d ns\n",tmp,(int)(1000.0/40.0*tmp*(int)(cfg.datawidth))); // div by integer is dangerous!!!
}
}
else if(cfg.old_pwm_mode == false)
{
printf("senddata0= %#08x senddata1= %#08x \n",cfg.senddata0,cfg.senddata1);
}
ioctl(pwm_fd, PWM_CONFIGURE, &cfg);
ioctl(pwm_fd, PWM_ENABLE, &cfg);
/*----------------- breath light -----------------*/
/*
while(1){
for(tmp=0;tmp<5000;tmp++){
cfg.threshold=tmp;
usleep(200);
ioctl(pwm_fd,PWM_CONFIGURE,&cfg);}
for(tmp=5000;tmp>5;tmp--){
cfg.threshold=tmp;
usleep(200);
ioctl(pwm_fd,PWM_CONFIGURE,&cfg);}
}
*/
/*
while (1) {
static int cnt = 0;
sleep(5);
ioctl(pwm_fd, PWM_GETSNDNUM, &cfg);
printf("send wave num = %d\n", cfg.wavenum);
cnt++;
if (cnt == 10) {
ioctl(pwm_fd, PWM_DISABLE, &cfg);
break;
}
}
*/
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。