- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在设备驱动程序编程中,我们使用 1. 设备驱动程序代码、2. 设备文件、3. 用户空间应用程序代码和 4. 实际物理硬件。
我能够编写驱动程序代码、用户空间应用程序代码并手动创 build 备文件,但我想尝试连接硬件(至少通过 Raspberry Pi 中的设备驱动程序使 LED 闪烁),这对我来说看起来没什么困难。
如果我能够使 LED 闪烁,则表示上述所有四个列出的项目之间正在发生通信。
我获取了一些用于闪烁 LED 的在线代码并进行了测试,但它不起作用。
最佳答案
Driver code:
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#define BUF_MAX_SIZE 1024
int major_num;
char driver_buf[BUF_MAX_SIZE];
int myopen(struct inode *inodep, struct file *filep)
{
printk(KERN_INFO "Bhaskar: Open function called.\n");
return 0;
}
int myclose(struct inode *indoep, struct file *filep)
{
printk(KERN_INFO "Bhaskar: Close function called.\n");
return 0;
}
ssize_t myread(struct file *filep, char *ubuf, size_t nbytes, loff_t *offset)
{
printk(KERN_INFO "Bhaskar: Read function called.\n");
copy_to_user(ubuf, driver_buf + filep->f_pos, nbytes);
filep->f_pos += nbytes;
return 0;
}
ssize_t mywrite(struct file *filep, const char *ubuf, size_t nbytes, loff_t *offset)
{
printk(KERN_INFO "Bhaskar: Write function called.\n");
copy_from_user(driver_buf + filep->f_pos, ubuf, nbytes);
filep->f_pos += nbytes;
return 0;
}
loff_t mylseek(struct file *filep, loff_t offset, int whence)
{
int newpos;
printk(KERN_INFO "Bhaskar: llseek function called.\n");
switch(whence)
{
case SEEK_SET:
newpos = offset;
printk(KERN_INFO "llseek called with SEEK_SET.\n");
break;
case SEEK_CUR:
newpos = filep->f_pos + offset;
printk(KERN_INFO "llseek called with SEEK_CUR.\n");
break;
case SEEK_END:
newpos = BUF_MAX_SIZE + offset;
printk(KERN_INFO "llseek called with SEEK_END.\n");
break;
}
filep->f_pos = newpos;
printk(KERN_INFO "new position of file pointer is:%d\n", newpos);
return newpos;
}
struct file_operations fops = {
.open = myopen,
.release = myclose,
.read = myread,
.write = mywrite,
.llseek = mylseek
};
static int hello_init(void)
{
printk(KERN_INFO "Bhaskar: Module loaded successfully.\n");
major_num = register_chrdev(0, "MyCharDriver", &fops);
printk(KERN_INFO "Char driver registered with major num is:%d\n", major_num);
return 0;
}
static void hello_exit(void)
{
printk(KERN_INFO "Bhaskar: Module unloaded successfully.\n");
unregister_chrdev(major_num, "MyCharDriver");
}
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Bhaskar <bhaskarauvsp@gmail.com>");
MODULE_DESCRIPTION("Its a dummy char driver");
module_init(hello_init);
module_exit(hello_exit);
关于linux - LED 通过 Rpi Linux 设备驱动程序闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58234681/
嘿,我 wounderd 如果有什么。我可以继续阅读以改进此代码的突击队吗?至少它现在可以工作,但需要做一些微调:) 如您所见,代码非常困惑且难以阅读。希望有人能帮忙。 提前谢谢。 int potPi
我使用 AVR 作为微 Controller ,ATMEGA8 作为处理器(在微 Controller 内部)。带有微 Controller 的电路板有 4 个 LED。我能够刻录程序并点亮 LEDS
谁能解释一下两者之间的关系 LED 像素密度, LED像素高度和宽度 , 和 分辨率在创建模拟器时方法很详细。。并在启动时再次默认值:皮肤尺寸、密度;缩放密度以实现大小? 最佳答案 像素密度:每英寸像
我有一个由大小为 64*64 的 LED 组成的阵列。每个 LED 都可以点亮各种颜色,并且可以非常快速地改变颜色。我的最终目标是:对于网络摄像头接收到的每一帧,我希望能够从帧中“提取”LED 数组,
我正在使用 Arduino Uno 软件进行编码,但遇到了问题。我试图以随机顺序打开 8 个 LED,然后立即将它们全部关闭。我的问题是 LED 会多次点亮相同的 LED,但最终不会全部点亮。这使得电
当我使用Ethernet.begin(mac,ip)时,LED灯不会打开和关闭。但是当我不使用那条线时它就可以工作。但我需要使用以太网和 UPP 模块来打开和关闭。我怎样才能? 板卡型号:以太网08T
我试图顺时针和逆时针方向点亮我的 LED 灯。我使用mpu6050作为LED的方向控制。我检查了我的 mpu6050 驱动代码,它们没问题。顺时针方向工作时效果很好,所有 LED 灯均呈红色亮起。像这
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 4 年前。 Improve this ques
我是一名优秀的程序员,十分优秀!