Exemplo n.º 1
0
void key_port_isr_hook(void) {
  if (KEY_STATE() == 1) {
    // Is high. Set high-low transition
    KEY_IRQ_LEVEL(1);
  } else {
    // Is low. Set low-high transition
    KEY_IRQ_LEVEL(0);
  }

  if (KEY_STATE() != last_state) {
    ll_key_event(KEY_STATE() == KEY_DOWN);
    last_state = KEY_STATE();
  } else {
    // Break here.
    __no_operation();
  }

  KEY_ISR_ACK();
}
Exemplo n.º 2
0
void key_init() {
  KEY_INIT();
  KEY_ENABLE_IRQ();
  last_state = KEY_STATE();
}
Exemplo n.º 3
0
int kbdclient_held(unsigned short keycode) {
	return KEY_STATE(keycode);
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
void key_scan(void) {

    // read the column lines
    int col = key_rd();
    int key = keys.row;

    for (int i = 0; i < KEY_COLS; i ++) {
        int down = col & 1;

        switch (KEY_STATE(key)) {
            case KEY_STATE_WAIT4_DOWN: {
                // wait for n successive key down conditions
                if (!down) {
                    keys.state[key] = KEY_STATE_UP;
                } else {
                    int n = KEY_COUNT(key);
                    if (n >= DEBOUNCE_COUNT_DOWN) {
                        keys.state[key] = KEY_STATE_DOWN;
                        if (keys.key_down) {
                            keys.key_down(key);
                        }
                    } else {
                        keys.state[key] = KEY_STATE_WAIT4_DOWN | (n + 1);
                    }
                }
                break;
            }
            case KEY_STATE_DOWN: {
                // the key is down
                if (!down) {
                    keys.state[key] = KEY_STATE_WAIT4_UP;
                }
                break;
            }
            case KEY_STATE_WAIT4_UP: {
                // wait for n successive key up conditions
                if (down) {
                    keys.state[key] = KEY_STATE_DOWN;
                } else {
                    int n = KEY_COUNT(key);
                    if (n >= DEBOUNCE_COUNT_UP) {
                        keys.state[key] = KEY_STATE_UP;
                        if (keys.key_up) {
                            keys.key_up(key);
                        }
                    } else {
                        keys.state[key] = KEY_STATE_WAIT4_UP | (n + 1);
                    }
                }
                break;
            }
            case KEY_STATE_UP: {
                // the key is up
                if (down) {
                    keys.state[key] = KEY_STATE_WAIT4_DOWN;
                }
                break;
            }
            default: {
                keys.state[key] = down ? KEY_STATE_DOWN : KEY_STATE_UP;
                break;
            }
        }
        col >>= 1;
        key += KEY_ROWS; 
    }

    // Set the next row line
    keys.row ++;
    if (keys.row == KEY_ROWS) {
        keys.row = 0;
    }
    key_wr(keys.row);
}
Exemplo n.º 6
0
AGE_MAIN * initialize(void)
{
  AGE_MAIN *p_age = new AGE_MAIN;
  
  GRAPH3D *p_grf = p_age->graph_sdl_set(1024, 768);
  
  SCENE *p_scene = p_age->scene_new();
  p_scene->render_state_set(TRUE);

  //log_open("/home/komat/b1log.txt");
  
  //GAME_MESH *p_mesh = p_scene->mesh_new();
  //MESH_MATERIAL *p_mat = p_scene->material_new();
  
  // TODO -> material_load() ->
  
  // TODO
  // Loading mesh / mesh list
  // Set material list for meshes during loading
  
  //p_scene->load(NULL, "/home/komat/Projekty/Graph/test.b2m");
  //p_scene->load(NULL, "/home/komat/Projekty/Graph/Scenes/level1.bpr");
  //p_scene->load(NULL, "/home/komat/Projekty/test.3ds",SCENE_3DS);
  //p_scene->load(NULL, "/home/komat/Projekty/komat.3ds",SCENE_3DS);
  //p_scene->load(NULL, "/home/komat/Projekty/redshit.3ds",SCENE_3DS);
  //p_scene->load(NULL, "/home/komat/Projekty/test.b2m");
  //p_scene->load(NULL, "/home/komat/Projekty/auto.b2m");
  //p_scene->save(NULL, "/home/komat/Projekty/auto-1.b2m");
  //p_scene->load(NULL, "/home/komat/Projekty/auto-1.b2m");
  //p_scene->load(NULL, "/home/komat/tmp310/apollo13.3ds",SCENE_3DS);
  //p_scene->texture_dir_add("/home/komat/Projekty/Graph/Textures");
  //p_scene->texture_reload();
    
  CAMERA_POLAR *p_camera = (CAMERA_POLAR *)camera_control_get(p_age);
  p_scene->camera_active_set(p_camera);
  
  /*
  GAME_MESH *p_mesh = p_scene->mesh_get("bedna8.b2m");
  p_mesh->translate_set(0.0f,0.0f,5.0f);
  */
 
  p_age->callback_set(callback);

  INPUT *p_input = p_age->input_get();
  
  static INPUT_EVENT events[] = 
  {
    INPUT_EVENT(KEY_STATE(K_M), (INPUT_EVENT_FUNC)scene_move),
    INPUT_EVENT(KEY_STATE(K_R), (INPUT_EVENT_FUNC)scene_rotate),
    INPUT_EVENT(KEY_STATE(K_R), (INPUT_EVENT_FUNC)scene_reset),
    INPUT_EVENT(KEY_STATE(K_A), (INPUT_EVENT_FUNC)scene_test)
  };
  
  p_input->events_add(events, sizeof(events)/sizeof(events[0]));
  
  p_grf->config_draw_grid(FALSE);
  p_grf->config_draw_mouse_cursor(TRUE);
  //p_grf->config_draw_boxes(TRUE);
  p_grf->config_draw_console(TRUE);
  p_grf->config_draw_wired(TRUE);
  //p_grf->config_normals_draw(TRUE);
  //p_grf->config_opengl_lighting(TRUE);
  p_grf->config_draw_all_objects(TRUE);
  p_grf->config_draw_pivots(TRUE);
  
  p_grf->console_font_color_set(RGBB(0,0xff,0));
  p_grf->console_origin_set(0,10);
  p_grf->console_print("Zdar ty jelito 1!");
  p_grf->console_print("Zdar ty jelito 2!");
  p_grf->console_print("Zdar ty jelito 3!");
    
  
  return(p_age);
}