Ejemplo n.º 1
0
// called when a scancode has been received (makecode = key pressed)
static void keyboard_process_scancode(uint8_t is_makecode) {    
    event.keycode = keyboard_get_keycode_from_scancode(scancode_buf, scancode_len);
    event.pressed = is_makecode;
    // the pause key never sends a breakcode and we don't need lock breakcodes
    // (in bochs they are not even sent, maybe because of the LED toggling)
    if (event.keycode != KEY("PAUSE") && event.keycode != KEY("SCROLL") &&
        event.keycode != KEY("NUM")   && event.keycode != KEY("CAPS"))
        keyboard_set_key_pressed(event.keycode, event.pressed);
    event.ascii = keyboard_get_ascii_from_keycode(current_layout, event.keycode, event.flags);
    
    // handle modifier keys
    event.flags.shift = keyboard_get_key_pressed(KEY("L SHFT")) ||
                        keyboard_get_key_pressed(KEY("R SHFT"));
    event.flags.ctrl  = keyboard_get_key_pressed(KEY("L CTRL")) ||
                        keyboard_get_key_pressed(KEY("R CTRL"));
    event.flags.gui   = keyboard_get_key_pressed(KEY("L GUI"))  ||
                        keyboard_get_key_pressed(KEY("R GUI"));
    event.flags.alt   = keyboard_get_key_pressed(KEY("L ALT"))  ||
                        keyboard_get_key_pressed(KEY("R ALT"));
    if (event.pressed) {
        if (event.keycode == KEY("SCROLL"))
            keyboard_leds(SCROLL, event.flags.scroll_lock = !event.flags.scroll_lock);
        if (event.keycode == KEY("NUM"))
            keyboard_leds(NUM,    event.flags.num_lock    = !event.flags.num_lock);
        if (event.keycode == KEY("CAPS"))
            keyboard_leds(CAPS,   event.flags.caps_lock   = !event.flags.caps_lock);
    }
    
    if (handler) handler(event); // call our event handler if there is one
    
    keyboard_state = START; // reset the state machine so
    scancode_len = 0; // we can proceed with a fresh scancode
}
Ejemplo n.º 2
0
/* Main thread
 */
int main(void) {
  /* ChibiOS/RT init */
  halInit();
#if defined(F042)
  SYSCFG->CFGR1 |= SYSCFG_CFGR1_PA11_PA12_RMP; /* remap pins to USB */
#endif /* F042 */

  chSysInit();

  palSetPad(LED_GPIO, LED_PIN);
  chThdSleepMilliseconds(400);
  palClearPad(LED_GPIO, LED_PIN);

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

  /* Start blinking */
  chThdCreateStatic(waBlinkerThread, sizeof(waBlinkerThread), NORMALPRIO, blinkerThread, NULL);

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

  chThdSleepMilliseconds(500);

  /* Start the button thread */
  palSetPadMode(BUTTON_GPIO, BUTTON_PIN, BUTTON_MODE);
  chThdCreateStatic(waButtonThread, sizeof(waButtonThread), NORMALPRIO, buttonThread, NULL);

  /* Main loop */
  while(true) {
    chThdSleepMilliseconds(200);
    /* caps lock led status */
#if defined(LED2_GPIO)
    palWritePad(LED2_GPIO, LED2_PIN, ((keyboard_leds() & 2) == 2));
#endif
  }
}
Ejemplo n.º 3
0
void led_matrix_run(led_setup_t *f)
{
    float ro;
    float go;
    float bo;
    float px;
    uint8_t led_this_run = 0;

    if (led_cur == 0) //Denotes start of new processing cycle in the case of chunked processing
    {
        led_cur = led_map;

        disp.frame += 1;

        breathe_mult = 1;

        if (led_animation_breathing)
        {
            led_animation_breathe_cur += breathe_step * breathe_dir;

            if (led_animation_breathe_cur >= BREATHE_MAX_STEP)
                breathe_dir = -1;
            else if (led_animation_breathe_cur <= BREATHE_MIN_STEP)
                breathe_dir = 1;

            //Brightness curve created for 256 steps, 0 - ~98%
            breathe_mult = 0.000015 * led_animation_breathe_cur * led_animation_breathe_cur;
            if (breathe_mult > 1) breathe_mult = 1;
            else if (breathe_mult < 0) breathe_mult = 0;
        }
    }

    uint8_t fcur = 0;
    uint8_t fmax = 0;

    //Frames setup
    while (f[fcur].end != 1)
    {
        fcur++; //Count frames
    }

    fmax = fcur; //Store total frames count

    while (led_cur < lede && led_this_run < led_per_run)
    {
        ro = 0;
        go = 0;
        bo = 0;

        if (led_lighting_mode == LED_MODE_KEYS_ONLY && led_cur->scan == 255)
        {
            //Do not act on this LED
        }
        else if (led_lighting_mode == LED_MODE_NON_KEYS_ONLY && led_cur->scan != 255)
        {
            //Do not act on this LED
        }
        else if (led_lighting_mode == LED_MODE_INDICATORS_ONLY)
        {
            //Do not act on this LED (Only show indicators)
        }
        else
        {
            //Act on LED
            for (fcur = 0; fcur < fmax; fcur++)
            {
                px = led_cur->px;
                float pxmod;
                pxmod = (float)(disp.frame % (uint32_t)(1000.0f / led_animation_speed)) / 10.0f * led_animation_speed;

                //Add in any moving effects
                if ((!led_animation_direction && f[fcur].ef & EF_SCR_R) || (led_animation_direction && (f[fcur].ef & EF_SCR_L)))
                {
                    pxmod *= 100.0f;
                    pxmod = (uint32_t)pxmod % 10000;
                    pxmod /= 100.0f;

                    px -= pxmod;

                    if (px > 100) px -= 100;
                    else if (px < 0) px += 100;
                }
                else if ((!led_animation_direction && f[fcur].ef & EF_SCR_L) || (led_animation_direction && (f[fcur].ef & EF_SCR_R)))
                {
                    pxmod *= 100.0f;
                    pxmod = (uint32_t)pxmod % 10000;
                    pxmod /= 100.0f;
                    px += pxmod;

                    if (px > 100) px -= 100;
                    else if (px < 0) px += 100;
                }

                //Check if LED's px is in current frame
                if (px < f[fcur].hs) continue;
                if (px > f[fcur].he) continue;
                //note: < 0 or > 100 continue

                //Calculate the px within the start-stop percentage for color blending
                px = (px - f[fcur].hs) / (f[fcur].he - f[fcur].hs);

                //Add in any color effects
                if (f[fcur].ef & EF_OVER)
                {
                    ro = (px * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5;
                    go = (px * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5;
                    bo = (px * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5;
                }
                else if (f[fcur].ef & EF_SUBTRACT)
                {
                    ro -= (px * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5;
                    go -= (px * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5;
                    bo -= (px * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5;
                }
                else
                {
                    ro += (px * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5;
                    go += (px * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5;
                    bo += (px * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5;
                }
            }
        }

        //Clamp values 0-255
        if (ro > 255) ro = 255; else if (ro < 0) ro = 0;
        if (go > 255) go = 255; else if (go < 0) go = 0;
        if (bo > 255) bo = 255; else if (bo < 0) bo = 0;

        if (led_animation_breathing)
        {
            ro *= breathe_mult;
            go *= breathe_mult;
            bo *= breathe_mult;
        }

        *led_cur->rgb.r = (uint8_t)ro;
        *led_cur->rgb.g = (uint8_t)go;
        *led_cur->rgb.b = (uint8_t)bo;

#ifdef USB_LED_INDICATOR_ENABLE
        if (keyboard_leds())
        {
            uint8_t kbled = keyboard_leds();
            if (
                #if USB_LED_NUM_LOCK_SCANCODE != 255
                (led_cur->scan == USB_LED_NUM_LOCK_SCANCODE && kbled & (1<<USB_LED_NUM_LOCK)) ||
                #endif //NUM LOCK
                #if USB_LED_CAPS_LOCK_SCANCODE != 255
                (led_cur->scan == USB_LED_CAPS_LOCK_SCANCODE && kbled & (1<<USB_LED_CAPS_LOCK)) ||
                #endif //CAPS LOCK
                #if USB_LED_SCROLL_LOCK_SCANCODE != 255
                (led_cur->scan == USB_LED_SCROLL_LOCK_SCANCODE && kbled & (1<<USB_LED_SCROLL_LOCK)) ||
                #endif //SCROLL LOCK
                #if USB_LED_COMPOSE_SCANCODE != 255
                (led_cur->scan == USB_LED_COMPOSE_SCANCODE && kbled & (1<<USB_LED_COMPOSE)) ||
                #endif //COMPOSE
                #if USB_LED_KANA_SCANCODE != 255
                (led_cur->scan == USB_LED_KANA_SCANCODE && kbled & (1<<USB_LED_KANA)) ||
                #endif //KANA
                (0))
            {
                if (*led_cur->rgb.r > 127) *led_cur->rgb.r = 0;
                else *led_cur->rgb.r = 255;
                if (*led_cur->rgb.g > 127) *led_cur->rgb.g = 0;
                else *led_cur->rgb.g = 255;
                if (*led_cur->rgb.b > 127) *led_cur->rgb.b = 0;
                else *led_cur->rgb.b = 255;
            }
        }
#endif //USB_LED_INDICATOR_ENABLE

        led_cur++;
        led_this_run++;
    }
}
Ejemplo n.º 4
0
void keyboard_init(ps2_port_t _port) {
    port = _port;
    keyboard_leds(ALL, 0);
    keyboard_scancode_set(2); // scancode set 2 is widely supported
}