16 #ifndef _USB_DEFAULTS_H 17 #define _USB_DEFAULTS_H 25 #include <avr/interrupt.h> 26 #include <avr/pgmspace.h> 27 #include <util/delay.h> 29 #define ARCH_HAS_EEPROM_ADDRESS_SPACE 30 #define ARCH_HAS_FLASH_ADDRESS_SPACE 31 #define ARCH_HAS_MULTI_ADDRESS_SPACE 32 #define ARCH_LITTLE_ENDIAN 34 #define USB_DEF_VID 0x03EB // VID for USB 36 #define USB_DEF_PID 0x2404 // PID for USB 38 #define USB_DEF_EP_NUM 3 // Number of Endpoints used (ep0, In, out, notification... ) 39 #define USB_DEF_EP_MAX 16 // Number of max endpoints for this device (to allocate the endpoint-table) 40 #define USB_DEF_EP0_SIZE 64 // size of endpoint0 to handle controll-requests 42 #define ENDPOINT_DIR_IN 0x80 43 #define ENDPOINT_DIR_MASK 0x80 44 #define ENDPOINT_DIR_OUT 0x00 49 #define CPU_TO_LE16(x) x 51 #define VERSION_TENS(x) (int)((x) / 10) 52 #define VERSION_ONES(x) (int)((x) - (10 * VERSION_TENS(x))) 53 #define VERSION_TENTHS(x) (int)(((x) - (int)(x)) * 10) 54 #define VERSION_HUNDREDTHS(x) (int)((((x) - (int)(x)) * 100) - (10 * VERSION_TENTHS(x))) 56 #define CONTROL_REQTYPE_DIRECTION 0x80 57 #define CONTROL_REQTYPE_TYPE 0x60 58 #define CONTROL_REQTYPE_RECIPIENT 0x1F 59 #define REQDIR_HOSTTODEVICE (0 << 7) 60 #define REQDIR_DEVICETOHOST (1 << 7) 61 #define REQTYPE_STANDARD (0 << 5) 62 #define REQTYPE_CLASS (1 << 5) 63 #define REQTYPE_VENDOR (2 << 5) 64 #define REQREC_DEVICE (0 << 0) 65 #define REQREC_INTERFACE (1 << 0) 66 #define REQREC_ENDPOINT (2 << 0) 67 #define REQREC_OTHER (3 << 0) 69 #define NO_DESCRIPTOR 0 70 #define USB_CONFIG_POWER_MA(mA) ((mA) >> 1) 71 #define USB_STRING_LEN(UnicodeChars) (sizeof(USB_Descriptor_Header_t) + ((UnicodeChars) << 1)) 72 #define VERSION_BCD(x) CPU_TO_LE16((((VERSION_TENS(x) << 4) | VERSION_ONES(x)) << 8) | ((VERSION_TENTHS(x) << 4) | VERSION_HUNDREDTHS(x))) 73 #define LANGUAGE_ID_ENG 0x0409 74 #define ENDPOINT_DESCRIPTOR_DIR_IN ENDPOINT_DIR_IN 75 #define ENDPOINT_DESCRIPTOR_DIR_OUT ENDPOINT_DIR_OUT 76 #define USB_CONFIG_ATTR_BUSPOWERED 0x80 77 #define USB_CONFIG_ATTR_SELFPOWERED 0x40 78 #define USB_CONFIG_ATTR_REMOTEWAKEUP 0x20 79 #define ENDPOINT_ATTR_NO_SYNC (0 << 2) 80 #define ENDPOINT_ATTR_ASYNC (1 << 2) 81 #define ENDPOINT_ATTR_ADAPTIVE (2 << 2) 82 #define ENDPOINT_ATTR_SYNC (3 << 2) 83 #define ENDPOINT_USAGE_DATA (0 << 4) 84 #define ENDPOINT_USAGE_FEEDBACK (1 << 4) 85 #define ENDPOINT_USAGE_IMPLICIT_FEEDBACK (2 << 4) 86 #define EP_TYPE_CONTROL 0x00 87 #define EP_TYPE_ISOCHRONOUS 0x01 88 #define EP_TYPE_BULK 0x02 89 #define EP_TYPE_INTERRUPT 0x03 91 #define FEATURE_SELFPOWERED_ENABLED (1 << 0) 92 #define FEATURE_REMOTE_WAKEUP_ENABLED (1 << 1) 94 #define USE_INTERNAL_SERIAL 0xDC 96 #define INTERNAL_SERIAL_LENGTH_BITS (8 * (1 + (offsetof(NVM_PROD_SIGNATURES_t, COORDY1) - offsetof(NVM_PROD_SIGNATURES_t, LOTNUM0)))) 97 #define INTERNAL_SERIAL_START_ADDRESS offsetof(NVM_PROD_SIGNATURES_t, LOTNUM0) 99 typedef uint8_t uint_reg_t;
106 #define LACR16(addr,msk) \ 107 __asm__ __volatile__ ( \ 108 "ldi r16, %1" "\n\t" \ 109 ".dc.w 0x9306" "\n\t"\ 110 ::"z" (addr), "M" (msk):"r16") 112 #define LACR16(addr,msk) __lac((unsigned char)msk,(unsigned char*)addr) 117 #define LASR16(addr,msk) \ 118 __asm__ __volatile__ ( \ 119 "ldi r16, %1" "\n\t" \ 120 ".dc.w 0x9305" "\n\t"\ 121 ::"z" (addr), "M" (msk):"r16") 123 #define LASR16(addr,msk) __las((unsigned char)msk,(unsigned char*)addr) 128 #define XCHR16(addr,msk) \ 129 __asm__ __volatile__ ( \ 130 "ldi r16, %1" "\n\t" \ 131 ".dc.w 0x9304" "\n\t"\ 132 ::"z" (addr), "M" (msk):"r16") 134 #define XCHR16(addr,msk) __xch(msk,addr) 139 #define LATR16(addr,msk) \ 140 __asm__ __volatile__ ( \ 141 "ldi r16, %1" "\n\t" \ 142 ".dc.w 0x9307" "\n\t"\ 143 ::"z" (addr), "M" (msk):"r16") 145 #define LATR16(addr,msk) __lat(msk,addr) 149 #define MACROE while (0) 151 #define MAX(x, y) (((x) > (y)) ? (x) : (y)) 155 #define MIN(x, y) (((x) < (y)) ? (x) : (y)) 158 #if !defined(STRINGIFY) 159 #define STRINGIFY(x) #x 160 #define STRINGIFY_EXPANDED(x) STRINGIFY(x) 163 #if defined(__GNUC__) 164 #define GCC_FORCE_POINTER_ACCESS(StructPtr) __asm__ __volatile__("" : "=b" (StructPtr) : "0" (StructPtr)) 165 #define GCC_MEMORY_BARRIER() __asm__ __volatile__("" ::: "memory"); 166 #define GCC_IS_COMPILE_CONST(x) __builtin_constant_p(x) 169 #define GCC_ASSERT(e) ((void)sizeof(char[1 - 2*!(__builtin_constant_p(e) && (e))])) 174 #define GCC_FORCE_ALIGN_2 __attribute__((section (".data,\"aw\",@progbits\n.p2align 1;"))) 176 #define likely(x) __builtin_expect((x),1) 177 #define unlikely(x) __builtin_expect((x),0) 179 #define GCC_FORCE_POINTER_ACCESS(StructPtr) 180 #define GCC_MEMORY_BARRIER() 181 #define GCC_IS_COMPILE_CONST(x) 0 182 #define GCC_FORCE_ALIGN_2 184 #define unlikely(x) x 187 #define ATTR_NO_RETURN __attribute__ ((noreturn)) 188 #define ATTR_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) 189 #define ATTR_NON_NULL_PTR_ARG(...) __attribute__ ((nonnull (__VA_ARGS__))) 190 #define ATTR_NAKED __attribute__ ((naked)) 191 #define ATTR_NO_INLINE __attribute__ ((noinline)) 192 #define ATTR_ALWAYS_INLINE __attribute__ ((always_inline)) 193 #define ATTR_PURE __attribute__ ((pure)) 194 #define ATTR_CONST __attribute__ ((const)) 195 #define ATTR_DEPRECATED __attribute__ ((deprecated)) 196 #define ATTR_WEAK __attribute__ ((weak)) 197 #define ATTR_NO_INIT __attribute__ ((section (".noinit"))) 198 #define ATTR_INIT_SECTION(SectionIndex) __attribute__ ((naked, section (".init" #SectionIndex ))) 199 #define ATTR_ALIAS(Func) __attribute__ ((alias( #Func ))) 200 #define ATTR_PACKED __attribute__ ((packed)) 295 uint8_t bDescriptorType;
302 USB_Descriptor_Header_t Header;
345 uint8_t bDescriptorType;
385 USB_Descriptor_Header_t Header;
387 uint16_t USBSpecification;
392 uint8_t Endpoint0Size;
393 uint8_t NumberOfConfigurations;
402 uint8_t bDescriptorType;
406 uint8_t bDeviceClass;
407 uint8_t bDeviceSubClass;
408 uint8_t bDeviceProtocol;
409 uint8_t bMaxPacketSize0;
410 uint8_t bNumConfigurations;
418 USB_Descriptor_Header_t Header;
436 }
ATTR_PACKED USB_Descriptor_Configuration_Header_t;
441 uint8_t bDescriptorType;
457 }
ATTR_PACKED USB_StdDescriptor_Configuration_Header_t;
461 USB_Descriptor_Header_t Header;
481 uint8_t bDescriptorType;
501 USB_Descriptor_Header_t Header;
504 uint8_t TotalInterfaces;
513 }
ATTR_PACKED USB_Descriptor_Interface_Association_t;
518 uint8_t bDescriptorType;
529 }
ATTR_PACKED USB_StdDescriptor_Interface_Association_t;
533 USB_Descriptor_Header_t Header;
552 uint8_t bDescriptorType;
558 uint8_t bmAttributes;
571 USB_Descriptor_Header_t Header;
573 wchar_t UnicodeString[];
579 uint8_t bDescriptorType;
uint8_t MaxPowerConsumption
void EVENT_USB_Device_StartOfFrame(void)
void EVENT_USB_Device_ConfigurationChanged(uint8_t config)
USB_Descriptor_ClassSubclassProtocol_t
void EVENT_USB_Device_WakeUp(void)
bool EVENT_USB_Device_ControlRequest(struct USB_Request_Header *req)
uint8_t bInterfaceProtocol
void EVENT_USB_Device_Suspend(void)
uint8_t SerialNumStrIndex
uint8_t bInterfaceSubClass
uint8_t ConfigurationStrIndex
uint8_t NumberOfConfigurations
uint8_t FirstInterfaceIndex
uint8_t InterfaceStrIndex
uint8_t ManufacturerStrIndex
uint8_t bFunctionProtocol
uint8_t PollingIntervalMS
uint16_t TotalConfigurationSize
uint8_t ConfigurationNumber
uint8_t bConfigurationValue
void EVENT_USB_Device_Reset(void)
bool EVENT_USB_Device_SetInterface(uint8_t interface, uint8_t altsetting)
uint8_t bFunctionSubClass
uint8_t bAlternateSetting
void EVENT_USB_Device_ControlOUT(uint8_t *data, uint8_t len)
uint8_t bNumConfigurations
uint16_t USBSpecification