Ejemplo n.º 1
0
void animate()
{
    if (!animation.is_running || animation.animationLoop == 0)
        return;

    if (timer_elapsed(animation.loop_timer) < animation.delay_in_ms)
        return;

    if (suspend_animation_on_idle && timer_elapsed32(last_key_pressed_timestamp) > ANIMATION_SUSPEND_TIMEOUT)
        return;

	/*
	if (animation.duration_in_ms > 0 && timer_elapsed32(animation.duration_timer) > animation.duration_in_ms)
	{
		stop_animation();
		return;
	}
	*/

#ifdef DEBUG_ANIMATION_SPEED
    if (loop_count)
    {
        loop_count--;
        elapsed_ms = timer_read32();
    }
    else
    {
        loop_count = 10;
        duration_ms /= 10;
        dprintf("avg: %lu\n", duration_ms);
        duration_ms = 0;
        elapsed_ms = timer_read32();
    }
#endif

    animation.loop_timer = timer_read();
    animation.animationLoop();

#ifdef DEBUG_ANIMATION_SPEED
    duration_ms += timer_elapsed32(elapsed_ms);
    // dprintf("el: %u\n", duration_ms);
#endif
}
Ejemplo n.º 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 */ ;

    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" );
	}


}
Ejemplo n.º 3
0
void hook_keyboard_loop(void)
{

    if (test_status)
    {
        // 
        if (timer_elapsed32(last_press_timer) > 480000) // 8 minutes since last keypress
        {
            dprintf("test after\n");
	    rn42_disconnect();
	    led_set(host_keyboard_leds() & ~(1<<USB_LED_CAPS_LOCK)); // Turn off Caps Lock LED
	    sleep_led_toggle();
	    // if layer state x == 1, turn off layer LED and set bool saying it was on previously	    
	      if (third_test){
		quiet_mode();
		third_test = 0;
	      }
            rn42_cts_hi();
	    test_status = 0;
	    second_test = 1;
        }
    }
}
Ejemplo n.º 4
0
static void rgb_task_timers(void) {
  // Update double buffer timers
  uint16_t deltaTime = timer_elapsed32(rgb_counters_buffer);
  rgb_counters_buffer = timer_read32();
  if (g_rgb_counters.any_key_hit < UINT32_MAX) {
    if (UINT32_MAX - deltaTime < g_rgb_counters.any_key_hit) {
      g_rgb_counters.any_key_hit = UINT32_MAX;
    } else {
      g_rgb_counters.any_key_hit += deltaTime;
    }
  }

  // Update double buffer last hit timers
#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
  uint8_t count = last_hit_buffer.count;
  for (uint8_t i = 0; i < count; ++i) {
    if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) {
      last_hit_buffer.count--;
      continue;
    }
    last_hit_buffer.tick[i] += deltaTime;
  }
#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
}
Ejemplo n.º 5
0
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
    static uint32_t key_timer;

    switch (keycode) {
        case L_BRI:
            if (record->event.pressed) {
                if (LED_GCR_STEP > LED_GCR_MAX - gcr_desired) gcr_desired = LED_GCR_MAX;
                else gcr_desired += LED_GCR_STEP;
                if (led_animation_breathing) gcr_breathe = gcr_desired;
            }
            return false;
        case L_BRD:
            if (record->event.pressed) {
                if (LED_GCR_STEP > gcr_desired) gcr_desired = 0;
                else gcr_desired -= LED_GCR_STEP;
                if (led_animation_breathing) gcr_breathe = gcr_desired;
            }
            return false;
        case L_PTN:
            if (record->event.pressed) {
                if (led_animation_id == led_setups_count - 1) led_animation_id = 0;
                else led_animation_id++;
            }
            return false;
        case L_PTP:
            if (record->event.pressed) {
                if (led_animation_id == 0) led_animation_id = led_setups_count - 1;
                else led_animation_id--;
            }
            return false;
        case L_PSI:
            if (record->event.pressed) {
                led_animation_speed += ANIMATION_SPEED_STEP;
            }
            return false;
        case L_PSD:
            if (record->event.pressed) {
                led_animation_speed -= ANIMATION_SPEED_STEP;
                if (led_animation_speed < 0) led_animation_speed = 0;
            }
            return false;
        case L_T_MD:
            if (record->event.pressed) {
                led_lighting_mode++;
                if (led_lighting_mode > LED_MODE_MAX_INDEX) led_lighting_mode = LED_MODE_NORMAL;
            }
            return false;
        case L_T_ONF:
            if (record->event.pressed) {
                led_enabled = !led_enabled;
                I2C3733_Control_Set(led_enabled);
            }
            return false;
        case L_ON:
            if (record->event.pressed) {
                led_enabled = 1;
                I2C3733_Control_Set(led_enabled);
            }
            return false;
        case L_OFF:
            if (record->event.pressed) {
                led_enabled = 0;
                I2C3733_Control_Set(led_enabled);
            }
            return false;
        case L_T_BR:
            if (record->event.pressed) {
                led_animation_breathing = !led_animation_breathing;
                if (led_animation_breathing) {
                    gcr_breathe = gcr_desired;
                    led_animation_breathe_cur = BREATHE_MIN_STEP;
                    breathe_dir = 1;
                }
            }
            return false;
        case L_T_PTD:
            if (record->event.pressed) {
                led_animation_direction = !led_animation_direction;
            }
            return false;
        case U_T_AGCR:
            if (record->event.pressed && MODS_SHIFT && MODS_CTRL) {
                TOGGLE_FLAG_AND_PRINT(usb_gcr_auto, "USB GCR auto mode");
            }
            return false;
        case DBG_TOG:
            if (record->event.pressed) {
                TOGGLE_FLAG_AND_PRINT(debug_enable, "Debug mode");
            }
            return false;
        case DBG_MTRX:
            if (record->event.pressed) {
                TOGGLE_FLAG_AND_PRINT(debug_matrix, "Debug matrix");
            }
            return false;
        case DBG_KBD:
            if (record->event.pressed) {
                TOGGLE_FLAG_AND_PRINT(debug_keyboard, "Debug keyboard");
            }
            return false;
        case DBG_MOU:
            if (record->event.pressed) {
                TOGGLE_FLAG_AND_PRINT(debug_mouse, "Debug mouse");
            }
            return false;
        case MD_BOOT:
            if (record->event.pressed) {
                key_timer = timer_read32();
            } else {
                if (timer_elapsed32(key_timer) >= 500) {
                    reset_keyboard();
                }
            }
            return false;
        default:
            return true; //Process all other keycodes normally
    }
}
Ejemplo n.º 6
0
uint8_t matrix_scan(void)
{
    uint8_t *tmp;

    tmp = matrix_prev;
    matrix_prev = matrix;
    matrix = tmp;

    // power on
    if (!KEY_POWER_STATE()) KEY_POWER_ON();
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        for (uint8_t col = 0; col < MATRIX_COLS; col++) {
            KEY_SELECT(row, col);
            _delay_us(5);

            // Not sure this is needed. This just emulates HHKB controller's behaviour.
            if (matrix_prev[row] & (1<<col)) {
                KEY_PREV_ON();
            }
            _delay_us(10);

            // NOTE: KEY_STATE is valid only in 20us after KEY_ENABLE.
            // If V-USB interrupts in this section we could lose 40us or so
            // and would read invalid value from KEY_STATE.
            uint8_t last = TIMER_RAW;

            KEY_ENABLE();

            // Wait for KEY_STATE outputs its value.
            // 1us was ok on one HHKB, but not worked on another.
            // no   wait doesn't work on Teensy++ with pro(1us works)
            // no   wait does    work on tmk PCB(8MHz) with pro2
            // 1us  wait does    work on both of above
            // 1us  wait doesn't work on tmk(16MHz)
            // 5us  wait does    work on tmk(16MHz)
            // 5us  wait does    work on tmk(16MHz/2)
            // 5us  wait does    work on tmk(8MHz)
            // 10us wait does    work on Teensy++ with pro
            // 10us wait does    work on 328p+iwrap with pro
            // 10us wait doesn't work on tmk PCB(8MHz) with pro2(very lagged scan)
            _delay_us(5);

            if (KEY_STATE()) {
                matrix[row] &= ~(1<<col);
            } else {
                matrix[row] |= (1<<col);
            }

            // Ignore if this code region execution time elapses more than 20us.
            // MEMO: 20[us] * (TIMER_RAW_FREQ / 1000000)[count per us]
            // MEMO: then change above using this rule: a/(b/c) = a*1/(b/c) = a*(c/b)
            if (TIMER_DIFF_RAW(TIMER_RAW, last) > 20/(1000000/TIMER_RAW_FREQ)) {
                matrix[row] = matrix_prev[row];
            }

            _delay_us(5);
            KEY_PREV_OFF();
            KEY_UNABLE();

            // NOTE: KEY_STATE keep its state in 20us after KEY_ENABLE.
            // This takes 25us or more to make sure KEY_STATE returns to idle state.
#ifdef HHKB_JP
            // Looks like JP needs faster scan due to its twice larger matrix
            // or it can drop keys in fast key typing
            _delay_us(30);
#else
            _delay_us(75);
#endif
        }
        if (matrix[row] ^ matrix_prev[row]) matrix_last_modified = timer_read32();
    }
    // power off
    if (KEY_POWER_STATE() &&
            (USB_DeviceState == DEVICE_STATE_Suspended ||
             USB_DeviceState == DEVICE_STATE_Unattached ) &&
            timer_elapsed32(matrix_last_modified) > MATRIX_POWER_SAVE) {
        KEY_POWER_OFF();
        suspend_power_down();
    }
    return 1;
}
Ejemplo n.º 7
0
static void rgb_task_sync(void) {
  // next task
  if (timer_elapsed32(g_rgb_counters.tick) >= RGB_MATRIX_LED_FLUSH_LIMIT)
    rgb_task_state = STARTING;
}