static void console_fb_set_color(struct console_fb_data_t * dat, enum tcolor_t f, enum tcolor_t b) { dat->f = f; dat->b = b; tcolor_to_color(f, dat->bright, &(dat->fc)); tcolor_to_color(b, dat->bright, &(dat->bc)); }
/* * set console's front color and background color */ static bool_t fbcon_setcolor(struct console * console, enum tcolor f, enum tcolor b) { struct fb_console_info * info = console->priv; struct color_t col; if(!info->onoff) return FALSE; info->f = f; info->b = b; tcolor_to_color(f, &col); info->fc = fb_map_color(info->fb, &col); tcolor_to_color(b, &col); info->bc = fb_map_color(info->fb, &col); return TRUE; }
/* * register framebuffer driver. */ bool_t register_framebuffer(struct fb * fb) { struct chrdev * dev; struct console * console; struct fb_console_info * info; struct color_t col; u8_t brightness; if(!fb || !fb->info || !fb->info->name) return FALSE; surface_set_maps(&fb->info->surface.maps); dev = malloc(sizeof(struct chrdev)); if(!dev) return FALSE; dev->name = fb->info->name; dev->type = CHR_DEV_FRAMEBUFFER; dev->open = fb_open; dev->read = fb_read; dev->write = fb_write; dev->ioctl = fb_ioctl; dev->close = fb_close; dev->driver = fb; if(!register_chrdev(dev)) { free(dev); return FALSE; } if(search_chrdev_with_type(dev->name, CHR_DEV_FRAMEBUFFER) == NULL) { unregister_chrdev(dev->name); free(dev); return FALSE; } if(fb->init) (fb->init)(fb); display_logo(fb); if(fb->ioctl) { brightness = 0xff; (fb->ioctl)(fb, IOCTL_SET_FB_BACKLIGHT, &brightness); } if(default_framebuffer == NULL) default_framebuffer = fb; /* * register a console */ console = malloc(sizeof(struct console)); info = malloc(sizeof(struct fb_console_info)); if(!console || !info) { unregister_chrdev(dev->name); free(dev); free(console); free(info); return FALSE; } info->name = (char *)fb->info->name; info->fb = fb; info->fw = 8; info->fh = 16; info->w = fb->info->surface.w / info->fw; info->h = fb->info->surface.h / info->fh; info->x = 0; info->y = 0; info->f = TCOLOR_WHITE; info->b = TCOLOR_BLACK; tcolor_to_color(info->f, &col); info->fc = fb_map_color(fb, &col); tcolor_to_color(info->b, &col); info->bc = fb_map_color(fb, &col); info->cursor = TRUE; info->onoff = TRUE; info->clen = info->w * info->h; info->cell = malloc(info->clen * sizeof(struct fbcon_cell)); if(!info->cell) { unregister_chrdev(dev->name); free(dev); free(console); free(info); return FALSE; } memset(info->cell, 0, info->clen * sizeof(struct fbcon_cell)); console->name = info->name; console->getwh = fbcon_getwh; console->getxy = fbcon_getxy; console->gotoxy = fbcon_gotoxy; console->setcursor = fbcon_setcursor; console->getcursor = fbcon_getcursor; console->setcolor = fbcon_setcolor; console->getcolor = fbcon_getcolor; console->cls = fbcon_cls; console->getcode = NULL; console->putcode = fbcon_putcode; console->onoff = fbcon_onoff; console->priv = info; if(!register_console(console)) { unregister_chrdev(dev->name); free(dev); free(console); free(info->cell); free(info); return FALSE; } return TRUE; }
bool_t register_console_framebuffer(struct fb_t * fb) { struct console_fb_data_t * dat; struct console_t * console; if(!fb || !fb->name) return FALSE; dat = malloc(sizeof(struct console_fb_data_t)); if(!dat) return FALSE; console = malloc(sizeof(struct console_t)); if(!console) { free(dat); return FALSE; } dat->fb = fb; dat->fw = 8; dat->fh = 16; dat->w = fb->alone->width / dat->fw; dat->h = fb->alone->height / dat->fh; dat->x = 0; dat->y = 0; dat->sx = dat->x; dat->sy = dat->y; dat->cursor = 1; dat->bright = 0; dat->sbright = dat->bright; dat->f = TCOLOR_WHITE; dat->b = TCOLOR_BLACK; dat->sf = dat->f; dat->sb = dat->b; tcolor_to_color(dat->f, dat->bright, &(dat->fc)); tcolor_to_color(dat->b, dat->bright, &(dat->bc)); dat->clen = dat->w * dat->h; dat->cell = malloc(dat->clen * sizeof(struct cell_t)); if(!dat->cell) { free(console); free(dat); return FALSE; } memset(dat->cell, 0, dat->clen * sizeof(struct cell_t)); dat->state = ESC_STATE_NORMAL; dat->csize = 0; dat->asize = 0; dat->usize = 0; console->name = strdup(fb->name); console->read = NULL, console->write = console_fb_write, console->suspend = console_fb_suspend, console->resume = console_fb_resume, console->priv = dat; if(register_console(console)) return TRUE; free(dat->cell); free(console->priv); free(console->name); free(console); return FALSE; }