Beispiel #1
0
/*
 * Get button pressed from hardware
 */
int button_read_device(void)
{
#ifdef SANSA_FUZE
    static unsigned power_counter = 0;
#endif
    unsigned short dbop_din;
    int btn = BUTTON_NONE;

    dbop_din = button_read_dbop();

    /* hold button handling */
    hold_button = ((dbop_din & (1<<12)) != 0);
#ifndef BOOTLOADER
    /* light handling */
    if (hold_button != hold_button_old)
    {
        hold_button_old = hold_button;
        backlight_hold_changed(hold_button);
    }
#endif /* BOOTLOADER */
    if (hold_button) {
#ifdef SANSA_FUZE
        power_counter = HZ;
#endif
        return 0;
    }

    /* push button handling */
    if ((dbop_din & (1 << 2)) == 0)
        btn |= BUTTON_UP;
    if ((dbop_din & (1 << 3)) == 0)
        btn |= BUTTON_LEFT;
    if ((dbop_din & (1 << 4)) == 0)
        btn |= BUTTON_SELECT;
    if ((dbop_din & (1 << 5)) == 0)
        btn |= BUTTON_RIGHT;
    if ((dbop_din & (1 << 6)) == 0)
        btn |= BUTTON_DOWN;
    if ((dbop_din & (1 << 8)) != 0)
        btn |= BUTTON_POWER;
    if ((dbop_din & (1 << 15)) == 0)
        btn |= DBOP_BIT15_BUTTON;

#ifdef SANSA_FUZE
    /* read power on bit 8, but not if hold button was just released, since
     * you basically always hit power due to the slider mechanism after releasing
     * (fuze only)
     */
    if (power_counter > 0) {
            power_counter--;
        btn &= ~BUTTON_POWER;
    }
#endif

    return btn;
}
void INT_TIMER2(void)
{
    if (!poll_scrollwheel)
        call_tick_tasks();      /* Run through the list of tick tasks
                                 * (that includes reading the scrollwheel) */
    else
    {
        if (!button_hold())
            button_read_dbop(); /* Read the scrollwheel */
    }

    poll_scrollwheel ^= 1;
    TIMER2_INTCLR = 0;  /* clear interrupt */
}