Пример #1
0
static void DrawLineInBox(TInt32 startX, TInt32 startY, TInt32 winX, TInt32 winY)
{
    // Draw point only if in bounds
    if ((startX > DR_IMAGE_LEFT) && (startX < DR_IMAGE_RIGHT) &&
            (startY > DR_IMAGE_TOP) && (startY < DR_IMAGE_BOTTOM)) {
        if ((winX > DR_IMAGE_LEFT) && (winX < DR_IMAGE_RIGHT) &&
                (winY > DR_IMAGE_TOP) && (winY < DR_IMAGE_BOTTOM)) {
            swim_put_line(&G_drWin, startX, startY, winX, winY);
        }
    }
}
Пример #2
0
/*---------------------------------------------------------------------------*
 * Routine:  DrawMode
 *---------------------------------------------------------------------------*
 * Description:
 *      Put the processor in the draw mode 'application' or 'demo'.
 *      Buttons are shown to load, save, exit, and change the current color.
 *      The user can then draw in the designated area a small picture using
 *      the current color.
 * Inputs:
 *      const T_choice *aChoice   -- Choice object selected for this action.
 *---------------------------------------------------------------------------*/
void DrawMode(const T_choice *aChoice)
{
    T_uezDevice lcd;
    T_uezDevice ts;
    static T_uezQueue queue = (TUInt32)NULL;
    INT_32 winX, winY;
    T_pixelColor *pixels;
    T_uezInputEvent inputEvent;
    TBool isDrawing = EFalse;
    INT_32 lastWinX, lastWinY;

    G_drExit = EFalse;

#ifdef NO_DYNAMIC_MEMORY_ALLOC	
	if (NULL == queue)
	{
	  	if (UEZQueueCreate(1, sizeof(T_uezInputEvent), &queue) != UEZ_ERROR_NONE)
		{
		  	queue = NULL;
		}
	}
	
    if (NULL != queue) {
		/* Register the queue so that the IAR Stateviewer Plugin knows about it. */
	  	UEZQueueAddToRegistry( queue, "Draw TS" );	
#else
	if (UEZQueueCreate(1, sizeof(T_uezInputEvent), &queue) == UEZ_ERROR_NONE) {
#endif
        // Open up the touchscreen and pass in the queue to receive events
        if (UEZTSOpen("Touchscreen", &ts, &queue)==UEZ_ERROR_NONE)  {
            // Open the LCD and get the pixel buffer
            if (UEZLCDOpen("LCD", &lcd) == UEZ_ERROR_NONE)  {
                UEZLCDGetFrame(lcd, 0, (void **)&pixels);

                // Put the draw screen up
                DR_Screen(lcd);
                DR_DrawColor();

                while (!G_drExit) {
                    // Wait forever until we receive a touchscreen event
                    // NOTE: UEZTSGetReading() can also be used, but it doesn't wait.
                    if (UEZQueueReceive(queue, &inputEvent, UEZ_TIMEOUT_INFINITE)==UEZ_ERROR_NONE) {
                        winX = inputEvent.iEvent.iXY.iX;
                        winY = inputEvent.iEvent.iXY.iY;
                        swim_get_virtual_xy(&G_drWin, &winX, &winY);

                        // Are we in the drawing area?
                        if ((winX > DR_IMAGE_LEFT) && (winX < DR_IMAGE_RIGHT) &&
                                (winY > DR_IMAGE_TOP) && (winY < DR_IMAGE_BOTTOM)) {
                            // Pen down or up?
                            if (inputEvent.iEvent.iXY.iAction == XY_ACTION_PRESS_AND_HOLD)  {
                            
                                UEZLCDScreensaverWake();
                            
                                if (G_drColor == BLACK) {
                                    // Draw a 3x3 block in the area
                                    swim_set_pen_color(&G_drWin, G_drColor);
                                    if (isDrawing) {
                                        DrawBlockLine(lastWinX, lastWinY, winX, winY);
                                    } else {
                                        DrawBlockPixel(winX, winY);
                                    }
                                } else {
                                    // Draw a dot
                                    swim_set_pen_color(&G_drWin, G_drColor);
                                    if (isDrawing) {
                                        swim_put_line(&G_drWin, lastWinX, lastWinY, winX, winY);
                                    } else {
                                        swim_put_pixel(&G_drWin, winX, winY);
                                    }
                                }
                                isDrawing = ETrue;
                                lastWinX = winX;
                                lastWinY = winY;
                            } else {
                                // No longer drawing
                                isDrawing = EFalse;
                            }
                        } else {
                            ChoicesUpdateByReading(&G_drWin, G_drChoices, &inputEvent);
                            if (inputEvent.iEvent.iXY.iAction == XY_ACTION_RELEASE)
                                isDrawing = EFalse;
                        }
                    }
                }
                UEZLCDClose(lcd);
            }
            UEZTSClose(ts, queue);
        }
#ifndef NO_DYNAMIC_MEMORY_ALLOC	
        UEZQueueDelete(queue);
#endif
    }
}
Пример #3
0
/**********************************************************************
 *
 * Function: c_entry
 *
 * Purpose: Application entry point from the startup code
 *
 * Processing:
 *     See function.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 *********************************************************************/
void c_entry(void)
{
    SWIM_WINDOW_T win1;
    COLOR_T clr, *fblog;
    int idx;
    INT_32 lcddev;
    UNS_16 xgs, ygs, curx, cury, curym, xidx;

    /* Disable interrupts in ARM core */
    disable_irq_fiq();

    /* Set virtual address of MMU table */
    cp15_set_vmmu_addr((void *)
		(IRAM_BASE + (256 * 1024) - (16 * 1024)));

    /* Setup miscellaneous board functions */
    phy3250_board_init();
  
    /* Setup LCD muxing for STN Color 16BPP */
    clkpwr_setup_lcd(CLKPWR_LCDMUX_TFT16, 1);

    /* Enable clock to LCD block (HCLK_EN)*/
    clkpwr_clk_en_dis(CLKPWR_LCD_CLK, 1);
	
    /* Setup LCD paramaters in the LCD controller */
    lcddev = lcd_open(CLCDC, (INT_32) &LCD_DISPLAY);

    /* Upper Panel Frame Base Address register */
    lcd_ioctl(lcddev, LCD_SET_UP_FB, PHY_LCD_FRAME_BUF); 

    /* Enable LCD controller and power signals */
    lcd_ioctl(lcddev, LCD_PWENABLE, 1);

    /* Enable LCD backlight */
    phy3250_lcd_backlight_enable(TRUE);

    /* Enable LCD power */
    phy3250_lcd_power_enable(TRUE);

    /* Set frame buffer address */
    fblog = (COLOR_T *) 
            cp15_map_physical_to_virtual(PHY_LCD_FRAME_BUF);

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

    /* Compute vertical size for bars */
    ygs = LCD_DISPLAY.lines_per_panel / 3;

    /* Draw Red bars */
    cury = 0;
    curx = 0;
    curym = ygs - 1;
    xgs = LCD_DISPLAY.pixels_per_line / RED_COLORS;
    clr = BLACK;
    for (xidx = 0; xidx < RED_COLORS; xidx++)
    {
        swim_set_pen_color(&win1, clr);
        for (idx = 0; idx <= xgs; idx++)
        {
            swim_put_line(&win1, curx, cury, curx, curym);
            curx++;
        }
        clr = clr + 0x0800;
        }

    /* Draw green bars */
    cury = cury + ygs;
    curx = 0;
    curym = cury + (ygs - 1);
    xgs = LCD_DISPLAY.pixels_per_line / GREEN_COLORS;
    clr = BLACK;
    for (xidx = 0; xidx < GREEN_COLORS; xidx++)
    {
        swim_set_pen_color(&win1, clr);
        for (idx = 0; idx <= xgs; idx++)
        {
            swim_put_line(&win1, curx, cury, curx, curym);
            curx++;
        }
        clr = clr + 0x0020;
    }

    /* Draw blue bars */
    cury = cury + ygs;
    curx = 0;
    curym = cury + (ygs - 1);
    xgs = LCD_DISPLAY.pixels_per_line / BLUE_COLORS;
    clr = BLACK;
    for (xidx = 0; xidx < BLUE_COLORS; xidx++)
    {
        swim_set_pen_color(&win1, clr);
        for (idx = 0; idx <= xgs; idx++)
        {
            swim_put_line(&win1, curx, cury, curx, curym);
            curx++;
        }
        clr = clr + 0x0001;
    }
}
Пример #4
0
/**********************************************************************
 *
 * Function: c_entry
 *
 * Purpose: Application entry point from the startup code
 *
 * Processing:
 *     See function.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 *********************************************************************/
void c_entry(void)
{
    SWIM_WINDOW_T win1;
    COLOR_T clr, *fblog;
    int idx;
    UNS_16 xgs, ygs, curx, cury, curym, xidx;

    /* Disable interrupts in ARM core */
    disable_irq_fiq();

    /* Set virtual address of MMU table */
    cp15_set_vmmu_addr((void *)
		(IRAM_BASE + (256 * 1024) - (16 * 1024)));

	/* Initialize interrupt system */
    int_initialize(0xFFFFFFFF);

    /* Install standard IRQ dispatcher at ARM IRQ vector */
    int_install_arm_vec_handler(IRQ_VEC, (PFV) lpc32xx_irq_handler);

    /* Setup miscellaneous board functions */
    phy3250_board_init();

    /* enable clock to ADC block - 32KHz clock */
    clkpwr_clk_en_dis(CLKPWR_ADC_CLK,1);

    /* TSC IRQ goes active when the FIFO reaches the Interrupt level */
    int_install_irq_handler(IRQ_TS_IRQ, (PFV) tsc_user_interrupt);

    /* Enable interrupt */
    int_enable(IRQ_TS_IRQ);

    /* Open TSC, sets default timing values, fifo = 16, 
	 resolution = 10bits */
    tscdev = tsc_open(TSC, 0);

    /* TSC Auto mode enable, this also sets AUTO bit */
    tsc_ioctl(tscdev,TSC_AUTO_EN, 1);
	  
    /* Setup LCD muxing for STN Color 16BPP */
    clkpwr_setup_lcd(CLKPWR_LCDMUX_TFT16, 1);

    /* Enable clock to LCD block (HCLK_EN)*/
    clkpwr_clk_en_dis(CLKPWR_LCD_CLK, 1);
	
    /* Setup LCD paramaters in the LCD controller */
    lcddev = lcd_open(CLCDC, (INT_32) &LCD_DISPLAY);

    /* Upper Panel Frame Base Address register */
    lcd_ioctl(lcddev, LCD_SET_UP_FB, PHY_LCD_FRAME_BUF); 

    /* Enable LCD controller and power signals */
    lcd_ioctl(lcddev, LCD_PWENABLE, 1);

    /* Enable LCD backlight */
    phy3250_lcd_backlight_enable(TRUE);

    /* Enable LCD power */
    phy3250_lcd_power_enable(TRUE);
	
    /* write cursor image array data to cursor image RAM */
    lcd_ioctl(lcddev, LCD_CRSR_INIT_IMG, (INT_32) &cursorimage[0]);

    /* enable the default cursor 0 */
    lcd_ioctl(lcddev,LCD_CRSR_EN,1);

    /* set the cursor X/Y position */
    lcd_ioctl(lcddev, LCD_CRSR_XY, 0x0); 

    /* set the cursor pallette BGR value, col0*/
    lcd_ioctl(lcddev, LCD_CRSR_PAL0, 0x00ff0000); 

    /* set the cursor pallette BGR value, col1 */
    lcd_ioctl(lcddev, LCD_CRSR_PAL1, 0x000000ff); 

    /* Enable IRQ interrupts in the ARM core */
    enable_irq();

    /* Set frame buffer address */
    fblog = (COLOR_T *)cp15_map_physical_to_virtual(PHY_LCD_FRAME_BUF);

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

	/* Compute vertical size for bars */
	ygs = LCD_DISPLAY.lines_per_panel / 3;

	/* Draw Red bars */
	cury = 0;
	curx = 0;
	curym = ygs - 1;
	xgs = LCD_DISPLAY.pixels_per_line / RED_COLORS;
	clr = BLACK;
	for (xidx = 0; xidx < RED_COLORS; xidx++)
	{
		swim_set_pen_color(&win1, clr);
		for (idx = 0; idx <= xgs; idx++)
		{
			swim_put_line(&win1, curx, cury, curx, curym);
			curx++;
		}

		clr = clr + 0x0800;
	}

	/* Draw green bars */
	cury = cury + ygs;
	curx = 0;
	curym = cury + (ygs - 1);
	xgs = LCD_DISPLAY.pixels_per_line / GREEN_COLORS;
	clr = BLACK;
	for (xidx = 0; xidx < GREEN_COLORS; xidx++)
	{
		swim_set_pen_color(&win1, clr);
		for (idx = 0; idx <= xgs; idx++)
		{
			swim_put_line(&win1, curx, cury, curx, curym);
			curx++;
		}

		clr = clr + 0x0020;
	}

	/* Draw blue bars */
	cury = cury + ygs;
	curx = 0;
	curym = cury + (ygs - 1);
	xgs = LCD_DISPLAY.pixels_per_line / BLUE_COLORS;
	clr = BLACK;
	for (xidx = 0; xidx < BLUE_COLORS; xidx++)
	{
		swim_set_pen_color(&win1, clr);
		for (idx = 0; idx <= xgs; idx++)
		{
			swim_put_line(&win1, curx, cury, curx, curym);
			curx++;
		}

		clr = clr + 0x0001;
	}


    /* lets stay here forever */
    while(1);

}
Пример #5
0
/* Creates a title bar for the window */
void swim_set_title(SWIM_WINDOW_T *win,
					const CHAR *title,
					COLOR_T ttlbkcolor)
{
	COLOR_T savedf, savedp, savedb;
	int32_t savedt;

	/* Is present font height larger than window client height? */
	if ((swim_get_font_height(win) < (4 + win->yvsize)) &&
		(title != (CHAR *) 0)) {
		/* There is enough room for title bar, so continue */

		/* Save original colors and font transparentcy flag */
		savedf = win->fill;
		savedp = win->pen;
		savedb = win->bkg;
		savedt = win->tfont;

		/* Set fill color to background color (temporarily)
		   used with box function */
		win->fill = ttlbkcolor;
		win->bkg = ttlbkcolor;
		win->pen = win->bkg;

		/* Draw the background for the title bar */
		swim_put_box(win, 0, 0, win->xvsize,
					 (4 + swim_get_font_height(win) - 2));

		/* Reset text starting position for title string */
		win->xvpos = win->xpvmin + 2;
		win->yvpos = win->ypvmin + 1;

		/* Restore original pen color (used for text color) */
		win->pen = savedp;

		/* Restore the original colors */
		win->fill = savedf;
		win->bkg = savedb;

		/* Put string in title bar area (with transparent background) */
		win->tfont = 0;
		swim_put_text(win, title);
		win->tfont = savedt;

		/* Draw a line under the title bar, but before the
		   (new) client area */
		swim_put_line(win, 0,
					  (4 + swim_get_font_height(win) - 1),
					  win->xpvmax, (4 + swim_get_font_height(win) - 1));

		/* Adjust client height of window (virtual and physcal) */
		win->ypmin = win->ypmin + swim_get_font_height(win) + 4;
		win->ypvmin = win->ypvmin + swim_get_font_height(win) + 4;

		/* Resize y dimension */
		win->yvsize = win->yvsize - swim_get_font_height(win) + 4;

		/* Reset text starting position to new client area */
		win->xvpos = win->xpvmin;
		win->yvpos = win->ypvmin;
	}
}
Пример #6
0
/***********************************************************************
 *
 * Function: swim_put_diamond
 *
 * Purpose:
 * Purpose: Draw a diamond in the virtual window
 *
 * Processing:
 *     See function.
 *
 * Parameters:
 *     win : Window identifier
 *     x   : Virtual X position of the diamond
 *     y   : Virtual Y position of the diamond
 *     rx  : Radius for horizontal
 *     ry  : Radius for vertical
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes:
 *     This function supports clipping.
 *
 **********************************************************************/
void swim_put_diamond(SWIM_WINDOW_T *win,
                      INT_32 x,
                      INT_32 y,
                      INT_32 rx,
                      INT_32 ry)
{
  INT_32 xleft, xright, xleft1, xleft2, xright1, idy, ypmid;
  INT_32 ypmin, ypmax, dlta, err, e2;

  /* Use line draw functions to draw border in pen color in virtual
     coordinates */
  swim_put_line(win, x - rx, y, x, y - ry);
  swim_put_line(win, x + rx, y, x, y - ry);
  swim_put_line(win, x - rx, y, x, y + ry);
  swim_put_line(win, x + rx, y, x, y + ry);

  /* Adjust rx and rx for interior fill region minus border */
  rx--;
  ry--;
  if ((rx <= 0) || (ry <= 0))
    return;

  /* Y limits in physical coordinates minus border line */
  ypmin = y - ry + win->ypvmin;
  ypmid = y + win->ypvmin;
  ypmax = y + ry + win->ypvmin;

  /* X starts draw from center line */
  xleft = xright = x + win->xpvmin;

  err = rx - ry;
  dlta = 1 + rx / ry;

  for (idy = ypmin; idy <= ypmid; idy++)
  {
    xleft1 = xleft2 = xleft;
	xright1 = xright;

    /* Clip left and right to virtual window size */
	if (xleft1 < win->xpvmin)
	  xleft2 = xleft1 = win->xpvmin;
	if (xright1 > win->xpvmax)
	  xright1 = win->xpvmax;

    /* Is top half visible? */
    if ((idy >= win->ypvmin) && (idy <= win->ypvmax))
	{
	  while (xleft1 <= xright1)
	  {
	    * (win->fb + xleft1 + (idy * win->xpsize)) = win->fill;
		xleft1++;
	  }
	}

    /* Draw bottom half if visible */
    if ((ypmax >= ypmid) && (ypmax <= win->ypvmax))
	{
	  /* Mirror bottom */
	  while (xleft2 <= xright1)
	  {
	    * (win->fb + xleft2 + (ypmax * win->xpsize)) = win->fill;
		xleft2++;
	  }
	}
	ypmax--;

    e2 = 2 * err;
    if (e2 > -ry)
    {
      err -= ry;
      xleft -= dlta;
      xright += dlta;
    }
    if (e2 < rx)
    {
      err += rx;
    }
  }
}