コード例 #1
0
//
//Return 1 to start scan, 2 to end scan
//
int checkPCCmd(){
	usb_rawhid_recv(data_in, 15);
	cmd = data_in[0] >> 6;
	if(cmd == 1){
		return 1;
	}else if (cmd == 2){
		return 2;
	}
	return -1;
}
コード例 #2
0
ファイル: example.c プロジェクト: 7h3rAm/crackmes
int main(void)
{
	int8_t r;
	uint16_t count=0;

	// set for 16 MHz clock
	CPU_PRESCALE(0);

	// Initialize the USB, and then wait for the host to set configuration.
	// If the Teensy is powered without a PC connected to the USB port,
	// this will wait forever.
	usb_init();
	while (!usb_configured()) /* wait */ ;

	// Wait an extra second for the PC's operating system to load drivers
	// and do whatever it does to actually be ready for input
	_delay_ms(1000);

	// Configure timer 0 to generate a timer overflow interrupt every
	// 256*1024 clock cycles, or approx 61 Hz when using 16 MHz clock
	TCCR0A = 0x00;
	TCCR0B = 0x05;
	TIMSK0 = (1<<TOIE0);

	eeprom_read_block(buffer, EEPROM_BUF_ADDR, RAWHID_TX_SIZE);

	while (1) {
		// if received data, do something with it
		r = usb_rawhid_recv(buffer, 0);
		if (r > 0) {
			// save received data into eeprom
			eeprom_update_block(buffer, EEPROM_BUF_ADDR, RAWHID_TX_SIZE);
		}
		// if time to send output, transmit whatever we received earlier
		if (do_output) {
			do_output = 0;

			// put a count in the last 2 bytes
			buffer[62] = count >> 8;
			buffer[63] = count & 255;
			// send the packet
			usb_rawhid_send(buffer, 50);
			count++;
		}
	}
}
コード例 #3
0
int main(void)
{
	int8_t r;

	// set for 16 MHz clock
	CPU_PRESCALE(0);

	// Initialize the USB, and then wait for the host to set configuration.
	// If the Teensy is powered without a PC connected to the USB port,
	// this will wait forever.
	usb_init();
	while (!usb_configured()) /* wait */ ;

	// Wait an extra second for the PC's operating system to load drivers
	// and do whatever it does to actually be ready for input
	_delay_ms(1000);

        // configure LED as output
        DDRD |= LEDMASK;

	while (1) {
		// if received data, do something with it
		r = usb_rawhid_recv(buffer, 0);
		if (r > 0) {
                    // turn on the LED
                    PORTD |= LEDMASK;

                    /* For the response packet, we add 1 to each byte of the
                     * received packet. */
                    uint8_t i;
                    for (i = 0; i < BUFLEN; i++)
                        buffer[i]++;

                    // send the packet
                    usb_rawhid_send(buffer, 50);

                    // turn off the LED
                    PORTD &= ~LEDMASK;
		}
	}
}
コード例 #4
0
ファイル: teensyHW2USB.c プロジェクト: andrewsw/expose-teensy
int main(void)
{
        int8_t r;
    struct teensy_msg msg;

	// set for 16 MHz clock
	CPU_PRESCALE(0);

	// Initialize the USB, and then wait for the host to set configuration.
	// If the Teensy is powered without a PC connected to the USB port,
	// this will wait forever.
	usb_init();
	while (!usb_configured()) /* wait */ ;

	// Wait an extra second for the PC's operating system to load drivers
	// and do whatever it does to actually be ready for input
	_delay_ms(1000);

// Set up Timer 1 for PWM control.
// P&F Correct, Runs 5KHz. Divide 16Mhz clock by 8, cycle = 200.
// Make OCR1A & B outputs.
	DDRB |= ((1<<PORTB5) | (1<<PORTB6));
	//TCCR1A = (1<<COM1A1) | (1<<COM1A0) | (1<<COM1B1) | (1<<COM1B0);
	TCCR1A = (1<<COM1A1)  | (1<<COM1B1) ; 
	TCCR1B = (1<<WGM13) | (1<<CS11);
	ICR1 = 200;
	OCR1A = 0;	// Should stay low to start
	OCR1B = 0; 

// Set up Control Signals. PD6&7 for OCR1B; PC6&7 for OCR1A.
	DDRD |= (1<<PORTD6) | (1<<PORTD7);
	DDRC |= (1<<PORTC6) | (1<<PORTC7);
	PORTD &= ~((1<<PORTD6) | (1<<PORTD7));	// take low to start (off)
	PORTC &= ~((1<<PORTC6) | (1<<PORTC7));

// Timer 0 is not necessary - leave code in case we later want it.
        // Configure timer 0 to generate a timer overflow interrupt every
        // 256*1024 clock cycles, or approx 61 Hz when using 16 MHz clock
//        TCCR0A = 0x00;
//        TCCR0B = 0x05;
 //       TIMSK0 = (1<<TOIE0);
// give a blink at the start
// Loop for debug
//while (1){

	DDRD |= (1<<PORTD3);
	PORTD |= (1<<PORTD3);
	_delay_ms(500);
	PORTD &= ~(1<<PORTD3);
	_delay_ms(500);
//}
	while (1) {
		// if received data, do something with it
		r = usb_rawhid_recv(buffer, 0);
		if (r > 0) {
// give a blink on packet received - uncomment for debug
/*
	DDRD |= (1<<PORTD3);
	PORTD |= (1<<PORTD3);
	_delay_ms(500);
	PORTD &= ~(1<<PORTD3);
	_delay_ms(500);	*/
            msg = unpack(buffer);
        switch(msg.destination){
            case 'a':
                    handle_adc(msg);
	            break;
            case 'm':
                    handle_mc(msg);
                    break;
            default:
                    fail_spectacularly();
	            break;
	}
            free(msg.buf);
            // _delay_ms(50);
		}
	}
}
コード例 #5
0
ファイル: tvote.c プロジェクト: bennyjh/TV2010
int main(void)
{
	int8_t r;
	
	// set for 16 MHz clock
	CPU_PRESCALE(0);

	// Initialize the USB, and then wait for the host to set configuration.
	// If the Teensy is powered without a PC connected to the USB port,
	// this will wait forever.
	usb_init();
	while (!usb_configured()) /* wait */ ;

	// Wait an extra second for the PC's operating system to load drivers
	// and do whatever it does to actually be ready for input
	_delay_ms(1000);

        // Configure timer 0 to generate a timer overflow interrupt every
        // 256*1024 clock cycles, or approx 61 Hz when using 16 MHz clock
	// This interrupt is used to check for button presses (JBS)
        TCCR0A = 0x00;
        TCCR0B = 0x05;
        TIMSK0 = (1<<TOIE0);

	// set the default direction for all of the ports
	DDRD |= (1<<PORTD4);  // set pin D4 to output, i.e. LED 1 pin 4, red
	DDRD |= (1<<PORTD6);  // set pin D6 to output, i.e. LED 1 pin 1, green
	DDRD |= (1<<PORTD7);  // set pin D7 to output, i.e. LED 1 pin 3, blue
	DDRD |= (1<<PORTD1);  // set pin D1 to output, i.e. LED 2 pin 4, red
	DDRD |= (1<<PORTD2);  // set pin D2 to output, i.e. LED 2 pin 3, blue
	DDRD |= (1<<PORTD3);  // set pin D3 to output, i.e. LED 2 pin 1, green
	DDRD |= (0<<PORTC6);  // set button 2 to input
	DDRD |= (0<<PORTC7);  // set button 1 to input

	while (1) {
		// if received data, do something with it
		r = usb_rawhid_recv(buffer, 0);
		if (r > 0) {
// PD4 --> Red 1
// PD6 --> Green 1
// PD7 --> Blue 1

			switch(buffer[0]){
				// set the default LED color to blue for LED 1 & 2

				case 'g':
					PORTD &= ~(1<<PORTD1);
					PORTD &= ~(1<<PORTD2);
					PORTD &= ~(1<<PORTD3);
					PORTD &= ~(1<<PORTD4);
					PORTD &= ~(1<<PORTD6);
					PORTD &= ~(1<<PORTD7);
					PORTD |= (1<<PORTD7);
                                        PORTD |= (1<<PORTD3);
					
					//set initial vote to blue = A abstain
					buffer[0] = 'A';
					continue;

                                        break;
				default:
					break;
			}
		
		}

		// if time to check for button press, do so
		if (do_output) {
			do_output = 0;
			if ( !(PINC & (1<<7)) ) // if button 1 is pressed
			{
				if ( PIND & (1<<7) ) // if LED is blue
				{
					PORTD &= ~(1<<PORTD7); // turn off blue
					PORTD |= (1<<PORTD6);  // turn on green
					buffer[0] = 'Y'; // set buffer to green
				}
				else
				{
					if ( PIND & (1<<6) ) // if LED is green
					{
						// turn off green
						PORTD &= ~(1<<PORTD6);
						// turn on red
						PORTD |= (1<<PORTD4);
						// set buffer char to red
						buffer[0] = 'N';
					}
					else
					{
						// if LED is red
						if ( PIND & (1<<4) )
						{
							// turn off red
							PORTD &= ~(1<<PORTD4);
							// turn on blue
							PORTD |= (1<<PORTD7);
							buffer[0] = 'A';
						}
					}
				}
			}

			if ( !(PINC & (1<<6)) ) // if button 2 is pressed
			{
				// if LED 2 is blue
				if ( PIND & (1<<3) )
				{
					// send the packet
					usb_rawhid_send(buffer, 50);
					PORTD &= ~(1<<PORTD3); // turn off blue
					PORTD |= (1<<PORTD2);  // turn on green
				}
				else
				{
					// if LED 2 is green
					if ( PIND & (1<<2) )
					{
						// turn off green
						PORTD &= ~(1<<PORTD2);
						// turn on blue, i.e. ready
						// to vote
						PORTD |= (1<<PORTD3);
					}
				}
			}
		}
	}
}
コード例 #6
0
ファイル: usb.cpp プロジェクト: vishwa91/ewaste_printer
uint8_t usb_recv(void)
{
	return usb_rawhid_recv(usb_in_buffer, TIMEOUT_RECV);
}