Beispiel #1
0
/*FUNCTION*-------------------------------------------------------------
*
*  Function Name  : _usb_khci_task_stun
*  Returned Value : none
*  Comments       :
*        KHCI task
*END*-----------------------------------------------------------------*/
void keyboard_task_stun(uint32_t param)
{
    while(1)
    {	
        keyboard_task(param);
    }
}
Beispiel #2
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(); 
    }
}
Beispiel #3
0
int main(void)
{
    setup_mcu();
    keyboard_setup();
    setup_usb();
    sei();
    /* init modules */
    serial_init();
    keyboard_init();
    host_set_driver(&lufa_driver);
#ifdef SLEEP_LED_ENABLE
    sleep_led_init();
#endif
    print("Keyboard start.\n");
    while (1) {
        while (USB_DeviceState == DEVICE_STATE_Suspended) {
            print("[s]");
            matrix_power_down();
            suspend_power_down();
            if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
                    USB_Device_SendRemoteWakeup();
            }
        }

        keyboard_task();

#if !defined(INTERRUPT_CONTROL_ENDPOINT)
        USB_USBTask();
#endif
    }
}
Beispiel #4
0
/* Main thread
 */
int main(void) {
  /* ChibiOS/RT init */
  halInit();
  chSysInit();

  // TESTING
  // chThdCreateStatic(waBlinkerThread, sizeof(waBlinkerThread), NORMALPRIO, blinkerThread, NULL);

  hook_early_init();

  /* Init USB */
  init_usb_driver(&USB_DRIVER);

  /* init printf */
  init_printf(NULL,sendchar_pf);

  /* Wait until the USB is active */
  while(USB_DRIVER.state != USB_ACTIVE)
    chThdSleepMilliseconds(50);

  /* Do need to wait here!
   * Otherwise the next print might start a transfer on console EP
   * before the USB is completely ready, which sometimes causes
   * HardFaults.
   */
  chThdSleepMilliseconds(50);

  print("USB configured.\n");

  /* init TMK modules */
  keyboard_init();
  host_set_driver(&chibios_driver);

#ifdef SLEEP_LED_ENABLE
  sleep_led_init();
#endif

  print("Keyboard start.\n");

  hook_late_init();

  /* Main loop */
  while(true) {

    if(USB_DRIVER.state == USB_SUSPENDED) {
      print("[s]");
      while(USB_DRIVER.state == USB_SUSPENDED) {
        hook_usb_suspend_loop();
      }
      /* Woken up */
      // variables have been already cleared
      send_keyboard_report();
#ifdef MOUSEKEY_ENABLE
      mousekey_send();
#endif /* MOUSEKEY_ENABLE */
    }

    keyboard_task();
  }
}
Beispiel #5
0
int main(void)
{
    bool suspended = false;
#if USB_COUNT_SOF
    uint16_t last_timer = timer_read();
#endif
#if !defined(__AVR_ATmega32__)
    CLKPR = 0x80, CLKPR = 0;
#endif
#ifndef PS2_USE_USART
    uart_init(UART_BAUD_RATE);
#endif

    keyboard_init();
    host_set_driver(vusb_driver());

    debug("initForUsbConnectivity()\n");
    initForUsbConnectivity();

    debug("main loop\n");
    while (1) {
#if USB_COUNT_SOF
        if (usbSofCount != 0) {
            suspended = false;
            usbSofCount = 0;
            last_timer = timer_read();
        } else {
            // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1)
            if (timer_elapsed(last_timer) > 5) {
                suspended = true;
/*
                uart_putchar('S');
                _delay_ms(1);
                cli();
                set_sleep_mode(SLEEP_MODE_PWR_DOWN);
                sleep_enable();
                sleep_bod_disable();
                sei();
                sleep_cpu();
                sleep_disable();
                _delay_ms(10);
                uart_putchar('W');
*/
            }
        }
#endif
        if (!suspended) {
            usbPoll();

            // TODO: configuration process is incosistent. it sometime fails.
            // To prevent failing to configure NOT scan keyboard during configuration
            if (usbConfiguration && usbInterruptIsReady()) {
                keyboard_task();
            }
            vusb_transfer_keyboard();
        }
    }
}
Beispiel #6
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" );
	}


}
Beispiel #7
0
int main(void)
{
    bool suspended = false;
#if USB_COUNT_SOF
    uint16_t last_timer = timer_read();
#endif

    CLKPR = 0x80, CLKPR = 0;
#ifndef NO_UART
    uart_init(UART_BAUD_RATE);
#endif

    keyboard_init();
    host_set_driver(vusb_driver());

    debug("initForUsbConnectivity()\n");
    initForUsbConnectivity();

    debug("main loop\n");
    while (1) {
#if USB_COUNT_SOF
        if (usbSofCount != 0) {
            suspended = false;
            usbSofCount = 0;
            last_timer = timer_read();
        } else {
            // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1)
            if (timer_elapsed(last_timer) > 5) {
                suspended = true;
            }
        }
#endif
        if (!suspended) {
            usbPoll();

            // TODO: configuration process is incosistent. it sometime fails.
            // To prevent failing to configure NOT scan keyboard during configuration
            if (usbConfiguration && usbInterruptIsReady()) {
                keyboard_task();
            }
            vusb_transfer_keyboard();
        } else if (suspend_wakeup_condition()) {
            usb_remote_wakeup();
        }
    }
}
Beispiel #8
0
int main(void)
{
    setup_hardware();
    setup_set_handedness();
    sei();

    /* wait for USB startup to get ready for debug output */
    uint8_t timeout = 200;  // timeout when USB is not available
    while (timeout-- && USB_DeviceState != DEVICE_STATE_Configured) {
        wait_ms(5);
#if defined(INTERRUPT_CONTROL_ENDPOINT)
        ;
#else
        USB_USBTask();
#endif
    }

    /* if (USB_DeviceState != DEVICE_STATE_Configured) { */
    if (!has_usb()) {
        // USB failed to connect, so run this device in slave mode.
        matrix_init();
        serial_slave_init();

        while (1) {
            matrix_slave_scan();
        }
    }

    /* init modules */
    keyboard_init();
    host_set_driver(&lufa_driver);

#ifdef SLEEP_LED_ENABLE
    sleep_led_init();
#endif

    while (1) {
        keyboard_task();

#if !defined(INTERRUPT_CONTROL_ENDPOINT)
        USB_USBTask();
#endif
    }
}
Beispiel #9
0
/* Main thread
 */
int main(void) {
    /* ChibiOS/RT init */
    halInit();
    chSysInit();

    // TESTING
    // chThdCreateStatic(waBlinkerThread, sizeof(waBlinkerThread), NORMALPRIO, blinkerThread, NULL);

    /* Init USB */
    init_usb_driver(&USB_DRIVER);

    /* init printf */
    init_printf(NULL,sendchar_pf);

#ifdef SERIAL_LINK_ENABLE
    init_serial_link();
#endif

#ifdef VISUALIZER_ENABLE
    visualizer_init();
#endif


    host_driver_t* driver = NULL;

    /* Wait until the USB or serial link is active */
    while (true) {
        if(USB_DRIVER.state == USB_ACTIVE) {
            driver = &chibios_driver;
            break;
        }
#ifdef SERIAL_LINK_ENABLE
        if(is_serial_link_connected()) {
            driver = get_serial_link_driver();
            break;
        }
        serial_link_update();
#endif
        chThdSleepMilliseconds(50);
    }

    /* Do need to wait here!
     * Otherwise the next print might start a transfer on console EP
     * before the USB is completely ready, which sometimes causes
     * HardFaults.
     */
    chThdSleepMilliseconds(50);

    print("USB configured.\n");

    /* init TMK modules */
    keyboard_init();
    host_set_driver(driver);

#ifdef SLEEP_LED_ENABLE
    sleep_led_init();
#endif

    print("Keyboard start.\n");

    /* Main loop */
    while(true) {

        if(USB_DRIVER.state == USB_SUSPENDED) {
            print("[s]");
#ifdef VISUALIZER_ENABLE
            visualizer_suspend();
#endif
            while(USB_DRIVER.state == USB_SUSPENDED) {
                /* Do this in the suspended state */
#ifdef SERIAL_LINK_ENABLE
                serial_link_update();
#endif
                suspend_power_down(); // on AVR this deep sleeps for 15ms
                /* Remote wakeup */
                if((USB_DRIVER.status & 2) && suspend_wakeup_condition()) {
                    send_remote_wakeup(&USB_DRIVER);
                }
            }
            /* Woken up */
            // variables has been already cleared by the wakeup hook
            send_keyboard_report();
#ifdef MOUSEKEY_ENABLE
            mousekey_send();
#endif /* MOUSEKEY_ENABLE */

#ifdef VISUALIZER_ENABLE
            visualizer_resume();
#endif
        }

        keyboard_task();
    }
}
Beispiel #10
0
int main(void)
{
    SetupHardware();
    sei();

    /* wait for USB startup to get ready for debug output */
    uint8_t timeout = 255;  // timeout when USB is not available(Bluetooth)
    while (timeout-- && USB_DeviceState != DEVICE_STATE_Configured) {
        wait_ms(4);
#if defined(INTERRUPT_CONTROL_ENDPOINT)
        ;
#else
        USB_USBTask();
#endif
    }
    print("\nUSB init\n");

    rn42_init();
    rn42_task_init();
    print("RN-42 init\n");

    /* init modules */
    keyboard_init();

    if (!rn42_rts()) {
        host_set_driver(&rn42_driver);
    } else {
        host_set_driver(&lufa_driver);
    }

#ifdef SLEEP_LED_ENABLE
    sleep_led_init();
#endif

    print("Keyboard start\n");
    while (1) {
        while (rn42_rts() && // RN42 is off
                USB_DeviceState == DEVICE_STATE_Suspended) {
            print("[s]");
            matrix_power_down();
            suspend_power_down();
            suspend_power_down();
            suspend_power_down();
            suspend_power_down();
            suspend_power_down();
            suspend_power_down();
            suspend_power_down();
            if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
                    USB_Device_SendRemoteWakeup();
            }
        }

        keyboard_task();

#if !defined(INTERRUPT_CONTROL_ENDPOINT)
        USB_USBTask();
#endif

        rn42_task();
    }
}
Beispiel #11
0
/* Main thread
 */
int main(void) {
  /* ChibiOS/RT init */
  halInit();
  chSysInit();

#ifdef STM32_EEPROM_ENABLE
  EEPROM_Init();
#endif

  // TESTING
  // chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

  keyboard_setup();

  /* Init USB */
  init_usb_driver(&USB_DRIVER);

  /* init printf */
  init_printf(NULL,sendchar_pf);

#ifdef MIDI_ENABLE
  setup_midi();
#endif

#ifdef SERIAL_LINK_ENABLE
  init_serial_link();
#endif

#ifdef VISUALIZER_ENABLE
  visualizer_init();
#endif


  host_driver_t* driver = NULL;

  /* Wait until the USB or serial link is active */
  while (true) {
#if defined(WAIT_FOR_USB) || defined(SERIAL_LINK_ENABLE)
    if(USB_DRIVER.state == USB_ACTIVE) {
      driver = &chibios_driver;
      break;
    }
#else
    driver = &chibios_driver;
    break;
#endif
#ifdef SERIAL_LINK_ENABLE
    if(is_serial_link_connected()) {
      driver = get_serial_link_driver();
      break;
    }
    serial_link_update();
#endif
    wait_ms(50);
  }

  /* Do need to wait here!
   * Otherwise the next print might start a transfer on console EP
   * before the USB is completely ready, which sometimes causes
   * HardFaults.
   */
  wait_ms(50);

  print("USB configured.\n");

  /* init TMK modules */
  keyboard_init();
  host_set_driver(driver);

#ifdef SLEEP_LED_ENABLE
  sleep_led_init();
#endif

  print("Keyboard start.\n");

  /* Main loop */
  while(true) {

#if !defined(NO_USB_STARTUP_CHECK)
    if(USB_DRIVER.state == USB_SUSPENDED) {
      print("[s]");
#ifdef VISUALIZER_ENABLE
      visualizer_suspend();
#endif
      while(USB_DRIVER.state == USB_SUSPENDED) {
        /* Do this in the suspended state */
#ifdef SERIAL_LINK_ENABLE
        serial_link_update();
#endif
        suspend_power_down(); // on AVR this deep sleeps for 15ms
        /* Remote wakeup */
        if(suspend_wakeup_condition()) {
          usbWakeupHost(&USB_DRIVER);
        }
      }
      /* Woken up */
      // variables has been already cleared by the wakeup hook
      send_keyboard_report();
#ifdef MOUSEKEY_ENABLE
      mousekey_send();
#endif /* MOUSEKEY_ENABLE */

#ifdef VISUALIZER_ENABLE
      visualizer_resume();
#endif
    }
#endif

    keyboard_task();
#ifdef CONSOLE_ENABLE
    console_task();
#endif
#ifdef VIRTSER_ENABLE
    virtser_task();
#endif
#ifdef RAW_ENABLE
    raw_hid_task();
#endif
  }
}
Beispiel #12
0
int main(void)
{   

    CPU_PRESCALE(0);

    // DDRD  = _BV(PD5);
    // DDRB  = _BV(PB0);
    
    // PORTD = _BV(PD5);
    // PORTB = _BV(PB0);

    print_set_sendchar(sendchar);

    // usb_init();
    // _delay_ms(2000);
    // while (!usb_configured()) /* wait */



    dprintf("Initializing keyboard...\n");
    keyboard_init();
    
    // This implementation is pretty simplistic... if the USB connection
    // is not configured, choose the Bluefruit, otherwise use USB
    // Definitely would prefer to have this driven by an input pin and make
    // it switch dynamically - BCG
    // if (!usb_configured()) {
    
    //     // Send power to Bluefruit... Adafruit says it takes 27 mA, I think
    //     // the pins should provide 40 mA, but just in case I switch the 
    //     // Bluefruit using a transistor - BCG
    //     DDRB   = _BV(PB6);
    //     PORTB |= _BV(PB6);
    
        dprintf("Setting host driver to bluefruit...\n");
        host_set_driver(bluefruit_driver());

        dprintf("Initializing serial...\n");
        serial_init();

    // char swpa[] = "+++\r\n";
    // for (int i = 0; i < 5; i++) {
    //     serial_send(swpa[i]);
    // }

    // char ble_enable[] = "AT+BLEKEYBOARDEN=1\r\n";
    // for (int i = 0; i < 20; i++) {
    //     serial_send(ble_enable[i]);
    // }

    // char reset[] = "ATZ\r\n";
    // for (int i = 0; i < 5; i++) {
    //     serial_send(reset[i]);
    // }

    // for (int i = 0; i < 5; i++) {
    //     serial_send(swpa[i]);
    // }

        // 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);
        // PORTD = ~_BV(PD5);
        dprintf("Starting main loop");
        while (1) {
            keyboard_task();
        }

//     } else {

//         // I'm not smart enough to get this done with LUFA - BCG
//         dprintf("Setting host driver to PJRC...\n");
//         host_set_driver(pjrc_driver());
// #ifdef SLEEP_LED_ENABLE
//     sleep_led_init();
// #endif
//         // 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);
//         PORTB = ~_BV(PB0);
//         dprintf("Starting main loop");
//         while (1) {
//             while (suspend) {
//                 suspend_power_down();
//                 if (remote_wakeup && suspend_wakeup_condition()) {
//                     usb_remote_wakeup();
//                 }
//             }
//             keyboard_task(); 
//         }
//     }

}
int main(void)
{
    DBG_LED_ENA;
    DBG_1_ENA;
    DBG_1_OFF;
    DBG_2_ENA;
    DBG_2_OFF;
    DBG_3_ENA;
    DBG_3_OFF;

    debug_code_init();

    CLK_init();

    ADC0_init();

    SR_EXP_Init();

#ifdef RGB_MATRIX_ENABLE
    i2c1_init();
#endif // RGB_MATRIX_ENABLE

    matrix_init();

    USB2422_init();

    DBGC(DC_MAIN_UDC_START_BEGIN);
    udc_start();
    DBGC(DC_MAIN_UDC_START_COMPLETE);

    DBGC(DC_MAIN_CDC_INIT_BEGIN);
    CDC_init();
    DBGC(DC_MAIN_CDC_INIT_COMPLETE);

    while (USB2422_Port_Detect_Init() == 0) {}

    DBG_LED_OFF;

#ifdef RGB_MATRIX_ENABLE
    while (I2C3733_Init_Control() != 1) {}
    while (I2C3733_Init_Drivers() != 1) {}

    I2C_DMAC_LED_Init();

    i2c_led_q_init();

    for (uint8_t drvid = 0; drvid < ISSI3733_DRIVER_COUNT; drvid++)
        I2C_LED_Q_ONOFF(drvid); //Queue data
#endif // RGB_MATRIX_ENABLE

    keyboard_setup();

    keyboard_init();

    host_set_driver(&arm_atsam_driver);

#ifdef CONSOLE_ENABLE
    uint64_t next_print = 0;
#endif //CONSOLE_ENABLE

    v_5v_avg = adc_get(ADC_5V);

    debug_code_disable();

    while (1)
    {
        main_subtasks(); //Note these tasks will also be run while waiting for USB keyboard polling intervals

        if (g_usb_state == USB_FSMSTATUS_FSMSTATE_SUSPEND_Val || g_usb_state == USB_FSMSTATUS_FSMSTATE_SLEEP_Val)
        {
            if (suspend_wakeup_condition())
            {
                udc_remotewakeup(); //Send remote wakeup signal
                wait_ms(50);
            }

            continue;
        }

        keyboard_task();

#ifdef CONSOLE_ENABLE
        if (timer_read64() > next_print)
        {
            next_print = timer_read64() + 250;
            //Add any debug information here that you want to see very often
            //dprintf("5v=%u 5vu=%u dlow=%u dhi=%u gca=%u gcd=%u\r\n", v_5v, v_5v_avg, v_5v_avg - V5_LOW, v_5v_avg - V5_HIGH, gcr_actual, gcr_desired);
        }
#endif //CONSOLE_ENABLE
    }


    return 1;
}