Exemplo n.º 1
0
unsigned int getkeyab(unsigned int dmin,unsigned int dmax,unsigned char display){   //bien x dung xac nhan dat timeout, nhap va0 so >=a <=b
	//unsigned char arrbuff[33];//so toi da 65536 la 5 chu + 1 null cua chuoi =6
	unsigned char i,strmax,strmin,sobam;
	unsigned long digi=0,temp,toadotruyen=lcd_wait();
	while(getbell()!=offbell);
	strmax=digi2text(lcd_buff,10,dmax)-1;//so chu so cua dmax, bi loi truyen tham so sai
	strmin=digi2text(lcd_buff,10,dmin)-1;
	if(display&minmax_){
		sprintf(lcd_buff,"%u->%u",dmin,dmax);
		lcd_putsxy(lcd_buff,0,lines-1);
		lcd_goto(toadotruyen);
	}
	
	if(display&PAXX_)for(i=0;i<strmax+1;i++){lcd_putchar('X');}
	lcd_goto(toadotruyen);
	
	for(i=(strmax);i!=0xFF;i--){
		//while(ir_in());
		thulaichuso:
		delay_ms(100);
		while((temp=ir_getkeytimeout(offbell&(~diir_),0))>9);//tranh tran so ma thoi
		sobam=(unsigned char)temp+0x30;
		temp=digi+temp*xpowy(10,i);
		if(strmin<i){if(temp>dmax)goto thulaichuso;}
		else {if((temp<dmin)||(temp>dmax)) goto thulaichuso;}
		
		if(display&phimtm_)lcd_putchar(sobam);
		//xongthem1chuso:
		digi=temp;
		setbell(binhthuong);
	}
	setbell(bellsucsesful);//da nhap thanh cong	
	while(getbell()!=offbell);
	return digi;
}
Exemplo n.º 2
0
static int boot_menu(void)
{
    const char* strings[] = {"Boot Rockbox", "Boot OF", "USB mode", "Reset Rockbox configuration"};
    int button, touch, poweroff_repeat = 0;
    unsigned int i;

    verbose = true;
    adc_init();

redraw:
    lcd_clear_display();
    for(i=0; i<ARRAYLEN(strings); i++)
    {
        lcd_drawrect(RECT_X, RECT_Y(i), RECT_WIDTH, RECT_HEIGHT);
        lcd_putsxy(TEXT_X(i), TEXT_Y(i), strings[i]);
    }
    lcd_update();

    while(1)
    {
        button = button_get_w_tmo(HZ/4);
        if(button & BUTTON_TOUCHSCREEN)
        {
            touch = button_get_data();
            unsigned int x = touch & 0xFFFF, y = touch >> 16;
            int found = -1;
            for(i=0; i<ARRAYLEN(strings); i++)
            {
                if(x > RECT_X && x < RECT_X+RECT_WIDTH &&
                   y > RECT_Y(i) && y < RECT_Y(i)+RECT_HEIGHT)
                {
                    found = i;
                    break;
                }
            }

            switch(found)
            {
                case 0:
                    reset_screen();
                    boot_rockbox();
                    break;
                case 1:
                    reset_screen();
                    boot_of();
                    break;
                case 2:
                    usb_mode();
                    break;
                case 3:
                    reset_configuration();
                    break;
            }

            if(found != -1)
                goto redraw;
        }
        else if(button & BUTTON_POWER)
Exemplo n.º 3
0
static void show_splash(int timeout, const char *msg)
{
    reset_screen();
    lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
                (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
    lcd_update();

    sleep(timeout);
}
Exemplo n.º 4
0
int show_logo( void )
{
    lcd_clear_display();
    lcd_setfont(FONT_SYSFIXED);

#ifdef SANSA_CLIP
    /* The top 16 lines of the Sansa Clip screen are yellow, and the bottom 48 
       are blue, so we reverse the usual positioning */
    lcd_putsxy(TEXT_XPOS, 0, BOOT_VERSION);
    lcd_bitmap(rockboxlogo, 0, 16, BMPWIDTH_rockboxlogo, BMPHEIGHT_rockboxlogo);
#else
    lcd_bitmap(rockboxlogo, 0, 10, BMPWIDTH_rockboxlogo, BMPHEIGHT_rockboxlogo);
    lcd_putsxy(TEXT_XPOS, LCD_HEIGHT-SYSFONT_HEIGHT, BOOT_VERSION);
#endif

    lcd_update();
    
    return 0;
}
Exemplo n.º 5
0
unsigned char nhappass(unsigned int pass){
	#define solannhap  5
	cou=0;		//pass da bi thay doi
	temp=0;
	lcd_clr(lines);lcd_puts("He Thong Duoc Bao Ve Nhap Ma Bao Ve!");
	while(++cou!=solannhap) {delay_ms(1500);
		lcd_clr(lines);sprintf(lcd_buff,"Lan Nhap Pass:%u\n",(uint)(cou));lcd_putsxy(lcd_buff,0,0);
		lcd_puts("InPuting..");
		temp=getkeyab(0,65535,phimtm_|PAXX_);
		lcd_clr(lines);
		if(temp==pass){lcd_puts("    Pass OK !!\nHello Boss Son");return 1;}
		else if(temp==1985) {lcd_puts(" Vao Loi He Thong!\nHello Boss NTS");return 1;}
		else {sprintf(lcd_buff,"Con:%bu Lan Nhap Pass",(uchar)(solannhap-cou));lcd_puts(lcd_buff);}
	}
	lcd_clr(lines);
	lcd_puts("Truy Cap Trai Phep\nKhong Thanh Cong!!");
	settimeout(ljmp0,tioums(60000L));//settime out
	flagstatus|=(chongat_|flagtimeout_);
	while(1);
}
Exemplo n.º 6
0
void GIO0(void)
{
    /* Mask GIO0 interrupt */
    IO_INTC_IRQ1 = INTR_IRQ1_EXT0;
    
    unsigned char msg[4];
    i2c_read(PIC_ADR, msg, sizeof(msg));
    tick_diff = current_tick - last_tick;
    last_tick = current_tick;
    unsigned short btn_press = le2short(msg);
    if(tick_diff >= TICK_MIN && tick_diff <= TICK_MAX)
    {
        /* Ignore this, as it is a hold event */
        return;
    }
    last_btn = btn_press;
    switch(btn_press)
    {
        map_button(BTN_LEFT,                 BUTTON_LEFT);
        map_button(BTN_RIGHT,                BUTTON_RIGHT);
        map_button(BTN_BACK,                 BUTTON_BACK);
        map_button(BTN_CUSTOM,               BUTTON_CUSTOM);
        map_button(BTN_MENU,                 BUTTON_MENU);
        map_button(BTN_PLAY,                 BUTTON_PLAY);
        map_button(BTN_POWER,                BUTTON_POWER);
        map_button(BTN_TOUCHPAD_PRESS,       BUTTON_SELECT);
        map_button(BTN_TOUCHPAD_CORNER_DOWN, BUTTON_DOWN);
        map_button(BTN_TOUCHPAD_CORNER_UP,   BUTTON_UP);
    #ifndef ZEN_VISION
    /* These don't seem to work for some reason on the Zen Vision.. */
    case BTN_TOUCHPAD_SCROLL_DOWN:
        btn = BUTTON_DOWN;
        break;
    case BTN_TOUCHPAD_SCROLL_UP:
        btn = BUTTON_UP;
        break;
    #endif
    case BTN_HOLD:
        hold_switch = true;
        break;
    case BTN_UNHOLD:
        hold_switch = false;
        break;
    #ifndef ZEN_VISION
    /* These don't seem to work for some reason.. */
    case HEADPHONE_PLUGIN_A:
    case HEADPHONE_PLUGIN_B:
        nonbtn |= NONBUTTON_HEADPHONE;
        break;
    case HEADPHONE_UNPLUG_A:
    case HEADPHONE_UNPLUG_B:
        nonbtn &= ~NONBUTTON_HEADPHONE;
        break;
    #endif
    case DOCK_INSERT:
        nonbtn |= NONBUTTON_DOCK;
        break;
    case DOCK_UNPLUG:
        nonbtn &= ~(NONBUTTON_DOCK | NONBUTTON_USB | NONBUTTON_POWER);
        break;
    case DOCK_USB_INSERT:
        nonbtn |= NONBUTTON_USB;
        break;
    case DOCK_USB_UNPLUG:
        nonbtn &= ~NONBUTTON_USB;
        break;
    case DOCK_POWER_INSERT:
        nonbtn |= NONBUTTON_POWER;
        break;
    case DOCK_POWER_UNPLUG:
        nonbtn &= ~NONBUTTON_POWER;
        break;
    }
#ifdef BUTTON_DEBUG
    unsigned char weergvn[10];
#ifdef BOOTLOADER
    lcd_set_foreground((sw ? LCD_RGBPACK(255,0,0) : LCD_RGBPACK(0,255,0) ));
#endif
    snprintf(weergvn, sizeof(char)*10, "%x",
             (unsigned int)((msg[3] << 24) |
                            (msg[2] << 16) | (msg[1] << 8) | msg[0]));
    lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*10, LCD_HEIGHT-SYSFONT_HEIGHT*10,
               weergvn);
    snprintf(weergvn, sizeof(char)*10, "%x", btn);
    lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*10, LCD_HEIGHT-SYSFONT_HEIGHT*7,
               weergvn);
#ifdef BOOTLOADER
    lcd_set_foreground(LCD_BLACK);
#endif
    lcd_update();
    sw = !sw;
#endif
    logf("PIC: 0x%x", (unsigned int)((msg[3] << 24) |
                            (msg[2] << 16) | (msg[1] << 8) | msg[0]));
}
void main(void)
{
    unsigned char* loadbuffer;
    int buffer_size;
    int rc;
    int(*kernel_entry)(void);

    /* Make sure interrupts are disabled */
    set_irq_level(IRQ_DISABLED);
    set_fiq_status(FIQ_DISABLED);
    system_init();
    kernel_init();
    
    /* Now enable interrupts */
    set_irq_level(IRQ_ENABLED);
    set_fiq_status(FIQ_ENABLED);

    lcd_init();
    backlight_init();
    font_init();
    button_init();
    usb_init();
    
    
    power_init();
//    enable_irq();
//    enable_fiq();

    adc_init();

    lcd_setfont(FONT_SYSFIXED);

    /* Show debug messages if button is pressed */
//    if(button_read_device())
        verbose = true;

    printf("Rockbox boot loader");
    printf("Version %s", rbversion);

    /* Enter USB mode without USB thread */
    if(usb_detect() == USB_INSERTED)
    {
        const char msg[] = "Bootloader USB mode";
        reset_screen();
        lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
                    (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
        lcd_update();

        ide_power_enable(true);
        storage_enable(false);
        sleep(HZ/20);
        usb_enable(true);

        while (usb_detect() == USB_INSERTED)
        {
            storage_spin(); /* Prevent the drive from spinning down */
            sleep(HZ);
        }

        usb_enable(false);

        reset_screen();
        lcd_update();
    }
    
    sleep(50);

    printf("ATA");
    rc = storage_init();
    if(rc)
    {
        reset_screen();
        error(EATA, rc, true);
    }

    printf("filesystem");
    filesystem_init();

    printf("mount");
    rc = disk_mount_all();
    if (rc<=0)
    {
        error(EDISK,rc, true);
    }

    printf("Loading firmware");

    loadbuffer = (unsigned char*) 0x00900000;
    buffer_size = (unsigned char*)0x01900000 - loadbuffer;

    rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
    if(rc <= EFILE_EMPTY)
        error(EBOOTFILE, rc, true);

    kernel_entry = (void*) loadbuffer;
    rc = kernel_entry();

    /* Should not get here! */
    return rc;
}
Exemplo n.º 8
0
void main(void)
{
    unsigned char* loadbuffer;
    int buffer_size;
    int rc;
    int(*kernel_entry)(void);

    system_init();
    kernel_init(); /* Need the kernel to sleep */

    enable_interrupt(IRQ_FIQ_STATUS);

    lcd_init();
    backlight_init();
    button_init();
    font_init();
    adc_init();

    lcd_setfont(FONT_SYSFIXED);
    
    /* These checks should only run if the bootloader is flashed */
    if(GSTATUS3&0x02)
    {
        GSTATUS3&=0xFFFFFFFD;
        if(!(GPGDAT&BUTTON_POWER) && charger_inserted())
        {
            while(!(GPGDAT&BUTTON_POWER) && charger_inserted())
            {
                char msg[20];
                if(charging_state())
                {
                    snprintf(msg,sizeof(msg),"Charging");
                }
                else
                {
                    snprintf(msg,sizeof(msg),"Charge Complete");
                }
                reset_screen();
                lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
                        (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
                lcd_update();
                
#if defined(HAVE_RTC_ALARM)            
                /* Check if the alarm went off while charging */
                if(rtc_check_alarm_flag())
                {
                    GSTATUS3=1; /* Normally this is set in crt0.s */
                    break;
                }
#endif
            }
            if(!(GPGDAT&BUTTON_POWER) 
#if defined(HAVE_RTC_ALARM)
                && !GSTATUS3
#endif
                )
            {
                shutdown();
            }
        }

        if(button_hold())
        {
            const char msg[] = "HOLD is enabled";
            reset_screen();
            lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
                        (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
            lcd_update();
            
            sleep(2*HZ);
            
            shutdown();
        }
    }

    power_init();
    usb_init();

    /* Enter USB mode without USB thread */
    if(usb_detect() == USB_INSERTED)
    {
        const char msg[] = "Bootloader USB mode";
        reset_screen();
        lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
                    (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
        lcd_update();

        storage_enable(false);
        sleep(HZ/20);
        usb_enable(true);

        while (usb_detect() == USB_INSERTED)
            sleep(HZ);

        usb_enable(false);

        reset_screen();
        lcd_update();
    }
    
    reset_screen();

    /* Show debug messages if button is pressed */
    if(button_read_device()&BUTTON_A)
        verbose = true;

    printf("Rockbox boot loader");
    printf("Version %s", rbversion);

    sleep(50); /* ATA seems to error without this pause */

    rc = storage_init();
    if(rc)
    {
        reset_screen();
        error(EATA, rc, true);
    }

    filesystem_init();

    rc = disk_mount_all();
    if (rc<=0)
    {
        error(EDISK, rc, true);
    }

    printf("Loading firmware");

    /* Flush out anything pending first */
    commit_discard_idcache();

    loadbuffer = (unsigned char*) 0x31000000;
    buffer_size = (unsigned char*)0x31400000 - loadbuffer;

    rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
    if(rc <= EFILE_EMPTY)
        error(EBOOTFILE, rc, true);

    storage_close();
    system_prepare_fw_start();

    commit_discard_idcache();
    kernel_entry = (void*) loadbuffer;
    rc = kernel_entry();

#if 0
    /* Halt */
    while (1)
        core_idle();
#else
    /* Return and restart */
#endif
}
Exemplo n.º 9
0
bool logfdisplay(void)
{
    int action;
    int w, h, i, index;
    int fontnr;
    int cur_x, cur_y, delta_y, delta_x;
    struct font* font;
    int user_index;/* user_index will be number of the first line to display (warning: line!=logf entry) */
    char buf[2];
    
    fontnr = lcd_getfont();
    font = font_get(fontnr);
    
    /* get the horizontal size of each line */
    font_getstringsize("A", NULL, &delta_y, fontnr);
    
    buf[1] = '\0';
    w = LCD_WIDTH;
    h = LCD_HEIGHT;
    /* start at the end of the log */
    user_index = compute_nb_lines(w, font) - h/delta_y -1; /* if negative, will be set 0 to zero later */

    do {
        lcd_clear_display();
        
        if(user_index < 0)
            user_index = 0;
        
        if(logfwrap)
            i = logfindex;
        else
            i = 0;
        
        index = 0;
        cur_x = 0;
        cur_y = 0;
        
        /* nothing to print ? */
        if(logfindex == 0 && !logfwrap)
            goto end_print;
        
        do {
            if(logfbuffer[i] == '\0')
            {
                /* should be display a newline ? */
                if(index >= user_index)
                    cur_y += delta_y;
                cur_x = 0;
                index++;
            }
            else
            {
                /* does character fit on this line ? */
                delta_x = font_get_width(font, logfbuffer[i]);
                
                if(cur_x + delta_x > w)
                {
                    /* should be display a newline ? */
                    if(index >= user_index)
                        cur_y += delta_y;
                    cur_x = 0;
                    index++;
                }
                
                /* should we print character ? */
                if(index >= user_index)
                {
                    buf[0] = logfbuffer[i];
                    lcd_putsxy(cur_x, cur_y, buf);
                }
                
                /* update pointer */
                cur_x += delta_x;
            }
            
            /* did we fill the screen ? */
            if(cur_y > h)
                break;
            
            i++;
            if(i >= MAX_LOGF_SIZE)
                i = 0;
        } while(i != logfindex);
        
        end_print:
        lcd_update();
        
        action = get_action(CONTEXT_STD, HZ);
        switch( action )
        {
            case ACTION_STD_NEXT:
            case ACTION_STD_NEXTREPEAT:
                user_index++;
                break;
            case ACTION_STD_PREV:
            case ACTION_STD_PREVREPEAT:
                user_index--;
                break;
            case ACTION_STD_OK:
                user_index = 0;
                break;
#ifdef HAVE_TOUCHSCREEN
            case ACTION_TOUCHSCREEN:
            {
                short x, y;
                static int prev_y;
                
                action = action_get_touchscreen_press(&x, &y);
                
                if(action & BUTTON_REL)
                    prev_y = 0;
                else
                {
                    if(prev_y != 0)
                        user_index += (prev_y - y) / delta_y;
                    
                    prev_y = y;
                }
            }
#endif
            default:
                break;
        }
    } while(action != ACTION_STD_CANCEL);

    return false;
}