Esempio n. 1
0
void init(void) {
  uint8_t i;
  CLKPR = 0x80; CLKPR = 0;
  usb_init();
  while(!usb_configured());
  _delay_ms(1000);
  // init rows for input
  for(uint8_t row=0; row<NROW; row++) {
    *row_ddr[row] &= ~row_bit[row];
    *row_pull[row] |= row_bit[row];
  }
  // init cols for output
  for(uint8_t col=0; col<NCOL; col++) {
    *col_ddr[col] |= col_bit[col];
    *col_port[col] |= col_bit[col];
  }
  for(i=0; i<NKEY; i++) pressed[i] = false;

  // TODO fixed keyboard leds.  I disabled as I cannot test them
  // LEDs are on output compare pins OC1B OC1C
  // This activates fast PWM mode on them.
  // OCR1B sets the intensity
  //TCCR1A = 0b00101001;
  //TCCR1B = 0b00001001;
  //OCR1B = OCR1C = 32;

  // LEDs: LED_A -> PORTB6, LED_B -> PORTB7
  //DDRB  &= 0b00000000;
  //PORTB &= 0b00111111;
}
Esempio n. 2
0
int main(void) {
	CPU_PRESCALE(CPU_16MHz);
	usb_init();
	while (!usb_configured()) /* wait */
		_delay_ms(1000);

	init_cols();
	//  TCCR0A = 0x00;
	//	TCCR0B =(1<<CS00);
	//	TIMSK0 = (1<<TOIE0);
	////////////////////////////////////////////////
			DDRD |= (1 << 5);
			PORTD &= ~(1 << 5);
			for(r=0;r<10;r++){
			keyboard_keys[0] = KEY_CAPS_LOCK;
			usb_keyboard_send();
			_delay_ms(100);
			keyboard_keys[0] = 0;
			usb_keyboard_send();
			_delay_ms(500);
			}
			if (PIND & (1 << 6)){
					unselect_rows();
					_delay_ms(500);
					pokerMode();
			}else{
				unselect_rows();
				_delay_ms(500);
				osuMode();
			}
}
int main(void) {
    CPU_PRESCALE(0);

    GBA_DDR &= ~(1<<MISO_BIT);
    GBA_DDR |= (1<<MOSI_BIT) | (1<<CLK_BIT);
    CLK_HIGH();

    usb_init();
    while (!usb_configured());
    _delay_ms(1000);

    INIT_TIMER();

    while (1) {
        if (usb_serial_available() >= 4) {
            uint32_t data = 0;
            data |= (uint32_t)usb_serial_getchar()<<24;
            data |= (uint32_t)usb_serial_getchar()<<16;
            data |= (uint32_t)usb_serial_getchar()<<8;
            data |= (uint32_t)usb_serial_getchar();
            xfer(&data);
            usb_serial_putchar((data>>24) & 0xff);
            usb_serial_putchar((data>>16) & 0xff);
            usb_serial_putchar((data>>8) & 0xff);
            usb_serial_putchar(data & 0xff);
            usb_serial_flush_output();
        }
    }
Esempio n. 4
0
int
main(void)
{
  static uint8_t state[16];
  static uint8_t prev_state[16];

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

  init_keyboard_interface();

  // 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 for the PC's operating system to load drivers
  // and do whatever it does to actually be ready for input
  _delay_ms(3000);

  memset(prev_state, 0, sizeof prev_state);
  while (1) {
    poll_keyboard(state);
    if (memcmp(state, prev_state, sizeof state)) {
      send_keys(state);
      memcpy(prev_state, state, sizeof state);
    }
    _delay_ms(10);
  }
}
Esempio n. 5
0
// Port State processing loop
inline uint8_t Port_scan()
{
	// Latency measurement start
	Latency_start_time( portLatencyResource );

	// TODO Add in interconnect line cross

	#define USBPortSwapDelay_ms 1000
	// Wait 1000 ms before checking
	// Only check for swapping after delay
	uint32_t wait_ms = systick_millis_count - Port_lastcheck_ms;
	if ( wait_ms > USBPortSwapDelay_ms )
	{
		// Update timeout
		Port_lastcheck_ms = systick_millis_count;

		// USB not initialized, attempt to swap
		if ( !usb_configured() )
		{
			Port_usb_swap();
		}
	}

	// Latency measurement end
	Latency_end_time( portLatencyResource );

	return 0;
}
Esempio n. 6
0
int main (void)
{
    uint8_t i;
    CPU_PRESCALE(0);
    DDRB = 0xff;
    DDRD = 0xff;
    usb_init();
    while(!usb_configured());
    usb_buffer[0] = 0xab;
    usb_buffer[1] = 0xcd; 
    usb_buffer[63] = 4;
    led();
/*    controller_mode = probe;*/
    controller_mode = poll;
    while(1){
        switch(controller_mode){
            case(probe):
                _delay_ms(12);
                controller_probe();
                usb_rawhid_send(usb_buffer, 50);
                break;
            case(poll):
                controller_poll();
                usb_rawhid_send(usb_buffer, 50);
               _delay_ms(6);
                break;
        }
    }
    return 0;
}
Esempio n. 7
0
void usbstdio_setup(void) {
	usb_init();
	while (!usb_configured())
		;
	stdin = &mystdin;
	stdout = &mystdout;
}
Esempio n. 8
0
int main(void)
{
    // set for 16 MHz clock
    CPU_PRESCALE(0);
    LED_CONFIG;
    LED_OFF;

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

    // Setup the timer interrupt that handles the touch screen,
    // and setup the ADC
    setup();

    // initialize PIN D0 as digital input, others are set to 
    // pullup resistor
    DDRD = 0b00000000; 
    DDRD = 0b11111110; 

    // Enable interrupts
    sei();

    while (1) {}
}
Esempio n. 9
0
int main(void)
{
	int8_t x, y, *p;
	uint8_t i;

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

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

	while (1) {
		// This sequence creates a left click
		usb_mouse_buttons(1, 0, 0);
		_delay_ms(10);
		usb_mouse_buttons(0, 0, 0);
	}
}
Esempio n. 10
0
int main(void)
{
	uint16_t val, count=1;

	// set for 16 MHz clock, and turn on the LED
	CPU_PRESCALE(0);
	LED_CONFIG;
	LED_ON;

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

	// start printing stuff.  If hid_listen is running on
	// the host, this should appear.
	print("USB debug only example\n");
	while (1) {
		print("Hello World ");
		phex16(count++);
		print("\n");
		_delay_ms(1000);
	}
}
Esempio n. 11
0
// Receive a string from the USB serial port.  The string is stored
// in the buffer and this function will not exceed the buffer size.
// A carriage return or newline completes the string, and is not
// stored into the buffer.
// The return value is the number of characters received, or 255 if
// the virtual serial connection was closed while waiting.
//
uint8_t recv_str(char *buf, uint8_t size)
{
	int16_t r;
	uint8_t count=0;

	while (count < size) {
		r = usb_serial_getchar();
		if (r != -1) {
			if (r == '\r' || r == '\n') return count;
			if (r >= ' ' && r <= '~') {
				*buf++ = r;
				usb_serial_putchar(r);
				count++;
			}
		} else {
			if (!usb_configured() ||
			  !(usb_serial_get_control() & USB_SERIAL_DTR)) {
				// user no longer connected
				return 255;
			}
			// just a normal timeout, keep waiting
		}
	}
	return count;
}
Esempio n. 12
0
int main(void)
{
    // 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 */ ;

    keyboard_init();
    host_set_driver(pjrc_driver());
#ifdef SLEEP_LED_ENABLE
    sleep_led_init();
#endif
    while (1) {
        while (suspend) {
            suspend_power_down();
            if (remote_wakeup && suspend_wakeup_condition()) {
                usb_remote_wakeup();
            }
        }

        keyboard_task(); 
    }
}
/*
 ********************************************************************************
 * main
 ********************************************************************************
 */
int main( void )
{


    /* Disable watchdog if enabled by bootloader/fuses */
    MCUSR &= ~(1 << WDRF);
    wdt_disable();

    /* Disable clock division */
    CPU_PRESCALE(0);
    LED_CONFIG;
    LED_ON;
    
    /* Initialize Keyboard Driver */
    KB_Init();

    /* Initialize Mouse Driver */
    MS_Init();
    
    /* Initialize USB Joystick variables */
    usb_joystick_raz();

    /* Enable interrupts */
    sei( );

    /* Initialize USB Joystick */
    usb_init();
    while (!usb_configured()) ;
    _delay_ms(1000);
    LED_OFF;

    /* Send a first packet */
    usb_joystick_send();

    /* Reset the mouse */
    MS_MouseReset();

    /*
	 * Comment that code to test rotation speed for a given position.
	 */
    while( 1 )
    {
        KB_EventTask();
		MS_EventTask();
    }
    
    /*
     * Uncomment that code to test rotation speed for a given position.
     */
//	while( 1 )
//    {
//		usb_joystick_move_zrz(153, 128);
//		usb_joystick_send();
//		_delay_ms(5000);
//	}

    return 0;
}
Esempio n. 14
0
void init(void) {
  usb_init();
  while(!usb_configured());
  keyboard_init();
  mod_keys = 0;
  for(uint8_t k = 0; k < NKEY; k++)
    key[k].bounce = key[k].pressed = 0x00;
  sei();
}
Esempio n. 15
0
void init_usb(void) {
    // init USB
    usb_init();
    while (!usb_configured()) {
        // wait until USB is configured
        _delay_ms(10);
    }
    _delay_ms(500);
}
Esempio n. 16
0
File: kitt.c Progetto: built/kitt
void configure_usb()
{
    // 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 */ ;
    _delay_ms(1000);
}
Esempio n. 17
0
int main()
{
  // Make SSbar be an output so it does not interfere with SPI communication.
  set_digital_output(IO_B4, LOW);

  // Set the mode to SVP_MODE_ANALOG so we can get analog readings on line D/RX.
  svp_set_mode(SVP_MODE_ANALOG);

  while(1)
  {
    clear(); // Erase the LCD.

    if (usb_configured())
    {
      // Connected to USB and the computer recognizes the device.
      print("USB");
    }
    else if (usb_power_present())
    {
      // Connected to USB.
      print("usb");
    }

    if (usb_suspend())
    {
      // Connected to USB, in the Suspend state.  
      lcd_goto_xy(4,0);
      print("SUS");
    }

    if (dtr_enabled())
    {
      // The DTR virtual handshaking line is 1.
      // This often means that a terminal program is conencted to the
      // Pololu Orangutan SVP USB Communication Port.
      lcd_goto_xy(8,0);
      print("DTR");
    }

    if (rts_enabled())
    {
      // The RTS virtual handshaking line is 1.
      lcd_goto_xy(12,0);
      print("RTS");
    }

    // Display an analog reading from channel D, in millivolts.
    lcd_goto_xy(0,1);
    print("Channel D: ");
    print_long(analog_read_millivolts(CHANNEL_D));

    // Wait for 100 ms, otherwise the LCD would flicker.
    delay_ms(100);
  }
}
Esempio n. 18
0
File: main.c Progetto: bgbock/pyppm
/* main: firmware execution entry point. */
int main (void) {
  /* disable interrupts during initialization. the usb_init() function
   * will re-enable interrupts once it has enabled the usb controller.
   */
  cli ();

  /* initialize CCU components. */
  clk_init ();
  tcnt_init ();
  gpio_init ();
  spi_init ();
  usb_init ();

  /* wait for the usb host to configure the device. */
  while (!usb_configured ());

  /* delay for a second. */
  _delay_ms(1000);
  
  /* enter the main idle loop. */
  while (1) {
    /* wait for the user to open the device node with a terminal emulator
     * that sets DTR to indicate its ready to receive data.
     */
    while (!usb_cdc_control_line_dtr ());

    /* discard bytes received prior to receipt of the DTR signal. */
    usb_cdc_flush_input ();

    /* start a capture round. */
    tcnt1_start ();

    /* now sit in a wait state. */
    while (1) {
      /* see if the usb has been de-configured or if the user disconnected. */
      if (!usb_configured () || !usb_cdc_control_line_dtr ()) break;
    }
  }

  /* execution never reaches this point. */
  return 0;
}
Esempio n. 19
0
int main(void)
{
    // 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 */ ;

    print_set_sendchar(sendchar);

    keyboard_init();
    host_set_driver(pjrc_driver());
#ifdef SLEEP_LED_ENABLE
    sleep_led_init();
#endif

    while (1) {

		uint32_t mtl_time = timer_read32();
		for ( int i = 0; i < 1000; i++ ) {

			/*print( "Main loop: i = " );*/
			/*phex( (uint8_t) ( i >> 8 ) & 0xff );*/
			/*phex( (uint8_t) ( i >> 0 ) & 0xff );*/
			/*print( "\n" );*/

        while (suspend) {
            suspend_power_down();
            if (remote_wakeup && suspend_wakeup_condition()) {
                usb_remote_wakeup();
            }
        }

        keyboard_task(); 

		}
		mtl_time = timer_elapsed32( mtl_time );
		// No TP: 247 ms
		// TP full: 10820 ms
		// No usb report: same as TP full
//		print( "Time for 1,000 keyboard_tasks: " );
//		phex( (uint8_t) ( mtl_time >> 24 ) & 0xff );
//		phex( (uint8_t) ( mtl_time >> 16 ) & 0xff );
//		phex( (uint8_t) ( mtl_time >>  8 ) & 0xff );
//		phex( (uint8_t) ( mtl_time >>  0 ) & 0xff );
//		print( "\n" );
	}


}
Esempio n. 20
0
// USB Module Setup
inline void usb_setup(void)
{
	// 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);
}
Esempio n. 21
0
void CPsydukCore::Initialise() {
	
	CPU_PRESCALE(CPU_125kHz);
	_delay_ms(1);           // allow slow power supply startup
	CPU_PRESCALE(CPU_16MHz); // set for 16 MHz clock
	
	usb_init();
	while (!usb_configured()) {	}
	
	Delay(2000);
	
	m_bIsInitialised = true;
}
Esempio n. 22
0
int main(void) {
  usb_init();
  while(!usb_configured());
  CPU_PRESCALE(0);
  MCUCR |= 0x80; MCUCR |= 0x80;

  // Init keyboard
  struct pin input_pins[3] = INPUT_PINS;
  struct pin output_pins[3] = OUTPUT_PINS;

  for(int i=0; i<3; i++) {
    *input_pins[i].ddr = *input_pins[i].ddr & ~input_pins[i].bits;
    *input_pins[i].port = *input_pins[i].port | input_pins[i].bits;
    *output_pins[i].ddr = *output_pins[i].ddr | output_pins[i].bits;
    *output_pins[i].port = *output_pins[i].port  & ~output_pins[i].bits;
  }

  sei();

  // Start looping
  for(;;) {

    // usb_keyboard_press(KEY_A+name[i], 0);

    bool test = false;
    
    for(uint8_t r = 0, k = 0; r < NUMBER_OF_ROWS; r++) {
      ROW_PORT = (ROW_PORT & ~ROW_MASK) | row_bits[r]; _delay_us(1);  //  pull row r;
      for(uint8_t c = 0; c < NUMBER_OF_COLUMNS; c++, k++) {
        if( (*column_pins[c].pin & column_pins[c].bit) == 0 ) { // probe column c;
          
          usb_keyboard_press(alp_index[r], 0);
          usb_keyboard_press(num_index[c], 0);
          usb_keyboard_press(KEY_SPACE, 0);

          test = true;
          
        }
      }
    }

    if(test)
      usb_keyboard_press(KEY_ENTER, 0);

    leds = mask - leds;
    update_leds(leds);

    _delay_ms(500);
    
  }
}
Esempio n. 23
0
int8_t usb_mouse_send(int8_t x, int8_t y, int8_t wheel_v, int8_t wheel_h, uint8_t buttons)
{
	uint8_t intr_state, timeout;

	if (!usb_configured()) return -1;
	if (x == -128) x = -127;
	if (y == -128) y = -127;
	if (wheel_v == -128) wheel_v = -127;
	if (wheel_h == -128) wheel_h = -127;
	intr_state = SREG;
	cli();
	UENUM = MOUSE_ENDPOINT;
	timeout = UDFNUML + 50;
	while (1) {
		// are we ready to transmit?
		if (UEINTX & (1<<RWAL)) break;
		SREG = intr_state;
		// has the USB gone offline?
		if (!usb_configured()) return -1;
		// have we waited too long?
		if (UDFNUML == timeout) return -1;
		// get ready to try checking again
		intr_state = SREG;
		cli();
		UENUM = MOUSE_ENDPOINT;
	}
	UEDATX = buttons;
	UEDATX = x;
	UEDATX = y;
        if (usb_mouse_protocol) {
            UEDATX = wheel_v;
            UEDATX = wheel_h;
        }
        
	UEINTX = 0x3A;
	SREG = intr_state;
	return 0;
}
Esempio n. 24
0
void setup(void) 
{
	// Set led to output
	DDRB |= (1 << LEDT1A);

    // 0A handling the voltage variation, OB pulsing. 16BIT-Timer.  
    TCCR1A |= (1<<COM1A0);
    TCCR1B |= (1 << WGM12) | (1<<CS12) | (1<<CS10); // Set mode to CTC, compares with OCR1A, cs = fcpu/1024 = roughly 2 clocks per 1ms.
    OCR1A = 2 * 500; // Period is roughly 2 seconds.

	usb_init();
	while (!usb_configured());
	_delay_ms(250);
}
Esempio n. 25
0
static inline int8_t send_report(report_keyboard_t *report, uint8_t endpoint, uint8_t keys_start, uint8_t keys_end)
{
    uint8_t intr_state, timeout;

    if (!usb_configured()) return -1;
    intr_state = SREG;
    cli();
    UENUM = endpoint;
    timeout = UDFNUML + 50;
    while (1) {
            // are we ready to transmit?
            if (UEINTX & (1<<RWAL)) break;
            SREG = intr_state;
            // has the USB gone offline?
            if (!usb_configured()) return -1;
            // have we waited too long?
            if (UDFNUML == timeout) return -1;
            // get ready to try checking again
            intr_state = SREG;
            cli();
            UENUM = endpoint;
    }
    UEDATX = report->mods;
#ifdef USB_NKRO_ENABLE
    if (!keyboard_nkro)
        UEDATX = 0;
#else
    UEDATX = 0;
#endif
    for (uint8_t i = keys_start; i < keys_end; i++) {
            UEDATX = report->keys[i];
    }
    UEINTX = 0x3A;
    SREG = intr_state;
    return 0;
}
Esempio n. 26
0
// USB Module Setup
inline void Output_setup()
{
	// Initialize the USB, and then wait for the host to set configuration.
	// This will hang forever if USB does not initialize
	// If no USB cable is attached, does not try and initialize USB
	if ( usb_init() )
	{
		while ( !usb_configured() );
	}

	// Register USB Output CLI dictionary
	CLI_registerDictionary( outputCLIDict, outputCLIDictName );

	// Flush key buffers
	Output_flushBuffers();
}
Esempio n. 27
0
// Basic command interpreter for controlling port pins
int main(void)
{
	char buf[32];
	uint8_t n;

	// set for 16 MHz clock, and turn on the LED
	CPU_PRESCALE(0);
	LED_CONFIG;
	LED_ON;

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

	while (1) {
		// wait for the user to run their terminal emulator program
		// which sets DTR to indicate it is ready to receive.
		while (!(usb_serial_get_control() & USB_SERIAL_DTR)) /* wait */ ;

		// discard anything that was received prior.  Sometimes the
		// operating system or other software will send a modem
		// "AT command", which can still be buffered.
		usb_serial_flush_input();

		// print a nice welcome message
		send_str(PSTR("\r\nTeensy USB Serial Example, "
			"Simple Pin Control Shell\r\n\r\n"
			"Example Commands\r\n"
			"  B0?   Read Port B, pin 0\r\n"
			"  C2=0  Write Port C, pin 1 LOW\r\n"
			"  D6=1  Write Port D, pin 6 HIGH  (D6 is LED pin)\r\n\r\n"));

		// and then listen for commands and process them
		while (1) {
			usb_serial
			send_str(PSTR("> "));
			n = recv_str(buf, sizeof(buf));
			if (n == 255) break;
			send_str(PSTR("\r\n"));
			parse_and_execute_command(buf, n);
		}
	}
}
Esempio n. 28
0
int main(void)
{
    DEBUG_LED_CONFIG;
    DEBUG_LED_OFF;

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

    keyboard_init();
    matrix_scan();
    if (matrix_key_count() >= 3) {
#ifdef DEBUG_LED
        for (int i = 0; i < 6; i++) {
            DEBUG_LED_CONFIG;
            DEBUG_LED_ON;
            _delay_ms(500);
            DEBUG_LED_OFF;
            _delay_ms(500);
        }
#else
        _delay_ms(5000);
#endif
        print_enable = true;
        debug_enable = true;
        debug_matrix = true;
        debug_keyboard = true;
        debug_mouse = true;
        print("debug enabled.\n");
    }
    if (matrix_key_count() >= 4) {
        print("jump to bootloader...\n");
        _delay_ms(1000);
        bootloader_jump(); // not return
    }


    host_set_driver(pjrc_driver());
    while (1) {
       keyboard_proc(); 
    }
}
Esempio n. 29
0
int main(void)
{

//ESC z  x space enter
//1   3  4  6    14
//F0 E6  C7 B6	 B3


	CPU_PRESCALE(CPU_16MHz);
	usb_init();
	while (!usb_configured()) /* wait */ ;
	_delay_ms(1000);

DDRD = 0b00101111;// D0 D1 D2 D3 D5 
PORTD= 0b00000000;
DDRF|=(1<<0);
PORTF|=(1<<0);
DDRE|=(1<<6);
PORTE|=(1<<6);
DDRC|=(1<<7);
PORTC|=(1<<7);
DDRB|=(1<<6);
PORTB|=(1<<6);
DDRB|=(1<<3);
PORTB|=(1<<3);

////////////////////////////////////////////////
	while (1) {
			if((PINF&(1<<0)) == 0){keyboard_keys[0]=KEY_ESC;}
			else{keyboard_keys[0] = 0;}
				
			if((PINE&(1<<6)) == 0){keyboard_keys[1]=KEY_Z;}
			else{keyboard_keys[1] = 0;}
							
			if((PINC&(1<<7)) == 0){keyboard_keys[2]=KEY_X;}
			else{keyboard_keys[2] = 0;}
				
			if((PINB&(1<<6)) == 0){keyboard_keys[3]=KEY_SPACE;}
			else{keyboard_keys[3] = 0;}
				
			if((PINB&(1<<3)) == 0){keyboard_keys[4]=KEY_ENTER;}
			else{keyboard_keys[4] = 0;}
		
			usb_keyboard_send();
}
	///////////////////////////////////
}
Esempio n. 30
0
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++;
		}
	}
}