Commit a2a5729fc1247bb45d794e9d731c0b03bf58096f

Authored by Che-Liang Chiou
Committed by Anatolij Gustschin
1 parent d3983ee853

api: export LCD device to external apps

This patch exports LCD info-query and bitmap-rendering functions to
external apps.

This patch is tested on a Seaboard.  Because the LCD driver is not yet
upstreamed, the test was done in a local downstream repo.

Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>

Showing 8 changed files with 210 additions and 1 deletions Side-by-side Diff

... ... @@ -24,7 +24,8 @@
24 24  
25 25 LIB = $(obj)libapi.o
26 26  
27   -COBJS-$(CONFIG_API) += api.o api_net.o api_storage.o api_platform-$(ARCH).o
  27 +COBJS-$(CONFIG_API) += api.o api_display.o api_net.o api_storage.o \
  28 + api_platform-$(ARCH).o
28 29  
29 30 COBJS := $(COBJS-y)
30 31 SRCS := $(COBJS:.o=.c)
... ... @@ -553,6 +553,50 @@
553 553 return 0;
554 554 }
555 555  
  556 +/*
  557 + * pseudo signature:
  558 + *
  559 + * int API_display_get_info(int type, struct display_info *di)
  560 + */
  561 +static int API_display_get_info(va_list ap)
  562 +{
  563 + int type;
  564 + struct display_info *di;
  565 +
  566 + type = va_arg(ap, int);
  567 + di = va_arg(ap, struct display_info *);
  568 +
  569 + return display_get_info(type, di);
  570 +}
  571 +
  572 +/*
  573 + * pseudo signature:
  574 + *
  575 + * int API_display_draw_bitmap(ulong bitmap, int x, int y)
  576 + */
  577 +static int API_display_draw_bitmap(va_list ap)
  578 +{
  579 + ulong bitmap;
  580 + int x, y;
  581 +
  582 + bitmap = va_arg(ap, ulong);
  583 + x = va_arg(ap, int);
  584 + y = va_arg(ap, int);
  585 +
  586 + return display_draw_bitmap(bitmap, x, y);
  587 +}
  588 +
  589 +/*
  590 + * pseudo signature:
  591 + *
  592 + * void API_display_clear(void)
  593 + */
  594 +static int API_display_clear(va_list ap)
  595 +{
  596 + display_clear();
  597 + return 0;
  598 +}
  599 +
556 600 static cfp_t calls_table[API_MAXCALL] = { NULL, };
557 601  
558 602 /*
... ... @@ -616,6 +660,9 @@
616 660 calls_table[API_ENV_GET] = &API_env_get;
617 661 calls_table[API_ENV_SET] = &API_env_set;
618 662 calls_table[API_ENV_ENUM] = &API_env_enum;
  663 + calls_table[API_DISPLAY_GET_INFO] = &API_display_get_info;
  664 + calls_table[API_DISPLAY_DRAW_BITMAP] = &API_display_draw_bitmap;
  665 + calls_table[API_DISPLAY_CLEAR] = &API_display_clear;
619 666 calls_no = API_MAXCALL;
620 667  
621 668 debugf("API initialized with %d calls\n", calls_no);
  1 +/*
  2 + * Copyright (c) 2011 The Chromium OS Authors.
  3 + * See file CREDITS for list of people who contributed to this
  4 + * project.
  5 + *
  6 + * This program is free software; you can redistribute it and/or
  7 + * modify it under the terms of the GNU General Public License as
  8 + * published by the Free Software Foundation; either version 2 of
  9 + * the License, or (at your option) any later version.
  10 + *
  11 + * This program is distributed in the hope that it will be useful,
  12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 + * GNU General Public License for more details.
  15 + *
  16 + * You should have received a copy of the GNU General Public License
  17 + * along with this program; if not, write to the Free Software
  18 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19 + * MA 02111-1307 USA
  20 + */
  21 +
  22 +#include <common.h>
  23 +#include <api_public.h>
  24 +#include <lcd.h>
  25 +#include <video_font.h> /* Get font width and height */
  26 +
  27 +/* lcd.h needs BMP_LOGO_HEIGHT to calculate CONSOLE_ROWS */
  28 +#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
  29 +#include <bmp_logo.h>
  30 +#endif
  31 +
  32 +/* TODO(clchiou): add support of video device */
  33 +
  34 +int display_get_info(int type, struct display_info *di)
  35 +{
  36 + if (!di)
  37 + return API_EINVAL;
  38 +
  39 + switch (type) {
  40 + default:
  41 + debug("%s: unsupport display device type: %d\n",
  42 + __FILE__, type);
  43 + return API_ENODEV;
  44 +#ifdef CONFIG_LCD
  45 + case DISPLAY_TYPE_LCD:
  46 + di->pixel_width = panel_info.vl_col;
  47 + di->pixel_height = panel_info.vl_row;
  48 + di->screen_rows = CONSOLE_ROWS;
  49 + di->screen_cols = CONSOLE_COLS;
  50 + break;
  51 +#endif
  52 + }
  53 +
  54 + di->type = type;
  55 + return 0;
  56 +}
  57 +
  58 +int display_draw_bitmap(ulong bitmap, int x, int y)
  59 +{
  60 + if (!bitmap)
  61 + return API_EINVAL;
  62 +#ifdef CONFIG_LCD
  63 + return lcd_display_bitmap(bitmap, x, y);
  64 +#else
  65 + return API_ENODEV;
  66 +#endif
  67 +}
  68 +
  69 +void display_clear(void)
  70 +{
  71 +#ifdef CONFIG_LCD
  72 + lcd_clear();
  73 +#endif
  74 +}
... ... @@ -45,5 +45,9 @@
45 45  
46 46 void dev_stor_init(void);
47 47  
  48 +int display_get_info(int type, struct display_info *di);
  49 +int display_draw_bitmap(ulong bitmap, int x, int y);
  50 +void display_clear(void);
  51 +
48 52 #endif /* _API_PRIVATE_H_ */
... ... @@ -48,6 +48,7 @@
48 48 ulong start, now;
49 49 struct device_info *di;
50 50 lbasize_t rlen;
  51 + struct display_info disinfo;
51 52  
52 53 if (!api_search_sig(&sig))
53 54 return -1;
... ... @@ -175,6 +176,36 @@
175 176  
176 177 while ((env = ub_env_enum(env)) != NULL)
177 178 printf("%s = %s\n", env, ub_env_get(env));
  179 +
  180 + printf("\n*** Display ***\n");
  181 +
  182 + if (ub_display_get_info(DISPLAY_TYPE_LCD, &disinfo)) {
  183 + printf("LCD info: failed\n");
  184 + } else {
  185 + printf("LCD info:\n");
  186 + printf(" pixel width: %d\n", disinfo.pixel_width);
  187 + printf(" pixel height: %d\n", disinfo.pixel_height);
  188 + printf(" screen rows: %d\n", disinfo.screen_rows);
  189 + printf(" screen cols: %d\n", disinfo.screen_cols);
  190 + }
  191 + if (ub_display_get_info(DISPLAY_TYPE_VIDEO, &disinfo)) {
  192 + printf("video info: failed\n");
  193 + } else {
  194 + printf("video info:\n");
  195 + printf(" pixel width: %d\n", disinfo.pixel_width);
  196 + printf(" pixel height: %d\n", disinfo.pixel_height);
  197 + printf(" screen rows: %d\n", disinfo.screen_rows);
  198 + printf(" screen cols: %d\n", disinfo.screen_cols);
  199 + }
  200 +
  201 + printf("*** Press any key to continue ***\n");
  202 + printf("got char 0x%x\n", ub_getc());
  203 +
  204 + /*
  205 + * This only clears messages on screen, not on serial port. It is
  206 + * equivalent to a no-op if no display is available.
  207 + */
  208 + ub_display_clear();
178 209  
179 210 /* reset */
180 211 printf("\n*** Resetting board ***\n");
... ... @@ -402,4 +402,35 @@
402 402  
403 403 return env_name;
404 404 }
  405 +
  406 +/****************************************
  407 + *
  408 + * display
  409 + *
  410 + ****************************************/
  411 +
  412 +int ub_display_get_info(int type, struct display_info *di)
  413 +{
  414 + int err = 0;
  415 +
  416 + if (!syscall(API_DISPLAY_GET_INFO, &err, (uint32_t)type, (uint32_t)di))
  417 + return API_ESYSC;
  418 +
  419 + return err;
  420 +}
  421 +
  422 +int ub_display_draw_bitmap(ulong bitmap, int x, int y)
  423 +{
  424 + int err = 0;
  425 +
  426 + if (!syscall(API_DISPLAY_DRAW_BITMAP, &err, bitmap, x, y))
  427 + return API_ESYSC;
  428 +
  429 + return err;
  430 +}
  431 +
  432 +void ub_display_clear(void)
  433 +{
  434 + syscall(API_DISPLAY_CLEAR, NULL);
  435 +}
... ... @@ -77,5 +77,10 @@
77 77 int ub_dev_recv(int handle, void *buf, int len, int *rlen);
78 78 struct device_info * ub_dev_get(int);
79 79  
  80 +/* display */
  81 +int ub_display_get_info(int type, struct display_info *di);
  82 +int ub_display_draw_bitmap(ulong bitmap, int x, int y);
  83 +void ub_display_clear(void);
  84 +
80 85 #endif /* _API_GLUE_H_ */
include/api_public.h
... ... @@ -90,6 +90,9 @@
90 90 API_ENV_ENUM,
91 91 API_ENV_GET,
92 92 API_ENV_SET,
  93 + API_DISPLAY_GET_INFO,
  94 + API_DISPLAY_DRAW_BITMAP,
  95 + API_DISPLAY_CLEAR,
93 96 API_MAXCALL
94 97 };
95 98  
... ... @@ -150,6 +153,19 @@
150 153 #define di_net info.net
151 154  
152 155 int state;
  156 +};
  157 +
  158 +#define DISPLAY_TYPE_LCD 0x0001
  159 +#define DISPLAY_TYPE_VIDEO 0x0002
  160 +
  161 +struct display_info {
  162 + int type;
  163 + /* screen size in pixels */
  164 + int pixel_width;
  165 + int pixel_height;
  166 + /* screen size in rows and columns of text */
  167 + int screen_rows;
  168 + int screen_cols;
153 169 };
154 170  
155 171 #endif /* _API_PUBLIC_H_ */