Ejemplo n.º 1
0
/**
  * @brief  USBD_Init
  *         Initializes the device stack and load the class driver
  * @param  pdev: device instance
  * @param  class_cb: Class callback structure address
  * @param  usr_cb: User callback structure address
  * @retval None
  */
void USBD_Init(USB_CORE_HANDLE *pdev,
               USBD_DEVICE *pDevice,                  
               USBD_Class_cb_TypeDef *class_cb, 
               USBD_Usr_cb_TypeDef *usr_cb)
{
  /* Hardware Init */
  USB_BSP_Init(pdev);  
  
  USBD_DeInit(pdev);
  
  /*Register class and user callbacks */
  pdev->dev.class_cb = class_cb;
  pdev->dev.usr_cb = usr_cb;  
  pdev->dev.usr_device = pDevice;    
  
  /* Update the serial number string descriptor with the data from the unique ID*/
  Get_SerialNum();
  
  /* set USB DEVICE core params */
  DCD_Init(pdev);
  
  /* Upon Init call usr callback */
  pdev->dev.usr_cb->Init();
  
  /* Enable Interrupts */
  USB_BSP_EnableInterrupt(pdev);
  
  /* Enable the pull-up */
#ifdef INTERNAL_PULLUP
  DCD_DevConnect(pdev);
#else
 USB_BSP_DevConnect(pdev);
#endif
}
Ejemplo n.º 2
0
/*******************************************************************************
  MASS_init: Mass Storage init routine.
*******************************************************************************/
void MASS_init()
{
  Get_SerialNum(); // Update the serial number string descriptor with the data from the unique ID
  pInformation->Current_Configuration = 0;
  PowerOn();       // Connect the device
  _SetISTR(0);     // USB interrupts initialization. clear pending interrupts
  wInterrupt_Mask = IMR_MSK;
  _SetCNTR(wInterrupt_Mask); // set interrupts mask
  bDeviceState = UNCONNECTED;
}
Ejemplo n.º 3
0
/*******************************************************************************
    Function Name  : USBdev_Init.
    Description    : USB device init routine.
    Input          : None.
    Output         : None.
    Return         : None.
*******************************************************************************/
void USBdev_Init() {
	// Update the serial number string descriptor with the data from the unique ID
	Get_SerialNum();
	// Initialize the current configuration
	pInformation->Current_Configuration = 0;
	// Connect the device
	PowerOn();
	// Perform basic device initialization operations
	USB_SIL_Init();
	bDeviceState = UNCONNECTED;
}
Ejemplo n.º 4
0
/******************************************************************************
 * @brief	CDC init routine.
 */
void CDC_Init(void)
{
	Get_SerialNum();		/* Update the serial number string descriptor with the data from the unique ID */
	pInformation->Current_Configuration = 0;

	USB_Config();

	PowerOn();				/* Connect the device */
	USB_SIL_Init();			/* Perform basic device initialization operations */

	pInformation->bDeviceState = UNCONNECTED;
}
/*******************************************************************************
* Function Name  : CustomHID_init.
* Description    : Custom HID init routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
static void composite_cdc_hid_init(void)
{
  /* Update the serial number string descriptor with the data from the unique 
  ID*/
  Get_SerialNum();
    
  pInformation->Current_Configuration = 0;
  /* Connect the device */
  PowerOn();

  /* Perform basic device initialization operations */
  USB_SIL_Init();

  bDeviceState = UNCONNECTED;
}
/**
  * @brief  Joystick Mouse init routine.
  * @param  None
  * @retval None
  */
void Joystick_init(void)
{

    /* Update the serial number string descriptor with the data from the unique
    ID*/
    Get_SerialNum();

    pInformation->Current_Configuration = 0;
    /* Connect the device */
    PowerOn();

    /* Perform basic device initialization operations */
    USB_SIL_Init(wInterrupt_Mask = IMR_MSK);

    bDeviceState = UNCONNECTED;
}
Ejemplo n.º 7
0
/*******************************************************************************
* Function Name  : CustomHID_init.
* Description    : Custom HID init routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void CustomHID_init(void)
{
  /* Update the serial number string descriptor with the data from the unique 
  ID*/
     Get_SerialNum();
    
     pInformation->Current_Configuration = 0;
  /* Connect the device */
     PowerOn();
  /* USB interrupts initialization */
     _SetISTR(0);               /* clear pending interrupts */
     wInterrupt_Mask = IMR_MSK;
    _SetCNTR(wInterrupt_Mask); /* set interrupts mask */

     bDeviceState = UNCONNECTED;
}
Ejemplo n.º 8
0
// Инициализация USB-девайса
void SomeDev_init()
{
	// Получаем серийный номер
	Get_SerialNum();
	
	// Задаем текущую конфигурацию
	pInformation->Current_Configuration = 0;
	
	// Подключение 
	PowerOn();
	
	// Основные инициализации
	USB_SIL_Init();
	
	bDeviceState = UNCONNECTED;
}
Ejemplo n.º 9
0
/*******************************************************************************
* Function Name  : Speaker_init.
* Description    : Speaker init routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void Speaker_init()
{
  /* Update the serial number string descriptor with the data from the unique
  ID*/
  Get_SerialNum();

  /* Initialize the current configuration */
  pInformation->Current_Configuration = 0;

  /* Connect the device */
  PowerOn();

  /* Perform basic device initialization operations */
  USB_SIL_Init();

  bDeviceState = UNCONNECTED;
}
Ejemplo n.º 10
0
/*******************************************************************************
 * Function Name  : Virtual_Com_Port_init.
 * Description    : Virtual COM Port Mouse init routine.
 * Input          : None.
 * Output         : None.
 * Return         : None.
 *******************************************************************************/
void Virtual_Com_Port_init(void) {

	/* Update the serial number string descriptor with the data from the unique
	 ID*/
	Get_SerialNum();

	pInformation->Current_Configuration = 0;

	/* Connect the device */
	PowerOn();

	/* Perform basic device initialization operations */
	USB_SIL_Init();

	/* configure the USART to the default settings */
	//USART_Config_Default();
	bDeviceState = UNCONNECTED;
}
Ejemplo n.º 11
0
/*******************************************************************************
* Function Name  : DFU_init.
* Description    : DFU init routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void DFU_init(void)
{
  DEVICE_INFO *pInfo = &Device_Info;

  /* Update the serial number string descriptor with the data from the unique ID*/
  Get_SerialNum();

  pInfo->Current_Configuration = 0;

  /* Connect the device */
  PowerOn();

  /* Perform basic device initialization operations */
  USB_SIL_Init();

  /* Enable USB interrupts */
  USB_Interrupts_Config();

  bDeviceState = UNCONNECTED;
}
Ejemplo n.º 12
0
uint8_t *feature_config_getreport(uint16_t length)
{
    // Switch based on ReportID
    switch (pInformation->USBwValue0) {
    case FEATURE_CONFIG:
        // On the first callback, we supply the length
        if (!length) {
            pInformation->Ctrl_Info.Usb_wLength = FEATURE_CONFIG_SIZE;
        } else {
            // On the second we return the filled buffer
            feature_config_pack_config();
            return feature_get_buf;
        }
        break;

    case FEATURE_CALIBRATE:
        if (!length) {
            pInformation->Ctrl_Info.Usb_wLength = FEATURE_CALIBRATE_SIZE;
        } else {
            feature_get_buf[0] = FEATURE_CALIBRATE;
            *(uint16_t *)(feature_get_buf+1) = global_calibrate.command_id;
            // Pack in the payload
            calibrate_get(feature_get_buf+3);
            // Calibrate is above 64 bytes, so we get called again with offset
            return feature_get_buf + pInformation->Ctrl_Info.Usb_wOffset;
        }
        break;

    case FEATURE_RANGE:
        if (!length) {
            pInformation->Ctrl_Info.Usb_wLength = FEATURE_RANGE_SIZE;
        } else {
            feature_config_pack_range();
            return feature_get_buf;
        }
        break;

    case FEATURE_REGISTER:
        if (!length) {
            pInformation->Ctrl_Info.Usb_wLength = FEATURE_REGISTER_SIZE;
        } else {
            feature_config_pack_register();
            return feature_get_buf;
        }
        break;

    case FEATURE_DFU:
        if (!length) {
            pInformation->Ctrl_Info.Usb_wLength = FEATURE_DFU_SIZE;
        } else {
            feature_get_buf[0] = FEATURE_DFU;
            *(uint16_t *)(feature_get_buf+1) = global_dfu.command_id;
            feature_get_buf[3] = global_dfu.use_dfu;
            return feature_get_buf;
        }
        break;

    case FEATURE_GPIO:
        if (!length) {
            pInformation->Ctrl_Info.Usb_wLength = FEATURE_GPIO_SIZE;
        } else {
            feature_get_buf[0] = FEATURE_GPIO;
            *(uint16_t *)(feature_get_buf+1) = global_gpio.command_id;
            feature_get_buf[3] = global_gpio.direction;
            feature_get_buf[4] = global_gpio.value = gpio_get_value();
            return feature_get_buf;
        }
        break;

    case FEATURE_KEEP_ALIVE:
        if (!length) {
            pInformation->Ctrl_Info.Usb_wLength = FEATURE_KEEP_ALIVE_SIZE;
        } else {
            feature_get_buf[0] = FEATURE_KEEP_ALIVE;
            *(uint16_t *)(feature_get_buf+1) = global_keep_alive.command_id;
            *(uint16_t *)(feature_get_buf+3) = global_keep_alive.keep_alive;
            return feature_get_buf;
        }
        break;

    case FEATURE_DISPLAY_INFO:
        if (!length) {
            pInformation->Ctrl_Info.Usb_wLength = FEATURE_DISPLAY_INFO_SIZE;
        } else {
            feature_get_buf[0] = FEATURE_DISPLAY_INFO;
            *(uint16_t *)(feature_get_buf+1) = global_display_info.command_id;
            // fill the actual parameters
            display_info_get(feature_get_buf+3, feature_get_buf+4);
            return feature_get_buf;
        }
        break;

    case FEATURE_SERIAL:
        if (!length) {
            pInformation->Ctrl_Info.Usb_wLength = FEATURE_SERIAL_SIZE;
        } else {
            feature_get_buf[0] = FEATURE_SERIAL;
            *(uint16_t *)(feature_get_buf+1) = global_serial.command_id;
            Get_SerialNum((char *)(feature_get_buf+3), 0);
            return feature_get_buf;
        }
        break;

    default:
        break;
    }

    return NULL;
}