/****************************************************************************
* 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的更多相关文章

  1. I.MX6 PWM buzzer driver hacking with Demo test

    /***************************************************************************** * I.MX6 PWM buzzer dr ...

  2. OK335xS LAN8710 phy driver hacking

    /******************************************************************** * OK335xS LAN8710 phy driver h ...

  3. OK335xS pwm device register hacking

    /************************************************************************* * OK335xS pwm device regi ...

  4. OK335xS knob driver hacking

    /************************************************************************* * OK335xS knob driver hac ...

  5. OK335xS davinci mdio driver hacking

    /******************************************************************************* * OK335xS davinci m ...

  6. I.MX6 Linux I2C device& driver hacking

    /******************************************************************************************* * I.MX6 ...

  7. OK335xS 网络连接打印信息 hacking

    /*********************************************************************** * OK335xS 网络连接打印信息 hacking ...

  8. I.MX6 gpio-keys driver hacking

    /**************************************************************************** * I.MX6 gpio-keys driv ...

  9. I.MX6 bq27441 driver hacking

    /************************************************************************* * I.MX6 bq27441 driver ha ...

随机推荐

  1. PAT 1080 Graduate Admission[排序][难]

    1080 Graduate Admission(30 分) It is said that in 2011, there are about 100 graduate schools ready to ...

  2. [golang note] 协程基础

    协程概念 √ 协程通常称为coroutine,在golang中称为goroutine. √ 协程本质上是一种用户态线程,它不需要操作系统来进行抢占式调度,在实际实现中寄存在线程之中. √ 协程系统开销 ...

  3. 01 - spring mvc 概述及配置DispatcherServlet

    1.Spring mvc 基于model2实现,整体框架流程如(图片来自百度): ①web容器接收到http请求,若匹配DispatcherServlet的请求映射路径(web.xml),则容器会交给 ...

  4. 20145118 《Java程序设计》第1周学习总结

    20145118 <Java程序设计>第1周学习总结 教材学习内容总结 由于寒假在家已经安装了java开发工具,所以安装过程在这里不再赘述.这一周我开始了Java初学阶段,从Java的历史 ...

  5. Cooperation.GTST团队第三周项目总结

    项目进展 这周我们仍然在学习使用博客园的相关接口,页面的一个基本模块已经搭建出来了,但是页面整体效果还没有完全做出来.另外,我们在使用其他的APP时留意到许多APP都使用上拉加载和下拉刷新的效果,所以 ...

  6. HttpContext.Current and Web Api

    Using HttpContext.Current in WebApi is dangerous because of async HttpContext.Current gets the curre ...

  7. JS中innerHTML和innerText,outerHTML和outerText

      innerHTML 声明了元素含有的HTML文本,不包括元素本身的开始标记和结束标记 innerHTML是符合W3C标准的属性,而innerText只适用于IE浏览器(现在也适应chrome浏览器 ...

  8. springboot2 统一异常处理

    统一异常处理,不需要在每一层上单独捕获异常,只需要关注业务的开发: 代码如下: @RestControllerAdvice @Slf4j public class GlobalExceptionHan ...

  9. ongene database

    http://ongene.bioinfo-minzhao.org/index.html

  10. 16s workfollw

    http://bioconductor.org/packages/devel/bioc/vignettes/metagenomeFeatures/inst/doc/Example_16S_Annota ...