Trammell Hudson avatar Trammell Hudson committed 13bb4bb Draft

Convert device_descriptor to struct

Comments (0)

Files changed (3)

 
 # Define programs and commands.
 SHELL = sh
-AVR_PATH = /Applications/Arduino.app/Contents//Resources/Java/hardware/tools/avr/bin/
-CC = $(AVR_PATH)avr-gcc
-OBJCOPY = $(AVR_PATH)avr-objcopy
-OBJDUMP = $(AVR_PATH)avr-objdump
-SIZE = $(AVR_PATH)avr-size
-AR = $(AVR_PATH)avr-ar rcs
-NM = $(AVR_PATH)avr-nm
-AVRDUDE = $(AVR_PATH)avrdude
+AVR_PATH = /Applications/Arduino.app/Contents//Resources/Java/hardware/tools/avr
+CC = $(AVR_PATH)/bin/avr-gcc
+OBJCOPY = $(AVR_PATH)/bin/avr-objcopy
+OBJDUMP = $(AVR_PATH)/bin/avr-objdump
+SIZE = $(AVR_PATH)/bin/avr-size
+AR = $(AVR_PATH)/bin/avr-ar rcs
+NM = $(AVR_PATH)/bin/avr-nm
+AVRDUDE = $(AVR_PATH)/bin/avrdude
 REMOVE = rm -f
 REMOVEDIR = rm -rf
 COPY = cp
 # Compiler flags to generate dependency files.
 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
 
+## Include the files from avr/include/
+#CFLAGS += -I$(AVR_PATH)/include
 
 # Combine all necessary flags and optional flags.
 # Add target processor to flags.
 #ifndef __USB_H__
 #define __USB_H__
 
-#include <unistd.h>
-#include <stdlib.h>
-#include <limits.h>
-
-#include <dirent.h>
+#include <avr/io.h>
+#include <stdint.h>
 
 /*
  * USB spec information
 
 /* All standard descriptors have these 2 fields in common */
 struct usb_descriptor_header {
-	u_int8_t  bLength;
-	u_int8_t  bDescriptorType;
+	uint8_t  bLength;
+	uint8_t  bDescriptorType;
 };
 
 /* String descriptor */
 struct usb_string_descriptor {
-	u_int8_t  bLength;
-	u_int8_t  bDescriptorType;
-	u_int16_t wData[1];
+	uint8_t  bLength;
+	uint8_t  bDescriptorType;
+	uint16_t wData[1];
 };
 
 /* HID descriptor */
 struct usb_hid_descriptor {
-	u_int8_t  bLength;
-	u_int8_t  bDescriptorType;
-	u_int16_t bcdHID;
-	u_int8_t  bCountryCode;
-	u_int8_t  bNumDescriptors;
-	/* u_int8_t  bReportDescriptorType; */
-	/* u_int16_t wDescriptorLength; */
+	uint8_t  bLength;
+	uint8_t  bDescriptorType;
+	uint16_t bcdHID;
+	uint8_t  bCountryCode;
+	uint8_t  bNumDescriptors;
+	/* uint8_t  bReportDescriptorType; */
+	/* uint16_t wDescriptorLength; */
 	/* ... */
 };
 
 /* Endpoint descriptor */
 #define USB_MAXENDPOINTS	32
 struct usb_endpoint_descriptor {
-	u_int8_t  bLength;
-	u_int8_t  bDescriptorType;
-	u_int8_t  bEndpointAddress;
-	u_int8_t  bmAttributes;
-	u_int16_t wMaxPacketSize;
-	u_int8_t  bInterval;
-	u_int8_t  bRefresh;
-	u_int8_t  bSynchAddress;
+	uint8_t  bLength;
+	uint8_t  bDescriptorType;
+	uint8_t  bEndpointAddress;
+	uint8_t  bmAttributes;
+	uint16_t wMaxPacketSize;
+	uint8_t  bInterval;
+	uint8_t  bRefresh;
+	uint8_t  bSynchAddress;
 
 	unsigned char *extra;	/* Extra descriptors */
 	int extralen;
 /* Interface descriptor */
 #define USB_MAXINTERFACES	32
 struct usb_interface_descriptor {
-	u_int8_t  bLength;
-	u_int8_t  bDescriptorType;
-	u_int8_t  bInterfaceNumber;
-	u_int8_t  bAlternateSetting;
-	u_int8_t  bNumEndpoints;
-	u_int8_t  bInterfaceClass;
-	u_int8_t  bInterfaceSubClass;
-	u_int8_t  bInterfaceProtocol;
-	u_int8_t  iInterface;
+	uint8_t  bLength;
+	uint8_t  bDescriptorType;
+	uint8_t  bInterfaceNumber;
+	uint8_t  bAlternateSetting;
+	uint8_t  bNumEndpoints;
+	uint8_t  bInterfaceClass;
+	uint8_t  bInterfaceSubClass;
+	uint8_t  bInterfaceProtocol;
+	uint8_t  iInterface;
 
 	struct usb_endpoint_descriptor *endpoint;
 
 /* Configuration descriptor information.. */
 #define USB_MAXCONFIG		8
 struct usb_config_descriptor {
-	u_int8_t  bLength;
-	u_int8_t  bDescriptorType;
-	u_int16_t wTotalLength;
-	u_int8_t  bNumInterfaces;
-	u_int8_t  bConfigurationValue;
-	u_int8_t  iConfiguration;
-	u_int8_t  bmAttributes;
-	u_int8_t  MaxPower;
+	uint8_t  bLength;
+	uint8_t  bDescriptorType;
+	uint16_t wTotalLength;
+	uint8_t  bNumInterfaces;
+	uint8_t  bConfigurationValue;
+	uint8_t  iConfiguration;
+	uint8_t  bmAttributes;
+	uint8_t  MaxPower;
 
 	struct usb_interface *interface;
 
 
 /* Device descriptor */
 struct usb_device_descriptor {
-	u_int8_t  bLength;
-	u_int8_t  bDescriptorType;
-	u_int16_t bcdUSB;
-	u_int8_t  bDeviceClass;
-	u_int8_t  bDeviceSubClass;
-	u_int8_t  bDeviceProtocol;
-	u_int8_t  bMaxPacketSize0;
-	u_int16_t idVendor;
-	u_int16_t idProduct;
-	u_int16_t bcdDevice;
-	u_int8_t  iManufacturer;
-	u_int8_t  iProduct;
-	u_int8_t  iSerialNumber;
-	u_int8_t  bNumConfigurations;
+	uint8_t  bLength;
+	uint8_t  bDescriptorType;
+	uint16_t bcdUSB;
+	uint8_t  bDeviceClass;
+	uint8_t  bDeviceSubClass;
+	uint8_t  bDeviceProtocol;
+	uint8_t  bMaxPacketSize0;
+	uint16_t idVendor;
+	uint16_t idProduct;
+	uint16_t bcdDevice;
+	uint8_t  iManufacturer;
+	uint8_t  iProduct;
+	uint8_t  iSerialNumber;
+	uint8_t  bNumConfigurations;
 };
 
 struct usb_ctrl_setup {
-	u_int8_t  bRequestType;
-	u_int8_t  bRequest;
-	u_int16_t wValue;
-	u_int16_t wIndex;
-	u_int16_t wLength;
+	uint8_t  bRequestType;
+	uint8_t  bRequest;
+	uint16_t wValue;
+	uint16_t wIndex;
+	uint16_t wLength;
 };
 
 /*
 struct usb_device;
 struct usb_bus;
 
-/*
- * To maintain compatibility with applications already built with libusb,
- * we must only add entries to the end of this structure. NEVER delete or
- * move members and only change types if you really know what you're doing.
- */
-struct usb_device {
-  struct usb_device *next, *prev;
-
-  char filename[PATH_MAX + 1];
-
-  struct usb_bus *bus;
-
-  struct usb_device_descriptor descriptor;
-  struct usb_config_descriptor *config;
-
-  void *dev;		/* Darwin support */
-
-  u_int8_t devnum;
-
-  unsigned char num_children;
-  struct usb_device **children;
-};
-
-struct usb_bus {
-  struct usb_bus *next, *prev;
-
-  char dirname[PATH_MAX + 1];
-
-  struct usb_device *devices;
-  u_int32_t location;
-
-  struct usb_device *root_dev;
-};
 
 struct usb_dev_handle;
 typedef struct usb_dev_handle usb_dev_handle;
 #define USB_SERIAL_PRIVATE_INCLUDE
 #include "usb_serial.h"
 
+#include <usb.h>
+
 
 /**************************************************************************
  *
 // in here should only be done by those who've read chapter 9 of the USB
 // spec and relevant portions of any USB class specifications!
 
-static uint8_t PROGMEM device_descriptor[] = {
-	18,					// bLength
-	1,					// bDescriptorType
-	0x00, 0x02,				// bcdUSB
-	2,					// bDeviceClass
-	0,					// bDeviceSubClass
-	0,					// bDeviceProtocol
-	ENDPOINT0_SIZE,				// bMaxPacketSize0
-	LSB(VENDOR_ID), MSB(VENDOR_ID),		// idVendor
-	LSB(PRODUCT_ID), MSB(PRODUCT_ID),	// idProduct
-	0x00, 0x01,				// bcdDevice
-	1,					// iManufacturer
-	2,					// iProduct
-	3,					// iSerialNumber
-	1					// bNumConfigurations
+static struct usb_device_descriptor PROGMEM device_descriptor = {
+	.bLength		= sizeof(device_descriptor),
+	.bDescriptorType	= 1,
+	.bcdUSB			= 0x0200,
+	.bDeviceClass		= USB_CLASS_COMM,
+	.bDeviceSubClass	= 0,
+	.bDeviceProtocol	= 0,
+	.bMaxPacketSize0	= ENDPOINT0_SIZE,
+	.idVendor		= VENDOR_ID,
+	.idProduct		= PRODUCT_ID,
+	.bcdDevice		= 0x0100,
+	.iManufacturer		= 1,
+	.iProduct		= 2,
+	.iSerialNumber		= 3,
+	.bNumConfigurations	= 1,
 };
 
+
 #define CONFIG1_DESC_SIZE (9+9+5+5+4+5+7+9+7+7)
 static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
 	// configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
 	const uint8_t	*addr;
 	uint8_t		length;
 } PROGMEM descriptor_list[] = {
-	{0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
+	{0x0100, 0x0000, (const void *) &device_descriptor, sizeof(device_descriptor)},
 	{0x0200, 0x0000, config1_descriptor, sizeof(config1_descriptor)},
 	{0x0300, 0x0000, (const uint8_t *)&string0, 4},
 	{0x0301, 0x0409, (const uint8_t *)&string1, sizeof(STR_MANUFACTURER)},
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.