コード例 #1
0
ファイル: main.c プロジェクト: agural/Photuris
int __attribute__((noreturn)) main(void) {
    /* initialize hardware */
    bootLoaderInit();
    odDebugInit();
    DBG1(0x00, 0, 0);
    /* jump to application if jumper is set */
    if(bootLoaderCondition()) {
        uchar i = 0, j = 0;
#ifndef TEST_MODE
        GICR = (1 << IVCE);  /* enable change of interrupt vectors */
        GICR = (1 << IVSEL); /* move interrupts to boot flash section */
#endif
        initForUsbConnectivity();
        do { /* main event loop */
            wdt_reset();
            usbPoll();
#if BOOTLOADER_CAN_EXIT
            if(exitMainloop) {
#if F_CPU == 12800000
                break;  /* memory is tight at 12.8 MHz, save exit delay below */
#endif
                if(--i == 0) {
                    if(--j == 0)
                        break;
                }
            }
#endif
        } while(bootLoaderCondition());
    }
    leaveBootloader();
}
コード例 #2
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;
}
コード例 #3
0
ファイル: main.c プロジェクト: baracudaz/usb-sht
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 */
}
コード例 #4
0
ファイル: main.c プロジェクト: AkashGutha/avr
int main(void)
{

    wdt_enable(WDTO_1S);
    odDebugInit();
    hardwareInit();
    usbInit();

    intr3Status = 0;
    sendEmptyFrame  = 0;

    sei();
    for(;;){    /* main event loop */
        wdt_reset();
        usbPoll();
        uartPoll();

#if USB_CFG_HAVE_INTRIN_ENDPOINT3
        /* We need to report rx and tx carrier after open attempt */
        if(intr3Status != 0 && usbInterruptIsReady3()){
            static uchar serialStateNotification[10] = {0xa1, 0x20, 0, 0, 0, 0, 2, 0, 3, 0};

            if(intr3Status == 2){
                usbSetInterrupt3(serialStateNotification, 8);
            }else{
                usbSetInterrupt3(serialStateNotification+8, 2);
            }
            intr3Status--;
        }
#endif
    }

    return 0;
}
コード例 #5
0
ファイル: main.c プロジェクト: deanmao/laptop_alarm
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);
        }
    }
}
コード例 #6
0
ファイル: AVRflash.c プロジェクト: gpauli/AVRflash
int main(void) {
  // this provides a heartbeat on pin 9, so you can tell the software is running.
  uint8_t hbval=128;
  int8_t hbdelta=8;
  uint8_t osc = 0;
  uint8_t c = 0;
  sei();
  /* set LED pin as output */
  sbi(FLASH_LED_DDR,FLASH_LED);
  sbi(FLASH_LED_DDR,FLASH_LED1);
  osc = OSCCAL;
  odDebugInit();
  DBG1(0x01,&osc,1);

  TCCR1B = 0;
  // set timer 1 prescale factor to 64
  sbi(TCCR1B, CS11);
  sbi(TCCR1B, CS10);
  // put timer 1 in 8-bit phase correct pwm mode
  sbi(TCCR1A, WGM10);

  while (1) {
    DBG1(0x02,0,0);
  JB:
    //sbi(FLASH_LED_PORT,FLASH_LED);
    //cbi(FLASH_LED_PORT,FLASH_LED);
    //asm("nop\n");
    if (hbval > 192) hbdelta = -hbdelta;
    if (hbval < 32) hbdelta = -hbdelta;
    hbval += hbdelta;
    analogWrite(hbval);
    _delay_ms(40);
    if ( !(UCSRA & (1<<RXC))) {
      goto JB;
    }
    c = UDR;
    DBG1(0x03,&c,1);
    if ( c == '+' ) {
      osc++;
    } else if ( c == '-' ) {
      osc--;
    } else if ( c == '0' ) {
      hbval=0;
      hbdelta=0;
    } else if ( c == '1' ) {
      hbval=255;
      hbdelta=0;
    } else if ( c == 'd' ) {
      hbval=128;
      hbdelta=8;
    } else if ( c == 'o' ) {
      hbval=254;
      hbdelta=0;
    }
    OSCCAL = osc;
    DBG1(0x11,&osc,1);
    DBG1(0x12,&hbval,1);
    DBG1(0x13,&hbdelta,1);
  }
}
コード例 #7
0
ファイル: main.c プロジェクト: 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;
}
コード例 #8
0
ファイル: main.c プロジェクト: purcaro/panda-display
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;
}
コード例 #9
0
ファイル: main.c プロジェクト: esrijan/ddk-software
int __attribute__((noreturn)) main(void)
{
    unsigned int blink_cnt = 0;

    /* initialize hardware */
    bootLoaderInit();
    /*
     * Calling the function below for it to get included in the bootloader.
     * Also, making sure that it actually doesn't do anything. And hence,
     * passing an unaligned address 0x0001, for the function to fail.
     */
#if (FLASHEND) > 0xFFFF
    flash_write_block(0x00000001, NULL);
#else
    flash_write_block(0x0001, NULL);
#endif
    odDebugInit();
    DBG1(0x00, 0, 0);
    /* jump to application if jumper is set */
    if(bootLoaderCondition()){
#ifndef TEST_MODE
        uint8_t gicr;

        gicr = GICR;
        GICR = gicr | (1 << IVCE);  /* enable change of interrupt vectors */
        GICR = gicr | (1 << IVSEL); /* move interrupts to boot flash section */
#endif
        DBG1(0x02, 0, 0);
        initForUsbConnectivity();
        do{ /* main event loop */
            //DBG2(0x03, 0, 0);
            wdt_reset();
            usbPoll();

            /* The following piece of code indicates being in bootloader */
            if (++blink_cnt == 60000)
            {
                blink_cnt = 0;
                toggleLED();
                //DBG2(0x04, 0, 0);
            }

            //DBG2(0x05, 0, 0);
#if BOOTLOADER_CAN_EXIT
            if(exitMainloop){
                break;
            }
#endif
        }while(1);
    }
    leaveBootloader();
}
コード例 #10
0
ファイル: main.c プロジェクト: beigenmann/PPM2USB
int main(void) {
    wdt_enable(WDTO_1S);

    odDebugInit();
    DBG1(0x00, 0, 0);  /* debug output: main starts */

    ppmInit();

    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();
	
	DDRC|=3; // LEDs: Output

    sei();
    DBG1(0x01, 0, 0);  /* debug output: main loop starts */

    uchar changed=0;
    ppmNewData=1;
    for(;;){ /* main event loop */
        DBG1(0x02, 0, 0);  /* debug output: main loop iterates */
        wdt_reset();
        usbPoll();

        if (ppmNewData) {
            ppmNewData=0;
            for (i=0;i<sizeof(reportBuffer);i++) {
                unsigned char val=ppmGet(i);
                if (reportBuffer[i]!=val) {
                    reportBuffer[i]=val;
                    changed=1;
                }
            }
            if (changed) {
                if(usbInterruptIsReady()){
                    changed=0;
                    // called after every poll of the interrupt endpoint
                    DBG1(0x03, 0, 0);  // debug output: interrupt report prepared
                    usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
                }

            }
        }
    }
}
コード例 #11
0
ファイル: main.c プロジェクト: Bluebie/USBaspLoader-tiny85
int __attribute__((noreturn)) main(void)
{
    uint16_t idlePolls = 0;
#ifdef APPCHECKSUM
    int validApp = 0;
#endif

    /* initialize  */
    wdt_disable();      /* main app may have enabled watchdog */
#ifdef TINY85MODE
    tiny85FlashInit();
#endif
    bootLoaderInit();
    odDebugInit();
    DBG1(0x00, 0, 0);

#ifdef APPCHECKSUM
    validApp = testForValidApplication();
#endif

#ifndef TINY85MODE
#	ifndef NO_FLASH_WRITE
    GICR = (1 << IVCE);  /* enable change of interrupt vectors */
    GICR = (1 << IVSEL); /* move interrupts to boot flash section */
#	endif
#endif

    if(bootLoaderCondition()){
        initForUsbConnectivity();
        do{
            usbPoll();
            _delay_us(100);
            idlePolls++;
#ifdef TINY85MODE
            tiny85FlashWrites();
#endif

#if BOOTLOADER_CAN_EXIT
            // exit if requested by the programming app, or if we timeout waiting for the pc with a valid app
            if(requestBootLoaderExit || AUTO_EXIT_CONDITION()){
                _delay_ms(10);
                break;
            }
#endif
        }while(bootLoaderCondition());  /* main event loop */
    }
    leaveBootloader();
}
コード例 #12
0
ファイル: main.c プロジェクト: uISP/uisp-appsources
int	main(void) {
  wdt_enable(WDTO_1S);

#if DEBUG_LEVEL > 0
  /* let debug routines init the uart if they want to */
  odDebugInit();
#else
#ifdef DEBUG
  /* quick'n dirty uart init */
  UCSRB |= _BV(TXEN);
  UBRRL = F_CPU / (19200 * 16L) - 1;
#endif
#endif

#ifdef DEBUG
  stdout = &mystdout;
#endif

  DEBUGF("i2c-tiny-usb - (c) 2006 by Till Harbaum\n");

  i2c_init();

#ifdef DEBUG
  i2c_scan();
#endif

  /* clear usb ports */
//   USB_CFG_IOPORT   &= (uchar)~((1<<USB_CFG_DMINUS_BIT)|(1<<USB_CFG_DPLUS_BIT));

  /* make usb data lines outputs */
//   USBDDR    |= ((1<<USB_CFG_DMINUS_BIT)|(1<<USB_CFG_DPLUS_BIT));

  /* USB Reset by device only required on Watchdog Reset */
//   _delay_loop_2(40000);   // 10ms

  /* make usb data lines inputs */
//   USBDDR &= ~((1<<USB_CFG_DMINUS_BIT)|(1<<USB_CFG_DPLUS_BIT));

  usbInit();

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

  return 0;
}
コード例 #13
0
ファイル: main.c プロジェクト: fabiobaltieri/rf-synthesizer
int __attribute__((noreturn)) main(void)
{
	uint16_t blink = 0;
	volatile int zero = 0;

	loop = 0;

	odDebugInit();
	DBG1(0x00, 0, 0);

	uchar i = 0, j = 0;
#ifndef TEST_MODE
	GICR = (1 << IVCE);  /* enable change of interrupt vectors */
	GICR = (1 << IVSEL); /* move interrupts to boot flash section */
#endif

	LED_DDR |= LED;

	initForUsbConnectivity();
	do{ /* main event loop */
		wdt_reset();
		usbPoll();
#if BOOTLOADER_CAN_EXIT
		if(exitMainloop){
#if F_CPU == 12800000
			break;  /* memory is tight at 12.8 MHz, save exit delay below */
#endif
			if(--i == 0){
				if(--j == 0)
					break;
			}
		}
#endif
		if (blink++ == 0) {
			LED_PORT ^= LED;
			if (loop++ > 10 && (pgm_read_byte(zero) != 0xff))
				exitMainloop = 1;
		}
	} while (1);

	LED_DDR &= ~LED;
	LED_PORT &= ~LED;

	leaveBootloader();
}
コード例 #14
0
ファイル: psgroove.c プロジェクト: ixhundred/psgroove
void SetupHardware(void)
{
   usbDeviceConnect();
   odDebugInit();
	/* Disable watchdog if enabled by bootloader/fuses */
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	/* Disable clock division */
	clock_prescale_set(clock_div_1);

	/* Setup timer */
	TCCR1B = 0x03;  /* timer rate clk/64 */
	TIMSK1 = 0x01;

	/* Hardware Initialization */
	SetupLEDs();
   usbInit();
	sei(); 
}
コード例 #15
0
ファイル: main.c プロジェクト: elcerdo/avr
int main(void) {
    uint8_t i;

    keypad_init();
    led_init();
    status_init();
    layers_init();

    for (i=0; i<8; i++) led_send_command(i+1,0x00);

    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();
    DBG1(0x01, 0, 0);       /* debug output: main loop starts */
    for(;;){                /* main event loop */
        wdt_reset();
        usbPoll();
    }

    keypad_free();
    layers_free();

    return 0;
}
コード例 #16
0
ファイル: converter.c プロジェクト: edboel/projects
int main(void)
{
uchar   i;

    wdt_enable(WDTO_1S);
    odDebugInit();
    DDRD = ~(1 << 2);   /* all outputs except PD2 = INT0 */
    PORTC = 0xFF;  /* internall pullup */ 
    DDRC = 0;  /* portc all inputs  */
    PORTD = 0;
    PORTB = 0;          /* no pullups on USB pins */
/* We fake an USB disconnect by pulling D+ and D- to 0 during reset. This is
 * necessary if we had a watchdog reset or brownout reset to notify the host
 * that it should re-enumerate the device. Otherwise the host's and device's
 * concept of the device-ID would be out of sync.
 */
    DDRB = ~USBMASK;    /* set all pins as outputs except USB */
    ledstatus= 0xAA;
    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
    i = 0;
    while(--i){         /* fake USB disconnect for > 500 ms */
        wdt_reset();
        _delay_ms(2);
    }
    usbDeviceConnect();
    TCCR0 = 5;          /* set prescaler to 1/1024 */
    usbInit();
    sei();
    for(;;){    /* main event loop */
        wdt_reset();
        usbPoll();
        if(TIFR & (1 << TOV0)){
            TIFR |= 1 << TOV0;  /* clear pending flag */
            timerInterrupt();
        }
    }
    return 0;
}
コード例 #17
0
ファイル: VUSB.c プロジェクト: aBaTaPbl4/BuildOrb2
int main(void)
{
uchar   i;

//DDRA = 0xff;
//PORTA = 0xff;

    wdt_enable(WDTO_1S);
    /* Даже если Вы не используете сторожевой таймер (watchdog), выключите его здесь. На более новых 
     *  микроконтроллерах состояние watchdog (вкл\выкл, период) СОХРАНЯЕТСЯ ЧЕРЕЗ СБРОС!
     */
    DBG1(0x00, 0, 0);       /* отладочный вывод: стартует main */
    /* RESET статус: все биты портов являются входамибез нагрузочных резисторов (pull-up).
     *  Это нужно для D+ and D-. Таким образом, нам не нужна какая-либо дополнительная 
     *  инициализация портов.
     */
    odDebugInit();
    usbInit();
    usbDeviceDisconnect();  /* принудительно запускаем ре-энумерацию, делайте это, когда прерывания запрещены! */
    i = 0;
    while(--i)
    {             /* иммитируем USB дисконнект на время > 250 мс */
        wdt_reset();
        _delay_ms(1);
    }
    usbDeviceConnect();
    LED_PORT_DDR |= _BV(LED_BIT);   /* делаем ножку, куда подключен LED, выходом */
    sei();
    DBG1(0x01, 0, 0);       /* отладочный вывод: стартует цикл main */
    for(;;){                /* цикл событий main */
#if 0   /* это несколько агрессивно для отладочного вывода */
        DBG2(0x02, 0, 0);   /* отладочный вывод: повторы цикла main */
#endif
        wdt_reset();
        usbPoll();
    }
    return 0;
}
コード例 #18
0
ファイル: main.c プロジェクト: CalvinE/v-usb
int __attribute__((noreturn)) 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();
    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();
        if(usbInterruptIsReady()){
            /* called after every poll of the interrupt endpoint */
            advanceCircleByFixedAngle();
            DBG1(0x03, 0, 0);   /* debug output: interrupt report prepared */
            usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
        }
    }
}
コード例 #19
0
ファイル: main.c プロジェクト: powertomato/vusbmicro
int main(void)
{
    uchar   i;
    uchar   calibrationValue;

    calibrationValue = eeprom_read_byte(0); /* calibration value from last time */
    if(calibrationValue != 0xff) {
        OSCCAL = calibrationValue;
    }
    odDebugInit();
    usbDeviceDisconnect();
    for(i=0; i<20; i++) { /* 300 ms disconnect */
        _delay_ms(15);
    }
    usbDeviceConnect();

    wdt_enable(WDTO_1S);
    timerInit();
    TimerDelay = 630; /* initial 10 second delay */

    usbInit();
    sei();
    for(;;) {   /* main event loop */
        wdt_reset();
        usbPoll();

// lets have something waiting in here  or mabe generate a random number

        if(usbInterruptIsReady() && reportCount < 2) { /* we can send another key */
            buildReport();
            usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
        }
        timerPoll();
    }
    return 0;
}
コード例 #20
0
ファイル: main.c プロジェクト: mazzoo/usbflattinyheart
int __attribute__((noreturn)) main(void)
{
    int   led_timer   = 0;
    uchar led_counter = 0;

    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();
#if 0
    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();
#endif
    sei();

    /* usbflattiny code */
    DDRB |= (1<<PORTB5) | (1<<PORTB4) | (1<<PORTB3) | (1<<PORTB1);

    PORTB |= (1<<PORTB5);
    PORTB |= (1<<PORTB3);
    PORTB &= ~(1<<PORTB4);
    PORTB &= ~(1<<PORTB1);
    /* /usbflattiny code */

    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();
        if(usbInterruptIsReady()){
            /* called after every poll of the interrupt endpoint */
            advance_mouse();
            DBG1(0x03, 0, 0);   /* debug output: interrupt report prepared */
            usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
        }
        /* usbflattiny code */
        led_timer++;
        if (led_timer == 23*1000)
        {
            led_counter++;
            if (led_counter == 0x10) led_counter = 0;
            if (led_counter & 0x1) PORTB |= (1<<PORTB4); else PORTB &= ~(1<<PORTB4);
            if (led_counter & 0x2) PORTB |= (1<<PORTB3); else PORTB &= ~(1<<PORTB3);
            if (led_counter & 0x4) PORTB |= (1<<PORTB5); else PORTB &= ~(1<<PORTB5);
            if (led_counter & 0x8) PORTB |= (1<<PORTB1); else PORTB &= ~(1<<PORTB1);
            led_timer = 0;
        }
        /* /usbflattiny code */
    }
}
コード例 #21
0
ファイル: main.c プロジェクト: jjculber/diykeyboard
int main(void)
{
	int adcOld[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
	uchar key, lastKey = 0;
	uchar keyDidChange = 0;
	uchar midiMsg[8];
	uchar channel = 0;
	int value;
	uchar iii;

	wdt_enable(WDTO_1S);
	hardwareInit();
	odDebugInit();
	usbInit();

	sendEmptyFrame = 0;

	sei();

	// only ADC channel 6 and channel 7 are used, start with channel 6
	channel = 6;
	for (;;) {		/* main event loop */
		wdt_reset();
		usbPoll();

		key = keyPressed();
		if (lastKey != key)
			keyDidChange = 1;

		if (usbInterruptIsReady()) {
			if (keyDidChange) {
				PORTC ^= 0x40;	// DEBUG LED
				/* use last key and not current key status in order to avoid lost
				   changes in key status. */
				// up to two midi events in one midi msg.
				// For description of USB MIDI msg see:
				// http://www.usb.org/developers/devclass_docs/midi10.pdf
				// 4. USB MIDI Event Packets
				iii = 0;
				if (lastKey) {	/* release */
					midiMsg[iii++] = 0x08;
					midiMsg[iii++] = 0x80;
					midiMsg[iii++] = lastKey;
					midiMsg[iii++] = 0x00;
				}
				if (key) {	/* press */
					midiMsg[iii++] = 0x09;
					midiMsg[iii++] = 0x90;
					midiMsg[iii++] = key;
					midiMsg[iii++] = 0x7f;
				}
				if (8 == iii)
					sendEmptyFrame = 1;
				else
					sendEmptyFrame = 0;
				usbSetInterrupt(midiMsg, iii);
				keyDidChange = 0;
				lastKey = key;
			} else {	// check analog input if no key event 
				value = adc(channel);	// 0..1023
				// hysteresis
				if (adcOld[channel] - value > 7 || adcOld[channel] - value < -7) {	// analog value has changed
					PORTC ^= 0x80;	// DEBUG LED
					adcOld[channel] = value;
					// MIDI CC msg
					midiMsg[0] = 0x0b;
					midiMsg[1] = 0xb0;
					midiMsg[2] = channel + 70;	// cc 70..77 
					midiMsg[3] = value >> 3;
					sendEmptyFrame = 0;
					usbSetInterrupt(midiMsg, 4);
				}
				channel++;
				channel &= 0x07;
				// TEST start with channel 6 
				if (0 == channel)
					channel = 6;
			}
		}		// usbInterruptIsReady()
	}			// main event loop
コード例 #22
0
ファイル: atmega8_receiver.c プロジェクト: nixz/covise
// ----------------------------------------------------------------------------
// main
// ----------------------------------------------------------------------------
int main(void)
{
    ///////////////////////////////////////////////////////////////////////////
    // low level init
    // IO-pins and pullups

    _delay_ms(100);

    //all unused ports as input with pullups

    DDRC &= ~((1 << DDC0) | (1 << DDC1) | (1 << DDC2) | (1 << DDC3) | (1 << DDC4) | (1 << DDC5));
    PORTC |= ((1 << DDC0) | (1 << DDC1) | (1 << DDC2) | (1 << DDC3) | (1 << DDC4) | (1 << DDC5));
    DDRB &= ~((1 << DDB1));
    PORTB |= ((1 << DDB1));
    DDRD &= ~((1 << DDD4) | (1 << DDD5) | (1 << DDD6) | (1 << DDD7));
    PORTD |= ((1 << DDD4) | (1 << DDD5) | (1 << DDD6) | (1 << DDD7));

    // leds
    // DDD2 - red led
    DDRD |= (1 << DDD1);
    PORTD &= ~((1 << DDD1));

    // do SPI init after seting CE to LOW, this is important, otherwise the RFM73 module does not always answer to SPI requests.

    //out
    RFM73_CSN_DIR |= (1 << RFM73_CSN_PIN);
    RFM73_CE_DIR |= (1 << RFM73_CE_PIN);
    //in
    RFM73_IRQ_DIR &= ~(1 << RFM73_IRQ_PIN);
    RFM73_CE_LOW;

    DDRD |= (1 << USB_CFG_DMINUS_BIT) | (1 << USB_CFG_DPLUS_BIT);

    uchar i;
    odDebugInit();
    usbDeviceDisconnect();
    for (i = 0; i < 20; i++)
    { /* 300 ms disconnect */
        _delay_ms(15);
    }
    usbDeviceConnect();

    usbInit();
    sei();
    while (1)
    {

        usbPoll();
        _delay_ms(10);
        if (usbInterruptIsReady() && nextDigit != NULL)
        { // we can send another key
            buildReport();
            usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
            if (*++nextDigit == 0xff) // this was terminator character
                nextDigit = NULL;
        }
    }

    // low level init
    // IO-pins and pullups
    spiInit();
    spiSelect(csNONE);
    cbi(PORTD, LED_RED);
    _delay_ms(500);

    // ADC
    // TODO

    // TIMER INIT
    // TODO

    //////////////////////////////////////////////////////////////////////////
    // schrott

    unsigned char buf[32];
    // char charValue [6] = "      ";
    // int len = 6;

    //////////////////////////////////////////////////////////////////////////
    // start main loop

    // state machine
    // state 0  - exit
    // state 1  - choose transmitter or receiver
    // state 2  - init of transmitter module
    // state 3  - wait for button press and send something
    // state 10 - init and power up RX modules

    uint8_t smState = 1;

    //sei();

    sbi(PORTD, LED_RED);

    // RFM70
    // write registers
    // light green led if rfm70 found
    // light red led if rfm70 not found
    if (rfm70InitRegisters())
    {
        cbi(PORTD, LED_RED);
    }
    else
    {
        sbi(PORTD, LED_RED);
    }

    while (smState != 0)
    {
        while (1)
        {

            usbPoll();
            _delay_ms(10);
            if (usbInterruptIsReady() && nextDigit != NULL)
            { // we can send another key
                buildReport();
                usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
                if (*++nextDigit == 0xff) // this was terminator character
                    nextDigit = NULL;
            }
        }
        //------------------------------------------------------------------------
        // Receiver State Machine
        //------------------------------------------------------------------------
        switch (smState)
        {
        case 1:
        {
            // start state
            // we are the receiver
            smState = 10;
            break;
        }
        case 10:
        {

            // init and power up modules
            // goto RX mode
            rfm70SetModeRX();

            smState = 11;
            break;
        }
        case 11:
        {
            // try to receive something

            // _delay_ms(100);
            rfm70ReceivePayload(buf);

            break;
        }
        }
    }
}
コード例 #23
0
ファイル: main.c プロジェクト: edy555/avr-hidtemp
int main(void)
{
    uchar   i;

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

    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 */

    sbi(DDRB, WHITE_LED);
    sbi(DDRB, YELLOW_LED);
    cbi(DDRB, 4);
    cbi(PORTB, 4);
    sbi(MCUCR, PUD);

    timerInit();	//Create a timer that will trigger a flag at a ~60hz rate
    adcInit();		//Setup the ADC conversions
    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();
    //set_sleep_mode(SLEEP_MODE_PWR_SAVE);
    //sleep_mode();
    //sleep_enable();
    sei();
    DBG1(0x01, 0, 0);       /* debug output: main loop starts */
    for(;;) {               /* main event loop */
        DBG1(0x02, 0, 0);   /* debug output: main loop iterates */
        //sleep_cpu();
        sbi(PORTB, YELLOW_LED);
        wdt_reset();
        usbPoll();
        cbi(PORTB, YELLOW_LED);

        if(usbInterruptIsReady()) {
            /* called after every poll of the interrupt endpoint */
            reportBuffer.adcvalue = getAdcValue();
            DBG1(0x03, 0, 0);   /* debug output: interrupt report prepared */
            usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
        }

        timerPoll();
        adcPoll();
        _delay_ms(5);
    }
    return 0;
}
コード例 #24
0
ファイル: main.c プロジェクト: valentinz/avr-usb-keyboard
int main(void) {
	uchar i;
	DDRC = 0x00;
	DDRA = 0xff;
	PORTA = 0x00;
	DDRD &= ~(1<<PD3 | 1<<PD4);

	while ((PINC & 0x01) == 1) {
	}
	PORTA = 0xF0;

	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();


	// Enable timer0
	TCCR0 = (1<<CS10) | (1<<CS01) | (1<<CS00);     // CTC, XTAL / 64
	TIMSK |= (1<<TOIE0);

	// Enable INT1 for falling edges
	MCUCR |= (1<<ISC11);
	MCUCR &= ~(1<<ISC10);
	GICR |= (1<<INT1);

	sei();

	uint8_t pinC = 0x1F;
	uint8_t last = 0x1F;
	uint8_t history[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	uint8_t first = 1;
	uint8_t use, j;
	uint8_t historyPosition = 0;
	uint8_t beep = 0;


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

		//reportBuffer.mod = MOD_SHIFT_LEFT;
		//reportBuffer.key = KEY_A + (PINC & 0x0F);

		if (counter > 0x1FF && counter < 0x2FF && beep == 1) {
			PORTA |= (1<<PA6);
		} else {
			PORTA &= ~(1<<PA6);
		}

		history[(historyPosition++) & 0xF] = (PINC & 0x1F);
		first = history[(historyPosition+1) & 0xF];
		use = 1;
		for (j=1; j < 16; j++) {
			if (history[(historyPosition+1+j) & 0xF] != first) {
				use = 0;
				break;
			}
		}

		if (use == 1) {
			last = first;
			if (counter > 0x1FF && beep == 0) {

				if (last == 0x13) {
					PORTA |= (1<<PA6);
					beep = 1;
					sendStack[sendStackAdd] = 0x50;
					sendStackAdd = (sendStackAdd+1)&0x03;
				}
			}
		}
		if (last != pinC) {
			sendStack[sendStackAdd] = KEY_A;
			if (pinC != 0x1F) {
//			PORTA |= (1<<PA6);
				if (counter < 0x1FF) {
					sendStack[sendStackAdd] = (pinC & 0x1F);
				} else {
					sendStack[sendStackAdd] = 0x20 + (pinC & 0x1F);
				}
				sendStackAdd = (sendStackAdd+1)&0x03;
				beep = 0;
			} else {
				beep = 1;
			}
			pinC = last;
			counter = 0;
		}

		if(usbInterruptIsReady()) {
			reportBuffer.mod = 0;
			reportBuffer.key = 0;

			if (sendStackSend != sendStackAdd) {
				switch (sendStack[sendStackSend]) {
				case 0x1E: // button 1 short
					reportBuffer.mod = MOD_SHIFT_LEFT | MOD_CONTROL_LEFT;
					reportBuffer.key = KEY_TAB;
					break;
				case 0x1D: // button 2 short
					reportBuffer.mod = MOD_CONTROL_LEFT;
					reportBuffer.key = KEY_TAB;
					break;
				case 0x1B: // button 3 short
					reportBuffer.mod = 0;
					reportBuffer.key = KEY_UP_ARROW;
					break;
				case 0x17: // button 4 short
					reportBuffer.mod = 0;
					reportBuffer.key = KEY_DOWN_ARROW;
					break;
				case 0x0F: // button 5 short
					reportBuffer.mod = 0;
					reportBuffer.key = KEY_RETURN;
					break;
				case 0x3E: // button 1 long
					reportBuffer.mod = MOD_CONTROL_LEFT;
					reportBuffer.key = KEY_W;
					break;
				case 0x3D: // button 2 long
					reportBuffer.mod = MOD_SHIFT_LEFT | MOD_CONTROL_LEFT;
					reportBuffer.key = KEY_RETURN;
					break;
				case 0x3B: // button 3 long
					reportBuffer.mod = 0;
					reportBuffer.key = KEY_F5;
					break;
				case 0x37: // button 4 long
					reportBuffer.mod = MOD_ALT_LEFT;
					reportBuffer.key = KEY_POS1;
					break;
				case 0x2F: // button 5 long
					reportBuffer.mod = MOD_ALT_LEFT;
					reportBuffer.key = KEY_LEFT_ARROW;
					break;
				case 0x41: // rotate right
					reportBuffer.mod = 0;
					reportBuffer.key = KEY_TAB;
					break;
				case 0x40: // rotate left
					reportBuffer.mod = MOD_SHIFT_LEFT;
					reportBuffer.key = KEY_TAB;
					break;
				case 0x50: // shutdown
					reportBuffer.mod = MOD_CONTROL_LEFT | MOD_ALT_LEFT;
					reportBuffer.key = KEY_BACKSPACE;
					break;
				}
				sendStackSend = (sendStackSend+1)&0x03;
			}
			usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
		}
		counterLoop++;
	}
	return 0;
}