Пример #1
0
void lcd_remote_init_device(void)
{
#ifdef IRIVER_H300_SERIES
    or_l(0x10010000, &GPIO_FUNCTION); /* GPIO16: RS
                                         GPIO28: CLK */

    or_l(0x00040006, &GPIO1_FUNCTION); /* GPO33:  Backlight
                                          GPIO34: CS
                                          GPIO50: Data */
    or_l(0x10010000, &GPIO_ENABLE);
    or_l(0x00040006, &GPIO1_ENABLE);
#else
    or_l(0x10010800, &GPIO_FUNCTION); /* GPIO11: Backlight
                                         GPIO16: RS
                                         GPIO28: CLK */

    or_l(0x00040004, &GPIO1_FUNCTION); /* GPIO34: CS
                                          GPIO50: Data */
    or_l(0x10010800, &GPIO_ENABLE);
    or_l(0x00040004, &GPIO1_ENABLE);
#endif

    lcd_remote_clear_display();
    if (remote_detect())
        lcd_remote_on();
#ifndef BOOTLOADER
    tick_add_task(remote_tick);
#endif
}
bool remote_button_hold(void)
{
    /* On my remote hold gives readout of 44 */
    if (remote_detect())
        return adc_scan(ADC_REMOTE)<50?true:false;
    else
        return false;
}
Пример #3
0
void lcd_remote_init_device(void)
{
    lcd_remote_clear_display();
    if (remote_detect())
        lcd_remote_on();

    lcd_remote_update();

    /* put the remote control in the tick task */
    tick_add_task(remote_tick);
}
/*
 * Estimate how much current we are drawing just to run.
 */
static int runcurrent(void)
{
    int current = CURRENT_NORMAL;

#ifndef BOOTLOADER
    if (usb_inserted()
#ifdef HAVE_USB_POWER
#if (CURRENT_USB < CURRENT_NORMAL)
            || usb_powered()
#else
            && !usb_powered()
#endif
#endif
       ) {
        current = CURRENT_USB;
    }

#if defined(HAVE_BACKLIGHT)
    if (backlight_get_current_timeout() == 0) /* LED always on */
        current += CURRENT_BACKLIGHT;
#endif

#if defined(HAVE_RECORDING) && defined(CURRENT_RECORD)
    if (audio_status() & AUDIO_STATUS_RECORD)
        current += CURRENT_RECORD;
#endif

#ifdef HAVE_SPDIF_POWER
    if (spdif_powered())
        current += CURRENT_SPDIF_OUT;
#endif

#ifdef HAVE_REMOTE_LCD
    if (remote_detect())
        current += CURRENT_REMOTE;
#endif

#if defined(HAVE_ATA_POWER_OFF) && defined(CURRENT_ATA)
    if (ide_powered())
        current += CURRENT_ATA;
#endif

#endif /* BOOTLOADER */

    return current;
}
Пример #5
0
/* Monitor remote hotswap */
static void remote_tick(void)
{
    static bool last_status = false;
    static int countdown = 0;
    static int init_delay = 0;
    bool current_status;
    int val;
    int level;

    current_status = remote_detect();
    /* Only report when the status has changed */
    if (current_status != last_status)
    {
        last_status = current_status;
        countdown = current_status ? 20*HZ : 1;
    }
    else
    {
        /* Count down until it gets negative */
        if (countdown >= 0)
            countdown--;

        if (current_status)
        {
            if (!(countdown % 8))
            {
                /* Determine which type of remote it is */
                level = disable_irq_save();
                val = adc_scan(ADC_REMOTEDETECT);
                restore_irq(level);

                if (val < ADCVAL_H100_LCD_REMOTE_HOLD)
                {
                    if (val < ADCVAL_H100_LCD_REMOTE)
                        if (val < ADCVAL_H300_LCD_REMOTE)
                            _remote_type = REMOTETYPE_H300_LCD;  /* hold off */
                        else
                            _remote_type = REMOTETYPE_H100_LCD;  /* hold off */
                    else
                        if (val < ADCVAL_H300_LCD_REMOTE_HOLD)
                            _remote_type = REMOTETYPE_H300_LCD;  /* hold on */
                        else
                            _remote_type = REMOTETYPE_H100_LCD;  /* hold on */

                    if (--init_delay <= 0)
                    {
                        queue_broadcast(SYS_REMOTE_PLUGGED, 0);
                        init_delay = 6;
                    }
                }
                else
                {
                    _remote_type = REMOTETYPE_H300_NONLCD; /* hold on or off */
                }
            }
        }
        else
        {
            if (countdown == 0)
            {
                _remote_type = REMOTETYPE_UNPLUGGED;

                queue_broadcast(SYS_REMOTE_UNPLUGGED, 0);
            }
        }
    }

    /* handle chip select timeout */
    if (remote_cs_countdown >= 0)
        remote_cs_countdown--;
    if (remote_cs_countdown == 0)
        CS_HI;
}
Пример #6
0
bool dbg_ports(void)
{
    unsigned int gpio_out;
    unsigned int gpio1_out;
    unsigned int gpio_read;
    unsigned int gpio1_read;
    unsigned int gpio_function;
    unsigned int gpio1_function;
    unsigned int gpio_enable;
    unsigned int gpio1_enable;
    int adc_battery_voltage, adc_battery_level;
    int adc_buttons, adc_remote;
    int line;

    lcd_clear_display();
    lcd_setfont(FONT_SYSFIXED);

    while(1)
    {
        line = 0;
        gpio_read = GPIO_READ;
        gpio1_read = GPIO1_READ;
        gpio_out = GPIO_OUT;
        gpio1_out = GPIO1_OUT;
        gpio_function = GPIO_FUNCTION;
        gpio1_function = GPIO1_FUNCTION;
        gpio_enable = GPIO_ENABLE;
        gpio1_enable = GPIO1_ENABLE;

        lcd_putsf(0, line++, "GPIO_READ: %08x", gpio_read);
        lcd_putsf(0, line++, "GPIO_OUT:  %08x", gpio_out);
        lcd_putsf(0, line++, "GPIO_FUNC: %08x", gpio_function);
        lcd_putsf(0, line++, "GPIO_ENA:  %08x", gpio_enable);
        lcd_putsf(0, line++, "GPIO1_READ: %08x", gpio1_read);
        lcd_putsf(0, line++, "GPIO1_OUT:  %08x", gpio1_out);
        lcd_putsf(0, line++, "GPIO1_FUNC: %08x", gpio1_function);
        lcd_putsf(0, line++, "GPIO1_ENA:  %08x", gpio1_enable);

        adc_buttons = adc_read(ADC_BUTTONS);
        adc_remote  = adc_read(ADC_REMOTE);
        battery_read_info(&adc_battery_voltage, &adc_battery_level);
#if defined(IAUDIO_X5) ||  defined(IAUDIO_M5) || defined(IRIVER_H300_SERIES)
        lcd_putsf(0, line++, "ADC_BUTTONS (%c): %02x",
            button_scan_enabled() ? '+' : '-', adc_buttons);
#else
        lcd_putsf(0, line++, "ADC_BUTTONS: %02x", adc_buttons);
#endif
#if defined(IAUDIO_X5) || defined(IAUDIO_M5)
        lcd_putsf(0, line++, "ADC_REMOTE  (%c): %02x",
            remote_detect() ? '+' : '-', adc_remote);
#else
        lcd_putsf(0, line++, "ADC_REMOTE:  %02x", adc_remote);
#endif
#if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
        lcd_putsf(0, line++, "ADC_REMOTEDETECT: %02x",
                 adc_read(ADC_REMOTEDETECT));
#endif

        battery_read_info(&adc_battery_voltage, &adc_battery_level);
        lcd_putsf(0, line++, "Batt: %d.%03dV %d%%  ", adc_battery_voltage / 1000,
                 adc_battery_voltage % 1000, adc_battery_level);

#if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
        lcd_putsf(0, line++, "remotetype: %d", remote_type());
#endif

        lcd_update();
        if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL))
        {
            lcd_setfont(FONT_UI);
            return false;
        }
    }
    return false;
}
int button_read_device(void)
{
    int  btn = BUTTON_NONE;
    bool hold_button_old;
    bool remote_hold_button_old;
    static int prev_data = 0xff;
    static int last_valid = 0xff;
    int  data;

    /* normal buttons */
    hold_button_old = hold_button;
    hold_button = button_hold();

#ifndef BOOTLOADER
    /* give BL notice if HB state chaged */
    if (hold_button != hold_button_old)
        backlight_hold_changed(hold_button);
#endif

    if (button_scan_on && !hold_button)
    {
        data = adc_scan(ADC_BUTTONS);

        /* ADC debouncing: Only accept new reading if it's
         * stable (+/-1). Use latest stable value otherwise. */
        if ((unsigned)(data - prev_data + 1) <= 2)
            last_valid = data;
        prev_data = data;
        data = last_valid;
        
        if (data < 0xf0)
        {
            if(data < 0x7c)
                if(data < 0x42)
                    btn = BUTTON_LEFT;
                else
                    if(data < 0x62)
                        btn = BUTTON_RIGHT;
                    else
                        btn = BUTTON_SELECT;
            else
                if(data < 0xb6)
                    if(data < 0x98)
                        btn = BUTTON_REC;
                    else
                        btn = BUTTON_PLAY;
                else
                    if(data < 0xd3)
                        btn = BUTTON_DOWN;
                    else
                        btn = BUTTON_UP;
        }
    }

    /* remote buttons */
    data = remote_detect() ? adc_scan(ADC_REMOTE) : 0xff;

    remote_hold_button_old = remote_hold_button;
    remote_hold_button = data < 0x17;

#ifndef BOOTLOADER
    if (remote_hold_button != remote_hold_button_old)
        remote_backlight_hold_changed(remote_hold_button);
#endif

    if (!remote_hold_button)
    {
        if (data < 0xee)
        {
            if(data < 0x7a)
                if(data < 0x41)
                    btn |= BUTTON_RC_FF;
                else
                    if(data < 0x61)
                        btn |= BUTTON_RC_REW;
                    else
                        btn |= BUTTON_RC_MODE;
            else
                if(data < 0xb4)
                    if(data < 0x96)
                        btn |= BUTTON_RC_REC;
                    else
                        btn |= BUTTON_RC_MENU;
                else
                    if(data < 0xd1)
                        btn |= BUTTON_RC_VOL_UP;
                    else
                        btn |= BUTTON_RC_VOL_DOWN;
        }
    }

    data = GPIO_READ;

    /* hold and power are mutually exclusive */
    if (!(data & 0x04000000))
        btn |= BUTTON_POWER;

    /* remote play button should be dead if hold */
    if (!remote_hold_button && !(data & 0x02000000))
        btn |= BUTTON_RC_PLAY;

    return btn;
}
/*
 * Get button pressed from hardware
 */
int button_read_device(void)
{
    int btn = BUTTON_NONE;
    int data = 0;
    static bool hold_button = false;
    bool remote_hold_button = false;

    bool hold_button_old;
    bool remote_present;

    /* check if we have remote connected */
    remote_present = remote_detect();

    /* read hold buttons status */
    hold_button_old = hold_button;
    hold_button = button_hold();
    remote_hold_button = remote_button_hold();
    
#ifndef BOOTLOADER
    /* Only main hold affects backlight */
    if (hold_button != hold_button_old)
        backlight_hold_changed(hold_button);
#endif

    /* Skip if main hold is active */
    if (!hold_button)
    {
        data = adc_scan(ADC_BUTTONS);

        if (data < 2300) /* valid button */
        {
            if (data < 900) /* middle */
            {
                if (data < 500)
                {
                    if (data > 200)
                        /* 200 - 500 */
                        btn = BUTTON_REC;
                }
                else /* 900 - 500 */
                    btn = BUTTON_VOL_DOWN;
            }
            else /* 2250 - 900 */
            {
                if (data < 1600)
                {
                    /* 1600 - 900 */
                    if (data < 1200)
                        /* 1200 - 900 */
                        btn = BUTTON_VOL_UP;
                    else /* 1600 - 1200 */
                        btn = BUTTON_FF;
                }
                else /* 1600 - 2250 */
                {
                    if (data < 1900)
                        /* 1900 - 1600 */
                        btn = BUTTON_REW;
                    else /* 1900 - 2300 */
                        btn = BUTTON_FUNC;
                }
            }
        }
    }

    /* Skip if remote is not present or remote_hold is active */
    if (remote_present && !remote_hold_button)
    {
        data = adc_scan(ADC_REMOTE);

        if (data < 2050) /* valid button */
        {
        if (data < 950) /* middle */
            {
                if (data < 650)
                {
                    if (data < 400)
                    {
                        if (data > 250)
                            /* 250 - 400 */
                            btn = BUTTON_RC_VOL_DOWN;
                    }
                    else /* 650 - 400 */
                        btn = BUTTON_RC_VOL_UP;
                }
                else /* 950 - 650 */
                    btn = BUTTON_RC_FF;
            }
            else /* 2050 - 950 */
            {
                if (data < 1900)
                {
                    if (data < 1350)
                        /* 1350 - 900 */
                        btn = BUTTON_RC_REW;
                }
                else /* 2050 - 1900 */
                    btn = BUTTON_RC_FUNC;
            }
        }
    }

    /* PLAY buttons (both remote and main) are
     * GPIOs not ADC
     */
    data = GPIO1_READ;

    /* GPIO56 active high main PLAY/PAUSE/ON */
    if (!hold_button && ((data & (1<<24))))
        btn |= BUTTON_PLAY;

    /* GPIO41 active high remote PLAY/PAUSE/ON */
    if (remote_present && !remote_hold_button && ((data & (1<<9))))
        btn |= BUTTON_RC_PLAY;
        
    return btn;
}