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


	for (;;)
	{
		/* Only try to read in bytes from the CDC interface if the transmit buffer is not full */
		if (!(RingBuffer_IsFull(&USBtoUSART_Buffer)))
		{
			int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);

			/* Read bytes from the USB OUT endpoint into the USART transmit buffer */
			if (!(ReceivedByte < 0))
			  RingBuffer_Insert(&USBtoUSART_Buffer, ReceivedByte);
		}

		/* Check if the UART receive buffer flush timer has expired or the buffer is nearly full */
		uint16_t BufferCount = RingBuffer_GetCount(&USARTtoUSB_Buffer);
		if ((BufferCount > (uint8_t)(sizeof(USARTtoUSB_Buffer_Data) * .75)))
		{

			/* Read bytes from the USART receive buffer into the USB IN endpoint */
			while (BufferCount--)
			{
				/* Try to send the next byte of data to the host, abort if there is an error without dequeuing */
				if (CDC_Device_SendByte(&VirtualSerial_CDC_Interface,
				                        RingBuffer_Peek(&USARTtoUSB_Buffer)) != ENDPOINT_READYWAIT_NoError)
				{
					break;
				}

				/* Dequeue the already sent byte from the buffer now we have confirmed that no transmission error occurred */
				RingBuffer_Remove(&USARTtoUSB_Buffer);
			}
		}

		/* Load the next byte from the USART transmit buffer into the USART */
		if (!(RingBuffer_IsEmpty(&USBtoUSART_Buffer))){
		  //Serial_SendByte(RingBuffer_Remove(&USBtoUSART_Buffer));
		}

		CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();
	}
}
Пример #2
0
/** Main program entry point. This routine configures the hardware required by the application, then
 *  enters a loop to run the application tasks in sequence.
 */
int main(void)
{
	SetupHardware();

	puts_P(PSTR(ESC_FG_CYAN "HID Device Report Viewer Running.\r\n" ESC_FG_WHITE));

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	GlobalInterruptEnable();

	for (;;)
	{
		RetrieveDeviceData();

		HID_Host_USBTask(&Device_HID_Interface);
		USB_USBTask();
	}
}
Пример #3
0
/** Main program entry point. This routine configures the hardware required by the application, then
 *  enters a loop to run the application tasks in sequence.
 */
int main(void)
{
	SetupHardware();

	puts_P(PSTR(ESC_FG_CYAN "Still Image Host Demo running.\r\n" ESC_FG_WHITE));

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	GlobalInterruptEnable();

	for (;;)
	{
		StillImageHost_Task();

		SI_Host_USBTask(&DigitalCamera_SI_Interface);
		USB_USBTask();
	}
}
Пример #4
0
/** Main program entry point. This routine configures the hardware required by the application, then
 *  enters a loop to run the application tasks in sequence.
 */
int main(void)
{
	SetupHardware();

	CmdState = CMD_STOP;

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	sei();

	for (;;)
	{
		Read_Joystick_Status();
	
		HID_Host_Task();
		USB_USBTask();
	}
}
Пример #5
0
/** Main program entry point. This routine configures the hardware required by the application, then
 *  enters a loop to run the application tasks in sequence.
 */
int main(void)
{
	SetupHardware();

	puts_P(PSTR(ESC_FG_CYAN "CDC Host Demo running.\r\n" ESC_FG_WHITE));

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	GlobalInterruptEnable();

	for (;;)
	{
		CDCHost_Task();

		CDC_Host_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();
	}
}
Пример #6
0
/** Main program entry point. This routine configures the hardware required by the application, then
 *  enters a loop to run the application tasks in sequence.
 */
int main(void)
{
	SetupHardware();

	CmdState = CMD_STOP;

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	GlobalInterruptEnable();

	for (;;)
	{
		Read_Joystick_Status();
		DiscardNextReport();

		USB_USBTask();
	}
}
/** Main program entry point. This routine configures the hardware required by the application, then
 *  enters a loop to run the application tasks in sequence.
 */
int main(void)
{
	SetupHardware();

	puts_P(PSTR(ESC_FG_CYAN "Android Accessory Host Demo running.\r\n" ESC_FG_WHITE));

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	GlobalInterruptEnable();

	for (;;)
	{
		AOAHost_Task();

		AOA_Host_USBTask(&AndroidDevice_AOA_Interface);
		USB_USBTask();
	}
}
Пример #8
0
/** Main program entry point. This routine configures the hardware required by the application, then
 *  enters a loop to run the application tasks in sequence.
 */
int main(void)
{
	SetupHardware();

	puts_P(PSTR(ESC_FG_CYAN "RNDIS Host Demo running.\r\n" ESC_FG_WHITE));

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	sei();

	for (;;)
	{
		RNDISHost_Task();

		RNDIS_Host_USBTask(&Ethernet_RNDIS_Interface);
		USB_USBTask();
	}
}
Пример #9
0
/** Main program entry point. This routine configures the hardware required by the application, then
 *  enters a loop to run the application tasks in sequence.
 */
int main(void)
{
	SetupHardware();

	puts_P(PSTR(ESC_FG_CYAN "Keyboard Host Demo running.\r\n" ESC_FG_WHITE));

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	GlobalInterruptEnable();

	for (;;)
	{
		KeyboardHost_Task();

		HID_Host_USBTask(&Keyboard_HID_Interface);
		USB_USBTask();
	}
}
/** Main program entry point. This routine configures the hardware required by the application, then
 *  enters a loop to run the application tasks in sequence.
 */
int main(void)
{
	//RFCOMM_SendFrame(0x10003000,0x10003004,4,4,130,0x10003200);
	uint16_t tick;
	SetupHardware();

	LPC_TIM0->TCR = 1;
	Led1On();
	Led2On();
	Led1Off();
	Led2Off();

	EVENT_USB_Host_DeviceUnattached();
		
	for (;;)
	{
		//uint8_t ButtonStatus = Buttons_GetStateMask();

	
		/* Check if the system update interval has elapsed */
		if(LPC_TIM0->IR &0x01)
		{
			/* Clear the timer compare flag */
			LPC_TIM0->IR |= 0x01;
			if (RFCOMM_SensorStream){
				Led1On();
			}
			else{
				if(tick++>=50)
				{
					tick = 0;
					Led1Not();
				}
			}
			/* If the bluetooth stack is active, manage timeouts within each layer */
			BluetoothAdapter_TickElapsed();
			KeyScan();
			if(sendFlag){
				rfcomm_send_data();
			}	
		}
		
		BluetoothAdapter_USBTask();
		USB_USBTask();
	}
}
Пример #11
0
/** Main program entry point. This routine configures the hardware required by the application, then
 *  starts the scheduler to run the application tasks.
 */
int main(void)
{
	SetupHardware();

	/* Ring buffer Initialization */
	Buffer_Initialize(&Rx_Buffer);
	Buffer_Initialize(&Tx_Buffer);

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	
	for (;;)
	{
		CDC_Task();
        PENPROG_Task();
		USB_USBTask();
	}
}
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously
 *  runs the bootloader processing routine until instructed to soft-exit, or hard-reset via the watchdog to start
 *  the loaded application code.
 */
int main(void)
{
	/* Setup hardware required for the bootloader */
	SetupHardware();

	/* Turn on first LED on the board to indicate that the bootloader has started */
	LEDs_SetAllLEDs(LEDS_LED1);

	/* Fill in the UUID Report */
	/* Bootloader ID */
	UUIDReport[0] = BOOTLOADER_ID_SIG >> 8;
	UUIDReport[1] = BOOTLOADER_ID_SIG & 0xFF;
	/* Bootloader Version */
	UUIDReport[2] = BOOTLOADER_VERSION_SIG >> 8;
	UUIDReport[3] = BOOTLOADER_VERSION_SIG & 0xFF;
	/* Device ID */
	for (size_t i = 4; i < UUID_SIZE; i++)
	{
		UUIDReport[i] = eeprom_read_byte((uint8_t*)(intptr_t)(i));
	}

	/* Enable global interrupts so that the USB stack can function */
	GlobalInterruptEnable();

	while (RunBootloader)
	{
		MIDI_Task();
		CDC_Task();
		MIDI_Device_USBTask(&Keyboard_MIDI_Interface);
		USB_USBTask();
	}

	/* Wait a short time to end all USB transactions and then disconnect */
	_delay_us(1000);

	/* Disconnect from the host - USB interface will be reset later along with the AVR */
	USB_Detach();

	/* Unlock the forced application start mode of the bootloader if it is restarted */
	MagicBootKey = MAGIC_BOOT_KEY;

	/* Enable the watchdog and force a timeout to reset the AVR */
	wdt_enable(WDTO_250MS);

	for (;;);
}
Пример #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();

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	sei();

	for (;;)
	{
		if (CurrentFirmwareMode == MODE_USART_BRIDGE)
		  UARTBridge_Task();
		else
		  AVRISP_Task();

		USB_USBTask();
	}
}
Пример #14
0
/** Main program entry point. This routine configures the hardware required by the application, then
 *  enters a loop to run the application tasks in sequence.
 */
int main(void)
{
	SetupHardware();

	puts_P(PSTR(ESC_FG_CYAN "Mouse Host Demo running.\r\n" ESC_FG_WHITE));

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	sei();

	for (;;)
	{
		MouseHost_Task();

		HID_Host_USBTask(&Mouse_HID_Interface);
		USB_USBTask();
	}
}
/** Main program entry point. This routine configures the hardware required by the application, then
 *  enters a loop to run the application tasks in sequence.
 */
int main(void)
{
	SetupHardware();

	puts_P(PSTR(ESC_FG_CYAN "Printer Host Demo running.\r\n" ESC_FG_WHITE));

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	sei();

	for (;;)
	{
		PrinterHost_Task();

		PRNT_Host_USBTask(&Printer_PRNT_Interface);
		USB_USBTask();
	}
}
Пример #16
0
/** Main program entry point. This routine configures the hardware required by the application, then
 *  enters a loop to run the application tasks in sequence.
 */
int main(void)
{
    SetupHardware();

    LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
    GlobalInterruptEnable();

    for (;;)
    {
        if (USB_CurrentMode == USB_MODE_Host)
            USBHostMode_USBTask();
        else
            USBDeviceMode_USBTask();

        USB_USBTask();
    }
}
Пример #17
0
int main(int argc, char *argv[])
{
    pthread_t display_thread, speed_thread, ant_thread;

    // setup signal handler(s)
    signal(SIGINT, on_sigint);

    // setup hardware
    SetupHardware();

    // start the display thread
    runDisplayThread = 1;
    pthread_create (&display_thread, NULL, Display_Thread, NULL);

    // Start the speed sensor thread
    runSpeedThread = 1;
    pthread_create (&speed_thread, NULL, Speed_Thread, NULL);

    // start the ANT+ thread
    // todo: start broadcasting ANT data when movement sensed, and timeout/stop when idle
    runAntThread = 1;
    pthread_create (&ant_thread, NULL, ANT_Thread, NULL);

    milliSleep(500);

    //unsigned int i;

    // Run until Ctrl-C
    while (is_sigint == 0)
    {
        //sprintf(DisplayMessage, "main thread sleeping... %i", i++);
        sleep(1);
    }

    // wait for threads to finish
    //printf("\nWaiting for threads to finsh..\n");
    runDisplayThread = runSpeedThread = runAntThread = 0;
    pthread_join(display_thread, NULL);
    pthread_join(speed_thread, NULL);
    pthread_join(ant_thread, NULL);

    // cleanup hardware
    CleanupHardware();

    exit(0);
}
Пример #18
0
/** Main program entry point. This routine configures the hardware required by the application, then
 *  enters a loop to run the application tasks in sequence.
 */
int main(void)
{
	uint8_t cyc;
	SetupHardware();

	/* Webserver Initialization */
		setup_spi();

	DDRD |= _BV(6);
	PORTD &= ~_BV(6);
	PORTD = 0;

	GlobalInterruptEnable();

	//sendstr( "Boot" );

	et_init( 0 );

	InitTCP();
	InitDumbcraft();


	for (;;)
	{
//	SetManyWS( 0xff, 0x00, 0x00, 20 );

		RNDIS_Task();
		USB_USBTask();
		_delay_us(200);
		UpdateServer();
		cyc++;
		if( (cyc & 0x7f) == 0 )
		{
			struct Player * p = &Players[0];
//			sendhex2( p->npitch );
//			 = 1;
//			if( p->active )

			PORTD |= _BV(6);
			TickServer();
			TickTCP();
			PORTD &= ~_BV(6);
		}
	}
}
Пример #19
0
/**
 *  @brief  Main program entry point
 *  @return Will never return
 *  @note   This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();
	iap_init();

#ifdef WITH_USB	

	xprintf("\nLet's see some usb stuff");
	
	int i;
	// initially expect USB connection
	for (i = 0; ; i++) {
		#if !defined(USB_DEVICE_ROM_DRIVER)
		MS_Device_USBTask(&Disk_MS_Interface);
		USB_USBTask(Disk_MS_Interface.Config.PortNumber, USB_MODE_Device);
		#endif
		//if (i > 350000 && !USBConnected) break;
		if (i > 600000 && !USBConnected) break;
	}
#endif
	// if USB is unplugged, serve the vectrex bus
	PrepareLoader(DataRam_GetScratchRAM());

	xprintf("\nLOADER.BIN ROMBase=%x\n", ROMBase);
	void *loader = ROMBase;
	SelectROM(DataRam_GetScratchRAM(), 1); 
	xprintf("1 ROMBase=%x\nServing...", ROMBase);
	ROMBase = loader;

    NVIC_DisableIRQ(UART0_IRQn);
	UART0_UnInit();		
	VectrexBusInit();


	//SelectROM(DataRam_GetScratchRAM(), 1); -- this works
	int romIndex = VectrexBusSlave();	
	//VectrexBusHold();

	SelectROM(DataRam_GetScratchRAM(), romIndex); 

	//VectrexBusUnhold();
	//VectrexNMI();
	for(;;)
		VectrexBusSlave();
}
Пример #20
0
int main(void) {
  SetupHardware();

  // If digital pin 6 (PD7) is low, fill channel data with a distinctive
  // pattern.
  DDRD &= 0b01111111;
  bool fill_with_pattern = bit_is_clear(PIND, 7);
  if (fill_with_pattern) {
    memset(_chandata, 0b01010101, 2048);
  }

  LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
  GlobalInterruptEnable();

  while (true) {
    CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
    USB_USBTask();

    if (connected) {
      uint8_t* position = _chandata;
      int16_t universe = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
      if (universe == -1) {
        // just a normal timeout, continue
        continue;
      }
      position += universe;

      while (position < _chandata + 2048) {
        int16_t channel_level =
            CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
        if (channel_level != -1) {
          *position = (uint8_t)channel_level;
          position += 4;
        } else {
          if (!connected) {
            // connection lost, forget our position and wait for a connection
            break;
          }
          // just a normal timeout, continue
          continue;
        }
      }
    }
  }
}
Пример #21
0
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously 
 *  runs the bootloader processing routine until instructed to soft-exit, or hard-reset via the watchdog to start
 *  the loaded application code.
 */
int main(void)
{
	/* Setup hardware required for the bootloader */
	SetupHardware();

	while (RunBootloader)
	{
		CDC_Task();
		USB_USBTask();
	}
	
	/* Reset all configured hardware to their default states for the user app */
	ResetHardware();

	/* Start the user application */
	AppPtr_t AppStartPtr = (AppPtr_t)0x0000;
	AppStartPtr();	
}
Пример #22
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();

	for (uint8_t Buffer = 0; Buffer < TOTAL_TRACKS; Buffer++)
	  BitBuffer_Init(&TrackDataBuffers[Buffer]);

	sei();

	for (;;)
	{
		if (Magstripe_GetStatus() & MAG_CARDPRESENT)
		  ReadMagstripeData();

		HID_Device_USBTask(&Keyboard_HID_Interface);
		USB_USBTask();
	}
}
Пример #23
0
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously
 *  runs the bootloader processing routine until it times out or is instructed to exit.
 */
int main(void)
{
	/* Save the value of the boot key memory before it is overwritten */
	uint16_t bootKeyPtrVal = *bootKeyPtr;
	*bootKeyPtr = 0;

	/* Check the reason for the reset so we can act accordingly */
	uint8_t  mcusr_state = MCUSR;		// store the initial state of the Status register
	MCUSR = 0;							// clear all reset flags	

	/* Watchdog may be configured with a 15 ms period so must disable it before going any further */
	wdt_disable();
	
	/* Jump to bootloader only if correct key is present in eeprom */
	if ((eeprom_read_word((uint16_t*)EEP_BOOTKEY_ADDR) != BOOTLOADER_BOOTKEY) && (eeprom_read_word((uint16_t*)EEP_BACKUP_BOOTKEY_ADDR) != BOOTLOADER_BOOTKEY))
	{
		StartSketch();
	}

	/* Setup hardware required for the bootloader */
	SetupHardware();

	/* Enable global interrupts so that the USB stack can function */
	sei();
	
	Timeout = 0;
	
	while (RunBootloader)
	{
		CDC_Task();
		USB_USBTask();
		/* Time out and start the sketch if one is present */
		if (Timeout > TIMEOUT_PERIOD)
			RunBootloader = false;

		LEDPulse();
	}

	/* Disconnect from the host - USB interface will be reset later along with the AVR */
	USB_Detach();

	/* Jump to beginning of application space to run the sketch - do not reset */	
	StartSketch();
}
Пример #24
0
int main(void)
{
	SetupHardware();
	RingBuffer_InitBuffer(&USBtoUSART_Buffer, USBtoUSART_Buffer_Data, sizeof(USBtoUSART_Buffer_Data));
	RingBuffer_InitBuffer(&USARTtoUSB_Buffer, USARTtoUSB_Buffer_Data, sizeof(USARTtoUSB_Buffer_Data));
	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	GlobalInterruptEnable();
	
	while(1)
	{
		if(RTR==1)
		{
			if (ReceivedByte==0xFF)
			{
				for (uint8_t i = 0; i < 4; i++)
				{
					if (ReceivedByte==0)
					{
						ReceivedByte=1;
					}
					buff[i] = ReceivedByte;
					RTR = 0;
					while(RTR!=1){}
				}
				uint8_t range = ((buff[1]*256+buff[2])/100);
				RingBuffer_Insert(&USARTtoUSB_Buffer,buff[1]);
				RingBuffer_Insert(&USARTtoUSB_Buffer,buff[2]);
				//RingBuffer_Insert(&USARTtoUSB_Buffer,range);
				sendUSARTtoUSB();
				_delay_ms(500);
			}
		}		
//  		if (!RingBuffer_IsFull(&USBtoUSART_Buffer))
// 		{
// 			int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
// 			if (!(ReceivedByte < 0))
// 			{
// 				sendUSBtoUSART();
// 			}
			CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
			USB_USBTask();
//		}
	}
}
Пример #25
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();
	}
}
Пример #26
0
/** Main program entry point. This routine configures the hardware required by the application, then
		keeps calling the CDC application task for bulk data, CDC Host task for processing interrupt endpoints
		and the core USB host task.
 */
int main(void)
{
	uint8_t i;
	
	SetupHardware();
	
	serialInfCount = 0;

	DEBUGOUT("Serial Host Demo running.\r\n");

	for (;; ) {
		SerialHost_Task();

		for (i = 0; i < serialInfCount; i++) {
			CDC_Host_USBTask(&Serial_Interface[i]);
		}
		USB_USBTask(Serial_Interface[0].Config.PortNumber, USB_MODE_Host);
	}
}
/** 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();

	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);
		HID_Device_USBTask(&Mouse_HID_Interface);
		USB_USBTask();
	}
}
Пример #28
0
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously 
 *  runs the bootloader processing routine until instructed to soft-exit.
 */
int main(void)
{
	/* Setup hardware required for the bootloader */
	SetupHardware();
	
	/* Enable global interrupts so that the USB stack can function */
	sei();

	while (RunBootloader)
	  USB_USBTask();
	
	/* Disconnect from the host - USB interface will be reset later along with the AVR */
	USB_Detach();

	/* Enable the watchdog and force a timeout to reset the AVR */
	wdt_enable(WDTO_250MS);

	for (;;);
}
Пример #29
0
/** Main program entry point. This routine configures the hardware required by the application, then
 *  enters a loop to run the application tasks in sequence.
 */
int main(void)
{
	SetupHardware();

	/* Webserver Initialization */
	TCP_Init();
	Webserver_Init();

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	GlobalInterruptEnable();

	for (;;)
	{
		Ethernet_Task();
		TCP_Task();
		RNDIS_Task();
		USB_USBTask();
	}
}
Пример #30
0
int main(void)
{
  SetupHardware();
  GlobalInterruptEnable();
  _delay_ms(10);
  for (;;)
  {
    if ((PIND & 1) == 0) {
      if (state == 1) {
        pressed = true;
        state = 0;
      }
    } else {
      state = 1;
    }

    HID_Device_USBTask(&Keyboard_HID_Interface);
    USB_USBTask();
  }
}