//! Sends a USB report frame
void USB_DEVICE::_send_usb_report_frame(){

#ifdef MOUSE_REPORT

	//! Send the structure.
	usbSendHidReport(_packet_buffer, sizeof(mouse_report));
#endif

#ifdef JOYSTICK_REPORT

	//! Send the structure.
	usbSendHidReport(_packet_buffer, sizeof(joystick_report));
#endif

#ifdef MOUSE_JOYSTICK_REPORT

	//! Send the structure.
	usbSendHidReport(_packet_buffer, sizeof(joystick_report));
#endif

	_packet_in_sending_queue = false;
}
Example #2
0
int main()
{
//	uint8_t inp_b;
//	uint8_t inp_c;
//	uint8_t inp_d;

    wdt_disable(); // no watchdog, just because I'm lazy

    // Configure I/O PORTS - All Digital Inputs (ARCADE)
    DDRB = 0;
    DDRC = 0;
    DDRD = 0;
    // Configure Pullups except for Pins PD2 and PD3
    PORTB = 0xff;
    PORTC = 0xff;
    PORTD = 0xf3;      // 1 1 1 1 0 0 1 1

    // Configure timer
    TCCR1B = _BV(CS12) | _BV(CS11); // timer is initialized, used to keep track of idle period

    // Start the show!
    usbInit(); // start v-usb
    usbDeviceDisconnect(); // enforce USB re-enumeration, do this while interrupts are disabled!
    _delay_ms(250);
    usbDeviceConnect();

    sei(); // enable interrupts

    uint8_t to_send = 1; // boolean, true for first time

    while (1)
    {
        usbPoll();

        // Initialize the report IDs
        gamepad_report_1.report_id = 1;
        gamepad_report_2.report_id = 2;


        // Initialize report. No buttons pressed, directional at center
        gamepad_report_1.buttons5_1=0;
        gamepad_report_1.axes=0x5;       // - - - - 0 1 0 1 (X and Y centered);

        gamepad_report_2.buttons5_1=0;
        gamepad_report_2.axes=0x5;       // - - - - 0 1 0 1 (X and Y centered);

//		inp_b = PINB;
//		inp_c = PINC;
//		inp_d = PIND;

        // Populate directionals - Controller A
        if ( A4 ) gamepad_report_1.axes -=4; // up
        if ( A2 ) gamepad_report_1.axes +=4; // down
        if ( A1 ) gamepad_report_1.axes -=1; // left
        if ( A3 ) gamepad_report_1.axes +=1; // right

        // Populate buttons 1-5 - Controller A
        if ( A5 ) gamepad_report_1.buttons5_1	+= 1;
        if ( A6 ) gamepad_report_1.buttons5_1	+= 2;
        if ( A7 ) gamepad_report_1.buttons5_1	+= 4;
        if ( A8 ) gamepad_report_1.buttons5_1	+= 8;
        if ( A9 ) gamepad_report_1.buttons5_1	+= 16;

        // Populate directionals - Controller B
        if ( B4 ) gamepad_report_2.axes -=4; // up
        if ( B2 ) gamepad_report_2.axes +=4; // down
        if ( B1 ) gamepad_report_2.axes -=1; // left
        if ( B3 ) gamepad_report_2.axes +=1; // right

        // Populate buttons 1-5 - Controller B
        if ( B5 ) gamepad_report_2.buttons5_1	+= 1;
        if ( B6 ) gamepad_report_2.buttons5_1	+= 2;
        if ( B7 ) gamepad_report_2.buttons5_1	+= 4;
        if ( B8 ) gamepad_report_2.buttons5_1	+= 8;
        if ( B9 ) gamepad_report_2.buttons5_1	+= 16;



        // determine whether or not the report should be sent
        if ((TCNT1 > ((4 * (F_CPU / 1024000)) * idle_rate) || TCNT1 > 0x7FFF) && idle_rate != 0)
        {   // using idle rate
            to_send = 1;
        }
        else
        {   // or if data has changed

            if (memcmp(&gamepad_report_1, &gamepad_report_1_old, sizeof(gamepad_report_t)) != 0)
            {
                to_send = 1;
            }
            else if (memcmp(&gamepad_report_2, &gamepad_report_2_old, sizeof(gamepad_report_t)) != 0)
            {
                to_send = 1;
            }
        }

        usbPoll();
        if (to_send != 0)
        {
            // send the data if needed
            usbSendHidReport(&gamepad_report_1, sizeof(gamepad_report_t));
            usbSendHidReport(&gamepad_report_2, sizeof(gamepad_report_t));
            TCNT1 = 0; // reset timer
        }

        usbPoll();

        memcpy(&gamepad_report_1_old, &gamepad_report_1, sizeof(gamepad_report_t));
        memcpy(&gamepad_report_2_old, &gamepad_report_2, sizeof(gamepad_report_t));

        to_send = 0; // reset flag
    }

    return 0;
}
/**
 * This function by definition takes in a usb report structure and
 * sends it to the host.
 *
 * @param report - joystick_report_t*
 */
void send_joystick_report(struct joystick_report_t* report){
	usbSendHidReport((byte*)report, sizeof(joystick_report_t));
}
/**
 * This function by definition takes in a usb report structure and
 * sends it to the host.
 *
 * @param report - mouse_report_t*
 */
void send_mouse_report(struct mouse_report_t* report){
	usbSendHidReport((byte*)report, sizeof(mouse_report_t));
}
Example #5
0
int main()
{
 
	wdt_disable(); // no watchdog, just because I'm lazy
    
	// Configure I/O PORTS - All Digital Inputs (ARCADE)
	DDRB = 0;
	DDRC = 0;
	DDRD = 0;
	// Configure Pullups except for Pins PD2 and PD3
	PORTB = 0xff;
	PORTC = 0xff;
	PORTD = 0xf3;      // 1 1 1 1 0 0 1 1
	
	// Configure ADC	
    ADMUX = (1<<REFS0 | 1<<ADLAR );  // AREF = AVcc, Left Justified

    // 12000000/128 = 93750Hz  
    ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);  // ADC Enable and prescaler of 128
	
	 
	// Configure timer 	
	TCCR1B = _BV(CS12) | _BV(CS11); // timer is initialized, used to keep track of idle period
	
	// Start the show!
	usbInit(); // start v-usb
    usbDeviceDisconnect(); // enforce USB re-enumeration, do this while interrupts are disabled!
	_delay_ms(250);
    usbDeviceConnect();
	
    sei(); // enable interrupts
	
	uint8_t to_send = 1; // boolean, true for first time
	
	while (1)
	{
		usbPoll();
		
		// Initialize the report IDs 
//		gamepad_report_1.report_id = 1;  // no ID is sent. All data shall be within 8 bytes
		
		// Initialize report. No buttons pressed, directional at center
		gamepad_report_1.buttons8_1=0;
		gamepad_report_1.buttons12_9=0;		
		gamepad_report_1.vXaxis=0;
		gamepad_report_1.vYaxis=0;		
		gamepad_report_1.vZaxis=0;
		gamepad_report_1.vRXaxis=0;
		gamepad_report_1.vRYaxis=0;		
		gamepad_report_1.vRZaxis=0;		
 		
		
		// Populate Analog Axes 
        ADMUX = (ADMUX & 0xF8) | Xaxis; // Select X axis 
		ADCSRA |= (1<<ADSC); // start single convertion
		while(ADCSRA & (1<<ADSC)); // wait for conversion to complete		
		gamepad_report_1.vXaxis = 127-ADCH;
	
        ADMUX = (ADMUX & 0xF8) | Yaxis; // Select Y axis 
		ADCSRA |= (1<<ADSC); // start single convertion
		while(ADCSRA & (1<<ADSC)); // wait for conversion to complete		
		gamepad_report_1.vYaxis = 127-ADCH;		

        ADMUX = (ADMUX & 0xF8) | Zaxis; // Select Z axis 
		ADCSRA |= (1<<ADSC); // start single convertion
		while(ADCSRA & (1<<ADSC)); // wait for conversion to complete		
		gamepad_report_1.vZaxis = 127-ADCH;
		
        ADMUX = (ADMUX & 0xF8) | RXaxis; // Select RX axis 
		ADCSRA |= (1<<ADSC); // start single convertion
		while(ADCSRA & (1<<ADSC)); // wait for conversion to complete		
		gamepad_report_1.vRXaxis = 127-ADCH;
		
        ADMUX = (ADMUX & 0xF8) | RYaxis; // Select RY axis 
		ADCSRA |= (1<<ADSC); // start single convertion
		while(ADCSRA & (1<<ADSC)); // wait for conversion to complete		
		gamepad_report_1.vRYaxis = 127-ADCH;		

        ADMUX = (ADMUX & 0xF8) | RZaxis; // Select RZ axis 
		ADCSRA |= (1<<ADSC); // start single convertion
		while(ADCSRA & (1<<ADSC)); // wait for conversion to complete		
		gamepad_report_1.vRZaxis = 127-ADCH;


		// Populate buttons 1-7
		if ( B3 ) gamepad_report_1.buttons8_1	+= 1;	
		if ( B4 ) gamepad_report_1.buttons8_1	+= 2;		
		if ( B5 ) gamepad_report_1.buttons8_1	+= 4;	
		if ( B6 ) gamepad_report_1.buttons8_1	+= 8;		
		if ( B7 ) gamepad_report_1.buttons8_1	+= 16;	
		if ( B8 ) gamepad_report_1.buttons8_1	+= 32;	
		if ( B9 ) gamepad_report_1.buttons8_1	+= 64;	
		if ( A9 ) gamepad_report_1.buttons8_1	+= 128;

		// Populate buttons 12-9
		if ( A8 ) gamepad_report_1.buttons12_9	+= 1;	
		if ( A7 ) gamepad_report_1.buttons12_9	+= 2;		
		if ( A6 ) gamepad_report_1.buttons12_9	+= 4;	
		if ( A5 ) gamepad_report_1.buttons12_9	+= 8;

		
		
		// determine whether or not the report should be sent
		if ((TCNT1 > ((4 * (F_CPU / 1024000)) * idle_rate) || TCNT1 > 0x7FFF) && idle_rate != 0)
		{// using idle rate
			to_send = 1;
		}
		else
		{// or if data has changed

			if (memcmp(&gamepad_report_1, &gamepad_report_1_old, sizeof(gamepad_report_t)) != 0)
			{
				to_send = 1;
			}

		}
		
		usbPoll();
		if (to_send != 0)
		{
			// send the data if needed
			usbSendHidReport(&gamepad_report_1, sizeof(gamepad_report_t));
			TCNT1 = 0; // reset timer
		}
		
		usbPoll();
		
		memcpy(&gamepad_report_1_old, &gamepad_report_1, sizeof(gamepad_report_t));

	
		to_send = 0; // reset flag
	}
	
	return 0;
}
int main()
{
	// TODO: watchdog
	wdt_disable(); // no watchdog, just because I'm lazy
	
	//position = 0;
	
	TCCR1B = _BV(CS12) | _BV(CS11); // timer is initialized, used to keep track of idle period
	
	hardwareInit();
	
	usbInit(); // start v-usb
    usbDeviceDisconnect(); // enforce USB re-enumeration, do this while interrupts are disabled!
	_delay_ms(250);
    usbDeviceConnect();
	
    sei(); // enable interrupts
	
	uint8_t to_send = 1; // boolean, true for first time
	
	while (1)
	{
		usbPoll();
		
		/*
		 * this area is where you should set the movement
		 * and button values of the reports using the input
		 * method of your choice
		 *
		*/
		
		updateReport();
		
		// determine whether or not the report should be sent
		if ((TCNT1 > ((4 * (F_CPU / 1024000)) * idle_rate) || TCNT1 > 0x7FFF) && idle_rate != 0)
		{// using idle rate
			to_send = 1;
		}
		else
		{// or if data has changed
			if (memcmp(&gamepad_report, &gamepad_report_old, sizeof(gamepad_report_t)) != 0)
			{
				to_send = 1;
			}
		}
		
		usbPoll();
		if (to_send != 0)
		{
			// send the data if needed
			usbSendHidReport((uchar*)&gamepad_report, sizeof(gamepad_report_t));
			TCNT1 = 0; // reset timer
		}
		
		usbPoll();
		
		memcpy(&gamepad_report_old, &gamepad_report, sizeof(gamepad_report_t));
		
		to_send = 0; // reset flag
	}
	
	return 0;
}
Example #7
0
int main()
{
	
	wdt_disable(); // no watchdog, just because I'm lazy
    
	// Configure I/O PORTS - All Digital Inputs (ARCADE)
	DDRB = (1<<4);  // PB4 as output
	DDRC = (1<<5); // PC5 as output
	DDRD = 0;
	// Configure Pullups except for Pins PD2 and PD3
	PORTB = 0xff;
	PORTC = 0xff;
	PORTD = 0xf3;      // 1 1 1 1 0 0 1 1
	 
	// Configure timer 	
	TCCR1B = _BV(CS12) | _BV(CS11); // timer is initialized, used to keep track of idle period
	
	TCCR0B |= (1 << CS00) | (1<<CS02); // timer 0 prescaler 1024, overflow at FOSC/1024/256
	
	
	// Start the show!
	usbInit(); // start v-usb
    usbDeviceDisconnect(); // enforce USB re-enumeration, do this while interrupts are disabled!
	_delay_ms(250);
    usbDeviceConnect();
	
    sei(); // enable interrupts
	
	uint8_t to_send = 1; // boolean, true for first time
	

	
	// Initialize the report IDs 
	genesis_1_report.report_id = 1;
	genesis_2_report.report_id = 2;
	
	// Initialize report. No buttons pressed, directional at center		
	genesis_1_report.buttons=0;
	genesis_1_report.axes=0x5;       // - - - - 0 1 0 1 (X and Y centered);
	genesis_2_report.buttons=0;		
	genesis_2_report.axes=0x5;       // - - - - 0 1 0 1 (X and Y centered);

	
	
	
	while (1)
	{
		usbPoll();
			
		// Sample controllers each 16ms for 16MHz crystal (22ms for 12MHz)
		if (TIFR0 & (1<<TOV0)) {
					Get_genesis_controllers_data();
					TIFR0 |= (1<<TOV0); // reset overflow flag		
		}
 

		
		
		// determine whether or not the report should be sent
		if ((TCNT1 > ((4 * (F_CPU / 1024000)) * idle_rate) || TCNT1 > 0x7FFF) && idle_rate != 0)
		{// using idle rate

			to_send = 1;
		}
		else
		{// or if data has changed			
			if (memcmp(&genesis_1_report, &genesis_1_report_old, sizeof(genesis_1_report)) != 0)
			{
				to_send = 1;
			}
			if (memcmp(&genesis_2_report, &genesis_2_report_old, sizeof(genesis_2_report)) != 0)
			{
				to_send = 1;
			}
		}
		
		usbPoll();
		if (to_send != 0)
		{
			// send the data if needed
			usbSendHidReport(&genesis_1_report, sizeof(genesis_1_report));
			usbSendHidReport(&genesis_2_report, sizeof(genesis_2_report));			
			TCNT1 = 0; // reset timer
		}
		
		usbPoll();	
		memcpy(&genesis_1_report_old, &genesis_1_report, sizeof(genesis_1_report));
		memcpy(&genesis_2_report_old, &genesis_2_report, sizeof(genesis_2_report));			
		to_send = 0; // reset flag
	}
	
	return 0;
}