Changeset f4f866c in mainline for uspace/srv/hid/console


Ignore:
Timestamp:
2010-04-23T21:42:26Z (16 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6c39a907
Parents:
38aaacc2 (diff), 80badbe (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Location:
uspace/srv/hid/console
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/console/Makefile

    r38aaacc2 rf4f866c  
    3333GENERIC_SOURCES = \
    3434        console.c \
    35         screenbuffer.c \
    3635        keybuffer.c \
    3736        gcons.c
  • uspace/srv/hid/console/console.c

    r38aaacc2 rf4f866c  
    5454#include <vfs/vfs.h>
    5555#include <fibril_synch.h>
     56#include <io/style.h>
     57#include <io/screenbuffer.h>
    5658
    5759#include "console.h"
    5860#include "gcons.h"
    5961#include "keybuffer.h"
    60 #include "screenbuffer.h"
     62
    6163
    6264#define NAME       "console"
     
    7173/** Information about framebuffer */
    7274struct {
    73         int phone;      /**< Framebuffer phone */
    74         ipcarg_t cols;  /**< Framebuffer columns */
    75         ipcarg_t rows;  /**< Framebuffer rows */
    76         int color_cap;  /**< Color capabilities (FB_CCAP_xxx) */
     75        int phone;           /**< Framebuffer phone */
     76        ipcarg_t cols;       /**< Framebuffer columns */
     77        ipcarg_t rows;       /**< Framebuffer rows */
     78        ipcarg_t color_cap;  /**< Color capabilities (FB_CCAP_xxx) */
    7779} fb_info;
    7880
     
    99101/** Information on row-span yet unsent to FB driver. */
    100102struct {
    101         size_t col;  /**< Leftmost column of the span. */
    102         size_t row;  /**< Row where the span lies. */
    103         size_t cnt;  /**< Width of the span. */
     103        ipcarg_t col;  /**< Leftmost column of the span. */
     104        ipcarg_t row;  /**< Row where the span lies. */
     105        ipcarg_t cnt;  /**< Width of the span. */
    104106} fb_pending;
    105107
     
    117119}
    118120
    119 static void curs_goto(size_t x, size_t y)
     121static void curs_goto(ipcarg_t x, ipcarg_t y)
    120122{
    121123        async_msg_2(fb_info.phone, FB_CURSOR_GOTO, x, y);
     
    147149}
    148150
    149 static void set_style(int style)
     151static void set_style(uint8_t style)
    150152{
    151153        async_msg_1(fb_info.phone, FB_SET_STYLE, style);
    152154}
    153155
    154 static void set_color(int fgcolor, int bgcolor, int flags)
     156static void set_color(uint8_t fgcolor, uint8_t bgcolor, uint8_t flags)
    155157{
    156158        async_msg_3(fb_info.phone, FB_SET_COLOR, fgcolor, bgcolor, flags);
    157159}
    158160
    159 static void set_rgb_color(int fgcolor, int bgcolor)
     161static void set_rgb_color(uint32_t fgcolor, uint32_t bgcolor)
    160162{
    161163        async_msg_2(fb_info.phone, FB_SET_RGB_COLOR, fgcolor, bgcolor);
     
    178180}
    179181
    180 static int ccap_fb_to_con(int ccap_fb, int *ccap_con)
     182static int ccap_fb_to_con(ipcarg_t ccap_fb, ipcarg_t *ccap_con)
    181183{
    182184        switch (ccap_fb) {
    183         case FB_CCAP_NONE: *ccap_con = CONSOLE_CCAP_NONE; break;
    184         case FB_CCAP_STYLE: *ccap_con = CONSOLE_CCAP_STYLE; break;
    185         case FB_CCAP_INDEXED: *ccap_con = CONSOLE_CCAP_INDEXED; break;
    186         case FB_CCAP_RGB: *ccap_con = CONSOLE_CCAP_RGB; break;
    187         default: return EINVAL;
    188         }
    189 
     185        case FB_CCAP_NONE:
     186                *ccap_con = CONSOLE_CCAP_NONE;
     187                break;
     188        case FB_CCAP_STYLE:
     189                *ccap_con = CONSOLE_CCAP_STYLE;
     190                break;
     191        case FB_CCAP_INDEXED:
     192                *ccap_con = CONSOLE_CCAP_INDEXED;
     193                break;
     194        case FB_CCAP_RGB:
     195                *ccap_con = CONSOLE_CCAP_RGB;
     196                break;
     197        default:
     198                return EINVAL;
     199        }
     200       
    190201        return EOK;
    191202}
     
    226237 *
    227238 */
    228 static void cell_mark_changed(size_t col, size_t row)
     239static void cell_mark_changed(ipcarg_t col, ipcarg_t row)
    229240{
    230241        if (fb_pending.cnt != 0) {
     
    253264{
    254265        bool flush_cursor = false;
    255 
     266       
    256267        switch (ch) {
    257268        case '\n':
     
    297308                        async_msg_1(fb_info.phone, FB_SCROLL, 1);
    298309        }
    299 
     310       
    300311        if (cons == active_console && flush_cursor)
    301312                curs_goto(cons->scr.position_x, cons->scr.position_y);
     
    327338       
    328339        if (cons != kernel_console) {
    329                 size_t x;
    330                 size_t y;
    331                 int rc = 0;
    332                
    333340                async_serialize_start();
    334341               
     
    344351                set_attrs(&cons->scr.attrs);
    345352                curs_visibility(false);
     353               
     354                ipcarg_t x;
     355                ipcarg_t y;
     356                int rc = 0;
     357               
    346358                if (interbuffer) {
    347359                        for (y = 0; y < cons->scr.size_y; y++) {
     
    390402        /* Ignore parameters, the connection is already opened */
    391403        while (true) {
    392                
    393404                ipc_call_t call;
    394405                ipc_callid_t callid = async_get_call(&call);
     
    433444static void mouse_events(ipc_callid_t iid, ipc_call_t *icall)
    434445{
    435         int button, press;
    436         int dx, dy;
    437         int newcon;
    438 
    439446        /* Ignore parameters, the connection is already opened */
    440447        while (true) {
    441 
    442448                ipc_call_t call;
    443449                ipc_callid_t callid = async_get_call(&call);
    444 
     450               
    445451                int retval;
    446 
     452               
    447453                switch (IPC_GET_METHOD(call)) {
    448454                case IPC_M_PHONE_HUNGUP:
     
    450456                        return;
    451457                case MEVENT_BUTTON:
    452                         button = IPC_GET_ARG1(call);
    453                         press = IPC_GET_ARG2(call);
    454                         if (button == 1) {
    455                                 newcon = gcons_mouse_btn(press);
     458                        if (IPC_GET_ARG1(call) == 1) {
     459                                int newcon = gcons_mouse_btn((bool) IPC_GET_ARG2(call));
    456460                                if (newcon != -1)
    457461                                        change_console(&consoles[newcon]);
     
    460464                        break;
    461465                case MEVENT_MOVE:
    462                         dx = IPC_GET_ARG1(call);
    463                         dy = IPC_GET_ARG2(call);
    464                         gcons_mouse_move(dx, dy);
     466                        gcons_mouse_move((int) IPC_GET_ARG1(call),
     467                            (int) IPC_GET_ARG2(call));
    465468                        retval = 0;
    466469                        break;
     
    520523        console_event_t ev;
    521524        fibril_mutex_lock(&input_mutex);
     525       
    522526recheck:
    523527        while ((keybuffer_pop(&cons->keybuffer, &ev)) && (pos < size)) {
     
    536540                goto recheck;
    537541        }
     542       
    538543        fibril_mutex_unlock(&input_mutex);
    539544}
     
    542547{
    543548        console_event_t ev;
    544 
     549       
    545550        fibril_mutex_lock(&input_mutex);
     551       
    546552recheck:
    547553        if (keybuffer_pop(&cons->keybuffer, &ev)) {
     
    551557                goto recheck;
    552558        }
     559       
    553560        fibril_mutex_unlock(&input_mutex);
    554561}
     
    580587        ipcarg_t arg2;
    581588        ipcarg_t arg3;
    582 
    583         int cons_ccap;
     589       
    584590        int rc;
    585591       
     
    622628                        if (cons == active_console) {
    623629                                async_req_0_0(fb_info.phone, FB_FLUSH);
    624                                
    625630                                curs_goto(cons->scr.position_x, cons->scr.position_y);
    626631                        }
     
    650655                        break;
    651656                case CONSOLE_GET_COLOR_CAP:
    652                         rc = ccap_fb_to_con(fb_info.color_cap, &cons_ccap);
     657                        rc = ccap_fb_to_con(fb_info.color_cap, &arg1);
    653658                        if (rc != EOK) {
    654659                                ipc_answer_0(callid, rc);
    655660                                continue;
    656661                        }
    657                         arg1 = cons_ccap;
    658662                        break;
    659663                case CONSOLE_SET_STYLE:
     
    714718                return false;
    715719        }
    716 
     720       
    717721        kbd_phone = fd_phone(input_fd);
    718722        if (kbd_phone < 0) {
     
    720724                return false;
    721725        }
    722 
     726       
    723727        /* NB: The callback connection is slotted for removal */
    724728        ipcarg_t phonehash;
     
    727731                return false;
    728732        }
    729 
     733       
    730734        async_new_connection(phonehash, 0, NULL, keyboard_events);
    731 
     735       
    732736        /* Connect to mouse device */
    733737        mouse_phone = -1;
    734738        int mouse_fd = open("/dev/hid_in/mouse", O_RDONLY);
    735 
     739       
    736740        if (mouse_fd < 0) {
    737741                printf(NAME ": Notice - failed opening %s\n", "/dev/hid_in/mouse");
    738742                goto skip_mouse;
    739743        }
    740 
     744       
    741745        mouse_phone = fd_phone(mouse_fd);
    742746        if (mouse_phone < 0) {
     
    744748                goto skip_mouse;
    745749        }
    746 
     750       
    747751        if (ipc_connect_to_me(mouse_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) {
    748752                printf(NAME ": Failed to create callback from mouse device\n");
     
    750754                goto skip_mouse;
    751755        }
    752 
     756       
    753757        async_new_connection(phonehash, 0, NULL, mouse_events);
    754758skip_mouse:
    755 
     759       
    756760        /* Connect to framebuffer driver */
    757761        fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VIDEO, 0, 0);
     
    760764                return -1;
    761765        }
    762 
     766       
    763767        /* Register driver */
    764768        int rc = devmap_driver_register(NAME, client_connection);
     
    772776       
    773777        /* Synchronize, the gcons could put something in queue */
    774         ipcarg_t color_cap;
    775778        async_req_0_0(fb_info.phone, FB_FLUSH);
    776779        async_req_0_2(fb_info.phone, FB_GET_CSIZE, &fb_info.cols, &fb_info.rows);
    777         async_req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &color_cap);
    778         fb_info.color_cap = color_cap;
     780        async_req_0_1(fb_info.phone, FB_GET_COLOR_CAP, &fb_info.color_cap);
    779781       
    780782        /* Set up shared memory buffer. */
     
    827829        async_serialize_start();
    828830        gcons_redraw_console();
    829         set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
     831        set_style(STYLE_NORMAL);
    830832        screen_clear();
    831833        curs_goto(0, 0);
  • uspace/srv/hid/console/gcons.c

    r38aaacc2 rf4f866c  
    5454#define STATUS_HEIGHT  48
    5555
    56 #define MAIN_COLOR  0xffffff
     56#define COLOR_MAIN        0xffffff
     57#define COLOR_FOREGROUND  0x202020
     58#define COLOR_BACKGROUND  0xffffff
     59
     60extern char _binary_gfx_helenos_ppm_start[0];
     61extern int _binary_gfx_helenos_ppm_size;
     62extern char _binary_gfx_nameic_ppm_start[0];
     63extern int _binary_gfx_nameic_ppm_size;
     64
     65extern char _binary_gfx_anim_1_ppm_start[0];
     66extern int _binary_gfx_anim_1_ppm_size;
     67extern char _binary_gfx_anim_2_ppm_start[0];
     68extern int _binary_gfx_anim_2_ppm_size;
     69extern char _binary_gfx_anim_3_ppm_start[0];
     70extern int _binary_gfx_anim_3_ppm_size;
     71extern char _binary_gfx_anim_4_ppm_start[0];
     72extern int _binary_gfx_anim_4_ppm_size;
     73
     74extern char _binary_gfx_cons_selected_ppm_start[0];
     75extern int _binary_gfx_cons_selected_ppm_size;
     76extern char _binary_gfx_cons_idle_ppm_start[0];
     77extern int _binary_gfx_cons_idle_ppm_size;
     78extern char _binary_gfx_cons_has_data_ppm_start[0];
     79extern int _binary_gfx_cons_has_data_ppm_size;
     80extern char _binary_gfx_cons_kernel_ppm_start[0];
     81extern int _binary_gfx_cons_kernel_ppm_size;
    5782
    5883static bool use_gcons = false;
     
    82107static size_t active_console = 0;
    83108
    84 size_t mouse_x;
    85 size_t mouse_y;
    86 
    87 bool btn_pressed;
    88 size_t btn_x;
    89 size_t btn_y;
     109static ipcarg_t mouse_x = 0;
     110static ipcarg_t mouse_y= 0;
     111
     112static bool btn_pressed = false;
     113static ipcarg_t btn_x = 0;
     114static ipcarg_t btn_y = 0;
    90115
    91116static void vp_switch(int vp)
     
    95120
    96121/** Create view port */
    97 static int vp_create(size_t x, size_t y, size_t width, size_t height)
     122static int vp_create(ipcarg_t x, ipcarg_t y, ipcarg_t width, ipcarg_t height)
    98123{
    99124        return async_req_2_0(fbphone, FB_VIEWPORT_CREATE, (x << 16) | y,
     
    112137
    113138/** Transparent putchar */
    114 static void tran_putch(wchar_t ch, size_t col, size_t row)
     139static void tran_putch(wchar_t ch, ipcarg_t col, ipcarg_t row)
    115140{
    116141        async_msg_3(fbphone, FB_PUTCHAR, ch, col, row);
     
    259284void gcons_mouse_move(ssize_t dx, ssize_t dy)
    260285{
    261         mouse_x = limit(mouse_x + dx, 0, xres);
    262         mouse_y = limit(mouse_y + dy, 0, yres);
    263 
     286        ssize_t nx = (ssize_t) mouse_x + dx;
     287        ssize_t ny = (ssize_t) mouse_y + dy;
     288       
     289        mouse_x = (size_t) limit(nx, 0, xres);
     290        mouse_y = (size_t) limit(ny, 0, yres);
     291       
    264292        if (active_console != KERNEL_CONSOLE)
    265293                async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y);
    266294}
    267295
    268 static int gcons_find_conbut(int x, int y)
    269 {
    270         int status_start = STATUS_START + (xres - 800) / 2;
     296static int gcons_find_conbut(ipcarg_t x, ipcarg_t y)
     297{
     298        ipcarg_t status_start = STATUS_START + (xres - 800) / 2;
    271299       
    272300        if ((y < STATUS_TOP) || (y >= STATUS_TOP + STATUS_HEIGHT))
     
    278306        if (x >= status_start + (STATUS_WIDTH + STATUS_SPACE) * CONSOLE_COUNT)
    279307                return -1;
     308       
    280309        if (((x - status_start) % (STATUS_WIDTH + STATUS_SPACE)) < STATUS_SPACE)
    281310                return -1;
    282311       
    283         return (x - status_start) / (STATUS_WIDTH + STATUS_SPACE);
     312        ipcarg_t btn = (x - status_start) / (STATUS_WIDTH + STATUS_SPACE);
     313       
     314        if (btn < CONSOLE_COUNT)
     315                return btn;
     316       
     317        return -1;
    284318}
    285319
     
    287321 *
    288322 * @param state New state (true - pressed, false - depressed)
     323 *
    289324 */
    290325int gcons_mouse_btn(bool state)
    291326{
    292         int conbut;
     327        /* Ignore mouse clicks if no buttons
     328           are drawn at all */
     329        if (xres < 800)
     330                return -1;
    293331       
    294332        if (state) {
    295                 conbut = gcons_find_conbut(mouse_x, mouse_y);
     333                int conbut = gcons_find_conbut(mouse_x, mouse_y);
    296334                if (conbut != -1) {
    297335                        btn_pressed = true;
     
    307345        btn_pressed = false;
    308346       
    309         conbut = gcons_find_conbut(mouse_x, mouse_y);
     347        int conbut = gcons_find_conbut(mouse_x, mouse_y);
    310348        if (conbut == gcons_find_conbut(btn_x, btn_y))
    311349                return conbut;
     
    313351        return -1;
    314352}
    315 
    316353
    317354/** Draw a PPM pixmap to framebuffer
     
    321358 * @param x Coordinate of upper left corner
    322359 * @param y Coordinate of upper left corner
    323  */
    324 static void draw_pixmap(char *logo, size_t size, int x, int y)
    325 {
    326         char *shm;
    327         int rc;
    328        
     360 *
     361 */
     362static void draw_pixmap(char *logo, size_t size, ipcarg_t x, ipcarg_t y)
     363{
    329364        /* Create area */
    330         shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
     365        char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
    331366            MAP_ANONYMOUS, 0, 0);
    332367        if (shm == MAP_FAILED)
     
    336371       
    337372        /* Send area */
    338         rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
     373        int rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
    339374        if (rc)
    340375                goto exit;
     
    356391}
    357392
    358 extern char _binary_gfx_helenos_ppm_start[0];
    359 extern int _binary_gfx_helenos_ppm_size;
    360 extern char _binary_gfx_nameic_ppm_start[0];
    361 extern int _binary_gfx_nameic_ppm_size;
    362 
    363393/** Redraws console graphics */
    364394void gcons_redraw_console(void)
    365395{
    366         int i;
    367        
    368396        if (!use_gcons)
    369397                return;
    370398       
    371399        vp_switch(0);
    372         set_rgb_color(MAIN_COLOR, MAIN_COLOR);
     400        set_rgb_color(COLOR_MAIN, COLOR_MAIN);
    373401        clear();
    374402        draw_pixmap(_binary_gfx_helenos_ppm_start,
     
    377405            (size_t) &_binary_gfx_nameic_ppm_size, 5, 17);
    378406       
     407        unsigned int i;
    379408        for (i = 0; i < CONSOLE_COUNT; i++)
    380409                redraw_state(i);
     
    393422static int make_pixmap(char *data, size_t size)
    394423{
    395         char *shm;
    396         int rc;
    397         int pxid = -1;
    398        
    399424        /* Create area */
    400         shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
     425        char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
    401426            MAP_ANONYMOUS, 0, 0);
    402427        if (shm == MAP_FAILED)
     
    405430        memcpy(shm, data, size);
    406431       
     432        int pxid = -1;
     433       
    407434        /* Send area */
    408         rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
     435        int rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
    409436        if (rc)
    410437                goto exit;
     
    432459}
    433460
    434 extern char _binary_gfx_anim_1_ppm_start[0];
    435 extern int _binary_gfx_anim_1_ppm_size;
    436 extern char _binary_gfx_anim_2_ppm_start[0];
    437 extern int _binary_gfx_anim_2_ppm_size;
    438 extern char _binary_gfx_anim_3_ppm_start[0];
    439 extern int _binary_gfx_anim_3_ppm_size;
    440 extern char _binary_gfx_anim_4_ppm_start[0];
    441 extern int _binary_gfx_anim_4_ppm_size;
    442 
    443461static void make_anim(void)
    444462{
    445         int an = async_req_1_0(fbphone, FB_ANIM_CREATE, cstatus_vp[KERNEL_CONSOLE]);
     463        int an = async_req_1_0(fbphone, FB_ANIM_CREATE,
     464            cstatus_vp[KERNEL_CONSOLE]);
    446465        if (an < 0)
    447466                return;
     
    467486        animation = an;
    468487}
    469 
    470 extern char _binary_gfx_cons_selected_ppm_start[0];
    471 extern int _binary_gfx_cons_selected_ppm_size;
    472 extern char _binary_gfx_cons_idle_ppm_start[0];
    473 extern int _binary_gfx_cons_idle_ppm_size;
    474 extern char _binary_gfx_cons_has_data_ppm_start[0];
    475 extern int _binary_gfx_cons_has_data_ppm_size;
    476 extern char _binary_gfx_cons_kernel_ppm_start[0];
    477 extern int _binary_gfx_cons_kernel_ppm_size;
    478488
    479489/** Initialize nice graphical console environment */
     
    500510       
    501511        /* Create status buttons */
    502         size_t status_start = STATUS_START + (xres - 800) / 2;
     512        ipcarg_t status_start = STATUS_START + (xres - 800) / 2;
    503513        size_t i;
    504514        for (i = 0; i < CONSOLE_COUNT; i++) {
     
    511521               
    512522                vp_switch(cstatus_vp[i]);
    513                 set_rgb_color(0x202020, 0xffffff);
     523                set_rgb_color(COLOR_FOREGROUND, COLOR_BACKGROUND);
    514524        }
    515525       
  • uspace/srv/hid/console/gcons.h

    r38aaacc2 rf4f866c  
    3838#include <sys/types.h>
    3939
    40 void gcons_init(int phone);
     40void gcons_init(int);
    4141
    4242void gcons_redraw_console(void);
    43 void gcons_change_console(size_t index);
    44 void gcons_notify_char(size_t index);
     43void gcons_change_console(size_t);
     44void gcons_notify_char(size_t);
    4545void gcons_in_kernel(void);
    4646
    47 void gcons_notify_connect(size_t index);
    48 void gcons_notify_disconnect(size_t index);
     47void gcons_notify_connect(size_t);
     48void gcons_notify_disconnect(size_t);
    4949
    50 void gcons_mouse_move(ssize_t dx, ssize_t dy);
     50void gcons_mouse_move(ssize_t, ssize_t);
    5151int gcons_mouse_btn(bool state);
    5252
  • uspace/srv/hid/console/keybuffer.h

    r38aaacc2 rf4f866c  
    4747typedef struct {
    4848        console_event_t fifo[KEYBUFFER_SIZE];
    49         unsigned long head;
    50         unsigned long tail;
    51         unsigned long items;
     49        size_t head;
     50        size_t tail;
     51        size_t items;
    5252} keybuffer_t;
    5353
Note: See TracChangeset for help on using the changeset viewer.