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 ...
随机推荐
- TED #04#
Christopher Ategeka: How adoption worked for me 1. I experienced all the negative effects of poverty ...
- 微信小程序:页面配置 page.json
微信小程序:页面配置 page.json 一.页面配置 page.json 如果整个小程序的风格是蓝色调,那么可以在 app.json 里边声明顶部颜色是蓝色即可. 实际情况可能不是这样,可能你小程序 ...
- Codeforces Round #390 (Div. 2) D. Fedor and coupons(区间最大交集+优先队列)
http://codeforces.com/contest/754/problem/D 题意: 给定几组区间,找k组区间,使得它们的公共交集最大. 思路: 在k组区间中,它们的公共交集=k组区间中右端 ...
- Codeforces Round #169 (Div. 2) E. Little Girl and Problem on Trees dfs序+线段树
E. Little Girl and Problem on Trees time limit per test 2 seconds memory limit per test 256 megabyte ...
- Codeforces Round #394 (Div. 2) A,B,C,D,E
A. Dasha and Stairs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- MAC终端安装grunt--javascript世界得构建工具
祝贺我成为前端啦!~~从年前得小测试到今年得前端,成功转型!我真是一个进步得好青年,好少女! 这两天出去受虐,面了两家前端,表现非常不好,还是回到我现在得公司好好沉淀技术,做前端,要经常性得整理总结, ...
- H5 canvas控制坦克移动
接着上一篇(http://www.cnblogs.com/zhouhuan/p/H5_tankgame.html),这一篇研究一下怎么响应玩家的操作让坦克进行相应的移动. 1. 了解keydown ...
- Django框架基于session的登录/注销实现
博主最近想基于Django框架开发一个测试平台,第一版先实现查看下载自动化的测试报告文件 第一步:前端框架 网上选择一款开源boostrap的前端框架 AdminLTE,这里给个链接 https:/ ...
- Binding.RelativeSource 属性
Binding.RelativeSource 属性说明: 通过指定绑定源相对于绑定目标的位置,获取或设置绑定源. 此属性通常用于将对象的某个属性绑定到该对象的另一个属性,或用于在样式或模板中定义绑定. ...
- @RequestParam注解的作用及用法
最简单的两种写法,在写接口时:加或不加@RequestParam注解的区别 第一种写法参数为非必传,第二种写法参数为必传.参数名为userId 第二种写法可以通过@RequestParam(requi ...