implemented infrared-modules

This commit is contained in:
Siegfried Kienzle
2017-06-14 08:08:33 +02:00
parent f853d6b3e8
commit 1b80f5b89e
13 changed files with 481 additions and 0 deletions

View File

@@ -0,0 +1 @@
../Makefile

View File

@@ -0,0 +1,89 @@
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/gpio.h>
#include <linux/kobject.h>
#include <linux/device.h>
#include <linux/uaccess.h>
#define DEVICE_NAME "infrared_sensor_in_3"
#define NUMBER_OF_MINOR_DEVICE (1)
#include "../_common/infrared_sensor.def.h"
static unsigned int infrared_sensor_in_3 = 4;
static unsigned int count = 0;
static int infrared_sensor_open(struct inode *devfile, struct file *instance)
{
int err;
err = gpio_request(infrared_sensor_in_3, "rpi-gpio-2");
if (err) {
printk("gpio_request for in_1 failed %d\n", err);
return -1;
}
err = gpio_direction_input(infrared_sensor_in_3);
if (err) {
printk("gpio_direction_input for in_1 failed %d\n", err);
gpio_free(infrared_sensor_in_3);
return -1;
}
printk("gpio 2 successfull configured\n");
return 0;
}
<<<<<<< HEAD:project/module/infrared_sensor/infrared_sensor_in_3.c
static ssize_t infrared_sensor_read( struct file *file, char __user *buffer, size_t length, loff_t *offset)
{
unsigned long not_copied;
u32 value=0;
printk(KERN_DEBUG DEVICE_NAME ": read");
if (*offset > 0) {
return 0;
}
value = gpio_get_value(infrared_sensor_in_3);
not_copied = copy_to_user(buffer, &value, count);
*offset += count - not_copied;
return count - not_copied;
=======
static ssize_t infrared_sensor_read( struct file *instance, char __user *user,
size_t max_bytes_to_read, loff_t *offset)
{
unsigned long not_copied, to_copy;
u32 value = gpio_get_value;
to_copy = min( max_bytes_to_read, sizeof(value) );
not_copied=copy_to_user( user, &value, to_copy);
return to_copy - not_copied;
>>>>>>> 8ad08b638d0490724f49b13692420465d9c65658:project/modules/infrared_sensor_in_3/infrared_sensor_in_3.c
}
static int infrared_sensor_close( struct inode *devfile, struct file *instance)
{
printk( "driver_close called\n" );
gpio_free( infrared_sensor_in_3 );
return 0;
}
static struct file_operations fops = {
.owner = THIS_MODULE,
.open = infrared_sensor_open,
.release = infrared_sensor_close,
.read = infrared_sensor_read,
};
#include "../_common/infrared_sensor.h";