Пример #1
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
  SetupHardware();
  uint16_t bytesAvailable, currentByte;

  CDC_Device_CreateStream(&tpad_CDC_Interface, &USBSerialStream);
  sei();

  for (;;)
  {

    //
    // Read pressures from 16 buttons
    //
    ButtonStates();

    //
    // Handle incoming bytes
    //
    bytesAvailable = CDC_Device_BytesReceived(&tpad_CDC_Interface);
    while (bytesAvailable--) {
      currentByte = CDC_Device_ReceiveByte(&tpad_CDC_Interface);
      // TODO: implement led updates from host
    }

    CDC_Device_USBTask(&tpad_CDC_Interface);
    USB_USBTask();
  }
}
Пример #2
0
Файл: note.c Проект: Hylian/sdvx
int main(void)
{
  SetupHardware();

  /* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
  CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);

  GlobalInterruptEnable();

  while(1)
  {
    DebounceUpdate();
    EncoderUpdate();
    LedUpdate();

    SendSerial();

    /* Must throw away unused bytes from the host, or it will lock up while waiting for the device */
    CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);

    CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
    HID_Device_USBTask(&Mouse_HID_Interface);
    HID_Device_USBTask(&Keyboard_HID_Interface);

    USB_USBTask();
  }
}
Пример #3
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();

	/* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
	CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	GlobalInterruptEnable();

	_setBrightness(50);

	for (;;)
	{
		/* Must throw away unused bytes from the host, or it will lock up while waiting for the device */
		CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
		CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();

		DS1302_clock_burst_read((uint8_t *) &rtc);

		_setDigit( rtc.Seconds % 10 );
		_setBrightness( 50 );

		_delay_ms(4);
    }
}
Пример #4
0
void
init(void) {
    configured = 0;

    // Start with all pullups off, and all ports input
    DDRB  = 0x00;
    DDRC  = 0x00;
    DDRD  = 0x00;
    PORTB = 0x00;
    PORTC = 0x00;
    PORTD = 0x00;
    
    // Enable some LEDs, just to make sure it loads
    LED_DDRx  = (1 << LED_POWER) | (1 << LED_RX) | (1 << LED_TX);
    LED_PORTx = LEDS_INIT;
    
    // Disable watchdog
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

    // Disable prescaler (the CLKDIV8 fuse is set at the factory)
    clock_prescale_set(clock_div_1);

    // Initialize the SPI bus
    spi_init();
    
    // Initialize the transceiver
    MRF_init();
    
    // Initialize the USB system
	USB_Init();
    
    // Begin the interrupt-based USB checking
    TCCR0A = 0x00; // Disable compare A, B and the PWM
    TCCR0B = 0x04; // Disable force compare, enable divide-by 256 prescaler (31,250 Hz)
    // With the 256 overflow (8-bit) the 31,250 Hz base clock will yield a 122 Hz rate
    // this should be sufficient for the 30 mS rate required by USB (actual is 8mS).
    TIMSK0 = 0x01; // Enable the overflow timer interrupt
    
    // Create the CDC serial stream device
    CDC_Device_CreateStream(&CDC_interface, &USB_USART);
    
    // Setup the internal UART
    // Setup the DDRD for RXD and TXD
    DDRD &= ~(1 << 2);
    DDRD |=  (1 << 3);
    
    // set baud rate (8000000 / (16 * 4800)) - 1 = 103, for 4800 baud
    UBRR1H = 0;
    UBRR1L = 103;
    
    // Enable UART receiver and transmitter.
    UCSR1B = (1 << RXEN1) | (1 << TXEN1);
    
    // Set frame format: asynchronous, 8data, no parity, 1stop bit
    UCSR1C = (1 << UCSZ11)| (1 << UCSZ10);
    
    // Enable interrupts
    sei();
}
Пример #5
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
void initUSBSerial(void)
{
    SetupHardware();

    /* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
    CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);

    stdout = &USBSerialStream;
    stdin = &USBSerialStream;

}
Пример #6
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();

	/* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
	CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);

	sei();

    DDRB  |= (1 << 4);
    PORTB |= (1 << 4);


	for (;;)
	{
        int16_t c = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
        if (c > 0){
            switch (c) {
                case '1':
                    // this will eventually be to strobe the modem on pin of a telit module
                    // set port to output mode and low state
                    // stall for 1000 ms
                    // set port back to high impedance
                    CDC_Device_SendString(&VirtualSerial_CDC_Interface, "received 1\r\n");
                    DDRD  |=  (1 << 0);
                    PORTD &= ~(1 << 0);

                    _delay_ms(1000);
                    DDRD  &= ~(1 << 0);
                    PORTD |=  (1 << 0);
                    break;
                case 'r':
                    // this will be to strobe the reset pin of a telit module
                    CDC_Device_SendString(&VirtualSerial_CDC_Interface, "received r\r\n");
                    PORTB &= ~(1 << 4);
                    _delay_ms(200);
                    PORTB |= (1 << 4);
                    break;
                case '?':
                    // this wil be to inquire abouth the powermon pin of a telit module
                    CDC_Device_SendString(&VirtualSerial_CDC_Interface, "received ?\r\n");
                    PORTB |= ~(1 << 4);
                    break;
                default:
                    CDC_Device_SendString(&VirtualSerial_CDC_Interface, "unrecognized input\r\n");
            }
        }
		CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();
	}
}
Пример #7
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	HardwareInit();

	/* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
	CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);
	stdout = &USBSerialStream;

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	sei();

	//OldButtonState = GetButtonState();
	for (;;)
	{
		RunCommand();
		HandleButtonPress();
	}
}
Пример #8
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();
	setupIO();
	interruptInit();
	/* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
	CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);

	sei();
	
	while (1)
	{
		
		/* Must throw away unused bytes from the host, or it will lock up while waiting for the device */
		CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
		CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();
	}
}
Пример #9
0
// Main program entry point.
int main(void){
  // Disable watchdog if enabled by bootloader/fuses
  MCUSR &= ~(1 << WDRF);
  wdt_disable();

  // Disable clock division
  clock_prescale_set(clock_div_1);

  // Set the LED pins on Port D as output, and default the LED pins to HIGH (off)
  DDRD = 0b00110011;
  PORTD = 0b00110011;

  // Set Entropy pin to input
  DDRC = DDRC & 0b11111011;

  // Hardware Initialization
  USB_Init();

  // Create a regular character stream for the interface so that it can be used with the stdio.h functions
  CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);

  // Enable interrupts
  GlobalInterruptEnable();

  for (;;){
	// Blink the third LED as we gather entropy
	PORTD = PORTD & 0b11101111;
  
  	// Read a bit, and dump it out the USB Serial stream.
	fputc(((PINC & 0b00000100) >> 2) + '0', &USBSerialStream);
	
    // Un-blink the third LED
    PORTD = PORTD | 0b00010000;

    // Must throw away unused bytes from the host, or it will lock up while waiting for the device
    CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);

	// Run the LUFA stuff
    CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
    USB_USBTask();
  }
}
Пример #10
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();

	/* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
	CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	GlobalInterruptEnable();

	for (;;)
	{
		CheckJoystickMovement();

		/* Must throw away unused bytes from the host, or it will lock up while waiting for the device */
		CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);

		CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();
	}
}
Пример #11
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
    
    bitSet(DDRC,7); // HACK DEBUG
    
	SetupHardware();

	/* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
	CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);

	GlobalInterruptEnable();

	for (;;)
	{
		process_bytes();
		
		/*if(do_charge_test){
			charging_test();
		}*/
		
		CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();
	}
}
Пример #12
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	char s1 = 0;
	char data =0;
	SetupHardware();

	/* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
	CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);
	uart_init();
	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	GlobalInterruptEnable();

	for (;;)
	{
		CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();
		s1 = fread(&charIn,1,1,&USBSerialStream);
		if(s1>0){
			bufin[bcount] = charIn;
			bcount++;
			if(charIn == '\r'){
				for(uint8_t i=0; i<bcount; i++){
					fputc(bufin[0],&USBSerialStream);
					uart_write(bufin[i]);
				}
				bcount = 0;
			}else if(bcount>=256){
				bcount=0;
			}
		}
		while(uart_char_is_waiting()){
			data=uart_read();
			fputc(data,&USBSerialStream);
		}
	}
}
Пример #13
0
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();
    uint8_t last_motor_cmd=10;
    uint16_t counter=0;
    seq = 0;
    txBuffer = (uint8_t*)malloc(sizeof(packet_t));
    badPkts = 0;

	/* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
	CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);

// 	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);

     sei();
    ADCSRA |= 0x40; //start ADC conversion
    InitGyro();
 
    CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
    CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
    USB_USBTask();
//     LEDs_ToggleLEDs(LEDS_LED2);

//     uint8_t handOpen = 1;

    for (;;)
    {
        // returns negative on failure, byte value on success
        int16_t rxByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);

		if (!(rxByte < 0)){

            // oddly ReceiveByte returns a 16-bit int
            uint8_t byte = (uint8_t)rxByte;

            // incrementally builds packets byte-by-byte 
            if (PKT_Decoded(byte, &rxPkt, &rxStat) != DECODE_STATUS_INCOMPLETE) {
		togglePD4();
                switch (rxStat.state)
                {
                case DECODE_STATUS_COMPLETE:
                    switch (rxPkt.type) 
                    {
                    case PKTYPE_CMD_SET_ARM_POS:
//                         HL_SetBasePosition(rxPkt.payload[0]);
                        break;
                    case PKTYPE_CMD_SET_BASE_VEL:
		      togglePD4();
		      for(int i=0;i<4;i++)
		        echoback_payload[i] = rxPkt.payload[i];
//  			  HL_setMotor(rxPkt.payload[1],rxPkt.payload[0],rxPkt.payload[3],rxPkt.payload[2]);
 			  setSpeedRamps(rxPkt.payload[1],rxPkt.payload[0],rxPkt.payload[3],rxPkt.payload[2]);
			  last_motor_cmd=0;
			  // h_right,  l_right,  h_left,  l_left
                        break;
                    case PKTYPE_CMD_SET_PWR_STATE:
                        break;
                    case PKTYPE_CMD_ZERO_GYRO:
                        break;
                    case PKTYPE_CMD_TOGGLE_KINECT:
                        Toggle_KIN_EN;
                        break;
//                     case PKTYPE_CMD_TOGGLE_CREATE:
//                         Toggle_CREATE_ON;
//                         if(READ_CREATE_ON) {  // is the create powered?
//                             l_CREATE_CHRG_IND; // disable charging
//                             l_CREATE_PWR_EN;
//                         } else {
//                             h_CREATE_PWR_EN;
//                             h_CREATE_CHRG_IND;
//                         }
//                         break;
/*                    case PKTYPE_CMD_TOGGLE_HAND_STATE:
                        if (!handOpen) {
                            HL_OpenHand();
                            handOpen = 1;
                        } else {
                            HL_CloseHand();
                            handOpen = 0;
                        }
                        break;*/
                    }
                    break;
                case DECODE_STATUS_INVALID:
                    badPkts++; 
                    break;
                }
                rxStat.recvd = 0;
            }
		}

        // FIXME: this const counter check should be replace by timer delta function
		if ((counter % 100) ==0){
 		  transmitMotorBuffer();
  
		  togglePD7();
		}
		if (counter > 1000){
		  togglePD6();
		  if(last_motor_cmd>10)
		    setRamps(0,0);
		  
		  last_motor_cmd++;
//             LEDs_ToggleLEDs(LEDS_LED2);
//             transmitArmState();
//               transmitGyroState();
//               transmitEncoderState();
//               transmitMotorState();
//             transmitBattState();
            counter = 0;
		}

        handleUSB();
//         HL_UpdateState();
		counter++;
	}
}
Пример #14
0
int main(void)
{
	SetupHardware();
	CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);
	GlobalInterruptEnable();

	_delay_ms(5000);
	uart_puts("ATI\r");
	_delay_ms(500);

	numbers = eeprom_read_word(( uint16_t *)1);

	for (;;)
	{
		if(ConfigSuccess)
		{
			int16_t b = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);

			if(b > -1)
			{
				if(b == '*')
				{
					iRead = 0;
				}

				if(b == '\r' || b == 0x1A)
				{
					uart_puts("\",129,\"aa\"\r");
					_delay_ms(300);
					bufferLength = 1;

					fputs("ok\r\n", &USBSerialStream);
				}

				if(b == 0x1A)
				{
					if(numbers > iRead)
						pb_clear(iRead +1, numbers);

					numbers = iRead;
					eeprom_write_word((uint16_t*)1, (uint16_t)numbers);
				}

				if(b == '*' || b == '\r')
				{
					iRead++;
					uart_puts("AT+CPBW=");

					char buff[5];
					itoa(iRead, buff, 10);
					uart_puts(buff);
					uart_puts(",\"+48");
				}

				if(b > 47 && b < 58)
				{
					uart_put(b);
				}

				if(b == 0x1B)
					openGate();

				if(b == 'd')
					bDebug = !bDebug;

			}

			CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
			USB_USBTask();
		}
		bufferCheck();

		if(!(PINC && (1 << PC2)))
			PORTB |= (1 << PB5);
		else
			PORTB &= ~(1 << PB5);
	}
}
Пример #15
0
void usb_serial_init(){
    USB_Init();

    /* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
    CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);
}
Пример #16
0
int main(void)
{
    uint8_t loops_ocr1a = 0;
    /* Cache for OCR1A when PWM is disabled */
    uint16_t OCR1A_save;
    bool usb_initialized = 0;
    /* Is HV supply voltage reached? If not take bigger steps */
    bool hv_reached = 0;

    setupHardware();

    sei(); /*  Enable interrupts */
    while(1)
    {
        if(!usb_initialized) {
            /*  Check if USB power is connected */
            if (bit_is_set(PINB,4)) {
                /* USB initialization */
                USB_Init();
                CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);
                usb_initialized = 1;
            }
        }

        if (usb_connected) {
            /*  Check mail */
            usb_rx();
            CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
            USB_USBTask();
            /*  Send counter over usb and reset */
            if (send_count && tx_flag) {
                tx_flag = 0;
                /*  Print number of events and time of last event */
                fprintf(&USBSerialStream, "c%3d,%3d\r\n", tx_count, tx_event_time);
                /*  TODO: LCD */
            }
        }

        /*  HV supply feedback */
        if( use_comparator ) {
            /*  Check if output voltage is over threshold */
            if (bit_is_set(ACSR, ACO)) {
                /*  Not over 400V */
                if ((loops_ocr1a % 10) == 0) {
                    if (OCR1A < 100) {
                        if (!hv_reached) {
                            OCR1A += 15;
                        } else {
                            OCR1A += 1;
                        }
                    }
                    if (OCR1A < 500) {
                        if (!hv_reached) {
                            OCR1A += 10;
                        } else {
                            OCR1A += 1;
                        }
                    }
                }
            } else if((loops_ocr1a == 100)) {
                /* Required voltage reached, decrease step size */
                hv_reached = 1;
                /*  Decrease OCR1A when after some time to avoid creeping upwards */
                if (OCR1A > 2) {
                    OCR1A--;
                }

                /* Reset loop counter */
                loops_ocr1a = 0;
            }
            loops_ocr1a++;
        }

        if (buzzer_enabled && tick_pending) {
            bit_set(PORTC, 7);
            tick_pending = 0;
        }
        sleep1ms();
        bit_clear(PORTC, 7);
    }
}
Пример #17
0
int main(void)
{
	// USB BEGIN //
	SetupHardware();
	/* Create a regular character stream for the interface so that it can be used with the stdio.h functions */
	CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);
	
	TCCR0B = (1<<CS02)|(1<<CS00); // Set up timer to handle USB stuff.
	TIMSK0 = (1<<TOIE0);
	
	sei();
	// USB END //
	
	
	while(rxByte != 0x20)
	{
		fputs(".", &USBSerialStream);
		delay_ms(100);
	}
	rxByte = 0;
	nrf_init();

	delay_ms(500);
	
	nrf_spillRegisters();
	
	uint16_t number = 0;
	
	fputs("Last transmission: ",&USBSerialStream);
	itoa(number, buffer, 10);
	fputs(buffer,&USBSerialStream);
			
	
	for (;;)
	{	
		/*while(!rxByte)
		{
			fputs(".", &USBSerialStream);
			delay_ms(100);
		}*/
		number++;
		nrf_tx((uint16_t)number);
		
		fputs("\rLast transmission: ",&USBSerialStream);
		itoa(number, buffer, 10);
		fputs(buffer,&USBSerialStream);
		
		//rxByte = 0;
		
		GET_STATUS;
		if(nrf_last_status & (1<<MAX_RT))
		{
			fputs("\r\nPacket transmission failed. Clearing MAX_RT...\r\n",&USBSerialStream);
			delay_us(1);
			SS_DOWN;
			SPI_WRITE(W_REGISTER | NRG_STATUS);
			SPI_WRITE(1<<MAX_RT);
			SS_UP;
		}
		else
		{
			
		}
		
		delay_ms(500);
		
		//nrf_spillRegisters();
	}
}