RetroBSD

2.11BSD operating system for microcontrollers
It is currently Mon Jun 18, 2018 5:17 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sat Oct 10, 2015 4:11 am 
Committer
User avatar

Joined: Wed Oct 10, 2012 11:01 pm
Posts: 1079
Location: Sunnyvale, CA
gpanel_open, gpanel_close, gpanel_clear, gpanel_pixel, gpanel_line, gpanel_rect, gpanel_fill, gpanel_circle, gpanel_image, gpanel_char, gpanel_text, panel_text_width - graphics panel routines

This library provides a set of routines for access to a graphics panel like TFT LCD or OLED displays. HX8357 display on a Picadillo-35T board is an example of such display. Use cc option -lgpanel to link the gpanel library.

Code:
    #include <sys/gpanel.h>

    int gpanel_open(const char *devname);

gpanel_open - This routine opens a connection to the display driver. The argument to this function is the name of the device, like "/dev/tft0". Negative value is returned in case of error.

Code:
   void gpanel_close(void);

gpanel_close - Close a connection to the device.

Code:
   void gpanel_clear(int color, int *xsize, int *ysize);

gpanel_clear - This routine is used to clear the whole screen to a given color, optionally switch the display resolution and orientation, and get the display size in pixels. On input, parameters xsize and ysize should contain the desired dimensions of the display, or zeros to use the default screen size and orientation. On output, xsize and ysize are set to the current display size.

Code:
   void gpanel_pixel(int color, int x, int y);

gpanel_pixel - Draw a single pixel of a specified color.

Code:
   void gpanel_line(int color, int x0, int y0, int x1, int y1);

gpanel_line - Draw a line.

Code:
   void gpanel_rect(int color, int x0, int y0, int x1, int y1);

gpanel_rect - Draw a rectangular frame (not filled).

Code:
   void gpanel_fill(int color, int x0, int y0, int x1, int y1);

gpanel_fill - Draw a rectangle filled with specified color.

Code:
   void gpanel_circle(int color, int x, int y, int radius);

gpanel_circle - Draw a circle with a given center and radius.

Code:
   void gpanel_image(int x, int y, int width, int height,
                     const unsigned short *data);

gpanel_image - Draw an arbitrary image: fill a rectangular area with pixel values from a user-supplied data.

Code:
   void gpanel_char(const struct gpanel_font_t *font, int color,
                    int background, int x, int y, int sym);

gpanel_char - Draw a single character with a specified Unicode encoding.

Code:
   void gpanel_text(const struct gpanel_font_t *font, int color,
                    int background, int x, int y, const char *text);

gpanel_text - Draw a text string in UTF-8 encoding.

Code:
   int gpanel_text_width(const struct gpanel_font_t *font,
                         const char *text, int nchars);

gpanel_text_width - Compute a width in pixels for a text string in
UTF-8 encoding.

Example:
Code:
   #include <stdio.h>
   #include <sys/gpanel.h>

   int main()
   {
       int xsize, ysize;

       if (gpanel_open("/dev/tft0") < 0) {
           printf("Cannot open display0);
           exit(-1);
       }
       /* Get screen size */
       xsize = ysize = 0;
       gpanel_clear(0, &xsize, &ysize);

       /* Draw a white rectangle of max size */
       gpanel_rect(0xffff, 0, 0, xsize-1, ysize-1);
       return 0;
   }
More examples are present in /share/examples/gpanel directory:
See this post for demo output images.

Fonts are specified via a data structure struct gpanel_font_t, which defines character sizez and glyph images:
Code:
    struct gpanel_font_t {
        const char *    name;           /* font name */
        int             maxwidth;       /* max width in pixels */
        unsigned int    height;         /* height in pixels */
        int             ascent;         /* ascent (baseline) height */
        int             firstchar;      /* first character in bitmap */
        int             size;           /* font size in characters */
        const unsigned short *bits;     /* 16-bit right-padded bitmap data */
        const unsigned short *offset;   /* offsets into bitmap data */
        const unsigned char *width;     /* character widths or 0 if fixed */
        int             defaultchar;    /* default char (not glyph index) */
        long            bits_size;      /* number of words of bits */
    };

Font data for a few commonly used fonts are available in /share/examples/gpanel/fonts directory. A utility convbdf can be used to convert XWindows BDF fonts to a struct gpanel_font_t data. When combined with otf2bdf utility, this allows to generate font data for any TrueType font, like Verdana or Lucida Sans Unicode. See gpanel/fonts/Makefile for details.


Top
 Profile  
 
PostPosted: Mon Oct 12, 2015 7:56 am 
Contributor

Joined: Mon Apr 29, 2013 1:56 am
Posts: 196
Now that you've made gpanel IOCTLs available for two different displays, there should probably be another one to query the pixel dimensions of the display (480x320, 320x240) and the color pattern used in pixel colors (e.g. B:0/5, G:5/6, R:11/5 or B:0/8, G:8/8, R:16/8, etc).


Top
 Profile  
 
PostPosted: Mon Oct 12, 2015 3:19 pm 
Committer
User avatar

Joined: Wed Oct 10, 2012 11:01 pm
Posts: 1079
Location: Sunnyvale, CA
To query the screen dimensions, use gpanel_clear function:
Code:
       int xsize, ysize;

       /* Get screen size */
       xsize = ysize = 0;
       gpanel_clear(0, &xsize, &ysize);
       printf("Screen size %u x %u.\n", xsize, ysize);

For color pattern, a separate call is needed, indeed.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron




Powered by phpBB® Forum Software © phpBB Group

BSD Daemon used with permission