Esempio n. 1
0
File: Core.cpp Progetto: Dzenik/Cosa
void 
USBDevice_::attach()
{
  // Configure hardware and phase-locked-loop and enable 
  _usbConfiguration = 0;
  HW_CONFIG();
  USB_FREEZE();
  PLL_CONFIG();

  // Wait for the phase-locked-loop to lock on
  loop_until_bit_is_set(PLLCSR, PLOCK);

  // Give the host some extra time
  delay(1);

  // Start the usb clock and enable interrupt service
  USB_CONFIG();
  UDCON = 0;
  UDINT = 0;
  UDIEN = _BV(EORSTE) | _BV(SOFE) | _BV(SUSPE);

  // Wait for usb device to connect to host
  TX_RX_LED_INIT;
  while (!_usbConfiguration) delay(200);
}
Esempio n. 2
0
bool
USBDevice_::attach()
{
  // Configure hardware and phase-locked-loop and enable 
  _usbConfiguration = 0;
  HW_CONFIG();
  USB_FREEZE();
  PLL_CONFIG();

  // Wait for the phase-locked-loop to lock on
  loop_until_bit_is_set(PLLCSR, PLOCK);

  // Give the host some extra time
  delay(1);

  // Start the usb clock and enable interrupt service
  USB_CONFIG();
  UDCON = 0;
  UDINT = 0;
  UDIEN = _BV(EORSTE) | _BV(SOFE) | _BV(SUSPE);

  // Wait for usb device to connect to host
  TX_RX_LED_INIT;
  for (uint8_t timeout=10;timeout;timeout--) {   // 2 seconds
    if (_usbConfiguration)
      return (true);
    delay(200);
  }

  // Host didn't connect, disable USB, leave powered
  UDIEN = _BV(DETACH);
  USB_UNCONFIG();

  return (false);
}
Esempio n. 3
0
// initialize USB serial
void usb_init(void)
{
	uint8_t u;

	u = USBCON;
	if ((u & (1<<USBE)) && !(u & (1<<FRZCLK))) return;
	HW_CONFIG();
        USB_FREEZE();				// enable USB
        PLL_CONFIG();				// config PLL
        while (!(PLLCSR & (1<<PLOCK))) ;	// wait for PLL lock
        USB_CONFIG();				// start USB clock
        UDCON = 0;				// enable attach resistor
	usb_configuration = 0;
	usb_suspended = 0;
	keyboard_report_data[0] = 0;
	keyboard_report_data[1] = 0;
	keyboard_report_data[2] = 0;
	keyboard_report_data[3] = 0;
	keyboard_report_data[4] = 0;
	keyboard_report_data[5] = 0;
	keyboard_report_data[6] = 0;
	keyboard_report_data[7] = 0;
	keyboard_protocol = 1;
	keyboard_idle_config = 125;
	keyboard_idle_count = 0;
	keyboard_leds = 0;
	UDINT = 0;
        UDIEN = (1<<EORSTE)|(1<<SOFE);
	//sei();  // init() in wiring.c does this
}
Esempio n. 4
0
// initialize USB
void usb_init(void) {
	HW_CONFIG();
	USB_FREEZE();				// enable USB
	PLL_CONFIG();				// config PLL
        while (!(PLLCSR & (1<<PLOCK))) ;	// wait for PLL lock
        USB_CONFIG();				// start USB clock
        UDCON = 0;				// enable attach resistor
	usb_configuration = 0;
        UDIEN = (1<<EORSTE)|(1<<SOFE);
	sei();
}
Esempio n. 5
0
/*! \fn     initUsb(void)
*   \brief  USB controller initialization
*/
void initUsb(void)
{
    HW_CONFIG();                    // enable regulator
    USB_FREEZE();                   // enable USB
    PLL_CONFIG();                   // config PLL
    while (!(PLLCSR & (1<<PLOCK))); // wait for PLL lock
    USB_CONFIG();                   // start USB clock
    UDCON = 0x00;                   // enable attach resistor
    usb_configuration = 0;          // usb not configured by default
    UDIEN = (1<<EORSTE)|(1<<SOFE);  // start USB
}
Esempio n. 6
0
// initialize USB
void usb_init(void) {
  HW_CONFIG();
  USB_FREEZE(); // enable USB
  PLL_CONFIG(); // config PLL
  while (!(PLLCSR & (1 << PLOCK))) { ; }
  USB_CONFIG(); // start USB clock
  //	UDCON = (1<<LSM);			// enable attach resistor - Low Speed USB
  UDCON = 0; // enable attach resistor - Full Speed USB
  usb_configuration = 0;

  // enable End-Of-Reset and Start-Of-Frame interrupts
  UDIEN = (1<<EORSTE)|(1<<SOFE);
}
Esempio n. 7
0
// initialize USB serial
void usb_init(void)
{
	uint8_t u;

	u = USBCON;
	if ((u & (1<<USBE)) && !(u & (1<<FRZCLK))) return;
	HW_CONFIG();
        USB_FREEZE();				// enable USB
        PLL_CONFIG();				// config PLL
        while (!(PLLCSR & (1<<PLOCK))) ;	// wait for PLL lock
        USB_CONFIG();				// start USB clock
        UDCON = 0;				// enable attach resistor
	usb_configuration = 0;
	usb_suspended = 0;
	cdc_line_rtsdtr = 0;
	UDINT = 0;
        UDIEN = (1<<EORSTE)|(1<<SOFE)|(1<<SUSPE);
}
Esempio n. 8
0
// initialize USB serial
void usb_init(void)
{
	uint8_t u;

	u = USBCON;
	if ((u & (1<<USBE)) && !(u & (1<<FRZCLK))) return;
	HW_CONFIG();
        USB_FREEZE();				// enable USB
        PLL_CONFIG();				// config PLL
        while (!(PLLCSR & (1<<PLOCK))) ;	// wait for PLL lock
        USB_CONFIG();				// start USB clock
        UDCON = 0;				// enable attach resistor
	usb_configuration = 0;
	usb_suspended = 0;
	cdc_line_rtsdtr = 0;
        keyboard_report_data[0] = 0;
        keyboard_report_data[1] = 0;
        keyboard_report_data[2] = 0;
        keyboard_report_data[3] = 0;
        keyboard_report_data[4] = 0;
        keyboard_report_data[5] = 0;
        keyboard_report_data[6] = 0;
        keyboard_report_data[7] = 0;
        keyboard_protocol = 1;
        keyboard_idle_config = 125;
        keyboard_idle_count = 0;
        keyboard_leds = 0;
        mouse_buttons = 0;
        mouse_protocol = 1;
        joystick_report_data[0] = 0;
        joystick_report_data[1] = 0;
        joystick_report_data[2] = 0;
        joystick_report_data[3] = 0;
        joystick_report_data[4] =  0x0F;
        joystick_report_data[5] =  0x20;
        joystick_report_data[6] =  0x80;
        joystick_report_data[7] =  0x00;
        joystick_report_data[8] =  0x02;
        joystick_report_data[9] =  0x08;
        joystick_report_data[10] = 0x20;
        joystick_report_data[11] = 0x80;
	UDINT = 0;
        UDIEN = (1<<EORSTE)|(1<<SOFE)|(1<<SUSPE);
}
Esempio n. 9
0
// initialize USB serial
void usb_init(void)
{
	uint8_t u;

	u = USBCON;
	if ((u & (1<<USBE)) && !(u & (1<<FRZCLK))) return;
	HW_CONFIG();
        USB_FREEZE();				// enable USB
        PLL_CONFIG();				// config PLL
        while (!(PLLCSR & (1<<PLOCK))) ;	// wait for PLL lock
        USB_CONFIG();				// start USB clock
        UDCON = 0;				// enable attach resistor
	usb_configuration = 0;
	usb_suspended = 0;
	debug_flush_timer = 0;
	UDINT = 0;
        UDIEN = (1<<EORSTE)|(1<<SOFE);
	//sei();  // init() in wiring.c does this
}
Esempio n. 10
0
// initialize USB serial
void usb_init(void)
{
	uint8_t u;

	u = USBCON;
	if ((u & (1<<USBE)) && !(u & (1<<FRZCLK))) {
		media_restart();
		return;
	}
	HW_CONFIG();
	USB_FREEZE();				// enable USB
	PLL_CONFIG();				// config PLL
	while (!(PLLCSR & (1<<PLOCK))) ;	// wait for PLL lock
	USB_CONFIG();				// start USB clock
	UDCON = 0;				// enable attach resistor
	usb_configuration = 0;
	usb_suspended = 0;
	debug_flush_timer = 0;
	keyboard_modifier_keys = 0;
	keyboard_keys[0] = 0;
	keyboard_keys[1] = 0;
	keyboard_keys[2] = 0;
	keyboard_keys[3] = 0;
	keyboard_keys[4] = 0;
	keyboard_keys[5] = 0;
	keyboard_protocol = 1;
	keyboard_idle_config = 125;
	keyboard_idle_count = 0;
	keyboard_leds = 0;
	ms_state = MS_STATE_IDLE;
	media_lock_state = 0;
	UDINT = 0;
	UDIEN = (1<<EORSTE)|(1<<SOFE);
	//sei();  // init() in wiring.c does this
	media_init();
}