Exemplo n.º 1
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" );
	}


}
Exemplo n.º 2
0
bool iota_gfx_init(bool rotate) {
  bool success = false;

  i2c_master_init();
  send_cmd1(DisplayOff);
  send_cmd2(SetDisplayClockDiv, 0x80);
  send_cmd2(SetMultiPlex, DisplayHeight - 1);

  send_cmd2(SetDisplayOffset, 0);


  send_cmd1(SetStartLine | 0x0);
  send_cmd2(SetChargePump, 0x14 /* Enable */);
  send_cmd2(SetMemoryMode, 0 /* horizontal addressing */);

  if(rotate){
    // the following Flip the display orientation 180 degrees
    send_cmd1(SegRemap);
    send_cmd1(ComScanInc);
  }else{
    // Flips the display orientation 0 degrees
    send_cmd1(SegRemap | 0x1);
    send_cmd1(ComScanDec);
  }

  send_cmd2(SetComPins, 0x2);
  send_cmd2(SetContrast, 0x8f);
  send_cmd2(SetPreCharge, 0xf1);
  send_cmd2(SetVComDetect, 0x40);
  send_cmd1(DisplayAllOnResume);
  send_cmd1(NormalDisplay);
  send_cmd1(DeActivateScroll);
  send_cmd1(DisplayOn);

  send_cmd2(SetContrast, 0); // Dim

  clear_display();

  success = true;

  iota_gfx_flush();

#if DEBUG_TO_SCREEN
  print_set_sendchar(capture_sendchar);
#endif

done:
  return success;
}
Exemplo n.º 3
0
Arquivo: main.c Projeto: doopai/gh60
static void setup_usb(void)
{
    // Leonardo needs. Without this USB device is not recognized.
    USB_Disable();

    USB_Init();

    // for Console_Task
    USB_Device_EnableSOFEvents();
    print_set_sendchar(sendchar);
    /* wait for USB startup & debug output */
    uint8_t timeout = 255;  // timeout when USB is not available
    while (timeout-- &&USB_DeviceState != DEVICE_STATE_Configured) {
        wait_ms(4);
#if defined(INTERRUPT_CONTROL_ENDPOINT)
        ;
#else
        USB_USBTask();
#endif
    }
    print("USB configured.\n");
}
Exemplo n.º 4
0
static void SetupHardware(void)
{
    /* Disable watchdog if enabled by bootloader/fuses */
    MCUSR &= ~(1 << WDRF);
    wdt_disable();

    /* Disable clock division */
    clock_prescale_set(clock_div_1);

    // Leonardo needs. Without this USB device is not recognized.
    USB_Disable();

    USB_Init();

    // for Console_Task
    USB_Device_EnableSOFEvents();
    print_set_sendchar(sendchar_func);

    // SUART PD0:output, PD1:input
    DDRD |= (1<<0);
    PORTD |= (1<<0);
    DDRD &= ~(1<<1);
    PORTD |= (1<<1);
}
Exemplo n.º 5
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(); 
//         }
//     }

}