Skip to content

Instantly share code, notes, and snippets.

@roberthartung
Last active November 7, 2015 15:33
Show Gist options
  • Save roberthartung/bc89b8199795d563ae42 to your computer and use it in GitHub Desktop.
Save roberthartung/bc89b8199795d563ae42 to your computer and use it in GitHub Desktop.
#define NUM_INTERFACES (2)
#define NUM_ENDPOINTS (3)
GUD_InterfaceInitTypeDef interfaces[NUM_INTERFACES];
GUD_EndpointInitTypeDef endpoints[NUM_ENDPOINTS];
static GUD_GenericUsbDriverTypeDef hgud;
static GUD_CallbacksTypeDef callbacks = { GetStringDescriptor };
static char serial[25];
uint8_t* GetStringDescriptor(uint8_t index);
GUD_GenericUsbDriverTypeDef* potatoscope_usb_init() {
sprintf(serial, "%08X%08X%08X", STM32_UUID[0], STM32_UUID[1], STM32_UUID[2]);
serial[24] = '\0';
hgud.init.vendor_id = 0x0483;
hgud.init.product_id = 0x5740;
hgud.init.device_revision = 0x0100; // 1.0
hgud.init.num_configurations = 1; // Total number of configurations
hgud.init.num_interfaces = 0; // Total number of interfaces
hgud.init.num_endpoints = 0; // Total number of endpoints
hgud.init.functional_configuration_length = 0;
hgud.init.speed = USB_SPEED_HIGH;
#ifdef USE_USB_CDC
gud_setup_cdc(&hgud, interfaces, endpoints);
#endif
hgud.callbacks = &callbacks; // Callbacks
GUD_Init(&hpcd_USB_OTG_HS, &hgud);
// Init configuration #1
GUD_ConfigurationInitTypeDef conf;
conf.max_power = 50; // = 100mA/2
conf.self_powered = 0;
conf.remote_wakeup = 0;
conf.num_interfaces = NUM_INTERFACES;
conf.interfaces = interfaces;
// Register configuration
GUD_RegisterConfiguration(&conf);
GUD_Start();
return &hgud;
}
uint8_t* GetStringDescriptor(uint8_t index) {
switch(index) {
case GUD_MANUFACTURER_STRING_INDEX :
return (uint8_t*) "IBR";
case GUD_PRODUCT_STRING_INDEX :
return (uint8_t*) "PotatoScope";
case GUD_SERIAL_STRING_INDEX :
return (uint8_t*) serial;
default :
//printf("Unknown index: %d\r\n", index);
return (uint8_t*) "Unknown";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment