OK335xS pwm buzzer Linux driver hacking
/****************************************************************************
* OK335xS pwm buzzer Linux driver hacking
* 声明:
* 本文仅仅是为了知道如何使用pwm来控制buzzer,已达到控制不同声音的频率。
*
* 2015-10-7 雨 深圳 南山平山村 曾剑锋
***************************************************************************/ #include <linux/init.h>
#include <linux/export.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/errno.h>
#include <linux/miscdevice.h>
#include <linux/types.h>
#include <linux/io.h>
#include <linux/pwm/pwm.h>
#include <linux/fs.h> #define DEBUG
#if defined(DEBUG)
#define DPRINTK(fmt,arg...) printk(fmt,##arg);
#else
#define DPRINTK(fmt,arg...)
#endif #define BUZZER_FREQENCY 1
#define DEV_NAME "buzzer" /*pwm for this buzzer*/
struct pwm_device *pwm = NULL; static int buzzer_open(struct inode *inode, struct file *filp)
{ if(pwm != NULL)
return -EBUSY; /**
* 申请一个pwm设备
*/
pwm = pwm_request("ecap.1", -, "buzzer");
if ( pwm == NULL ) {
printk("buzzer open error.\n");
} printk("buzzer open\n");
return ;
} static int buzzer_release(struct inode *inode, struct file *filp)
{
/**
* 关闭、注销一个pwm设备
*/
pwm_stop(pwm);
pwm_release(pwm);
pwm = NULL; printk("buzzer release\n"); return ;
} static long buzzer_ioctl(struct file *filp,
unsigned int cmd, unsigned long arg)
{ if(pwm == NULL)
return -EINVAL; if(arg > || arg < )
return -EINVAL; switch (cmd) {
case BUZZER_FREQENCY: // 设置频率
if(arg==)
pwm_stop(pwm);
else
{
pwm_set_period_ns(pwm, /arg);
pwm_set_duty_ns(pwm, );
pwm_start(pwm);
} break;
default:
break;
} return ;
} static struct file_operations buzzer_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = buzzer_ioctl,
.open = buzzer_open,
.release = buzzer_release,
}; static struct miscdevice buzzer_miscdev =
{
.minor = MISC_DYNAMIC_MINOR,
.name = DEV_NAME,
.fops = &buzzer_fops,
}; static int __init buzzer_init(void)
{
/**
* 注册杂项设备
*/
misc_register(&buzzer_miscdev);
return ;
} static void __exit buzzer_exit(void)
{
misc_deregister(&buzzer_miscdev);
} module_init(buzzer_init);
module_exit(buzzer_exit);
OK335xS pwm buzzer Linux driver hacking的更多相关文章
- I.MX6 PWM buzzer driver hacking with Demo test
/***************************************************************************** * I.MX6 PWM buzzer dr ...
- OK335xS LAN8710 phy driver hacking
/******************************************************************** * OK335xS LAN8710 phy driver h ...
- OK335xS pwm device register hacking
/************************************************************************* * OK335xS pwm device regi ...
- OK335xS knob driver hacking
/************************************************************************* * OK335xS knob driver hac ...
- OK335xS davinci mdio driver hacking
/******************************************************************************* * OK335xS davinci m ...
- I.MX6 Linux I2C device& driver hacking
/******************************************************************************************* * I.MX6 ...
- OK335xS 网络连接打印信息 hacking
/*********************************************************************** * OK335xS 网络连接打印信息 hacking ...
- I.MX6 gpio-keys driver hacking
/**************************************************************************** * I.MX6 gpio-keys driv ...
- I.MX6 bq27441 driver hacking
/************************************************************************* * I.MX6 bq27441 driver ha ...
随机推荐
- Java打包可执行jar包 包含外部文件
外部文件在程序中设置成相对当前工程路径,执行jar包时,将外部文件放在和jar包平级的目录. public class Main { 3 public static void main(String[ ...
- 为什么要同时重写equals和hashcode
原文地址https://blog.csdn.net/tiantiandjava/article/details/46988461 原文地址https://blog.csdn.net/lijiecao0 ...
- Linux系统——公网定制化yum仓库部署
1)搭建公网源yum仓库 安装wget aliyun源 # wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel ...
- Spring—spring概述
Spring框架的特点? 1:轻量级,一站式开发 2:易用,追求代码的最佳实现 3:Spring的内容: a:Ioc容器 b:AOP实现 c:数据访问支持(ORM框架/声明事务[Transaction ...
- StarUML激活
感谢 http://blog.csdn.net/mergades/article/details/46662413 1,打开对应 mac版本的安装包位置,在对应目录/Applications/Sta ...
- 微信 audio 获取 duration 为 NaN 的解决方法
先加load() myaudio.load(); myaudio.oncanplay = function () { alert(myaudio.duration); } load() 方法用于在更改 ...
- Python3.x获取网页源码
Python3.x获取网页源码 1,获取网页的头部信息以确定网页的编码方式: import urllib.request res = urllib.request.urlopen('http://ww ...
- 使用MongoVUE无法添加Collection
说明: 问题MongoDB版本为3.2,MongoVUE 1.6.9 问题: 在数据库中添加集合不可用. 解决方法: MongoDB版本换成2 或者 切换存储引擎: 从MongoDB 3.2 版本开始 ...
- 模块的封装之C语言类的封装
[微知识]模块的封装(一):C语言类的封装 是的,你没有看错,我们要讨论的是C语言而不是C++语言中类的封装.在展开知识点之前,我首先要 重申两点: 1.面向对象是一种思想,基本与所用的语言是无关的. ...
- ubuntu18.04系统安装+基本环境配置【原创】
平台信息:PC:ubuntu18.04.i5.七彩虹GTX1060显卡.固态硬盘.机械硬盘 作者:庄泽彬(欢迎转载,请注明作者) 说明:在原本的电脑买一个独立显卡,装上去之后,出了各种问题,虽然后面勉 ...