SWIM and Linux

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SWIM and Linux

SWIM and Linux

To use SWIM in Linux, SWIM must have direct access to the frame buffer memory in Linux. This can be done by accessing the /dev/fb device and mapping virtual memory to the device that SWMO will be used. The basic code snippet below shows how to do it.

#define XSIZE 240
#define YSIZE 320

int fbdev;
Uint16 *fb; /* Assumes frame buffer is 16-bit data */

/* Open frame buffer device */
fbdev = open("/dev/fb0", O_RDWR);

/* Get mmap'd pointer to frame buffer */
fb = (Uint16 *) mmap(0, XSIZE * YSIZE * sizeof(Uint16), PROT_WRITE, MAP_SHARED, fbdev, 0);

After this code is executed, the variable 'fb' will point to a usable frame buffer in memory that can be directly written to and read from in the Linux application.
The next step is to initialize the SWIM window for the size of the display.

SWIM_WINDOW_T win1;

/* Create window with black background and no border */
if (swim_window_open(&win1, XSIZE, YSIZE, fb, 0, 0, XSIZE - 1, YSIZE - 1, 0, WHITE, BLACK, WHITE) == 0) {
fprintf(stderr, "Error opening chat window\n");
close (fbdev);
return -1;
}

/* select the font to use */
swim_set_font(&win1, (FONT_T *)&font_winfreesys14x16 );

/* set the pen color to use */
swim_set_pen_color(&win1, WHITE);

A title bar can be easily added to the window.
swim_set_title(&s1, "SWIM window demo", LIGHTGRAY);

All objects in the window are drawn using logical window coordinates. Positions for pixels/lines and text are independent of each other, so you can draw some text, then do a line, and then if you draw text again, it will place the next where the previous text output ended before the line was drawn.

/* Draw a simple box */
swim_put_line(&win1, 10, 10, 50, 10);
swim_put_line(&win1, 50, 10, 50, 50);
swim_put_line(&win1, 50, 50, 10, 50);
swim_put_line(&win1, 10, 50, 10, 10);

With Linux, finish the application by closing the frame buffer device.
close (fbdev);

The SWIM library and application note can be found here.

No ratings
Version history
Last update:
‎04-26-2016 07:40 AM
Updated by: