示例#1
0
/**
 * @brief	main routine for example
 * @return	Function should not exit.
 */
int main(void)
{
	USBD_API_INIT_PARAM_T usb_param;
	USB_CORE_DESCS_T desc;
	ErrorCode_t ret = LPC_OK;

	/* Initialize board and chip */
	SystemCoreClockUpdate();
	Board_Init();

	/* Init millisecond timer tick driver */
	systick_init();

	/* enable clocks and pinmux */
	usb_pin_clk_init();

	/* initialize call back structures */
	memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
	usb_param.usb_reg_base = LPC_USB_BASE + 0x200;
	usb_param.max_num_ep = 2;
	usb_param.mem_base = USB_STACK_MEM_BASE;
	usb_param.mem_size = USB_STACK_MEM_SIZE;

	/* Set the USB descriptors */
	desc.device_desc = (uint8_t *) USB_DeviceDescriptor;
	desc.string_desc = (uint8_t *) USB_StringDescriptor;

	/* Note, to pass USBCV test full-speed only devices should have both
	 * descriptor arrays point to same location and device_qualifier set
	 * to 0.
	 */
	desc.high_speed_desc = USB_FsConfigDescriptor;
	desc.full_speed_desc = USB_FsConfigDescriptor;
	desc.device_qualifier = 0;

	/* USB Initialization */
	ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);
	if (ret == LPC_OK) {

		/* Mice are generally low or full speed devices and not high speed. */
		USBD_API->hw->ForceFullSpeed(g_hUsb, 1);
		ret = Keyboard_init(g_hUsb,
			(USB_INTERFACE_DESCRIPTOR *) &USB_FsConfigDescriptor[sizeof(USB_CONFIGURATION_DESCRIPTOR)],
			&usb_param.mem_base, &usb_param.mem_size);
		if (ret == LPC_OK) {
			/*  enable USB interrupts */
			NVIC_EnableIRQ(USB_IRQn);
			/* now connect */
			USBD_API->hw->Connect(g_hUsb, 1);
		}
	}

	while (1) {
		/* Do Keyboard tasks */
		Keyboard_Tasks();
		/* Sleep until next IRQ happens */
		__WFI();
	}
}
示例#2
0
void USBInit(SemaphoreHandle_t usb_uart_connected_sem)
{
	USBD_API_INIT_PARAM_T usb_param;
	USB_CORE_DESCS_T desc;
	ErrorCode_t ret = LPC_OK;

	/* Initialize board and chip */
	SystemCoreClockUpdate();
	Board_Init();

	StopWatch_Init();

	/* enable clocks and pinmux */
	usb_pin_clk_init();

	/* initialize call back structures */
	memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
	usb_param.usb_reg_base = LPC_USB_BASE + 0x200;
	usb_param.max_num_ep = 3;
	usb_param.mem_base = USB_STACK_MEM_BASE;
	usb_param.mem_size = USB_STACK_MEM_SIZE;

	/* Set the USB descriptors */
	desc.device_desc = (uint8_t *) &USB_DeviceDescriptor[0];
	desc.string_desc = (uint8_t *) &USB_StringDescriptor[0];
	/* Note, to pass USBCV test full-speed only devices should have both
	   descriptor arrays point to same location and device_qualifier set to 0. */
	desc.high_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.full_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.device_qualifier = 0;

	/* USB Initialization */
	ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);
	if (ret == LPC_OK)
	{
		/* Init VCOM interface */
		ret = vcom_init(g_hUsb, &desc, &usb_param);
		if (ret == LPC_OK)
		{
			/*  enable USB interrupts */
			NVIC_EnableIRQ(USB_IRQn);
			/* now connect */
			USBD_API->hw->Connect(g_hUsb, 1);
		}
	}

	/* Check if host has connected and opened the VCOM port */
	while(!vcom_connected())
		;

	xSemaphoreGive(usb_uart_connected_sem);
}
示例#3
0
void usb_init(void)
{
	static Bool bUsbInit = FALSE;
	USBD_API_INIT_PARAM_T usb_param;
	USB_CORE_DESCS_T desc;
	ErrorCode_t ret = LPC_OK;

	if(bUsbInit)
		return;

	usb_pin_clk_init();

	/* Initialize call back structures */
	memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
	usb_param.usb_reg_base = LPC_USB0_BASE;
	usb_param.max_num_ep = 2;
	usb_param.mem_base = USB_STACK_MEM_BASE;
	usb_param.mem_size = USB_STACK_MEM_SIZE;

	/* Set the USB descriptors */
	desc.device_desc = (uint8_t *) &USB_DeviceDescriptor[0];
	desc.string_desc = (uint8_t *) &USB_StringDescriptor[0];
	/* Note, to pass USBCV test full-speed only devices should have both
	   descriptor arrays point to same location and device_qualifier set to 0.
	 */
	desc.high_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.full_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.device_qualifier = 0;

	/* USB Initialization */
	ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);
	if (ret == LPC_OK) {

		/* Init USB HID bridge interface */
		ret = UCOM_init(g_hUsb, find_IntfDesc(desc.high_speed_desc, USB_DEVICE_CLASS_HUMAN_INTERFACE), &usb_param);

		ret = dfu_init(g_hUsb, find_IntfDesc(desc.high_speed_desc, USB_DEVICE_CLASS_APP), &usb_param);
		if (ret == LPC_OK) {
			/* Make sure USB and IRQ priorities are same for this example */
			NVIC_SetPriority(USB0_IRQn, 1);
			/* Enable USB interrrupts */
			NVIC_EnableIRQ(USB0_IRQn);
			/* Now connect */
			USBD_API->hw->Connect(g_hUsb, 1);
		}
	}

	bUsbInit = TRUE;
}
示例#4
0
文件: main.c 项目: ppejic/temperatura
void USB_Periph_Init(void)
{
	USBD_API_INIT_PARAM_T usb_param;
	USB_CORE_DESCS_T desc;
	ErrorCode_t ret = LPC_OK;
	
	/* enable clocks and pinmux */
	usb_pin_clk_init();

	/* initilize call back structures */
	memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
	usb_param.usb_reg_base = LPC_USB0_BASE;
	usb_param.max_num_ep = 3;
	usb_param.mem_base = USB_STACK_MEM_BASE;
	usb_param.mem_size = USB_STACK_MEM_SIZE;

	/* Set the USB descriptors */
	desc.device_desc = (uint8_t *) &USB_DeviceDescriptor[0];
	desc.string_desc = (uint8_t *) &USB_StringDescriptor[0];
	/* Note, to pass USBCV test full-speed only devices should have both
	   descriptor arrays point to same location and device_qualifier set to 0.
	 */
	desc.high_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.full_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
	desc.device_qualifier = 0;

	/* USB Initialization */
	ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);
	if (ret == LPC_OK) {
		/* Init VCOM interface */
		ret = vcom_init(g_hUsb, &desc, &usb_param);
		if (ret == LPC_OK) {
			/*  enable USB interrrupts */
			NVIC_EnableIRQ(USB0_IRQn);
			/* now connect */
			USBD_API->hw->Connect(g_hUsb, 1);
		}
	}
}
示例#5
0
void setup() {
  // TODO(zapta): which ones can be non static?

   static USBD_API_INIT_PARAM_T usb_param;
   static USB_CORE_DESCS_T desc;

   ErrorCode_t ret = LPC_OK;

   /* enable clocks and pinmux */
   usb_pin_clk_init();

   // Get pointer to the base of the USB ROM struct.
   g_pUsbApi = (const USBD_API_T *) LPC_ROM_API->usbdApiBase;

   /* initialize call back structures */
   memset((void *) &usb_param, 0, sizeof(USBD_API_INIT_PARAM_T));
   usb_param.usb_reg_base = LPC_USB0_BASE;
   /*  WORKAROUND for artf44835 ROM driver BUG:
    Code clearing STALL bits in endpoint reset routine corrupts memory area
    next to the endpoint control data. For example When EP0, EP1_IN, EP1_OUT,
    EP2_IN are used we need to specify 3 here. But as a workaround for this
    issue specify 4. So that extra EPs control structure acts as padding buffer
    to avoid data corruption. Corruption of padding memory doesn’t affect the
    stack/program behaviour.
    */
   usb_param.max_num_ep = 3 + 1;
   usb_param.mem_base = USB_STACK_MEM_BASE;
   usb_param.mem_size = USB_STACK_MEM_SIZE;

   /* Set the USB descriptors */
   desc.device_desc = (uint8_t *) &USB_DeviceDescriptor[0];
   desc.string_desc = (uint8_t *) &USB_StringDescriptor[0];
   /* Note, to pass USBCV test full-speed only devices should have both
    descriptor arrays point to same location and device_qualifier set to 0.
    */
   desc.high_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
   desc.full_speed_desc = (uint8_t *) &USB_FsConfigDescriptor[0];
   desc.device_qualifier = 0;

   /* USB Initialization */
   ret = USBD_API->hw->Init(&g_hUsb, &desc, &usb_param);
   if (ret == LPC_OK) {

     /*  WORKAROUND for artf32219 ROM driver BUG:
      The mem_base parameter part of USB_param structure returned
      by Init() routine is not accurate causing memory allocation issues for
      further components.
      */
     usb_param.mem_base = USB_STACK_MEM_BASE
         + (USB_STACK_MEM_SIZE - usb_param.mem_size);

     /* Init VCOM interface */
     ret = vcom_init(g_hUsb, &desc, &usb_param);
     if (ret == LPC_OK) {
       /*  enable USB interrupts */
       NVIC_EnableIRQ(USB0_IRQn);
       /* now connect */
       USBD_API->hw->Connect(g_hUsb, 1);
     }

   }
}