Ejemplo n.º 1
0
int main(void) {
	wdt_enable(WDTO_1S);
  initPodControls();

	/* Even if you don't use the watchdog, turn it off here. On newer devices,
	 * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!
	 */
	/* RESET status: all port bits are inputs without pull-up.
	 * That's the way we need D+ and D-. Therefore we don't need any
	 * additional hardware initialization.
	 */
	usbInit();
	usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
	uchar i = 0;
	while(--i){             /* fake USB disconnect for > 250 ms */
			wdt_reset();
			_delay_ms(1);
	}

	usbDeviceConnect();
	sei();
	for(;;){                /* main event loop */
			wdt_reset();
			usbPoll();
			if(usbInterruptIsReady()){
				/* called after every poll of the interrupt endpoint */
				usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
			} else {
				updateSensorData();
        updateLEDState();
      }
	}
}
Ejemplo n.º 2
0
int main(void)
{
    extern uchar usbNewDeviceAddr;
    uint8_t i;
//Reconnect USB
    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
    i = 0;
    while(--i)
        _delay_ms(2);
    usbDeviceConnect();
    usbInit();
    sei();

    leds[LED_RED].frequency = LED_ON;
    LED_init();
    for (i=0; i<3; i++)
        TIMER_delay(250);
    leds[LED_RED].frequency = LED_OFF;
    leds[LED_GREEN].frequency = 1;


    while(1)
    {
        if (TIMER_timeout == 0)
        {
            if(usbNewDeviceAddr)
                leds[LED_BLUE].frequency = LED_ON;
            PORTD ^= (1<<PD7);
            TIMER_start(1);
            usbPoll();
            LED_poll();
        }
    }
}
Ejemplo n.º 3
0
int main(void)
{
    led_init();    
    sht1x_init();
    //sser_init();
    
    wdt_enable(WDTO_1S);    
    /* Even if you don't use the watchdog, turn it off here. On newer devices,
     * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!
     */
    /* RESET status: all port bits are inputs without pull-up.
     * That's the way we need D+ and D-. Therefore we don't need any
     * additional hardware initialization.
     */
    odDebugInit();
    DBG1(0x00, 0, 0);       /* debug output: main starts */
    usbInit();
    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
    unsigned char i = 0;
    while(--i){             /* fake USB disconnect for > 250 ms */
        wdt_reset();
        _delay_ms(1);
    }
    usbDeviceConnect();
    sei();
    DBG1(0x01, 0, 0);       /* debug output: main loop starts */        
    for(;;){
        wdt_reset();
        usbPoll();
    }
    return 0;   /* never reached */
}
Ejemplo n.º 4
0
int main()
{
	fabscan_setup();
	uchar i;
//    wdt_enable(WDTO_1S); // enable 1s watchdog timer
    usbInit();
    usbDeviceDisconnect(); // enforce re-enumeration
    for(i = 0; i<250; i++) { // wait 500 ms
//        wdt_reset(); // keep the watchdog happy
        _delay_ms(2);
    }
    usbDeviceConnect();
    sei(); // Enable interrupts after re-enumeration

    while(1)
    {
//    		wdt_reset(); // keep the watchdog happy
    		usbPoll();

    		if(fab_work_flag)	// if there is new data for fabscan → let it work
    		{
    			fab_work_flag=0;
    			fabscan_work(1,incomingByte);
    		}
    }
    return 0;
}
Ejemplo n.º 5
0
Archivo: main.c Proyecto: z80/avrusb
void __attribute__((noreturn)) main( void )
{
    cli();
    initLeds();

    wdt_enable( WDTO_1S );

    // USB initialization.
    usbInit();
    usbDeviceDisconnect();  // enforce re-enumeration, do this while interrupts are disabled!
    unsigned char b = 150;
    while ( b-- )
    {
        _delay_ms( 1 );
        wdt_reset();
    }
    cpuIoInit();

    usbDeviceConnect();
    sei();

    for ( ;; )
    {
        // main event loop
        usbPoll();
        wdt_reset();
        cpuIoPoll();
        //_delay_ms( 10 );
    }
}
Ejemplo n.º 6
0
int main() {
	initLCD();
	LCD_goto(1,0);
	lcd_puts("AVRLCD 4bit mode");
        uchar i;
		  DDRB = 1; // PB0 as output
    wdt_enable(WDTO_1S); // enable 1s watchdog timer

    usbInit();
        
    usbDeviceDisconnect(); // enforce re-enumeration
    for(i = 0; i<250; i++) { // wait 500 ms
        wdt_reset(); // keep the watchdog happy
        _delay_ms(2);
    }
    usbDeviceConnect();
        
    sei(); // Enable interrupts after re-enumeration
        
    while(1) {
        wdt_reset(); // keep the watchdog happy
        usbPoll();
    }
        
    return 0;
}
Ejemplo n.º 7
0
void vusb_init(void)
{
	// inits the timer used for idle rate
    // a rate of 12M/(1024 * 256) = 45.78 Hz (period = 21845us)
	TCCR0B = _BV(CS02) | _BV(CS00);
#define TMR1US	21845L

	// a rate of 12M/(64 * 256) = 732,42 Hz (1365us)
//	TCCR0B = _BV(CS01) | _BV(CS00);
//#define TMR1US	1365L

#define OVF2MS(tmr)		((uint16_t)(( (tmr) * TMR1US) / 1000))
#define OVF2US(tmr)		((uint16_t)( (tmr) * TMR1US))

	usbInit();

	usbDeviceDisconnect();	// enforce re-enumeration, do this while interrupts are disabled!
	_delay_ms(260);			// fake USB disconnect for > 250 ms
	usbDeviceConnect();

	vusb_idle_rate = 0;
	vusb_curr_protocol = 1;	// report protocol
	
	// clear the reports
	usb_consumer_report = 0;
	reset_keyboard_report();
}
Ejemplo n.º 8
0
int main( void )
{
	//===========================================
	uchar   calibrationValue;
    calibrationValue = eeprom_read_byte(0); /* calibration value from last time */
    if(calibrationValue != 0xff){
        OSCCAL = calibrationValue;
    }
	//===========================================
	usbInit();
    wdt_enable(WDTO_1S);
    /* Даже если Вы не используете сторожевой таймер (watchdog), выключите его здесь. На более новых
     *  микроконтроллерах состояние watchdog (вкл\выкл, период) СОХРАНЯЕТСЯ ЧЕРЕЗ СБРОС!
     */
	//===========================================
    usbDeviceDisconnect();
    _delay_ms(300);			/* 300 ms disconnect */
    usbDeviceConnect();
	//===========================================
    //LED_PORT_DDR |= _BV(LED_BIT);		/* делаем ножку, куда подключен LED, выходом */
	sbi(LED_PORT_DDR,LED_BIT);			/* делаем ножку, куда подключен LED, выходом */
	//===========================================
	sei();		/* Разрешаем прерывания*/
    for(;;){    /* main event loop */
        wdt_reset();
        usbPoll();
	}
	//===========================================
}
Ejemplo n.º 9
0
int main()
{
	uchar	i=0;

    wdt_enable(WDTO_1S);
    
    usbInit();
    
	usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
    
    for (i=0; i<250; i++)
    {         /* fake USB disconnect for > 500 ms */
        wdt_reset();
        _delay_ms(2);
    }
    usbDeviceConnect();
    //LED_PORT_DDR |= _BV(LED_BIT);   /* make the LED bit an output */
    sei();
    //DBG1(0x01, 0, 0);       /* debug output: main loop starts */
    while (1)
    {
        wdt_reset();
        usbPoll();
		
	}
}
Ejemplo n.º 10
0
int main(void) {
	uchar i, j;

	/* no pullups on USB and ISP pins */
	//PORTD = 0;
	//PORTB = 0;
	/* all outputs except PD2 = INT0 */
	/// LB - different pins on STK500 board
	//DDRD = ~(1 << 2);
	// make JTAG pins inputs with pullups	
	SET_JTAG_PULLUPS();

	/* output SE0 for USB reset */
	/// LB - different pins on STK500 board
	//DDRB = ~0;
	j = 0;
	/* USB Reset by device only required on Watchdog Reset */
	while (--j) {
		i = 0;
		/* delay >10ms for USB reset */
		while (--i)
			;
	}
	/* all USB and ISP pins inputs */
	//DDRB = 0;

	/// LB - LED pins are different from usbasp to sp duo - conflict: SP duo uses these for JTAG
	/* all inputs except PC0, PC1 */
	//DDRC = 0x03;
	//PORTC = 0xfe;
	SET_LED_OUTPUT();
	LED_OFF();

	/* init timer */
	clockInit();

	
#ifdef UART_DEBUG
    // init debug uart
    setupUART();

    TransmitString("\r\n\n***\r\nstarting up\r\n");
#endif
	
	// USB Re-Enumeration
	usbDeviceDisconnect();
	while(--i){         // fake USB disconnect for > 250 ms
	    wdt_reset();    // if watchdog is active, reset it
	    _delay_ms(1);   // library call -- has limited range
	}
	usbDeviceConnect();

	/* main event loop */
	usbInit();
	sei();
	for (;;) {
		usbPoll();
	}
	return 0;
}
Ejemplo n.º 11
0
int main()
{
	uchar i;
	DDRB |= 1; // PB0 as output
	DDRB |= (1<<1); // PB1 as output

    wdt_enable(WDTO_1S); // enable 1s watchdog timer

    usbInit();
        
    usbDeviceDisconnect(); // enforce re-enumeration
    for(i = 0; i<250; i++) // wait 500 ms
	{ 
        wdt_reset(); // keep the watchdog happy
        _delay_ms(2);
    }
    usbDeviceConnect();
        
    sei(); // Enable interrupts after re-enumeration
     
	PORTB |= (1<<1); // PB1 on
	 
    while(1)
	{
		
        wdt_reset(); // keep the watchdog happy
        usbPoll();
    }
        
    return 0;
}
Ejemplo n.º 12
0
int	main(void) 
{
  extern uchar usbNewDeviceAddr;
  uint8_t i;
  PORTC |= (1<<PC2);

//Reconnect USB
  usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
  i = 0;
  while(--i)
     _delay_ms(2);
  usbDeviceConnect();
  usbInit();
  sei();
  leds[LED_RED].frequency = LED_ON;
  LED_init();
  for (i=0;i<3;i++)
    TIMER_delay(250);
  leds[LED_RED].frequency = LED_OFF;
  LED_poll();
//  wdt_enable(WDTO_60MS);
  i2c_init();

  for(;;) 
    {
      if(usbNewDeviceAddr)
	    {
          leds[LED_BLUE].frequency = LED_ON;
		}
      wdt_reset();
      LED_poll();
      usbPoll();
    }
  return 0;
}
Ejemplo n.º 13
0
Archivo: main.c Proyecto: elcerdo/avr
int main(void)
{
uchar   i;

    wdt_enable(WDTO_1S);
    /* Even if you don't use the watchdog, turn it off here. On newer devices,
     * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!
     */
    DBG1(0x00, 0, 0);       /* debug output: main starts */
    /* RESET status: all port bits are inputs without pull-up.
     * That's the way we need D+ and D-. Therefore we don't need any
     * additional hardware initialization.
     */
    odDebugInit();
    usbInit();
    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
    i = 0;
    while(--i){             /* fake USB disconnect for > 250 ms */
        wdt_reset();
        _delay_ms(1);
    }
    usbDeviceConnect();
    LED_PORT_DDR |= _BV(LED_BIT);   /* make the LED bit an output */
    sei();
    DBG1(0x01, 0, 0);       /* debug output: main loop starts */
    for(;;){                /* main event loop */
        DBG1(0x02, 0, 0);   /* debug output: main loop iterates */
        wdt_reset();
        usbPoll();
    }
    return 0;
}
Ejemplo n.º 14
0
int main() {
    uchar i;

    DDRB = 1; // LED is on PB0

    // set up a 1 second watchdog timer that resets the microcontroller
    // if 1000 milliseconds pass without a call to wdt_reset()
    wdt_enable(WDTO_1S);

    // init v-usb
    usbInit();

    usbDeviceDisconnect(); // enforce re-enumeration
    for(i = 0; i < 250; i++) { // wait 500 ms
        wdt_reset(); // keep the watchdog happy
        _delay_ms(2);
    }
    usbDeviceConnect();

    sei(); // Enable interrupts after re-enumeration

    while(1) {
        wdt_reset(); // keep the watchdog happy
        usbPoll();
    }

    return 0;
}
Ejemplo n.º 15
0
static void hardwareInit(void)
{

    /* activate pull-ups except on USB lines */
    USB_CFG_IOPORT   = (uchar)~((1<<USB_CFG_DMINUS_BIT)|(1<<USB_CFG_DPLUS_BIT));
    /* all pins input except USB (-> USB reset) */
#ifdef USB_CFG_PULLUP_IOPORT    /* use usbDeviceConnect()/usbDeviceDisconnect() if available */
    USBDDR    = 0;    /* we do RESET by deactivating pullup */
    usbDeviceDisconnect();
#else
    USBDDR    = (1<<USB_CFG_DMINUS_BIT)|(1<<USB_CFG_DPLUS_BIT);
#endif

    /* 250 ms disconnect */
    wdt_reset();
    _delay_ms(250);

#ifdef USB_CFG_PULLUP_IOPORT
    usbDeviceConnect();
#else
    USBDDR    = 0;      /*  remove USB reset condition */
#endif

    /*    USART configuration    */
    baud.dword  = UART_DEFAULT_BPS;
    stopbit = 0;
    parity  = 0;
    databit = 8;
    resetUart();
}
Ejemplo n.º 16
0
//Main routine
int main(void) {
    int d;
    uint16_t v;
    
    // cli();
    initio();
    inittxt();

    usbInit();
    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
    uint8_t i = 0;
    while(--i){             /* fake USB disconnect for > 250 ms */
        _delay_ms(1);
    }
    usbDeviceConnect();
    
    sei();

    //Go display stuff
    while(1) {
	for (d=0; d<11; d++) {
	    v=getcharat(d);
	    setvfd(d,v);
	    _delay_ms(1);
	    handlepwm();
	    usbPoll();
	}
	
    }
}
Ejemplo n.º 17
0
/**************************************************************************************
Function Name 		:	main
Description			:	Initialize the USB and start the interrupt
Parameters 			:	void
Return 				:	int 
**************************************************************************************/
int main(void)
{
	uchar l_delayCount;
    wdt_enable(WDTO_1S);
    odDebugInit();
    DBG1(0x00, 0, 0);       /* debug output: main starts */
    usbInit();
    usbDeviceDisconnect();  /* enforce re-enumeration, 
    						   do this while interrupts are disabled! */
    l_delayCount = 0;
    while(--l_delayCount)
    {             
    	/* fake USB disconnect for > 250 ms */
        wdt_reset();
        _delay_ms(1);
    }
    usbDeviceConnect();
    sei();
    DBG1(0x01, 0, 0);       
    for(;;)
    {                
        DBG1(0x02, 0, 0);   /*debug output: main loop iterates*/
        wdt_reset();
        usbPoll();
    }
    return 0;
}
Ejemplo n.º 18
0
int main(void)
{
uchar   i;

    wdt_enable(WDTO_1S);
    /* Если не используется watchdog, отключите эту строчку. Для новых устройств
        статус watchdog (on/off, period) СОХРАНЯЕТСЯ ПОСЛЕ СБРОСА!
     */
    /* Статус RESET: все ножки портов в режиме ввода без нагрузочных резисторов (pull-up).
        Это то, что нужно для D+ and D-, таким образом, мы не нуждаемся в дополнительной аппаратной
        инициализации.
     */
    usbInit();              // см. usbdrv.h и usbdrv.c
    usbDeviceDisconnect();  /* см. usbdrv.h - запускает реэнумерацию, делаем это, пока отключены прерывания! */
    i = 0;
    while(--i)
    {            /* подделывам USB disconnect на время > 250 ms */
        wdt_reset();
        _delay_ms(1);
    }
    usbDeviceConnect();     // см. usbdrv.h
    LED_PORT_DDR |= _BV(LED_BIT);   /* переключаем ножку LED в режим вывода */
    sei();
    for(;;){                /* главный цикл события */
        wdt_reset();
        usbPoll();
    }
    return 0;
}
Ejemplo n.º 19
0
int main(void) {
    wdt_enable(WDTO_1S);  // watchdog status is preserved on reset


    hardwareInit();

    usbInit();
    usbDeviceDisconnect();

    // fake USB disconnect for > 250 ms
    for( uint8_t i=255; i>0; i-- ) {
        wdt_reset();
        _delay_ms(1);
    }
    usbDeviceConnect();

    sei();

    for(;;) {               // main event loop
        wdt_reset();
        usbPoll();
    }

    return 0;
}
Ejemplo n.º 20
0
int __attribute__((noreturn)) main(void)
{
uchar   i;

    wdt_enable(WDTO_1S);
    /* Even if you don't use the watchdog, turn it off here. On newer devices,
     * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!
     */
    /* RESET status: all port bits are inputs without pull-up.
     * That's the way we need D+ and D-. Therefore we don't need any
     * additional hardware initialization.
     */
    odDebugInit();
    usbInit();
    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
    i = 0;
    while(--i){             /* fake USB disconnect for > 250 ms */
        wdt_reset();
        _delay_ms(1);
    }
    usbDeviceConnect();
    sei();
    DDRB |= _BV(PB0);
    for(;;){                /* main event loop */
        wdt_reset();
        usbPoll();
        if (eeprom_read_byte(10) == 1) {
          PORTB |= _BV(PB0);
        } else {
          PORTB &= ~_BV(PB0);
        }
    }
}
Ejemplo n.º 21
0
Archivo: main.c Proyecto: mmitch/tasta
static void hardwareInit(void)
{
	uchar i;
	uchar calibrationValue;

	calibrationValue = eeprom_read_byte(0); /* calibration value from last time */
	if (calibrationValue != 0xff)
	{
		OSCCAL = calibrationValue;
	}

	usbInit();
	usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
	i = 0;
	while(--i){             /* fake USB disconnect for > 250 ms */
		wdt_reset();
		_delay_ms(1);
	}
	usbDeviceConnect();

	wdt_enable(WDTO_1S);

	/* activate pull-ups for the buttons */
	BUTTON_PORT |= _BV(BUTTON1_BIT) | _BV(BUTTON2_BIT);

	/* initialize LED output */
	LED_DDR |= _BV(LED_BIT);
	LED_ON;

	/* select clock: 16.5M/1k -> overflow rate = 16.5M/256k = 62.94 Hz (~11ms) */
	TCCR1 = 0x0b;
}
Ejemplo n.º 22
0
void
usb_init(void)
{
#ifdef USB_NET_SUPPORT
  usb_net_init();
#endif

#define USB_DDR_CONFIG(pin)  DDR_CHAR( pin ## _PORT) &= ~(_BV((pin ## _PIN)) | _BV(USB_INT_PIN))
#define USB_PORT_CONFIG(pin)  PORT_CHAR( pin ## _PORT) &= ~(_BV((pin ## _PIN)) | _BV(USB_INT_PIN))
  USB_DDR_CONFIG(USB_DMINUS);
  USB_PORT_CONFIG(USB_DMINUS);
#undef USB_DDR_CONFIG
#undef USB_PORT_CONFIG

  uint8_t i;
  /* Reenummerate the device */
  usbDeviceDisconnect();
  for(i = 0; i < 20; i++){  /* 300 ms disconnect */
    _delay_ms(15);
    wdt_kick();
  }
  usbDeviceConnect();

  /* USB Initialize */
  usbInit();
}
Ejemplo n.º 23
0
int main(void)
{
    uchar   i;

    wdt_enable(WDTO_1S);
    /* If you don't use the watchdog, replace the call above with a wdt_disable().
     * On newer devices, the status of the watchdog (on/off, period) is PRESERVED
     * OVER RESET!
     */
    /* RESET status: all port bits are inputs without pull-up.
     * That's the way we need D+ and D-. Therefore we don't need any
     * additional hardware initialization.
     */
    odDebugInit();
    DBG1(0x00, 0, 0);       /* debug output: main starts */
    usbInit();
    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
    i = 0;
    while(--i){             /* fake USB disconnect for > 250 ms */
        wdt_reset();
        _delay_ms(1);
    }
    usbDeviceConnect();
    sei();
    ledmatrix7219d88_init();

    DBG1(0x01, 0, 0);       /* debug output: main loop starts */
    for(;;){                /* main event loop */
        DBG1(0x02, 0, 0);   /* debug output: main loop iterates */
        wdt_reset();
        usbPoll();
	ledmatrix7219d88_setmatrix(0, rows);
    }
    return 0;
}
Ejemplo n.º 24
0
int main(void)
{

    uchar i;

    wdt_enable(WDTO_1S);
    wdt_disable();

    usbInit();

    usbDeviceDisconnect();

    i = 0;
    while(--i){
        wdt_reset();
        _delay_ms(1);
    }
	
    _delay_ms(250);
    usbDeviceConnect();
    sei();

    for(;;){
        //wdt_reset();
        usbPoll();
    }
    return 0;
}
Ejemplo n.º 25
0
int main(void)
{
    wdt_reset();
    wdt_enable(WDTO_120MS);

    usbInit();
    usbDeviceDisconnect();

    uint8_t t;
    for (t=255; t; t--) {
        _delay_ms(1);
        wdt_reset();
    }


    usbDeviceConnect();
    sei();

    gpib_init();

    for (;;) {
        usbPoll();
        wdt_reset();
    }
}
Ejemplo n.º 26
0
Archivo: main.c Proyecto: age/mss
void
configure (void)
{
  /* usb stuff. make the host re-enumerate our device */
  cli ();
  usbDeviceDisconnect ();
  /* configure timer 2 for calling usbPoll() */
  TIMSK2 = _BV (TOIE2);         /* overflow interrupt enabled */
  TCCR2B = _BV (CS02) | _BV (CS01) | _BV (CS00);        /* set prescaler to 1024, timer starts */
  /* end of usb stuff  */

  /* display configuration */
  d_status = &display[0];
  display[LCD_DISP_LENGTH] = '\0';
  d_content = &display[LCD_DISP_LENGTH + 1];
  display[LCD_DISP_LENGTH * 2 + 1] = '\0';
  lcd_init (LCD_DISP_ON);
  /* end display configuration */
  /* temperature sensors */
  t_sensors_count = search_sensors ();
  if (t_sensors_count)
    {
      have_ts = 1;
      d_status_update ("Found %d DS18B20", t_sensors_count);
      d_update ();
    }
  /* end if temperature sensors setup */
  /* twi/accelerometer configuration */
  i2c_init ();
  /* don't hurry! */
  _delay_ms (1000);
  if (!lis_initialize (0, 1, 0, 1))
    {
      have_ac = 1;
      d_content_update ("Found LIS302DL");
      d_update ();
    }
  /* end of accelerometer configuration */
  _delay_ms (1500);
  /* configure timer 0 for button state detection */
  TIMSK0 = _BV (TOIE0);         /* enable overflow interrupt */
  TCCR0B = _BV (CS02) | _BV (CS00);     /* set prescaler to 1024, timer starts */
  PORTD |= _BV (PD3) | _BV (PD4);       /* pullup for buttons */
  /* end if button detection setup */
  /* ADC configuration goes here */
  ADMUX = _BV (REFS0);
  ADCSRA = _BV (ADEN) | _BV (ADPS2) | _BV (ADPS1) | _BV (ADPS0);
  PORTC |= _BV (PC0) | _BV (PC1);
  /* end of ADC configuration */

  /* clear the display */
  d_content_update (" ");
  d_status_update (" ");
  d_update ();

  usbDeviceConnect ();
  usbInit ();
  sei ();
}
Ejemplo n.º 27
0
static inline void initForUsbConnectivity(void) {
    usbInit();
    /* enforce USB re-enumerate: */
    usbDeviceDisconnect();  /* do this while interrupts are disabled */
    _delay_ms(500);
    usbDeviceConnect();
    sei();
}
Ejemplo n.º 28
0
void setupUSB() {
    usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
    _delay_ms(300UL);/* fake USB disconnect for > 250 ms */
    usbDeviceConnect();
    usbInit();
    sei();
	usbPoll();
}
Ejemplo n.º 29
0
/****************************************************************************
 * main()																	*
 *																			*
 *																			*
 ***************************************************************************/
int main(void) {
	
	uchar i;
	uchar calibrationValue;


    calibrationValue = eeprom_read_byte(0); /* calibration value from last time */
    if(calibrationValue != 0xff){
        OSCCAL = calibrationValue;
    }

	i2c_init();
	
    usbInit();
    usbDeviceDisconnect(); 

    i = 0;
    while(--i) {
        _delay_ms(1);
    }

    usbDeviceConnect();

	DDRB &= ~_BV(DDB1);			// input from slave to indicate a msg is waiting

/////////
//	DDRB = 0b0010; // set pb1 as output
/////////
	
	sei();

    for(;;) {

        usbPoll();

		if (PINB & _BV(PB1)) {
			while (PINB & _BV(PB1)) {
				// wait until off
			}

			i2c_start((DEVICE_ID << 1) + I2C_READ);
			action = i2c_read(0);
			i2c_stop();

			if (action <= sizeof(keys)/sizeof(uchar)) {
				reportCount = 0;
			}
		}

		if(usbInterruptIsReady() && (reportCount < 2)){ /* we can send another key */
        	buildReport();
           	usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
        }

    }

    return 0;
}
Ejemplo n.º 30
0
int main(void)
{
    // Lights, backlights, and fan initialization
    set_output(F1DD,F1PIN);
    set_output(F2DD,F2PIN);
    set_output(LDD,LPIN);
    set_output(BLDD,BLPIN);
    set_high(LPORT,BLPIN);

    TCCR0A = 0xA3;					// Timer0, channels A and B to Fast PWM Mode
    TCCR2A = 0x23;					// Timer2, channel B to Fast PWM Mode
    TCCR0B = 0x05;					// Prescaler is 1024 to give MOSFETS plenty of time
    TCCR2B = 0x07;
    OCR0A = 0xFF;					// Rev up fans for 2s to avoid stalling
    OCR0B = 0xFF;
    _delay_ms(2000);
    OCR0A = 0x7F;					// Reduce fans to 50% power (127)
    OCR0B = 0x7F;
    uchar i;
    for (i=0; i<3; i++) {				// Blink lights to signal life
        OCR2B = 0xFF;
        _delay_ms(200);
        OCR2B = 0x00;
        _delay_ms(200);
    }
    OCR2B = 0x14;					// Init lights at low brightness (20)


    // LCD initialization
    _delay_ms(200);
    CHA_LCDinit();
    CHA_LCDclr();
    CHB_LCDinit();
    CHB_LCDclr();
    CHA_LCDstringLine(lcdinit,0);	// LCD ready to go!

    // USB initialization
    wdt_enable(WDTO_1S); 			// Enable 1s watchdog timer
    usbInit();
    usbDeviceDisconnect(); 			// Enforce re-enumeration
    for(i = 0; i<200; i++) { 		// Wait 200 ms
        wdt_reset();				// Keep the watchdog happy
        _delay_ms(1);
    }
    usbDeviceConnect();
    sei(); 							// Enable interrupts after re-enumeration
    CHB_LCDstringLine(usbinit,0);	// USB ready to go!

    while(1) {						// Feed watchdog and poll USB forever
        wdt_reset();
        usbPoll();
    }

    return 0;
}