Another simple SWIM example

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

Another simple SWIM example

Another simple SWIM example

Attached is another simple SWIM demo that setups a 240x320 window and draws an animated diamond in the window as fast as possible. Although the code is meant to be used with the LPC32x0 CDL, it can be easily ported to other devices. The code for setting up the window and doing the animations is below:

/* Create a SWIM window */
swim_window_open(&win1, LCD_DISPLAY.pixels_per_line,
    LCD_DISPLAY.lines_per_panel, fblog1, 0, 0,
    (LCD_DISPLAY.pixels_per_line - 1),
    (LCD_DISPLAY.lines_per_panel - 1), 3, WHITE, BLACK, MAGENTA);

    xf = 20;
    yf = 30;
    xinc = 1;
    yinc = 1;
    clr = RED | GREEN;

    /* Draw as fast as possible, no throttling */
    while (1)
    {
       swim_set_fill_color(&win1, clr);
       swim_put_diamond(&win1, LCD_DISPLAY.pixels_per_line / 2,
       LCD_DISPLAY.lines_per_panel / 2, xf, yf);
       lcd_ioctl(lcddev, LCD_SET_UP_FB, PHY_LCD_FRAME_BUF1);

       xf += xinc;
       if ((xf < 10) || (xf > 150))
           xinc = -xinc;
       yf += yinc;
       if ((yf < 10) || (yf > 230))
           yinc = -yinc;

       clr++;
       if (clr > 0xFFFF)
           clr = RED | GREEN;
    }

The file also includes a pre-built image of the program for use with the Phytec LPC3250 board using S1L. To use the image, just boot the board to the S1L prompt, type "load term srec', send the SREC file to the board via the serial port (no transfer protocol), and then type 'exec' to start it.

%3CLINGO-SUB%20id%3D%22lingo-sub-1115590%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EAnother%20simple%20SWIM%20example%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1115590%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%20style%3D%22color%3A%20%23646464%3B%20font-family%3A%20Arial%2C%20sans-serif%3B%20font-size%3A%2012px%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3EAttached%20is%20another%20simple%20SWIM%20demo%20that%20setups%20a%20240x320%20window%20and%20draws%20an%20animated%20diamond%20in%20the%20window%20as%20fast%20as%20possible.%20Although%20the%20code%20is%20meant%20to%20be%20used%20with%20the%20LPC32x0%20CDL%2C%20it%20can%20be%20easily%20ported%20to%20other%20devices.%20The%20code%20for%20setting%20up%20the%20window%20and%20doing%20the%20animations%20is%20below%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22color%3A%20%23646464%3B%20font-family%3A%20Arial%2C%20sans-serif%3B%20font-size%3A%2012px%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%2F*%20Create%20a%20SWIM%20window%20*%2F%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3Eswim_window_open(%26amp%3Bwin1%2C%20LCD_DISPLAY.pixels_per_line%2C%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20LCD_DISPLAY.lines_per_panel%2C%20fblog1%2C%200%2C%200%2C%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20(LCD_DISPLAY.pixels_per_line%20-%201)%2C%20%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20(LCD_DISPLAY.lines_per_panel%20-%201)%2C%203%2C%20WHITE%2C%20BLACK%2C%20MAGENTA)%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22color%3A%20%23646464%3B%20font-family%3A%20Arial%2C%20sans-serif%3B%20font-size%3A%2012px%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20xf%20%3D%2020%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20yf%20%3D%2030%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20xinc%20%3D%201%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20yinc%20%3D%201%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20clr%20%3D%20RED%20%7C%20GREEN%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22color%3A%20%23646464%3B%20font-family%3A%20Arial%2C%20sans-serif%3B%20font-size%3A%2012px%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F*%20Draw%20as%20fast%20as%20possible%2C%20no%20throttling%20*%2F%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20while%20(1)%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20swim_set_fill_color(%26amp%3Bwin1%2C%20clr)%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20swim_put_diamond(%26amp%3Bwin1%2C%20LCD_DISPLAY.pixels_per_line%20%2F%202%2C%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20LCD_DISPLAY.lines_per_panel%20%2F%202%2C%20xf%2C%20yf)%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20lcd_ioctl(lcddev%2C%20LCD_SET_UP_FB%2C%20PHY_LCD_FRAME_BUF1)%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22color%3A%20%23646464%3B%20font-family%3A%20Arial%2C%20sans-serif%3B%20font-size%3A%2012px%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20xf%20%2B%3D%20xinc%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20if%20((xf%20%26lt%3B%2010)%20%7C%7C%20(xf%20%26gt%3B%20150))%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20xinc%20%3D%20-xinc%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20yf%20%2B%3D%20yinc%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20if%20((yf%20%26lt%3B%2010)%20%7C%7C%20(yf%20%26gt%3B%20230))%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20yinc%20%3D%20-yinc%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22color%3A%20%23646464%3B%20font-family%3A%20Arial%2C%20sans-serif%3B%20font-size%3A%2012px%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20clr%2B%2B%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20if%20(clr%20%26gt%3B%200xFFFF)%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20clr%20%3D%20RED%20%7C%20GREEN%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20style%3D%22color%3A%20%23646464%3B%20font-family%3A%20Arial%2C%20sans-serif%3B%20font-size%3A%2012px%3B%22%3E%3CSPAN%20style%3D%22font-size%3A%2012pt%3B%22%3EThe%20file%20also%20includes%20a%20pre-built%20image%20of%20the%20program%20for%20use%20with%20the%20Phytec%20LPC3250%20board%20using%20S1L.%20To%20use%20the%20image%2C%20just%20boot%20the%20board%20to%20the%20S1L%20prompt%2C%20type%20%22load%20term%20srec'%2C%20send%20the%20SREC%20file%20to%20the%20board%20via%20the%20serial%20port%20(no%20transfer%20protocol)%2C%20and%20then%20type%20'exec'%20to%20start%20it.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
No ratings
Version history
Last update:
‎04-25-2016 04:49 PM
Updated by: