Linux 应用层PWM实现呼吸灯
Linux常用的外设驱动基本已经提供,先确保已经添加好PWM设备。
可查看 /sys/class/pwm
下是否有设备,
rock@rockpi-4cplus:/sys/class/pwm$ ls
pwmchip0 pwmchip1
本文使用的是pwmchip0
可根据自己的实际使用的PWM组修改代码
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include <linux/ioctl.h>
#define dbmsg(fmt, args...) printf("%s[%d]: " fmt "\n", __FUNCTION__, __LINE__, ##args)
#define DUTY "duty"
#define PERIOD "256000"
char DUTYCYCLE[] = "000000";