i.mx287学习笔记4-使用QT控制LED

网友投稿 316 2022-10-22


i.mx287学习笔记4-使用QT控制LED

目录

1.安装QT CREATOR

sudo apt-get install qt5-default qtcreator

2.硬件连接

照片看不太清,对照丝印和原理图,LED连接在GPIO3 PIN26上

在内核源码里面引脚定义是PINID_SAIF1_SDATA0

3.驱动源码

驱动是官方例程,直接改个IO口就行

/* GPIO Driver driver for EasyARM-iMX283 */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include <../arch/arm/mach-mx28/mx28_pins.h> #define DEVICE_NAME "imx28x_oled" #define LED_GPIO MXS_PIN_TO_GPIO(PINID_SAIF1_SDATA0) //for 283 287A/B /*-------------------------------------------------------------------------------------------------------- */ static int gpio_open(struct inode *inode, struct file *filp); static int gpio_release(struct inode *inode, struct file *filp); ssize_t gpio_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos); static int gpio_ioctl(struct inode *inode,struct file *flip,unsigned int command,unsigned long arg); static int gpio_init(void); static void gpio_exit(void); /*-------------------------------------------------------------------------------------------------------- */ static int gpio_open(struct inode *inode, struct file *filp) { gpio_request(LED_GPIO, "led"); return 0; } static int gpio_release(struct inode *inode, struct file *filp) { gpio_free(LED_GPIO); return 0; } ssize_t gpio_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos) { char data[2]; copy_from_user(data, buf, count); gpio_direction_output(LED_GPIO, data[0]); return count; } static int gpio_ioctl(struct inode *inode,struct file *flip,unsigned int command,unsigned long arg) { int data; switch (command) { case 0: gpio_direction_output(LED_GPIO, 0); break; case 1: gpio_direction_output(LED_GPIO, 1); break; } return 0; } static struct file_operations gpio_fops={ .owner = THIS_MODULE, .open = gpio_open, .write = gpio_write, .release = gpio_release, .ioctl = gpio_ioctl, }; static struct miscdevice gpio_miscdev = { .minor = MISC_DYNAMIC_MINOR, .name = DEVICE_NAME, .fops = &gpio_fops, }; static int __init gpio_init(void) { misc_register(&gpio_miscdev); printk(DEVICE_NAME" up. \n"); return 0; } static void __exit gpio_exit(void) { misc_deregister(&gpio_miscdev); printk(DEVICE_NAME " down.\n"); } module_init(gpio_init); module_exit(gpio_exit); MODULE_LICENSE("Dual BSD/GPL"); MODULE_AUTHOR("jun"); MODULE_DESCRIPTION("GPIO DRIVER FOR EasyARM-i.MX28xx");

4.编译驱动/测试驱动

测试代码

#include #include #include #include #include #include #include #include #include #include #include #include int main(void) { int fd; char buf[1] = {0}; fd = open("/dev/imx28x_led", O_RDWR); if (fd < 0) { perror("open /dev/imx283_led"); } printf("test write....\n"); buf[0] = 0; write(fd, buf, 1); sleep(2); buf[0] = 1; write(fd, buf, 1); sleep(1); printf("test ioctl..... \n"); ioctl(fd, 0); sleep(2); ioctl(fd, 1); }

编译测试代码

将代码拷贝到设备

可以看到设备上LED在翻转

5.创建QT界面

三个按键,每个按键实现一个功能

void MainWindow::on_pushButton_clicked() { QProcess *process = new QProcess(); process->start("sh led_insmod.sh"); } void MainWindow::on_pushButton_2_clicked() { QProcess *process = new QProcess(); process->start("sh led_rmmod.sh"); } void MainWindow::on_pushButton_3_clicked() { QProcess *process = new QProcess(); process->start("./led_test"); }

这里我创建了两个shell,其实没这么麻烦,直接输入命令就行,这里是为了测试qt调用shell

6.编译QT

下载到设备

7.运行

8.源码


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:知乎高赞:拼多多和国家电网,选哪个?
下一篇:servlet实现简单的权限管理和敏感词过滤功能
相关文章

 发表评论

暂时没有评论,来抢沙发吧~