add infrared_sensor

This commit is contained in:
Siegfried Kienzle
2017-06-07 10:04:40 +02:00
parent dca676ec38
commit b5a1cd4e25
4 changed files with 207 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
#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";
#define NUMBER_OF_MINOR_DEVICE (1);
#include "../_common/infrared_sensor.def.h"
static unsigned int infrared_sensor_in_2 = 3;
static int infrared_sensor_open(struct inode devfile, struct file *instance)
{
int err;
err = gpio_request(infrared_sensor_in_2, "rpi-gpio-2");
if (err) {
printk("gpio_request for in_2 failed %d\n", err);
return -1;
}
err = gpio_direction_input(infrared_sensor_in_2);
if (err) {
printk("gpio_direction_input for in_2 failed %d\n", err);
gpio_free(infrared_sensor_in_2);
return -1;
}
printk("gpio 3 successfull configured\n");
return 0;
}
static ssize_t infrared_sensor_read( struct file *instance, char __user *buffer,
size_t max_bytes_to_read, loff_t *offset)
{
}
static int infrared_sensor_close( struct inode devfile, struct file *instance)
{
printk( "driver_close called\n" );
gpio_free( infrared_sensor_in_2 );
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";

View File

@@ -0,0 +1,60 @@
#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";
#define NUMBER_OF_MINOR_DEVICE (1);
#include "../_common/infrared_sensor.def.h"
static unsigned int infrared_sensor_in_3 = 4;
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_3 failed %d\n", err);
return -1;
}
err = gpio_direction_input(infrared_sensor_in_3);
if (err) {
printk("gpio_direction_input for in_3 failed %d\n", err);
gpio_free(infrared_sensor_in_3);
return -1;
}
printk("gpio 4 successfull configured\n");
return 0;
}
static ssize_t infrared_sensor_read( struct file *instance, char __user *buffer,
size_t max_bytes_to_read, loff_t *offset)
{
}
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";