4412 gpio读取pwm
一、可以使用的GPIO管脚
去掉占用调用的GPIO驱动,包括leds,buzzer,camera ov5640,WIFI mt6620 ,Keyboards
- VIDEO_OV5640– Device Drivers
- – Multimedia support(MEDIA_SUPPORT [=y])
- – Video capture adapters(VIDEO_CAPTURE_DRIVERS [=y])(去掉)
- MTK_COMBO_CHIP_MT6620– Device Drivers
- – MediaTek Connectivity Combo Chip Config
- – MediaTek Connectivity Combo Chip Support (MTK_COMBO [=y])(去掉)
- – Select Chip (<choice> [=y])
- Enable LEDS config– Device Drivers
- – Character devices
- – Enable LEDS config
- Enable BUZZER config
- – Device Drivers
- – Character devices
- – Enable BUZZER config
- Enable Keyboards
- Device Drivers --->
- Input device support --->
- Keyboards --->
- static int led_gpios[] = {
- EXYNOS4_GPL2(), EXYNOS4_GPK(), /* Led IO 2个 */
- EXYNOS4_GPD0(), /* BUZZER IO 1个 */
- EXYNOS4_GPX1(), EXYNOS4_GPX1(),EXYNOS4_GPX1(),EXYNOS4_GPX1(), /* 矩阵健盘8个 */
- EXYNOS4_GPX3(),EXYNOS4_GPX2(),EXYNOS4_GPX2(),EXYNOS4_GPX3(),
- EXYNOS4212_GPJ1(),EXYNOS4_GPL0(),EXYNOS4_GPL0(),EXYNOS4212_GPJ1(), /* 摄像头14个 */
- EXYNOS4212_GPJ1(),EXYNOS4212_GPJ1(),EXYNOS4212_GPJ0(),EXYNOS4212_GPJ0(),
- EXYNOS4212_GPJ0(),EXYNOS4212_GPJ0(),EXYNOS4212_GPJ0(),EXYNOS4212_GPJ0(),
- EXYNOS4212_GPJ0(),EXYNOS4212_GPJ0(),
- EXYNOS4_GPK3(),EXYNOS4_GPK3(),EXYNOS4_GPK3(),EXYNOS4_GPK3(), /* WIFI 7个 */
- EXYNOS4_GPK3(),EXYNOS4_GPK3(),EXYNOS4_GPC1(),
- };
led_gpios数组
二、设计思路
- 通过外部中断来处理电路上升沿和下降沿的跳变处理
- 通过读取IO管脚,来判断是上升沿触发还是下降沿触发
- 使用do_gettimeofday来获取时间戳,从而计算高电平时间
下面是我的源码:
- #include <linux/init.h>
- #include <linux/module.h>
- /* */
- #include <linux/platform_device.h>
- #include <linux/miscdevice.h>
- #include <linux/fs.h>
- #include <linux/gpio.h>
- #include <plat/gpio-cfg.h>
- #include <mach/gpio.h>
- #include <mach/gpio-exynos4.h>
- #include <asm/uaccess.h>
- #include <linux/irq.h>
- #include <linux/interrupt.h>
- #include <linux/time.h>
- #define DRIVER_NAME "ReadPwm"
- #define DEVICE_NAME "read_pwm"
- MODULE_LICENSE("Dual BSD/GPL");
- MODULE_AUTHOR("TOPEET");
- #define GPIO_CHG_FLT EXYNOS4_GPX1(0)
- static int up_flag = ;
- struct platform_device *dev_int;
- /* led: KP_COL0, VDD50_EN */
- /* BUZZER: MOTOR_PWM */
- /* keyboards: CHG_FLT, HOOK_DET, CHG_UOK, XEINT14_BAK, GM_INT1,
- 6260_GPIO1, CHG_COK, XEINT29/KP_ROW13/ALV_DBG25 */
- /* camera: CAM_MCLK, CAM2M_RST, CAM2M_PWDN, CAM_D5, CAM_D7, CAM_D6,
- CAM_D4, CAM_D3, CAM_D2, CAM_D1, CAM_PCLK, CAM_D0, CAM_VSYNC, CAM_HREF */
- /* WIFI: WIFI_D3, WIFI_CMD, WIFI_D1, WIFI_CLK, WIFI_D0, WIFI_D2,GPC1_1 */
- struct timeval tv_begin, tv_end;
- static int interval = ;
- struct semaphore sem;
- static irqreturn_t qint8_interrupt(int irq, void *dev_id)
- {
- int ret;
- ret = gpio_get_value(GPIO_CHG_FLT);
- if(ret == ) {
- do_gettimeofday(&tv_end);
- if(tv_end.tv_usec - tv_begin.tv_usec > ) {
- down(&sem);
- interval = tv_end.tv_usec - tv_begin.tv_usec;
- up(&sem);
- }
- // if(printk_ratelimit()) {
- // printk("tv_end.usec:%d - tv_begin.usec:%d =\n%d\n", tv_end.usec,
- // tv_begin.usec, tv_end.usec - tv_begin.usec);
- // }
- } else if(ret == ) {
- do_gettimeofday(&tv_begin);
- }
- return IRQ_HANDLED;
- }
- static int read_pwm_open(struct inode *inode, struct file *file)
- {
- printk(KERN_EMERG "read pwm open\n");
- return ;
- }
- static int read_pwm_release(struct inode *inode, struct file *file)
- {
- printk(KERN_EMERG "read pwm release\n");
- return ;
- }
- static ssize_t read_pwm_read(struct file *filp, char __user *buff, size_t size, loff_t *ppos)
- {
- unsigned int key_value = ;
- char temp[];
- int ret;
- // printk(KERN_EMERG "sizeof(key_value) is %d\n", sizeof(key_value));
- if(size != sizeof(temp)) {
- return -;
- }
- down(&sem);
- key_value = interval;
- up(&sem);
- temp[] = ((key_value)&0xff);
- temp[] = ((key_value>>)&0xff);
- ret = copy_to_user(buff, temp, sizeof(temp));
- return ret;
- }
- static struct file_operations read_pwm_ops = {
- .owner = THIS_MODULE,
- .open = read_pwm_open,
- .release = read_pwm_release,
- .read = read_pwm_read,
- };
- static struct miscdevice read_pwm_dev = {
- .minor = MISC_DYNAMIC_MINOR,
- .name = DEVICE_NAME,
- .fops = &read_pwm_ops,
- };
- static int read_pwm_probe(struct platform_device *pdv)
- {
- int ret;
- printk(KERN_EMERG "\tread pwm start initialized\n");
- /* set up gpio */
- // ret = gpio_request(GPIO_CHG_FLT, "GPX1_0");
- // if(ret < 0) {
- // printk(KERN_EMERG "request GPIO %d for read pwm failed\n", GPIO_CHG_FLT);
- // return ret;
- // }
- // s3c_gpio_cfgpin(GPIO_CHG_FLT, S3C_GPIO_INPUT);
- // s3c_gpio_setpull(GPIO_CHG_FLT, S3C_GPIO_PULL_NONE);
- ret = request_irq(IRQ_EINT(), qint8_interrupt, IRQ_TYPE_EDGE_BOTH, "my_eint8", pdv);
- if(ret < ) {
- printk(KERN_EMERG "request irq 8 failed.\n");
- return ;
- }
- up_flag = ;
- dev_int = pdv;
- sema_init(&sem, );
- /* register */
- ret = misc_register(&read_pwm_dev);
- if(ret < ) {
- gpio_free(GPIO_CHG_FLT);
- misc_deregister(&read_pwm_dev);
- return -EINVAL;
- }
- return ;
- }
- static int read_pwm_remove(struct platform_device *pdv)
- {
- printk(KERN_EMERG "\tread pwm remove\n");
- // gpio_free(GPIO_CHG_FLT);
- free_irq(IRQ_EINT(), pdv);
- misc_deregister(&read_pwm_dev);
- return ;
- }
- static void read_pwm_shutdown(struct platform_device *pdv)
- {
- }
- static int read_pwm_suspend(struct platform_device *pdv, pm_message_t pmt)
- {
- return ;
- }
- static int read_pwm_resume(struct platform_device *pdv)
- {
- return ;
- }
- struct platform_driver read_pwm_driver = {
- .probe = read_pwm_probe,
- .remove = read_pwm_remove,
- .shutdown = read_pwm_shutdown,
- .suspend = read_pwm_suspend,
- .resume = read_pwm_resume,
- .driver = {
- .name = DRIVER_NAME,
- .owner = THIS_MODULE,
- }
- };
- static int read_pwm_init(void)
- {
- int DriverState;
- printk(KERN_EMERG "Read pwm init enter!\n");
- DriverState = platform_driver_register(&read_pwm_driver);
- printk(KERN_EMERG "\tDriverState is %d\n", DriverState);
- return ;
- }
- static void read_pwm_exit(void)
- {
- printk(KERN_EMERG "Read pwm exit!\n");
- platform_driver_unregister(&read_pwm_driver);
- }
- module_init(read_pwm_init);
- module_exit(read_pwm_exit);
read_pwm.c
还有一个问题,卸载模块后再装载就会报错,不知道为什么。
app源码:
- #include <sys/types.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/stat.h>
- #define READ_PWM "/dev/read_pwm"
- int main()
- {
- long value = ;
- int fd;
- char buff[];
- int ret;
- fd = open(READ_PWM, O_RDWR|O_NDELAY);
- if(fd < ) {
- perror("open");
- }
- while(ret = read(fd, buff, sizeof(buff)) >= ) {
- printf("value is %d\n", buff[]|buff[]<<);
- usleep();
- }
- printf("sizeof(value) is %d\n", sizeof(buff));
- printf("read return is %d\n", ret);
- return ;
- }
read_pwm_app
4412 gpio读取pwm的更多相关文章
- 4412 GPIO初始化
一.GPIO的初始化 • 在内核源码目录下使用命令“ls drivers/gpio/*.o”,可以看到“gpioexynos4”被编译进了内核.通过搜索*.o文件,可以知道内核编译内哪些文件.针对的看 ...
- 4412 4路pwm输出
一.4412 xpwmTOUT1 这是4412的GPD0_1路,itop中被使用为LCD的背光电路的pwm功能.因此如果使用教程中的代码,同样操作GPD0_1是行不通的. 会出现错误,所以需要解除在内 ...
- 4412 GPIO读 和 ioremap控制GPIO寄存器
一.配置GPIO读 在视频14的基础上做 1.利用拨码开关来实现GPIO输入 所以AP_SLEEP对应GPC0_3,然后在drivers/gpio/gpio-exynos4.c中对应EXYNOS4_G ...
- 使用linux内核hrtimer高精度定时器实现GPIO口模拟PWM,【原创】
关键词:Android linux hrtimer 蜂鸣器 等待队列 信号量 字符设备 平台信息:内核:linux3.4.39 系统:android/android5.1平台:S5P4418 作 ...
- 树莓派GPIO开发(二)RGB模块-PWM调节
配置环境 系统:Raspbian11(官方64位) 设备:树莓派CM4 一.PWM简单介绍 全称:Pulse-width modulation,脉冲宽度调制,简单的数模转换方法 1.基本原理 脉冲宽度 ...
- nrf51 官方PWM库
地址:https://github.com/NordicSemiconductor/nrf51-pwm-library nrf_pwm_init函数 初始化PWM参数 设置输出pwm的gpio pin ...
- STM32 - GPIO
买了一个STM32F4的开发板,想把上面的东西重新学一下 快速过: 一.GPIO控制 void GPIO_DeInit(GPIO_TypeDef* GPIOx); //把某一个IO口恢复到默认值 /* ...
- wiringPi库的pwm配置及使用说明
本文介绍树莓派(raspberry pi)在linux c 环境下的硬件pwm配置及使用方法. 1. 下载安装wiringPi 此步骤建议参考官网指南,wiringPi提供了对树莓派的硬件IO访问,包 ...
- RK3399/NanoPC-T4开发板使用/sys/class/gpio操作外接GPIO设备-【申嵌视频-RK3399篇】
实验2:RK3399/NanoPC-T4开发板使用/sys/class/gpio操作外接GPIO设备,比如外接一个LED模块,通过GPIO1_A0管脚 1 介绍 LED模块 Matrix-LE ...
随机推荐
- Spring Boot 读取外部的配置文件
Spring Boot 程序会按优先级从下面这些路径来加载application.properties 或者 application.yml 配置文件 jar包同级目录下的/config目录jar包同 ...
- php面向对象三大特性
1.封装: 目的:使类更加安全 步骤:1.成员变量变成private(私有的)2.设置方法/调用方法3.在方法中增加限制 <?php class shao { private $aa;//必须是 ...
- java Json 技术记录
1.Json-lib json-lib最开始的也是应用最广泛的json解析工具,json-lib 不好的地方确实是依赖于很多第三方包,包括commons-beanutils.jar,commons-c ...
- PHP防采集方法代码
<?php /** * FileName:test.php * Summary: 防采集 */ $HTTP_REFERER = $_SERVER["HTTP_REFERER" ...
- 排序算法三:堆排序(Heapsort)
堆排序(Heapsort)是一种利用数据结构中的堆进行排序的算法,分为构建初始堆,减小堆的元素个数,调整堆共3步. (一)算法实现 protected void sort(int[] toSort) ...
- LOJ 2183 / SDOI2015 序列统计 (DP+矩阵快速幂)
题面 传送门 分析 考虑容斥原理,用总的方案数-不含质数的方案数 设\(dp1[i][j]\)表示前i个数,和取模p为j的方案数, \(dp2[i][j]\)表示前i个数,和取模p为j的方案数,且所有 ...
- 11、numpy——字符串函数
NumPy 字符串函数 以下函数用于对 dtype 为 numpy.string_ 或 numpy.unicode_ 的数组执行向量化字符串操作. 它们基于 Python 内置库中的标准字符串函数. ...
- Codeforces - 1176E - Cover it! - bfs
https://codeforc.es/contest/1176/problem/E 久了不写bfs了.一开始用dfs写,的确用dfs是很有问题的,一些奇怪的情况就会导致多染一些色. 注意无向图的边要 ...
- vue 移动端列表筛选功能实现
最近兴趣所致,打算使用vant搭建一个webapp,由于需要使用列表筛选,没有找到合适组件,于是写了一个简单的功能,权当记录. 效果如下: HTML: <div class=&qu ...
- 廖雪峰Python电子书总结
函数 1.注意:函数的默认参数必须指向不可变对象 未修改前: def add_end(L=[]): L.append('END') return L 存在的问题:如果连续调用多次,会出现多个 'END ...