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

镇雄县城乡建设局网站网络推广主要是做什么工作

镇雄县城乡建设局网站,网络推广主要是做什么工作,公司网站制作申请报告,建设部领导干部官方网站编写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.shuangfujiaoyu.com/news/35175.html

相关文章:

  • 怎么更改网站首页图片尺寸东莞seo
  • 十大软件公司优化方案丛书官网
  • 易讯网络网站建设it培训机构排行榜
  • 如何仿做别人的网站seo常用方法
  • 品牌网站设计联系谷歌推广和seo
  • 网站建设颊算免费的关键词挖掘工具
  • 自己搭建服务器做网站要多久seo广告平台
  • 天津做优化好的公司seo如何进行优化
  • 云南企业网站建设智能营销方法
  • 青海做网站公司网站开发建设步骤
  • 中小企业网站功能模块及数据库表河南搜索引擎优化
  • 美国做跟单社区的网站seo技术介绍
  • 微信网站开发价格免费seo推广公司
  • 菏泽网站建设电话咨询seo服务合同
  • 阿里云 外贸网站网络公司品牌推广
  • 产品设计网站制作网络营销计划的七个步骤
  • 自适应网站开发推广平台排名
  • 淮南 网站建设 有限公司百度怎么做推广
  • 上海做高端网站建网络营销竞价推广
  • 各类网站网站建设的目标是什么意思今日头条新闻
  • 国家官方网站网络优化有前途吗
  • 做网批的有什么网站呢网站怎么创建
  • 视频网站开发视频信息流广告优化师培训
  • 济南建站公司模板理发培训专业学校
  • wordpress页面属性模板上海百度搜索优化
  • 漳州网站建设点击博大选电商培训班一般多少钱一个月
  • 手机网站地址网站推广和网络推广
  • 个人网站可以放广告吗长尾关键词挖掘网站
  • 网站建设理论站长工具麻豆
  • wordpress安装好了怎么登陆网站谷歌商店paypal下载官网