diff --git a/Makefile b/Makefile index da0d6cf..de2e54f 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,11 @@ modname := usb_gpio obj-m := $(modname).o DEFINES := -DDEBUG -ccflags-y= $(DEFINES) +ccflags-y= $(DEFINES) -I/usr/include/ KVERSION := $(shell uname -r) +KMACHINE := $(shell uname -m) + KDIR := /lib/modules/$(KVERSION)/build PWD := "$$(pwd)" @@ -13,8 +15,13 @@ default: clean: $(MAKE) -C $(KDIR) M=$(PWD) clean + $(MAKE) -f Makefile.helper clean rm -rf *~ load: -/sbin/rmmod $(modname) /sbin/insmod $(modname).ko + +helper: + $(MAKE) -f Makefile.helper + diff --git a/Makefile.helper b/Makefile.helper new file mode 100644 index 0000000..e429e85 --- /dev/null +++ b/Makefile.helper @@ -0,0 +1,16 @@ + +OBJS = ftdi_daemon.o + +CC=gcc +CFLAGS = +LDFLAGS = -lftdi + +usbgpiod: $(OBJS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< + +%.o: %.c + $(CC) $(CFLAGS) -Wa,-a=$*.list -c -o $@ $< + +clean: + rm -rf $(OBJS) usbgpiod + rm -rf *.list *~ diff --git a/ftdi_daemon.c b/ftdi_daemon.c new file mode 100644 index 0000000..855194f --- /dev/null +++ b/ftdi_daemon.c @@ -0,0 +1,120 @@ +#include "ftdi_daemon.h" + +struct ftdi_context ftdic; + +uint8_t USB_GPIO_DDR; +uint8_t USB_GPIO_PORT; +uint8_t USB_GPIO_PIN; + +volatile uint8_t main_loop=1; + +static int vendor=0x0403, device=0x6001; + + + +static int is_output(unsigned offset){ + return !!((USB_GPIO_DDR)&(1< 0 ){ + if( ftdi_read_data(&ftdic,&USB_GPIO_PIN,1) < 0){ + printf("%s: Unable to read pin%d \n",MOD_NAME,offset); + } + } + return !!((USB_GPIO_PIN) & (1< +#include +#include +#include + +#define MOD_NAME "usb_gpio" + +#ifdef DEBUG + #define DEBUG_OUT(FMT,...) printk(FMT, ## __VA_ARGS__) +#else + #define DEBUG_OUT(FMT,...) {} +#endif + +#define PIN_TX 0 +#define PIX_RX 1 +#define PIN_RTS 2 +#define PIN_CTS 3 +#define PIN_DTR 4 +#define PIN_DSR 5 +#define PIN_DCD 6 +#define PIN_RI 7 + +#define PIN_0 0 +#define PIN_1 1 +#define PIN_2 2 +#define PIN_3 3 +#define PIN_4 4 +#define PIN_5 5 +#define PIN_6 6 +#define PIN_7 7 + +#endif //_FTDL_DAEMON_H diff --git a/usb_gpio.c b/usb_gpio.c index 2b0f768..466eb4f 100644 --- a/usb_gpio.c +++ b/usb_gpio.c @@ -5,12 +5,20 @@ static struct gpio_chip ft232_chip; #include "gpio_callbacks.c" static void usb_gpio_exit(void) { - gpiochip_remove(&ft232_chip); + if( gpiochip_remove(&ft232_chip)<0 ){ + printk("<1>%s: Couldn't free GPIO-pins!\n",MOD_NAME); + } printk("<1>%s: Bye!\n",MOD_NAME); } static int usb_gpio_init(void) { int ret; + // Prepare user space handler call + char *argv[] = { "/usr/bin/logger", "help!", NULL }; + static char *envp[] = { + "HOME=/", + "TERM=linux", + "PATH=/sbin:/bin:/usr/sbin:/usr/bin", NULL }; printk("<1>%s: Loading... \n",MOD_NAME); @@ -35,7 +43,9 @@ static int usb_gpio_init(void) { if (ret){ printk("<1>%s: Can't register chip!\n",MOD_NAME); } - return ret; + + //Call the user space handler + return call_usermodehelper( argv[0], argv, envp, UMH_WAIT_PROC ); } module_init(usb_gpio_init); diff --git a/usb_gpio.h b/usb_gpio.h index f161de9..cee57f1 100644 --- a/usb_gpio.h +++ b/usb_gpio.h @@ -8,6 +8,7 @@ #include #include /* kmalloc() */ #include +#include #include "usb_gpio_util.h"