Windows is now working with libusb1.0 for the teensy-loader-cli.
- Not tested yet, but should be working.
This commit is contained in:
		
							parent
							
								
									cc3f062875
								
							
						
					
					
						commit
						c4c1d0a2b8
					
				
					 4 changed files with 10 additions and 171 deletions
				
			
		|  | @ -157,7 +157,7 @@ add_custom_target( SizeAfter ALL | |||
| 
 | ||||
| #| Provides the user with the correct teensy-loader-cli command for the built .HEX file | ||||
| #| Windows | ||||
| if( ${CMAKE_SYSTEM_NAME} MATCHES "Windows" ) | ||||
| if( CMAKE_SYSTEM_NAME MATCHES "Windows" ) | ||||
| 	configure_file( LoadFile/winload load NEWLINE_STYLE UNIX ) | ||||
| #| Default | ||||
| else() | ||||
|  |  | |||
|  | @ -45,8 +45,8 @@ set( SRCS | |||
| # | ||||
| list( APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR} ) # Use local find scripts | ||||
| 
 | ||||
| #| Linux - libusb | ||||
| if( CMAKE_SYSTEM_NAME MATCHES "Linux" ) | ||||
| #| Linux/Windows - libusb | ||||
| if( CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "CYGWIN" ) | ||||
| 	# Find libusb (not 1.0) | ||||
| 	find_package( LibUSB-1.0 REQUIRED ) | ||||
| 
 | ||||
|  | @ -59,16 +59,6 @@ if( CMAKE_SYSTEM_NAME MATCHES "Linux" ) | |||
| 	# Libraries | ||||
| 	set( LIBS ${LIBUSB_LIBRARIES} ) | ||||
| 
 | ||||
| #| Windows | ||||
| elseif( CMAKE_SYSTEM_NAME MATCHES "CYGWIN" ) | ||||
| 	message( AUTHOR_WARNING "Not Tested...") | ||||
| 
 | ||||
| 	# Defines | ||||
| 	set( DEFINES -s -DUSE_WIN32 ) | ||||
| 
 | ||||
| 	# Libraries | ||||
| 	set( LIBS hid setupapi ) | ||||
| 
 | ||||
| #| Mac OS X | ||||
| elseif( CMAKE_SYSTEM_NAME MATCHES "Darwin" ) | ||||
| 	message( AUTHOR_WARNING "Not Tested...") | ||||
|  |  | |||
|  | @ -192,7 +192,7 @@ int main(int argc, char **argv) | |||
| 
 | ||||
| /****************************************************************/ | ||||
| /*                                                              */ | ||||
| /*             USB Access - libusb (Linux & FreeBSD)            */ | ||||
| /*             USB Access - libusb (Linux, Windows & FreeBSD)   */ | ||||
| /*                                                              */ | ||||
| /****************************************************************/ | ||||
| 
 | ||||
|  | @ -335,156 +335,6 @@ int hard_reboot() | |||
| #endif | ||||
| 
 | ||||
| 
 | ||||
| /****************************************************************/ | ||||
| /*                                                              */ | ||||
| /*               USB Access - Microsoft WIN32                   */ | ||||
| /*                                                              */ | ||||
| /****************************************************************/ | ||||
| 
 | ||||
| #if defined(USE_WIN32) | ||||
| 
 | ||||
| // http://msdn.microsoft.com/en-us/library/ms790932.aspx
 | ||||
| #include <windows.h> | ||||
| #include <setupapi.h> | ||||
| #include <ddk/hidsdi.h> | ||||
| #include <ddk/hidclass.h> | ||||
| 
 | ||||
| HANDLE open_usb_device(int vid, int pid) | ||||
| { | ||||
| 	GUID guid; | ||||
| 	HDEVINFO info; | ||||
| 	DWORD index, required_size; | ||||
| 	SP_DEVICE_INTERFACE_DATA iface; | ||||
| 	SP_DEVICE_INTERFACE_DETAIL_DATA *details; | ||||
| 	HIDD_ATTRIBUTES attrib; | ||||
| 	HANDLE h; | ||||
| 	BOOL ret; | ||||
| 
 | ||||
| 	HidD_GetHidGuid(&guid); | ||||
| 	info = SetupDiGetClassDevs(&guid, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); | ||||
| 	if (info == INVALID_HANDLE_VALUE) return NULL; | ||||
| 	for (index=0; 1 ;index++) { | ||||
| 		iface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); | ||||
| 		ret = SetupDiEnumDeviceInterfaces(info, NULL, &guid, index, &iface); | ||||
| 		if (!ret) { | ||||
| 			SetupDiDestroyDeviceInfoList(info); | ||||
| 			break; | ||||
| 		} | ||||
| 		SetupDiGetInterfaceDeviceDetail(info, &iface, NULL, 0, &required_size, NULL); | ||||
| 		details = (SP_DEVICE_INTERFACE_DETAIL_DATA *)malloc(required_size); | ||||
| 		if (details == NULL) continue; | ||||
| 		memset(details, 0, required_size); | ||||
| 		details->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); | ||||
| 		ret = SetupDiGetDeviceInterfaceDetail(info, &iface, details, | ||||
| 			required_size, NULL, NULL); | ||||
| 		if (!ret) { | ||||
| 			free(details); | ||||
| 			continue; | ||||
| 		} | ||||
| 		h = CreateFile(details->DevicePath, GENERIC_READ|GENERIC_WRITE, | ||||
| 			FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, | ||||
| 			FILE_FLAG_OVERLAPPED, NULL); | ||||
| 		free(details); | ||||
| 		if (h == INVALID_HANDLE_VALUE) continue; | ||||
| 		attrib.Size = sizeof(HIDD_ATTRIBUTES); | ||||
| 		ret = HidD_GetAttributes(h, &attrib); | ||||
| 		if (!ret) { | ||||
| 			CloseHandle(h); | ||||
| 			continue; | ||||
| 		} | ||||
| 		if (attrib.VendorID != vid || attrib.ProductID != pid) { | ||||
| 			CloseHandle(h); | ||||
| 			continue; | ||||
| 		} | ||||
| 		SetupDiDestroyDeviceInfoList(info); | ||||
| 		return h; | ||||
| 	} | ||||
| 	return NULL; | ||||
| } | ||||
| 
 | ||||
| int write_usb_device(HANDLE h, void *buf, int len, int timeout) | ||||
| { | ||||
| 	static HANDLE event = NULL; | ||||
| 	unsigned char tmpbuf[1040]; | ||||
| 	OVERLAPPED ov; | ||||
| 	DWORD n, r; | ||||
| 
 | ||||
| 	if (len > sizeof(tmpbuf) - 1) return 0; | ||||
| 	if (event == NULL) { | ||||
| 		event = CreateEvent(NULL, TRUE, TRUE, NULL); | ||||
| 		if (!event) return 0; | ||||
| 	} | ||||
| 	ResetEvent(&event); | ||||
| 	memset(&ov, 0, sizeof(ov)); | ||||
| 	ov.hEvent = event; | ||||
| 	tmpbuf[0] = 0; | ||||
| 	memcpy(tmpbuf + 1, buf, len); | ||||
| 	if (!WriteFile(h, tmpbuf, len + 1, NULL, &ov)) { | ||||
| 		if (GetLastError() != ERROR_IO_PENDING) return 0; | ||||
| 		r = WaitForSingleObject(event, timeout); | ||||
| 		if (r == WAIT_TIMEOUT) { | ||||
| 			CancelIo(h); | ||||
| 			return 0; | ||||
| 		} | ||||
| 		if (r != WAIT_OBJECT_0) return 0; | ||||
| 	} | ||||
| 	if (!GetOverlappedResult(h, &ov, &n, FALSE)) return 0; | ||||
| 	if (n <= 0) return 0; | ||||
| 	return 1; | ||||
| } | ||||
| 
 | ||||
| void print_win32_err(void) | ||||
| { | ||||
|         char buf[256]; | ||||
|         DWORD err; | ||||
| 
 | ||||
|         err = GetLastError(); | ||||
|         FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, | ||||
|                 0, buf, sizeof(buf), NULL); | ||||
|         printf("err %ld: %s\n", err, buf); | ||||
| } | ||||
| 
 | ||||
| static HANDLE win32_teensy_handle = NULL; | ||||
| 
 | ||||
| int teensy_open(void) | ||||
| { | ||||
| 	teensy_close(); | ||||
| 	win32_teensy_handle = open_usb_device(0x16C0, 0x0478); | ||||
| 	if (win32_teensy_handle) return 1; | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
| int teensy_write(void *buf, int len, double timeout) | ||||
| { | ||||
| 	int r; | ||||
| 	if (!win32_teensy_handle) return 0; | ||||
| 	r = write_usb_device(win32_teensy_handle, buf, len, (int)(timeout * 1000.0)); | ||||
| 	//if (!r) print_win32_err();
 | ||||
| 	return r; | ||||
| } | ||||
| 
 | ||||
| void teensy_close(void) | ||||
| { | ||||
| 	if (!win32_teensy_handle) return; | ||||
| 	CloseHandle(win32_teensy_handle); | ||||
| 	win32_teensy_handle = NULL; | ||||
| } | ||||
| 
 | ||||
| int hard_reboot(void) | ||||
| { | ||||
| 	HANDLE rebootor; | ||||
| 	int r; | ||||
| 
 | ||||
| 	rebootor = open_usb_device(0x16C0, 0x0477); | ||||
| 	if (!rebootor) return 0; | ||||
| 	r = write_usb_device(rebootor, "reboot", 6, 100); | ||||
| 	CloseHandle(rebootor); | ||||
| 	return r; | ||||
| } | ||||
| 
 | ||||
| #endif | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /****************************************************************/ | ||||
| /*                                                              */ | ||||
|  |  | |||
							
								
								
									
										13
									
								
								README
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								README
									
										
									
									
									
								
							|  | @ -15,13 +15,12 @@ Below listed are the Arch Linux pacman names, AUR packages may be required. | |||
| 
 | ||||
| These depend a bit on which targets you are trying to build, but the general one: | ||||
| - cmake (2.8 and higher) | ||||
| - Teensy Loader (http://pjrc.com/teensy/loader.html) | ||||
| 
 | ||||
| 
 | ||||
| AVR Specific (Teensy 1.0/++,2.0/++) (try to use something recent, suggested versions below) | ||||
| - avr-gcc      (4.8.0) | ||||
| - avr-binutils (2.23.2) | ||||
| - avr-libc     (1.8.0) | ||||
| - avr-gcc      (~4.8.0) | ||||
| - avr-binutils (~2.23.2) | ||||
| - avr-libc     (~1.8.0) | ||||
| 
 | ||||
| 
 | ||||
| ARM Specific (Teensy 3.0/3.1) (Sourcery CodeBench Lite for ARM EABI | ||||
|  | @ -45,9 +44,8 @@ First make sure Cygwin is installed - http://www.cygwin.com/ - 32bit or 64bit is | |||
| - git (needed for some compilation info) | ||||
| - cmake | ||||
| - gcc-core | ||||
| 
 | ||||
| And make sure CMake is *NOT* installed through Cygwin. This is extremely important. | ||||
| If this is not possible, you'll have to play with your paths in Cygwin to prioritize the Windows version of CMake. | ||||
| - libusb1.0 | ||||
| - libusb1.0-devel | ||||
| 
 | ||||
| Also install the Windows version of CMake - http://cmake.org/cmake/resources/software.html | ||||
| This is in addition to the Cygwin version. This is an easier alternative to installing another C compiler. | ||||
|  | @ -56,6 +54,7 @@ Add the following line to your .bashrc, making sure the CMake path is correct: | |||
| 
 | ||||
| Next, install the compiler(s) you want. | ||||
| 
 | ||||
| 
 | ||||
|  --------- | ||||
| | AVR GCC | | ||||
|  --------- | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jacob Alexander
						Jacob Alexander