/* * ltcusb_init.c * * Created on: 23-Aug-2023 * Author: Satyam */ #include "ltcusb.h" #include "descriptor.h" #include "usb_reset_seq.h" #include "device_soft_rst.h" #include "initialization_on_USB_reset.h" #include "Initialization_on_Connect_Done.h" #include "event_fifo.h" int ltcusb_init() { //Device Descriptor device_descriptor_data.bLength = 0x12; device_descriptor_data.bDescriptorType = 0x01; device_descriptor_data.bcdUSB = 0x0200; device_descriptor_data.bDeviceClass = 0xFF; device_descriptor_data.bDeviceSubClass = 0xFF; device_descriptor_data.bDeviceProtocol = 0xFF; device_descriptor_data.bMaxPacketSize0 = 0x40; device_descriptor_data.idVendor = 0x2AC1; device_descriptor_data.idProduct = 0x20C8; device_descriptor_data.bcdDevice = 0x0600; device_descriptor_data.iManufacturer = 0x01; device_descriptor_data.iProduct = 0x02; device_descriptor_data.iSerialNumber = 0x03; device_descriptor_data.bNumConfigurations = 0x01; //Configuration Descriptor config_descriptor_data.bLength = 0x09; config_descriptor_data.bDescriptorType = 0x02; config_descriptor_data.wTotalLength = 0x002e; config_descriptor_data.bNumInterfaces = 0x01; config_descriptor_data.bConfigurationValue = 0x01; config_descriptor_data.iConfiguration = 0x00; config_descriptor_data.bmAttributes = 0xc0; config_descriptor_data.bMaxPower = 0xfa; //Interface Descriptor interface_descriptor_data.bLength = 0x09; interface_descriptor_data.bDescriptorType = 0x04; interface_descriptor_data.bInterfaceNumber = 0x00; interface_descriptor_data.bAlternateSetting = 0x00; interface_descriptor_data.bNumEndpoints = 0x04; interface_descriptor_data.bInterfaceClass = 0xff; interface_descriptor_data.bInterfaceSubClass = 0xff; interface_descriptor_data.bInterfaceProtocol = 0xff; interface_descriptor_data.iInterface = 0x00; //Endpoint Descriptor endpoint_descriptor_bin_1_data.bLength = 0x07; endpoint_descriptor_bin_1_data.bDescriptorType = 0x05; endpoint_descriptor_bin_1_data.bEndpointAddress = 0x81; endpoint_descriptor_bin_1_data.bmAttributes = 0x02; if(USB_SPEED == high_speed_usb) { endpoint_descriptor_bin_1_data.wMaxPacketSize = 0x0200; } else { endpoint_descriptor_bin_1_data.wMaxPacketSize = 0x0040; } endpoint_descriptor_bin_1_data.bInterval = 0x00; endpoint_descriptor_bout_1_data.bLength = 0x07; endpoint_descriptor_bout_1_data.bDescriptorType = 0x05; endpoint_descriptor_bout_1_data.bEndpointAddress = 0x01; endpoint_descriptor_bout_1_data.bmAttributes = 0x02; if(USB_SPEED == high_speed_usb) { endpoint_descriptor_bout_1_data.wMaxPacketSize = 0x0200; } else { endpoint_descriptor_bout_1_data.wMaxPacketSize = 0x0040; } endpoint_descriptor_bout_1_data.bInterval = 0x00; endpoint_descriptor_iin_5_data.bLength = 0x07; endpoint_descriptor_iin_5_data.bDescriptorType = 0x05; endpoint_descriptor_iin_5_data.bEndpointAddress = 0x85; endpoint_descriptor_iin_5_data.bmAttributes = 0x03; if(USB_SPEED == high_speed_usb) { endpoint_descriptor_iin_5_data.wMaxPacketSize = 0x0400; } else { endpoint_descriptor_iin_5_data.wMaxPacketSize = 0x0040; } endpoint_descriptor_iin_5_data.bInterval = 0x00; endpoint_descriptor_iout_5_data.bLength = 0x07; endpoint_descriptor_iout_5_data.bDescriptorType = 0x05; endpoint_descriptor_iout_5_data.bEndpointAddress = 0x05; endpoint_descriptor_iout_5_data.bmAttributes = 0x03; if(USB_SPEED == high_speed_usb) { endpoint_descriptor_iout_5_data.wMaxPacketSize = 0x0400; } else { endpoint_descriptor_iout_5_data.wMaxPacketSize = 0x0040; } endpoint_descriptor_iout_5_data.bInterval = 0x00; //device_qualifier_descriptor device_qualifier_descriptor_data.bLength = 0x0A; device_qualifier_descriptor_data.bDescriptorType= 0x06; device_qualifier_descriptor_data.bcdUSB = 0x0200; device_qualifier_descriptor_data.bDeviceClass = 0x00; device_qualifier_descriptor_data.bDeviceSubClass = 0x00; device_qualifier_descriptor_data.bDeviceProtocol = 0x00; device_qualifier_descriptor_data.bMaxPacketSize0 = 0x08; device_qualifier_descriptor_data.bNumConfigurations = 0x01; device_qualifier_descriptor_data.bReserved = 0x00; //string_language_descriptor string_language_descriptor_data.bLength = 0x04; string_language_descriptor_data.bDescriptorType = 0x03; string_language_descriptor_data.wLANGID_0 = 0x0409; int result = 0; //USB Reset Sequence result = usb_reset_seq(); if(result) { return result; } //Power on and Soft Reset Sequence result = device_power_on_soft_rst(); if(result) { return result; } // //USB Reset Event Sequence // result = event_while(device_event_USBRst,0,0); // // if(result) // { // return result; // } // // result = Initialization_on_USB_Reset(); // // if(result) // { // return result; // } // // //USB Connect Done Event Sequence // result = event_while(device_event_ConnectDone,0,0); // // if(result) // { // return result; // } // // result = Initialization_onConnect_Done(); // // if(result) // { // return result; // } return 0; }