touch infrared_senso_in_4.c
This commit is contained in:
60
project/module/infrared_sensor/infrared_sensor_in_4.c
Normal file
60
project/module/infrared_sensor/infrared_sensor_in_4.c
Normal 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_4 = 17;
|
||||||
|
|
||||||
|
static int infrared_sensor_open(struct inode devfile, struct file *instance)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = gpio_request(infrared_sensor_in_4, "rpi-gpio-17");
|
||||||
|
if (err) {
|
||||||
|
printk("gpio_request for in_4 failed %d\n", err);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
err = gpio_direction_input(infrared_sensor_in_3);
|
||||||
|
if (err) {
|
||||||
|
printk("gpio_direction_input for in_4 failed %d\n", err);
|
||||||
|
gpio_free(infrared_sensor_in_4);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
printk("gpio 17 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_4 );
|
||||||
|
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";
|
||||||
Reference in New Issue
Block a user