[tuxdroid-svn] r1076 - in software_suite_v2/middleware/tuxdriver/trunk: . src unix win32
Status: Beta
Brought to you by:
ks156
From: remi <c2m...@c2...> - 2008-05-02 12:21:10
|
Author: remi Date: 2008-05-02 14:21:13 +0200 (Fri, 02 May 2008) New Revision: 1076 Added: software_suite_v2/middleware/tuxdriver/trunk/src/tux_hid_unix.c software_suite_v2/middleware/tuxdriver/trunk/src/tux_hid_unix.h software_suite_v2/middleware/tuxdriver/trunk/src/tux_hid_win32.c software_suite_v2/middleware/tuxdriver/trunk/src/tux_hid_win32.h Removed: software_suite_v2/middleware/tuxdriver/trunk/libs/ software_suite_v2/middleware/tuxdriver/trunk/src/usb.h Modified: software_suite_v2/middleware/tuxdriver/trunk/src/tux_misc.c software_suite_v2/middleware/tuxdriver/trunk/src/tux_usb.c software_suite_v2/middleware/tuxdriver/trunk/src/tux_usb.h software_suite_v2/middleware/tuxdriver/trunk/unix/Makefile software_suite_v2/middleware/tuxdriver/trunk/win32/Makefile Log: merged the trunk with the HID branch. Added: software_suite_v2/middleware/tuxdriver/trunk/src/tux_hid_unix.c =================================================================== --- software_suite_v2/middleware/tuxdriver/trunk/src/tux_hid_unix.c (rev 0) +++ software_suite_v2/middleware/tuxdriver/trunk/src/tux_hid_unix.c 2008-05-02 12:21:13 UTC (rev 1076) @@ -0,0 +1,197 @@ +/* + * Tux Droid - Hid interface (only for unix) + * Copyright (C) 2008 C2ME Sa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#ifndef WIN32 + +#include <stdlib.h> +#include <stdio.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <asm/types.h> +#include <fcntl.h> +#include <unistd.h> +#include <linux/hiddev.h> + +#include <string.h> +#include <dirent.h> + +#include "tux_hid_unix.h" +#include "tux_misc.h" + +static int tux_device_hdl = -1; +static char tux_device_path[256] = ""; +static struct hiddev_usage_ref uref_out; +static struct hiddev_report_info rinfo_out; + +static bool +find_dongle_from_path(char *path, int vendor_id, int product_id) +{ + DIR* dir; + struct dirent *dinfo; + int fd = -1; + char device_path[256] = ""; + struct hiddev_devinfo device_info; + int err; + + dir = opendir(path); + if (dir != NULL) + { + while ((dinfo = readdir(dir)) != NULL) + { + if (strncmp(dinfo->d_name, "hiddev", 6) == 0) + { + sprintf(device_path, "%s/%s", path, dinfo->d_name); + + if ((fd = open(device_path, O_RDONLY)) >= 0) + { + err = ioctl(fd, HIDIOCGDEVINFO, &device_info); + if ((device_info.vendor == vendor_id) && + ((device_info.product & 0xFFFF) == product_id)) + { + sprintf(tux_device_path, "%s", device_path); + tux_device_hdl = fd; + + closedir(dir); + + return true; + } + else + { + close(fd); + } + } + } + } + + closedir(dir); + } + + return false; +} + +bool LIBLOCAL +tux_hid_capture(int vendor_id, int product_id) +{ + /* Normal path to scan is /dev/usb */ + if (find_dongle_from_path("/dev/usb", vendor_id, product_id)) + { + return true; + } + + /* Other possible path to scan is /dev/usb */ + if (find_dongle_from_path("/dev", vendor_id, product_id)) + { + return true; + } + + /* dongle not found */ + return false; +} + +void LIBLOCAL +tux_hid_release(void) +{ + if (tux_device_hdl != -1) + { + close(tux_device_hdl); + tux_device_hdl = -1; + } +} + +bool LIBLOCAL +tux_hid_write(int size, char *buffer) +{ + int i; + int err; + + rinfo_out.report_type = HID_REPORT_TYPE_OUTPUT; + rinfo_out.report_id = HID_REPORT_ID_FIRST; + + err = ioctl(tux_device_hdl, HIDIOCGREPORTINFO, &rinfo_out); + if (err < 0) + { + return false; + } + + for(i = 0; i < size; i++) + { + uref_out.report_type = HID_REPORT_TYPE_OUTPUT; + uref_out.report_id = HID_REPORT_ID_FIRST; + uref_out.usage_index = i; + uref_out.value = (unsigned char)buffer[i]; + + err = ioctl(tux_device_hdl,HIDIOCSUSAGE, &uref_out); + if (err < 0) + { + return false; + } + } + + err = ioctl(tux_device_hdl,HIDIOCSREPORT,&rinfo_out); + if (err < 0) + { + return false; + } + + return true; +} + +bool LIBLOCAL +tux_hid_read(int size, char *buffer) +{ + int i; + int err; + + rinfo_out.report_type = HID_REPORT_TYPE_INPUT; + rinfo_out.report_id = HID_REPORT_ID_FIRST; + + err = ioctl(tux_device_hdl, HIDIOCGREPORTINFO, &rinfo_out); + if (err < 0) + { + return false; + } + + for (i = 0; i < size; i++) + { + uref_out.report_type = HID_REPORT_TYPE_INPUT; + uref_out.report_id = HID_REPORT_ID_FIRST; + uref_out.usage_index = i; + + err = ioctl(tux_device_hdl, HIDIOCGUCODE, &uref_out); + if (err < 0) + { + return false; + } + + err = ioctl(tux_device_hdl, HIDIOCGUSAGE, &uref_out); + if (err < 0) + { + return false; + } + + buffer[i] = uref_out.value; + } + + return true; +} + +#endif /* Not WIN32 */ + Added: software_suite_v2/middleware/tuxdriver/trunk/src/tux_hid_unix.h =================================================================== --- software_suite_v2/middleware/tuxdriver/trunk/src/tux_hid_unix.h (rev 0) +++ software_suite_v2/middleware/tuxdriver/trunk/src/tux_hid_unix.h 2008-05-02 12:21:13 UTC (rev 1076) @@ -0,0 +1,38 @@ +/* + * Tux Droid - Hid interface (only for unix) + * Copyright (C) 2008 C2ME Sa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#ifndef WIN32 + +#ifndef _TUX_HID_H_ +#define _TUX_HID_H_ + +#include <stdbool.h> + +#define HID_RW_TIMEOUT 1000 + +extern bool tux_hid_capture(int vendor_id, int product_id); +extern void tux_hid_release(void); +extern bool tux_hid_write(int size, char *buffer); +extern bool tux_hid_read(int size, char *buffer); + +#endif /* _TUX_HID_H_ */ + +#endif /* Not WIN32 */ + Added: software_suite_v2/middleware/tuxdriver/trunk/src/tux_hid_win32.c =================================================================== --- software_suite_v2/middleware/tuxdriver/trunk/src/tux_hid_win32.c (rev 0) +++ software_suite_v2/middleware/tuxdriver/trunk/src/tux_hid_win32.c 2008-05-02 12:21:13 UTC (rev 1076) @@ -0,0 +1,200 @@ +/* + * Tux Droid - Hid interface (only for windows) + * Copyright (C) 2008 C2ME Sa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#ifdef WIN32 + +#include <windows.h> +#include <hidsdi.h> +#include <setupapi.h> +#include <dbt.h> +#include <stdbool.h> +#include <stdio.h> + +#include "tux_hid_win32.h" +#include "tux_misc.h" + +static char device_symbolic_name[256] = ""; +static HANDLE tux_device_hdl = NULL; +static COMMTIMEOUTS timeout; + +bool LIBLOCAL +tux_hid_capture(int vendor_id, int product_id) +{ + GUID hid_guid; + HANDLE h_dev_info; + SP_DEVICE_INTERFACE_DATA dev_info_data; + PSP_DEVICE_INTERFACE_DETAIL_DATA detail_data = NULL; + int member_index = 0; + bool last_device = false; + long result; + unsigned long length = 0; + ULONG required; + HANDLE device_hdl = NULL; + HIDD_ATTRIBUTES attributes; + bool tux_found = false;; + + if (tux_device_hdl != NULL) + { + return false; + } + + HidD_GetHidGuid(&hid_guid); + + h_dev_info = SetupDiGetClassDevs(&hid_guid, + NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); + + dev_info_data.cbSize = sizeof(dev_info_data); + + member_index = 0; + + do + { + result = SetupDiEnumDeviceInterfaces(h_dev_info, 0, + &hid_guid, member_index, &dev_info_data); + + if (result != 0) + { + result = SetupDiGetDeviceInterfaceDetail(h_dev_info, + &dev_info_data, NULL, 0, &length, NULL); + + detail_data = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(length); + detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); + + result = SetupDiGetDeviceInterfaceDetail(h_dev_info, + &dev_info_data, detail_data, length, &required, NULL); + + device_hdl = CreateFile(detail_data->DevicePath, 0, + FILE_SHARE_READ|FILE_SHARE_WRITE, (LPSECURITY_ATTRIBUTES)NULL, + OPEN_EXISTING, 0, NULL); + + attributes.Size = sizeof(attributes); + result = HidD_GetAttributes(device_hdl, &attributes); + + if ((attributes.VendorID == vendor_id) && + (attributes.ProductID == product_id)) + { + sprintf(device_symbolic_name, "%s", detail_data->DevicePath); + + CloseHandle(device_hdl); + + tux_device_hdl = CreateFile(detail_data->DevicePath, + GENERIC_WRITE|GENERIC_READ, + FILE_SHARE_READ|FILE_SHARE_WRITE, + (LPSECURITY_ATTRIBUTES)NULL, + OPEN_EXISTING, 0, NULL); + + timeout.ReadTotalTimeoutConstant = HID_RW_TIMEOUT; + timeout.WriteTotalTimeoutConstant = HID_RW_TIMEOUT; + SetCommTimeouts(tux_device_hdl, &timeout); + + tux_found = true; + + break; + } + + CloseHandle(device_hdl); + free(detail_data); + } + else + { + last_device = true; + } + + member_index++; + + } + while (last_device == false); + + if (tux_found) + { + return true; + } + else + { + return false; + } +} + +void LIBLOCAL +tux_hid_release(void) +{ + if (tux_device_hdl != NULL) + { + CloseHandle(tux_device_hdl); + tux_device_hdl = NULL; + } +} + +bool LIBLOCAL +tux_hid_write(int size, char *buffer) +{ + int wrt_count; + char report[65] = { [0 ... 64] = 0 }; + long result; + + if (tux_device_hdl == NULL) + { + return false; + } + + report[0] = 0; + memcpy(&report[1], buffer, size); + + result = WriteFile(tux_device_hdl, report, 65, &wrt_count, + NULL); + + if (!result) + { + return false; + } + else + { + return true; + } +} + +bool LIBLOCAL +tux_hid_read(int size, char *buffer) +{ + int rd_count; + char report[size + 1]; + long result; + + if (tux_device_hdl == NULL) + { + return false; + } + + result = ReadFile(tux_device_hdl, report, size + 1, &rd_count, + NULL); + + memcpy(buffer, &report[1], size); + + if (!result) + { + return false; + } + else + { + return true; + } +} + +#endif /* WIN32 */ Added: software_suite_v2/middleware/tuxdriver/trunk/src/tux_hid_win32.h =================================================================== --- software_suite_v2/middleware/tuxdriver/trunk/src/tux_hid_win32.h (rev 0) +++ software_suite_v2/middleware/tuxdriver/trunk/src/tux_hid_win32.h 2008-05-02 12:21:13 UTC (rev 1076) @@ -0,0 +1,35 @@ +/* + * Tux Droid - Hid interface (only for windows) + * Copyright (C) 2008 C2ME Sa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#ifdef WIN32 + +#ifndef _TUX_HID_H_ +#define _TUX_HID_H_ + +#define HID_RW_TIMEOUT 1000 + +extern bool tux_hid_capture(int vendor_id, int product_id); +extern void tux_hid_release(void); +extern bool tux_hid_write(int size, char *buffer); +extern bool tux_hid_read(int size, char *buffer); + +#endif /* _TUX_HID_H_ */ + +#endif /* WIN32 */ Modified: software_suite_v2/middleware/tuxdriver/trunk/src/tux_misc.c =================================================================== --- software_suite_v2/middleware/tuxdriver/trunk/src/tux_misc.c 2008-05-02 11:42:33 UTC (rev 1075) +++ software_suite_v2/middleware/tuxdriver/trunk/src/tux_misc.c 2008-05-02 12:21:13 UTC (rev 1076) @@ -93,7 +93,7 @@ struct timezone tz; gettimeofday(&tv, &tz); - result = ((float)tv.tv_usec / 1000000) + (float)tv.tv_sec; + result = ((double)tv.tv_usec / 1000000) + (double)tv.tv_sec; return result; } Modified: software_suite_v2/middleware/tuxdriver/trunk/src/tux_usb.c =================================================================== --- software_suite_v2/middleware/tuxdriver/trunk/src/tux_usb.c 2008-05-02 11:42:33 UTC (rev 1075) +++ software_suite_v2/middleware/tuxdriver/trunk/src/tux_usb.c 2008-05-02 12:21:13 UTC (rev 1076) @@ -23,9 +23,9 @@ #include "log.h" #ifdef WIN32 -# include "usb.h" +# include "tux_hid_win32.h" #else -# include <usb.h> +# include "tux_hid_unix.h" #endif #include "tux_usb.h" @@ -33,8 +33,6 @@ # include "threading_uniform.h" #endif -static usb_dev_handle *tux_handle = NULL; -static struct usb_device *tux_device = NULL; static bool usb_connected = false; static frame_callback_t frame_callback_function; static simple_callback_t dongle_disconnect_function; @@ -55,11 +53,6 @@ static bool read_loop_started = false; static void set_connected(bool value); -static struct usb_device *usb_find_TuxDroid(void); -static struct usb_dev_handle *usb_open_TuxDroid(struct usb_device *tux_dev); -static int usb_write_TuxDroid(const void *buf, int size); -static int usb_read_TuxDroid(char *buf); -static void print_usb_debug(const char *str); static void set_read_loop_started(bool value); static bool get_read_loop_started(void); @@ -68,15 +61,6 @@ /** * */ -static void -print_usb_debug(const char *str) -{ - log_debug("USB debug : %s\n", str); -} - -/** - * - */ LIBLOCAL void tux_usb_set_frame_callback(frame_callback_t funct) { @@ -155,11 +139,6 @@ LIBLOCAL void tux_usb_init_module(void) { -#ifdef USB_DEBUG - usb_set_debug(4); -#else - usb_set_debug(0); -#endif #ifdef USE_MUTEX mutex_init(__connected_mutex); mutex_init(__read_write_mutex); @@ -244,112 +223,15 @@ /** * */ -static struct usb_device * -usb_find_TuxDroid(void) -{ - struct usb_bus *bus; - struct usb_device *tux_dev; - struct usb_device *tux_dev2; - - print_usb_debug("usb_init()"); - usb_init(); - print_usb_debug("usb_find_busses()"); - usb_find_busses(); - print_usb_debug("usb_find_devices()"); - usb_find_devices(); - - tux_dev2 = NULL; - - for (bus = usb_busses; bus; bus = bus->next) - { - for (tux_dev = bus->devices; tux_dev; tux_dev = tux_dev->next) - { - if (tux_dev->descriptor.idVendor == TUX_VID - && tux_dev->descriptor.idProduct == TUX_PID) - { - if (tux_dev->config->bNumInterfaces > 1) - { - tux_dev2 = tux_dev; - } - } - } - } - return tux_dev2; -} - -/** - * - */ -static struct usb_dev_handle * -usb_open_TuxDroid(struct usb_device *tux_dev) -{ - usb_dev_handle *tux_hdl; - int error; - - /* Open usb device */ - print_usb_debug("usb_open(tux_dev)"); - tux_hdl = usb_open(tux_dev); - - if (!tux_hdl) - { - return NULL; - } - - /* Setting configuration is normally not necessary as the snd-usb-audio - * will already have that done at this point. But in case we don't have usb - * sound support, it may help to set the configuration. */ - print_usb_debug("usb_set_configuration(tux_hdl, 1)"); - usb_set_configuration(tux_hdl, 1); - - /* Claim device interface */ - print_usb_debug("usb_claim_interface(tux_hdl, TUX_INTERFACE)"); - error = usb_claim_interface(tux_hdl, TUX_INTERFACE); - if (error != 0) - { - print_usb_debug("usb_claim_interface(tux_hdl, TUX_INTERFACE)"); - error = usb_claim_interface(tux_hdl, TUX_INTERFACE); - if (error != 0) - { - usb_reset(tux_hdl); - return NULL; - } - } - - return tux_hdl; -} - -/** - * - */ LIBLOCAL TuxUSBError tux_usb_capture(void) { read_error_counter = 0; - tux_device = usb_find_TuxDroid(); - if (!tux_device) + if (!tux_hid_capture(TUX_VID, TUX_PID)) { - log_error("Fux not found"); return TuxUSBFuxNotFound; } - - /* Old firmware should be discarded here */ -#ifndef USB_DEBUG - print_usb_debug("read tux_device->descriptor.bcdDevice"); - if (tux_device->descriptor.bcdDevice < MIN_FIRMWARE_VERSION) - { - log_error("Your fux firmware is too old"); - return TuxUSBFirmwareTooOld; - } -#endif - - /* Get Device handle */ - tux_handle = usb_open_TuxDroid(tux_device); - if (tux_handle == NULL) - { - log_error("Can't open the USB device"); - return TuxUSBHandleNotOpen; - } set_connected(true); @@ -362,19 +244,7 @@ LIBLOCAL TuxUSBError tux_usb_release(void) { - print_usb_debug("usb_release_interface(tux_handle, TUX_INTERFACE)"); - if (usb_release_interface(tux_handle, TUX_INTERFACE) < 0) - { - log_error("TuxUSBCantReleaseInterface"); - return TuxUSBCantReleaseInterface; - } - - print_usb_debug("usb_close(tux_handle)"); - if (usb_close(tux_handle) < 0) - { - log_error("Can't close the USB device"); - return TuxUSBCantCloseDevice; - } + tux_hid_release(); set_connected(false); @@ -384,50 +254,10 @@ /** * */ -static bool -is_error_no_device(int error) -{ - switch (error) { - case -EIO: - return true; - case -ENODEV: - return true; - case -110: - read_error_counter++; - if (read_error_counter >= TUX_USB_ERROR_LIMIT) - tux_usb_reset(); - return false; - case -116: - read_error_counter++; - if (read_error_counter >= TUX_USB_ERROR_LIMIT) - tux_usb_reset(); - return false; - case 0: - return false; - default: - return false; - } -} - -/** - * - */ -static int -usb_write_TuxDroid(const void *buf, int size) -{ - return usb_interrupt_write( tux_handle, - TUX_WRITE_EP, - (char *)buf, size, - TUX_WRITE_TIMEOUT); -} - -/** - * - */ LIBLOCAL TuxUSBError tux_usb_write(const void *buff) { - int ret; + bool ret; #ifndef USB_DEBUG void *buff2; unsigned char dest; @@ -460,22 +290,17 @@ } #endif - ret = usb_write_TuxDroid(buff, TUX_SEND_LENGTH); + ret = tux_hid_write(TUX_SEND_LENGTH, (char *)buff); #ifdef USE_MUTEX mutex_unlock(__read_write_mutex); #endif - if (ret != TUX_SEND_LENGTH) + if (!ret) { - if (is_error_no_device(ret)) - { - set_connected(false); - tux_usb_release(); - log_error("Fux is disconnected"); - return TuxUSBDisconnected; - } - log_error("Failed to write on USB device (%d)", ret); - return TuxUSBWriteError; + set_connected(false); + tux_usb_release(); + log_error("Fux is disconnected"); + return TuxUSBDisconnected; } return TuxUSBNoError; } @@ -483,33 +308,35 @@ /** * */ -static int -usb_read_TuxDroid(char *buf) -{ - return usb_interrupt_read( tux_handle, - TUX_READ_EP, - (char *)buf, - TUX_RECEIVE_LENGTH, - TUX_READ_TIMEOUT); -} - -/** - * - */ static void process_usb_frame(const char *data) { int i, j; int rf_state; int packet_count; - unsigned char *data_buf; - unsigned char packet_data[4]; + char *data_buf; + char packet_data[4]; rf_state = data[1]; packet_count = data[3]; - data_buf = (unsigned char *)data; + data_buf = (char *)data; data_buf += 4; + /* Having RF state to ON and no status frame is not normal */ + if ((packet_count == 0) && (rf_state == 1)) + { + read_error_counter++; + if (read_error_counter >= TUX_USB_ERROR_LIMIT) + { + /* Reset of the dongle */ + tux_usb_reset(); + } + } + else + { + read_error_counter = 0; + } + if (last_knowed_rf_state != rf_state) { last_knowed_rf_state = rf_state; @@ -529,13 +356,13 @@ { for (j = 0; j < 4; j++) { - packet_data[j] = data_buf[j]; + packet_data[j] = (unsigned char)data_buf[j]; } #ifdef USE_MUTEX mutex_lock(__callback_mutex); #endif if (frame_callback_function) - frame_callback_function(packet_data); + frame_callback_function((unsigned char*)packet_data); #ifdef USE_MUTEX mutex_unlock(__callback_mutex); #endif @@ -550,7 +377,7 @@ LIBLOCAL TuxUSBError tux_usb_read(void *buf) { - int ret; + bool ret; if (!tux_usb_connected()) { @@ -563,43 +390,29 @@ #ifdef USE_MUTEX mutex_lock(__read_write_mutex); #endif - ret = usb_write_TuxDroid(frame_status_request, TUX_SEND_LENGTH); - if (ret != TUX_SEND_LENGTH) + ret = tux_hid_write(TUX_SEND_LENGTH, (char *)frame_status_request); + if (!ret) { #ifdef USE_MUTEX mutex_unlock(__read_write_mutex); #endif - if (is_error_no_device(ret)) - { /* USB device error */ - set_connected(false); - tux_usb_release(); - log_error("Fux is disconnected"); - return TuxUSBDisconnected; - } - log_error("Failed to write on USB device (%d)", ret); - return TuxUSBWriteError; + set_connected(false); + tux_usb_release(); + log_error("Fux is disconnected"); + return TuxUSBDisconnected; } - ret = usb_read_TuxDroid((char *)buf); + ret = tux_hid_read(TUX_RECEIVE_LENGTH, (char *)buf); #ifdef USE_MUTEX mutex_unlock(__read_write_mutex); #endif - if (ret != TUX_RECEIVE_LENGTH) - { /* Frame not have 64 bytes */ - if (is_error_no_device(ret)) - { /* USB device error */ - set_connected(false); - tux_usb_release(); - log_error("Fux is disconnected"); - return TuxUSBDisconnected; - } - log_error("Failed to read on USB device (%d)", ret); - return TuxUSBReadError; - } - else + if (!ret) { - read_error_counter = 0; + set_connected(false); + tux_usb_release(); + log_error("Fux is disconnected"); + return TuxUSBDisconnected; } process_usb_frame((char *)buf); @@ -740,7 +553,7 @@ LIBLOCAL void tux_usb_reset(void) { - usb_write_TuxDroid(frame_reset_dongle, TUX_SEND_LENGTH); + tux_hid_write(TUX_SEND_LENGTH, (char *)frame_reset_dongle); } /** Modified: software_suite_v2/middleware/tuxdriver/trunk/src/tux_usb.h =================================================================== --- software_suite_v2/middleware/tuxdriver/trunk/src/tux_usb.h 2008-05-02 11:42:33 UTC (rev 1075) +++ software_suite_v2/middleware/tuxdriver/trunk/src/tux_usb.h 2008-05-02 12:21:13 UTC (rev 1076) @@ -36,7 +36,7 @@ #define TUX_WRITE_TIMEOUT 1000 #define TUX_READ_TIMEOUT 1000 #define TUX_READ_LOOP_INTERVAL 0.05 -#define TUX_USB_ERROR_LIMIT 4 +#define TUX_USB_ERROR_LIMIT 50 #define MIN_FIRMWARE_VERSION 0x030 #ifdef WIN32 Deleted: software_suite_v2/middleware/tuxdriver/trunk/src/usb.h =================================================================== --- software_suite_v2/middleware/tuxdriver/trunk/src/usb.h 2008-05-02 11:42:33 UTC (rev 1075) +++ software_suite_v2/middleware/tuxdriver/trunk/src/usb.h 2008-05-02 12:21:13 UTC (rev 1076) @@ -1,394 +0,0 @@ -#ifndef __USB_H__ -#define __USB_H__ - -#include <stdlib.h> -#include <windows.h> - -/* ensure byte-packed structures */ -#include <pshpack1.h> - -/* - * 'interface' is defined somewhere in the Windows header files. This macro - * is deleted here to avoid conflicts and compile errors. - */ - -#ifdef interface -#undef interface -#endif - -/* - * PATH_MAX from limits.h can't be used on Windows if the dll and - * import libraries are build/used by different compilers - */ - -#define LIBUSB_PATH_MAX 512 - - -/* - * USB spec information - * - * This is all stuff grabbed from various USB specs and is pretty much - * not subject to change - */ - -/* - * Device and/or Interface Class codes - */ -#define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */ -#define USB_CLASS_AUDIO 1 -#define USB_CLASS_COMM 2 -#define USB_CLASS_HID 3 -#define USB_CLASS_PRINTER 7 -#define USB_CLASS_MASS_STORAGE 8 -#define USB_CLASS_HUB 9 -#define USB_CLASS_DATA 10 -#define USB_CLASS_VENDOR_SPEC 0xff - -/* - * Descriptor types - */ -#define USB_DT_DEVICE 0x01 -#define USB_DT_CONFIG 0x02 -#define USB_DT_STRING 0x03 -#define USB_DT_INTERFACE 0x04 -#define USB_DT_ENDPOINT 0x05 - -#define USB_DT_HID 0x21 -#define USB_DT_REPORT 0x22 -#define USB_DT_PHYSICAL 0x23 -#define USB_DT_HUB 0x29 - -/* - * Descriptor sizes per descriptor type - */ -#define USB_DT_DEVICE_SIZE 18 -#define USB_DT_CONFIG_SIZE 9 -#define USB_DT_INTERFACE_SIZE 9 -#define USB_DT_ENDPOINT_SIZE 7 -#define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */ -#define USB_DT_HUB_NONVAR_SIZE 7 - - - -/* All standard descriptors have these 2 fields in common */ -struct usb_descriptor_header { - unsigned char bLength; - unsigned char bDescriptorType; -}; - -/* String descriptor */ -struct usb_string_descriptor { - unsigned char bLength; - unsigned char bDescriptorType; - unsigned short wData[1]; -}; - -/* HID descriptor */ -struct usb_hid_descriptor { - unsigned char bLength; - unsigned char bDescriptorType; - unsigned short bcdHID; - unsigned char bCountryCode; - unsigned char bNumDescriptors; -}; - -/* Endpoint descriptor */ -#define USB_MAXENDPOINTS 32 -struct usb_endpoint_descriptor { - unsigned char bLength; - unsigned char bDescriptorType; - unsigned char bEndpointAddress; - unsigned char bmAttributes; - unsigned short wMaxPacketSize; - unsigned char bInterval; - unsigned char bRefresh; - unsigned char bSynchAddress; - - unsigned char *extra; /* Extra descriptors */ - int extralen; -}; - -#define USB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */ -#define USB_ENDPOINT_DIR_MASK 0x80 - -#define USB_ENDPOINT_TYPE_MASK 0x03 /* in bmAttributes */ -#define USB_ENDPOINT_TYPE_CONTROL 0 -#define USB_ENDPOINT_TYPE_ISOCHRONOUS 1 -#define USB_ENDPOINT_TYPE_BULK 2 -#define USB_ENDPOINT_TYPE_INTERRUPT 3 - -/* Interface descriptor */ -#define USB_MAXINTERFACES 32 -struct usb_interface_descriptor { - unsigned char bLength; - unsigned char bDescriptorType; - unsigned char bInterfaceNumber; - unsigned char bAlternateSetting; - unsigned char bNumEndpoints; - unsigned char bInterfaceClass; - unsigned char bInterfaceSubClass; - unsigned char bInterfaceProtocol; - unsigned char iInterface; - - struct usb_endpoint_descriptor *endpoint; - - unsigned char *extra; /* Extra descriptors */ - int extralen; -}; - -#define USB_MAXALTSETTING 128 /* Hard limit */ - -struct usb_interface { - struct usb_interface_descriptor *altsetting; - - int num_altsetting; -}; - -/* Configuration descriptor information.. */ -#define USB_MAXCONFIG 8 -struct usb_config_descriptor { - unsigned char bLength; - unsigned char bDescriptorType; - unsigned short wTotalLength; - unsigned char bNumInterfaces; - unsigned char bConfigurationValue; - unsigned char iConfiguration; - unsigned char bmAttributes; - unsigned char MaxPower; - - struct usb_interface *interface; - - unsigned char *extra; /* Extra descriptors */ - int extralen; -}; - -/* Device descriptor */ -struct usb_device_descriptor { - unsigned char bLength; - unsigned char bDescriptorType; - unsigned short bcdUSB; - unsigned char bDeviceClass; - unsigned char bDeviceSubClass; - unsigned char bDeviceProtocol; - unsigned char bMaxPacketSize0; - unsigned short idVendor; - unsigned short idProduct; - unsigned short bcdDevice; - unsigned char iManufacturer; - unsigned char iProduct; - unsigned char iSerialNumber; - unsigned char bNumConfigurations; -}; - -struct usb_ctrl_setup { - unsigned char bRequestType; - unsigned char bRequest; - unsigned short wValue; - unsigned short wIndex; - unsigned short wLength; -}; - -/* - * Standard requests - */ -#define USB_REQ_GET_STATUS 0x00 -#define USB_REQ_CLEAR_FEATURE 0x01 -/* 0x02 is reserved */ -#define USB_REQ_SET_FEATURE 0x03 -/* 0x04 is reserved */ -#define USB_REQ_SET_ADDRESS 0x05 -#define USB_REQ_GET_DESCRIPTOR 0x06 -#define USB_REQ_SET_DESCRIPTOR 0x07 -#define USB_REQ_GET_CONFIGURATION 0x08 -#define USB_REQ_SET_CONFIGURATION 0x09 -#define USB_REQ_GET_INTERFACE 0x0A -#define USB_REQ_SET_INTERFACE 0x0B -#define USB_REQ_SYNCH_FRAME 0x0C - -#define USB_TYPE_STANDARD (0x00 << 5) -#define USB_TYPE_CLASS (0x01 << 5) -#define USB_TYPE_VENDOR (0x02 << 5) -#define USB_TYPE_RESERVED (0x03 << 5) - -#define USB_RECIP_DEVICE 0x00 -#define USB_RECIP_INTERFACE 0x01 -#define USB_RECIP_ENDPOINT 0x02 -#define USB_RECIP_OTHER 0x03 - -/* - * Various libusb API related stuff - */ - -#define USB_ENDPOINT_IN 0x80 -#define USB_ENDPOINT_OUT 0x00 - -/* Error codes */ -#define USB_ERROR_BEGIN 500000 - -/* - * This is supposed to look weird. This file is generated from autoconf - * and I didn't want to make this too complicated. - */ -#define USB_LE16_TO_CPU(x) - -/* Data types */ -/* struct usb_device; */ -/* struct usb_bus; */ - -struct usb_device { - struct usb_device *next, *prev; - - char filename[LIBUSB_PATH_MAX]; - - struct usb_bus *bus; - - struct usb_device_descriptor descriptor; - struct usb_config_descriptor *config; - - void *dev; /* Darwin support */ - - unsigned char devnum; - - unsigned char num_children; - struct usb_device **children; -}; - -struct usb_bus { - struct usb_bus *next, *prev; - - char dirname[LIBUSB_PATH_MAX]; - - struct usb_device *devices; - unsigned long location; - - struct usb_device *root_dev; -}; - -/* Version information, Windows specific */ -struct usb_version { - struct { - int major; - int minor; - int micro; - int nano; - } dll; - struct { - int major; - int minor; - int micro; - int nano; - } driver; -}; - - -struct usb_dev_handle; -typedef struct usb_dev_handle usb_dev_handle; - -/* Variables */ -#ifndef __USB_C__ -#define usb_busses usb_get_busses() -#endif - - - -#include <poppack.h> - - -#ifdef __cplusplus -extern "C" { -#endif - - /* Function prototypes */ - - /* usb.c */ - usb_dev_handle *usb_open(struct usb_device *dev); - int usb_close(usb_dev_handle *dev); - int usb_get_string(usb_dev_handle *dev, int index, int langid, char *buf, - size_t buflen); - int usb_get_string_simple(usb_dev_handle *dev, int index, char *buf, - size_t buflen); - - /* descriptors.c */ - int usb_get_descriptor_by_endpoint(usb_dev_handle *udev, int ep, - unsigned char type, unsigned char index, - void *buf, int size); - int usb_get_descriptor(usb_dev_handle *udev, unsigned char type, - unsigned char index, void *buf, int size); - - /* <arch>.c */ - int usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int size, - int timeout); - int usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int size, - int timeout); - int usb_interrupt_write(usb_dev_handle *dev, int ep, char *bytes, int size, - int timeout); - int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size, - int timeout); - int usb_control_msg(usb_dev_handle *dev, int requesttype, int request, - int value, int index, char *bytes, int size, - int timeout); - int usb_set_configuration(usb_dev_handle *dev, int configuration); - int usb_claim_interface(usb_dev_handle *dev, int interface); - int usb_release_interface(usb_dev_handle *dev, int interface); - int usb_set_altinterface(usb_dev_handle *dev, int alternate); - int usb_resetep(usb_dev_handle *dev, unsigned int ep); - int usb_clear_halt(usb_dev_handle *dev, unsigned int ep); - int usb_reset(usb_dev_handle *dev); - - char *usb_strerror(void); - - void usb_init(void); - void usb_set_debug(int level); - int usb_find_busses(void); - int usb_find_devices(void); - struct usb_device *usb_device(usb_dev_handle *dev); - struct usb_bus *usb_get_busses(void); - - - /* Windows specific functions */ - - #define LIBUSB_HAS_INSTALL_SERVICE_NP 1 - int usb_install_service_np(void); - void CALLBACK usb_install_service_np_rundll(HWND wnd, HINSTANCE instance, - LPSTR cmd_line, int cmd_show); - - #define LIBUSB_HAS_UNINSTALL_SERVICE_NP 1 - int usb_uninstall_service_np(void); - void CALLBACK usb_uninstall_service_np_rundll(HWND wnd, HINSTANCE instance, - LPSTR cmd_line, int cmd_show); - - #define LIBUSB_HAS_INSTALL_DRIVER_NP 1 - int usb_install_driver_np(const char *inf_file); - void CALLBACK usb_install_driver_np_rundll(HWND wnd, HINSTANCE instance, - LPSTR cmd_line, int cmd_show); - - #define LIBUSB_HAS_TOUCH_INF_FILE_NP 1 - int usb_touch_inf_file_np(const char *inf_file); - void CALLBACK usb_touch_inf_file_np_rundll(HWND wnd, HINSTANCE instance, - LPSTR cmd_line, int cmd_show); - - #define LIBUSB_HAS_INSTALL_NEEDS_RESTART_NP 1 - int usb_install_needs_restart_np(void); - - const struct usb_version *usb_get_version(void); - - int usb_isochronous_setup_async(usb_dev_handle *dev, void **context, - unsigned char ep, int pktsize); - int usb_bulk_setup_async(usb_dev_handle *dev, void **context, - unsigned char ep); - int usb_interrupt_setup_async(usb_dev_handle *dev, void **context, - unsigned char ep); - - int usb_submit_async(void *context, char *bytes, int size); - int usb_reap_async(void *context, int timeout); - int usb_reap_async_nocancel(void *context, int timeout); - int usb_cancel_async(void *context); - int usb_free_async(void **context); - - -#ifdef __cplusplus -} -#endif - -#endif /* __USB_H__ */ - Modified: software_suite_v2/middleware/tuxdriver/trunk/unix/Makefile =================================================================== --- software_suite_v2/middleware/tuxdriver/trunk/unix/Makefile 2008-05-02 11:42:33 UTC (rev 1075) +++ software_suite_v2/middleware/tuxdriver/trunk/unix/Makefile 2008-05-02 12:21:13 UTC (rev 1076) @@ -12,7 +12,7 @@ C_PREPROC = CFLAGS = -pipe -std=gnu99 -DUSB_DEBUG0 -DSHOW_EVENTS -DNO_MOTORS_CHECK -DNO_THREAD -Wall -g0 -O2 -fPIC LIB_DIRS = -LIBS = -lusb -lgthread-2.0 -lm +LIBS = -lgthread-2.0 -lm LDFLAGS = -pipe -shared SRC_OBJS = \ @@ -22,6 +22,7 @@ $(OBJ_DIR)/tux_error.o \ $(OBJ_DIR)/tux_eyes.o \ $(OBJ_DIR)/tux_firmware.o \ + $(OBJ_DIR)/tux_hid_unix.o \ $(OBJ_DIR)/tux_hw_status.o \ $(OBJ_DIR)/tux_id.o \ $(OBJ_DIR)/tux_leds.o \ @@ -153,6 +154,11 @@ ../src/tux_hw_status.h \ ../src/tux_sw_status.h $(compile_source) + +$(OBJ_DIR)/tux_hid_unix.o: ../src/tux_hid_unix.c \ +../src/tux_misc.h \ +../src/tux_hid_unix.h + $(compile_source) $(OBJ_DIR)/tux_hw_status.o: ../src/tux_hw_status.c \ ../src/tux_hw_status.h \ @@ -279,7 +285,6 @@ $(compile_source) $(OBJ_DIR)/tux_usb.o: ../src/tux_usb.c \ -../src/usb.h \ ../src/tux_usb.h \ ../src/tux_misc.h \ ../src/tux_error.h \ Modified: software_suite_v2/middleware/tuxdriver/trunk/win32/Makefile =================================================================== --- software_suite_v2/middleware/tuxdriver/trunk/win32/Makefile 2008-05-02 11:42:33 UTC (rev 1075) +++ software_suite_v2/middleware/tuxdriver/trunk/win32/Makefile 2008-05-02 12:21:13 UTC (rev 1076) @@ -8,14 +8,14 @@ OBJ_DIR = ..\obj OUTPUT_DIR = ..\win32 TARGET = tux_driver.dll -C_INCLUDE_DIRS = +C_INCLUDE_DIRS = -I"E:\MinGWStudio\MinGW\include\ddk" C_PREPROC = CFLAGS = -pipe -Wall -g2 -O0 RC_INCLUDE_DIRS = RC_PREPROC = RCFLAGS = LIB_DIRS = -L"../libs" -LIBS = -llibusb -lwinmm +LIBS = -lwinmm -lhid -lsetupapi -lhidparse LDFLAGS = -pipe -shared -Wl,--output-def,"$(OBJ_DIR)\driver_dll.def",--out-implib,"$(OBJ_DIR)\libdriver_dll.dll.a" ifeq ($(OS),Windows_NT) @@ -31,6 +31,7 @@ $(OBJ_DIR)/tux_error.o \ $(OBJ_DIR)/tux_eyes.o \ $(OBJ_DIR)/tux_firmware.o \ + $(OBJ_DIR)/tux_hid_win32.o \ $(OBJ_DIR)/tux_hw_status.o \ $(OBJ_DIR)/tux_id.o \ $(OBJ_DIR)/tux_leds.o \ @@ -163,6 +164,11 @@ ../src/tux_hw_status.h \ ../src/tux_sw_status.h $(compile_source) + +$(OBJ_DIR)/tux_hid_win32.o: ../src/tux_hid_win32.c \ +../src/tux_hid_win32.h \ +../src/tux_misc.h + $(compile_source) $(OBJ_DIR)/tux_hw_status.o: ../src/tux_hw_status.c \ ../src/tux_hw_status.h \ @@ -289,7 +295,6 @@ $(compile_source) $(OBJ_DIR)/tux_usb.o: ../src/tux_usb.c \ -../src/usb.h \ ../src/tux_usb.h \ ../src/tux_misc.h \ ../src/tux_error.h \ |