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 @@
cmd_/home/sikienzl/git/resy-ss17-grp1/project/modules/infrared_sensor_in_1/infrared_sensor_in_1.ko := aarch64-linux-gnu-ld -EL -r -T ./scripts/module-common.lds --build-id -o /home/sikienzl/git/resy-ss17-grp1/project/modules/infrared_sensor_in_1/infrared_sensor_in_1.ko /home/sikienzl/git/resy-ss17-grp1/project/modules/infrared_sensor_in_1/infrared_sensor_in_1.o /home/sikienzl/git/resy-ss17-grp1/project/modules/infrared_sensor_in_1/infrared_sensor_in_1.mod.o ; true

View File

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

View File

@@ -0,0 +1,77 @@
#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_1"
#define NUMBER_OF_MINOR_DEVICE (1)
#include "../_common/infrared_sensor.def.h"
static unsigned int infrared_sensor_in_1 = 2;
static unsigned int count = 0;
static int infrared_sensor_open(struct inode *devfile, struct file *instance)
{
int err;
err = gpio_request(infrared_sensor_in_1, "rpi-gpio-2");
if (err) {
printk("gpio_request for in_1 failed %d\n", err);
return -1;
}
err = gpio_direction_input(infrared_sensor_in_1);
if (err) {
printk("gpio_direction_input for in_1 failed %d\n", err);
gpio_free(infrared_sensor_in_1);
return -1;
}
printk("gpio 2 successfull configured\n");
return 0;
}
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_1);
not_copied = copy_to_user(buffer, &value, count);
*offset += count - not_copied;
return count - not_copied;
}
static int infrared_sensor_close( struct inode *devfile, struct file *instance)
{
printk( "driver_close called\n" );
gpio_free( infrared_sensor_in_1 );
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";