当前位置: 首页 > news >正文

云商城是合法的吗班级优化大师免费下载安装

云商城是合法的吗,班级优化大师免费下载安装,个人养老金制度9月底前亮相,龙岩做网站编写LED灯的驱动&#xff0c;使用GPIO子系统&#xff0c;里面添加按键的中断处理 1.应用程序发送指令控制LED亮灭 2.按键1 按下&#xff0c;led1电位反转 按键2按下&#xff0c;led2电位反转 按键3 按下&#xff0c;led3电位反转 驱动程序 #include <linux/init.h> #i…

编写LED灯的驱动,使用GPIO子系统,里面添加按键的中断处理

1.应用程序发送指令控制LED亮灭

2.按键1 按下,led1电位反转 按键2按下,led2电位反转 按键3 按下,led3电位反转

驱动程序

#include <linux/init.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_irq.h>
#include <linux/interrupt.h>
#include <linux/of_gpio.h>
#include <linux/gpio.h>
#include <linux/fs.h>
#include <linux/io.h>
#include <linux/device.h>
#include "head.h"
struct device_node *dev_key;
unsigned int irqno_key1;
unsigned int irqno_key2;
unsigned int irqno_key3;struct device_node *dev_led;
struct gpio_desc *gpiono_led1;
struct gpio_desc *gpiono_led2;
struct gpio_desc *gpiono_led3;int major;
struct class *cls;
struct device *dev;
// 中断处理函数
irqreturn_t myirq_handler_key1(int irq, void *dev)
{gpiod_set_value(gpiono_led1,!gpiod_get_value(gpiono_led1));return IRQ_HANDLED;
}
irqreturn_t myirq_handler_key2(int irq, void *dev)
{gpiod_set_value(gpiono_led2,!gpiod_get_value(gpiono_led2));return IRQ_HANDLED;
}
irqreturn_t myirq_handler_key3(int irq, void *dev)
{gpiod_set_value(gpiono_led3,!gpiod_get_value(gpiono_led3));return IRQ_HANDLED;
}
long mycdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{switch (cmd){case LED_ON:switch (arg){case 1:                           // LED1gpiod_set_value(gpiono_led1,1);; // LED1开灯break;case 2:                           // LED2gpiod_set_value(gpiono_led2,1); // LED2开灯break;case 3:                          // LED3gpiod_set_value(gpiono_led3,1); // LED3开灯break;}break;case LED_OFF:switch (arg){case 1:gpiod_set_value(gpiono_led1,0);break;case 2:gpiod_set_value(gpiono_led2,0);break;case 3:gpiod_set_value(gpiono_led3,0);break;}break;}return 0;
}
struct file_operations fops = {.unlocked_ioctl = mycdev_ioctl,};
static int __init mycdev_init(void)
{int i;// 字符设备驱动注册major = register_chrdev(0, "mychrdev", &fops);if (major < 0){printk("字符设备驱动注册失败\n");return major;}printk("字符设备驱动注册成功:major=%d\n", major);// 向上提交目录cls = class_create(THIS_MODULE, "myled");if (IS_ERR(cls)){printk("向上提交目录失败\n");return -PTR_ERR(cls);}printk("向上提交目录信息成功\n");// 向上提交设备节点信息for (i = 0; i < 3; i++){dev = device_create(cls, NULL, MKDEV(major, i), NULL, "myled%d", i);if (IS_ERR(dev)){printk("向上提交设备节点信息失败\n");return -PTR_ERR(dev);}}printk("向上提交设备节点成功\n");int ret;// 解析按键的设备树节点dev_key = of_find_node_by_path("/myirq");if (dev_key == NULL){printk("解析设备树节点失败\n");return -EFAULT;}printk("解析设备树节点成功\n");// 根据设备树节点解析出软中断号irqno_key1 = irq_of_parse_and_map(dev_key, 0); // 按键1索引号为0if (!irqno_key1){printk("解析软中断号失败\n");return -ENXIO;}printk("key1解析软中断号成功 irqno=%d\n", irqno_key1);irqno_key2 = irq_of_parse_and_map(dev_key, 1); // 按键1索引号为0if (!irqno_key2){printk("解析软中断号失败\n");return -ENXIO;}printk("key2解析软中断号成功 irqno=%d\n", irqno_key2);irqno_key3 = irq_of_parse_and_map(dev_key, 2); // 按键1索引号为0if (!irqno_key3){printk("解析软中断号失败\n");return -ENXIO;}printk("key3解析软中断号成功 irqno=%d\n", irqno_key3);// 注册中断ret = request_irq(irqno_key1, myirq_handler_key1, IRQF_TRIGGER_FALLING, "key1", NULL);if (ret){printk("注册中断失败\n");return ret;}printk("key1注册中断成功\n");ret = request_irq(irqno_key2, myirq_handler_key2, IRQF_TRIGGER_FALLING, "key2", NULL);if (ret){printk("注册中断失败\n");return ret;}printk("key2注册中断成功\n");ret = request_irq(irqno_key3, myirq_handler_key3, IRQF_TRIGGER_FALLING, "key3", NULL);if (ret){printk("注册中断失败\n");return ret;}printk("key3注册中断成功\n");// 根据设备树节点的路径解析设备树信息dev_led = of_find_node_by_path("/leds");if (dev_led == NULL){printk("解析设备树节点失败\n");return -EFAULT;}printk("解析设备树节点成功\n");// 申请gpio_desc对象并设置输出为低电平gpiono_led1 = gpiod_get_from_of_node(dev_led, "led1-gpios", 0, GPIOD_OUT_LOW, NULL);if (IS_ERR(gpiono_led1)){printk("申请gpio对象失败\n");return -PTR_ERR(gpiono_led1);}printk("申请gpio_led1对象成功\n");gpiono_led2 = gpiod_get_from_of_node(dev_led, "led2-gpios", 0, GPIOD_OUT_LOW, NULL);if (IS_ERR(gpiono_led2)){printk("申请gpio对象失败\n");return -PTR_ERR(gpiono_led2);}printk("申请gpio_led1对象成功\n");gpiono_led3 = gpiod_get_from_of_node(dev_led, "led3-gpios", 0, GPIOD_OUT_LOW, NULL);if (IS_ERR(gpiono_led3)){printk("申请gpio对象失败\n");return -PTR_ERR(gpiono_led3);}printk("申请gpio_led1对象成功\n");return 0;
}
static void __exit mycdev_exit(void)
{// 注销中断free_irq(irqno_key1, NULL);free_irq(irqno_key2, NULL);free_irq(irqno_key3, NULL);// 灭灯gpiod_set_value(gpiono_led1, 0);// 释放gpio编号gpiod_put(gpiono_led1);// 灭灯gpiod_set_value(gpiono_led2, 0);// 释放gpio编号gpiod_put(gpiono_led2);// 灭灯gpiod_set_value(gpiono_led3, 0);// 释放gpio编号gpiod_put(gpiono_led3);int i;for (i = 0; i < 3; i++){device_destroy(cls, MKDEV(major, i));}// 销毁目录信息class_destroy(cls);// 注销字符设备驱动unregister_chrdev(major, "mychrdev");
}
module_init(mycdev_init);
module_exit(mycdev_exit);
MODULE_LICENSE("GPL");

应用程序

#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include "head.h"int main(int argc, char const *argv[])
{int a, b;char buf[128] = {0};int fd0 = open("/dev/mycdev0", O_RDWR);if (fd0 < 0){printf("打开设备文件失败\n");exit(-1);}int fd1 = open("/dev/mycdev1", O_RDWR);if (fd1 < 0){printf("打开设备文件失败\n");exit(-1);}int fd2 = open("/dev/mycdev2", O_RDWR);if (fd2 < 0){printf("打开设备文件失败\n");exit(-1);}while (1){// 从终端读取printf("请输入指令\n");printf("0(关灯) 1(开灯)\n");printf("请输入>");scanf("%d", &a);printf("请输入要控制的灯 1(LED1) 2(LED2) 3(LED3)>");scanf("%d", &b);switch (b){case 1:switch (a){case 1:ioctl(fd0, LED_ON); // 开灯break;case 0:ioctl(fd0, LED_OFF);break;}break;case 2:switch (a){case 1:ioctl(fd1, LED_ON); // 开灯break;case 0:ioctl(fd1, LED_OFF);break;}break;case 3:switch (a){case 1:ioctl(fd2, LED_ON); // 开灯break;case 0:ioctl(fd2, LED_OFF);break;}break;}}close(fd0);close(fd1);close(fd2);return 0;
}

http://www.mmbaike.com/news/60319.html

相关文章:

  • 网站外链什么时候做seo一个关键词多少钱
  • 企业网站建设需要哪些资料信息seo优化官网
  • 网站上的在线答题是怎么做的软文优化
  • 中山做网站优化油烟机seo关键词
  • 快速的网站开发nba最新交易汇总
  • 网站建设+管理系统开发互联网广告价格
  • 可以免费做网站百度seo点击排名优化
  • 流量对网站的作用优化网站建设seo
  • 盐城市城乡和住房建设厅网站seo网站营销推广
  • 网站目录命名规则百度知道首页官网
  • 做影视网站规模不大seo优化实训报告
  • 如何做网站专题百度站长工具链接提交
  • 学做网站要懂英语吗宣传推广网络推广
  • 基于淘宝的网站开发分析市场调研数据网站
  • 詹凌峰建盏简介网站优化排名方案
  • 百通互联网站建设优化设计三年级上册语文答案
  • 做外贸网站推广的步骤佛山市seo推广联系方式
  • 长安做英文网站外贸网站制作
  • 企业网站管理系统演示平台优化大师怎么强力卸载
  • 做网站的目的和要求上海已经开始二次感染了
  • 宝安西乡做网站链接买卖价格
  • 网站首页框架图北京新闻最新消息
  • 灌南网站建设sem优化托管
  • 我的世界寻找建筑网站厦门关键词优化网站
  • 深圳好的网站建设公司哪家好推广营销软件
  • 南宁网站推广经理网站专业术语中seo意思是
  • 目前专业做水果的网站市场营销专业就业方向
  • 免费网站建设知识搜索竞价
  • 做亚马逊网站的公司建议百度推广运营专员
  • 一个人 建设网站整站seo优化