示例#1
0
int main(void)
{
   SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

   Kentec320x240x16_SSD2119Init();
   GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);
   ClrScreen();

   GrImageDraw(&sContext, g_pui8Image, 0, 0);
   GrFlush(&sContext);

   SysCtlDelay(SysCtlClockGet());
   // Later lab steps go between here

   ClrScreen();

   sRect.i16XMin = 1;
   sRect.i16YMin = 1;
   sRect.i16XMax = 318;
   sRect.i16YMax = 238;
   GrContextForegroundSet(&sContext, ClrRed);
   GrContextFontSet(&sContext, &g_sFontCmss30b);
   GrStringDraw(&sContext, "Texas", -1, 110, 2, 0);
   GrStringDraw(&sContext, "Instruments", -1, 80, 32, 0);
   GrStringDraw(&sContext, "Graphics", -1, 100, 62, 0);
   GrStringDraw(&sContext, "Lab", -1, 135, 92, 0);
   GrContextForegroundSet(&sContext, ClrWhite);
   GrRectDraw(&sContext, &sRect);
   GrFlush(&sContext);

   SysCtlDelay(SysCtlClockGet());

   GrContextForegroundSet(&sContext, ClrYellow);
   GrCircleFill(&sContext, 80, 182, 50);

   sRect.i16XMin = 160;
   sRect.i16YMin = 132;
   sRect.i16XMax = 312;
   sRect.i16YMax = 232;
   GrContextForegroundSet(&sContext, ClrGreen);
   GrRectDraw(&sContext, &sRect);

   SysCtlDelay(SysCtlClockGet());

   // and here
   ClrScreen();
   while(1)
   {
   }
}
/*******************************************************************************
 * @fn          devpkLcdText
 *
 * @brief       Write a text string to a specific line/column of the display
 *
 * @param       str - text to apply
 * @param       line - line index (0 .. 11)
 * @param       col - column index (0 .. 15)
 *
 * @return      true if success
 */
bool devpkLcdText(const char *str, uint8_t line, uint8_t col)
{
  if (hLcdPin != NULL)
  {
    uint8_t xp, yp;

    Semaphore_pend(hSemLCD, BIOS_WAIT_FOREVER);

    xp = col * CHAR_WIDTH + 1;
    yp = line * CHAR_HEIGHT + 0;

    // Draw a text on the display
    GrStringDraw(&g_sContext,
                 str,
                 AUTO_STRING_LENGTH,
                 xp,
                 yp,
                 OPAQUE_TEXT);

    GrFlush(&g_sContext);

    Semaphore_post(hSemLCD);
  }

  return hLcdPin != NULL;
}
示例#3
0
int
XEventsQueued(Display * display, int mode)
{
	int ret;
	GR_EVENT temp;

	FUNC_ENTER;
	ret = GrQueueLength();

	/* check hack for local saved event*/
	if (saved)
		return ret+1;

	if (!ret && mode != QueuedAlready) {
		if (mode == QueuedAfterFlush)
			GrFlush();
		if (GrPeekEvent(&temp))
			ret = 1;
	}

	if (ret)
		DPRINTF("Returning %d events ready\n", ret);

	return ret;
}
//*****************************************************************************
//
// Display the interrupt state on the display.  The currently active and pending
// interrupts are displayed.
//
//*****************************************************************************
void
DisplayIntStatus(void)
{
    uint32_t ui32Temp;
    char pcBuffer[6];

    //
    // Display the currently active interrupts.
    //
    ui32Temp = HWREG(NVIC_ACTIVE0);
    pcBuffer[0] = ' ';
    pcBuffer[1] = (ui32Temp & 1) ? '1' : ' ';
    pcBuffer[2] = (ui32Temp & 2) ? '2' : ' ';
    pcBuffer[3] = (ui32Temp & 4) ? '3' : ' ';
    pcBuffer[4] = ' ';
    pcBuffer[5] = '\0';
    GrStringDrawCentered(&g_sContext, pcBuffer, -1, 130, 150, 1);

    //
    // Display the currently pending interrupts.
    //
    ui32Temp = HWREG(NVIC_PEND0);
    pcBuffer[1] = (ui32Temp & 1) ? '1' : ' ';
    pcBuffer[2] = (ui32Temp & 2) ? '2' : ' ';
    pcBuffer[3] = (ui32Temp & 4) ? '3' : ' ';
    GrStringDrawCentered(&g_sContext, pcBuffer, -1, 270, 150, 1);

    //
    // Flush the display.
    //
    GrFlush(&g_sContext);
}
示例#5
0
static void run_window_events(windowproc window, struct _event *events)
{
  struct _event *ev = events;
  PROCESS_CONTEXT_BEGIN(ui_process);
  
  int ret = window(ev->event, ev->lparam, ev->rparam);
  
  //GrContextFontSet(&context, (const tFont*)NULL);
  if (ret != 0x80)
  {
    status_process(EVENT_WINDOW_PAINT, 0, &context);

    GrContextClipRegionSet(&context, &client_clip);
  }
  else
    GrContextClipRegionSet(&context, &fullscreen_clip);

  ev++;
  for(; ev->delta != -1; ev++)
  {
    window(ev->event, ev->lparam, ev->rparam);
    if (ev->event == EVENT_WINDOW_PAINT)
    {
      GrFlush(&context);
    }
  }

  PROCESS_CONTEXT_END();
}
示例#6
0
/*
   Draw all roaches.
*/
void
DrawRoaches(void)
{
    Roach *roach;
    int rx;
    
    for (rx=0; rx<curRoaches; rx++) {
	roach = &roaches[rx];
	
	if (roach->intX >= 0) {
	    GrClearArea(GR_ROOT_WINDOW_ID, roach->intX, roach->intY,
		roach->rp->width, roach->rp->height, GR_FALSE);
	}
    }
    
    for (rx=0; rx<curRoaches; rx++) {
	roach = &roaches[rx];
	
	if (!roach->hidden) {
	    int size = roach->rp->width * roach->rp->height;
	    GR_PIXELVAL roachbuf[size];
	    GR_PIXELVAL screenbuf[size];
	    int i;

	    roach->intX = roach->x;
	    roach->intY = roach->y;
	    roach->rp = &roachPix[roach->index];

	    /*
    	    //XSetForeground(display, gc, AllocNamedColor(roachColor, black));
    	    //XSetFillStyle(display, gc, FillStippled);
	    //XSetStipple(display, gc, roach->rp->pixmap);
	    //XSetTSOrigin(display, gc, roach->intX, roach->intY);
	    //XFillRectangle(display, rootWin, gc,
		//roach->intX, roach->intY, roach->rp->width, roach->rp->height);
	    */

	    /* read roach bitmap*/
	    GrReadArea(roach->rp->pixmap, 0, 0,
		roach->rp->width, roach->rp->height, roachbuf);

	    /* read root window*/
	    GrReadArea(GR_ROOT_WINDOW_ID, roach->intX, roach->intY,
		roach->rp->width, roach->rp->height, screenbuf);

	    /* convert fg roach bitmap bits to roach color on root window bits*/
	    for (i=0; i<size; ++i)
		    if (roachbuf[i] != BLACK)
			    screenbuf[i] = roachColor;

	    /* write root window*/
	    GrArea(GR_ROOT_WINDOW_ID, gc, roach->intX, roach->intY,
		roach->rp->width, roach->rp->height, screenbuf, MWPF_PIXELVAL);
	}
	else {
	    roach->intX = -1;
	}
    }
    GrFlush();
}
// Needed since the TivaWare Graphics Library seems to not have a function
// for clearing the display.
void BlankScreen(void)
{
    GrContextForegroundSet(&g_sContext, ClrWhite);
	GrContextBackgroundSet(&g_sContext, ClrBlack);
    GrRectFill(&g_sContext, &(g_sContext.sClipRegion));
    GrFlush(&g_sContext);
	GrContextForegroundSet(&g_sContext, ClrBlack);
	GrContextBackgroundSet(&g_sContext, ClrWhite);
}
示例#8
0
void TestControl(CuTest* tc)
{
    GrContextClipRegionSet(&context, &client_clip);
    GrContextForegroundSet(&context, ClrBlack);
    GrRectFill(&context, &client_clip);

    GrContextForegroundSet(&context, ClrWhite);
    window_volume(&context, 20, 100, 8, 4);
    GrFlush(&context);    
}
/*******************************************************************************
 * @fn          devpkLcdClear
 *
 * @brief       Clears the display
 *
 * @return      true if success
 */
bool devpkLcdClear(void)
{
  if (hLcdPin != NULL)
  {
    GrClearDisplay(&g_sContext);
    GrFlush(&g_sContext);
  }

  return hLcdPin != 0;
}
示例#10
0
void ClrScreen()
{
   sRect.i16XMin = 0;
   sRect.i16YMin = 0;
   sRect.i16XMax = 319;
   sRect.i16YMax = 239;
   GrContextForegroundSet(&sContext, ClrBlack);
   GrRectFill(&sContext, &sRect);
   GrFlush(&sContext);
}
示例#11
0
/*
 * Delay for a while so that something can be seen.
 * This is done by drawing a large rectangle over the window using a mode
 * of XOR with the value of 0, (which does nothing except waste time).
 */
static void
delay(void)
{
    GR_COUNT	i;

    for (i = 0; i < 1; i++) {
        GrFillRect(boardwid, delaygc, 0, 0, xp * size - 1,
                   yp * size - 1);
        GrFlush();
    }
}
示例#12
0
/*
   Cover root window to erase roaches.
*/
void
CoverRoot(void)
{
    GR_WINDOW_ID roachWin;
    
    roachWin = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, display_width, display_height,
		    0, CYAN, BLACK);
    GrLowerWindow(roachWin);
    GrMapWindow(roachWin);
    GrFlush();
}    
示例#13
0
void main(void)
{
    CAP_BUTTON keypressed_state;

    int countdownCount;

    State state = STATE_WELCOME;

    // Stop WDT
    WDTCTL = WDTPW | WDTHOLD;		// Stop watchdog timer

    //Perform initializations (see peripherals.c)
    configTouchPadLEDs();
    configDisplay();
    configCapButtons();
    GrClearDisplay(&g_sContext);
    GrStringDrawCentered(&g_sContext, "MSP430 H3R0", AUTO_STRING_LENGTH, 51, 32,
                         TRANSPARENT_TEXT);
    GrFlush(&g_sContext);

    /* Monitor Capacitive Touch Pads in endless "forever" loop */
    while(1)
    {
        switch(state)
        {
        case STATE_WELCOME:
            if(checkButtons() & BUTTON1)
            {
                state = STATE_COUNTDOWN;
            }
            break;

        case STATE_COUNTDOWN:
            centerText("3");
            configLED1_3(BIT3);
            wait(COUNTDOWN_TIMER);

            centerText("2");
            configLED1_3(BIT2);
            wait(COUNTDOWN_TIMER);

            centerText("1");
            configLED1_3(BIT1);
            wait(COUNTDOWN_TIMER);

            centerText("GO!");
            configLED1_3(BIT3 | BIT2 | BIT1);
            wait(COUNTDOWN_TIMER);

            //TODO: next state
            break;
        }
    }
}
//*****************************************************************************
//
// Print "Hello World!" to the display on the Intelligent Display Module.
//
//*****************************************************************************
int
main(void)
{
    tContext sContext;
    uint32_t ui32SysClock;

    //
    // Run from the PLL at 120 MHz.
    //
    ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);

    //
    // Configure the device pins.
    //
    PinoutSet();

    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init(ui32SysClock);

    //
    // Initialize the graphics context.
    //
    GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Draw the application frame.
    //
    FrameDraw(&sContext, "hello");

    //
    // Say hello using the Computer Modern 40 point font.
    //
    GrContextFontSet(&sContext, g_psFontCm40);
    GrStringDrawCentered(&sContext, "Hello World!", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         ((GrContextDpyHeightGet(&sContext) - 32) / 2) + 24,
                         0);

    //
    // Flush any cached drawing operations.
    //
    GrFlush(&sContext);

    //
    // We are finished. Hang around doing nothing.
    //
    while(1)
    {
    }
}
示例#15
0
/*
 * Here when we get a button down event.
 */
static void
dobutton(GR_EVENT_BUTTON *bp)
{
    if (bp->wid == boardwid) {
        movetopos(findcell(bp->x, bp->y));
        return;
    }

    if (bp->wid == quitwid) {
        GrFillRect(quitwid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
        GrFlush();
        if (savefile)
            writegame(savefile);
        GrClose();
        exit(0);
    }

    if (bp->wid == savewid) {
        GrFillRect(savewid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
        GrFlush();
        if (savefile == NULL)
            savefile = SAVEFILE;
        if (writegame(savefile))
            write(1, "\007", 1);
        else
            delay();
        GrFillRect(savewid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
    }

    if (bp->wid == newgamewid) {
        GrFillRect(newgamewid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
        GrFlush();
        /*if (playing)
        	write(1, "\007", 1);
        else {*/
        newgame();
        delay();
        /*}*/
        GrFillRect(newgamewid, xorgc, 0, 0, BUTTONWIDTH, BUTTONHEIGHT);
    }
}
示例#16
0
static void test_window_stopwatch(windowproc window, void* data)
{
  window(EVENT_WINDOW_CREATED, 0, data);
//  GrContextClipRegionSet(&context, &status_clip);
//  status_process(EVENT_WINDOW_PAINT, 0, &context);
  for(int i = 3; i >= 0; i--)
    window(EVENT_KEY_PRESSED, KEY_ENTER, (void*)0);
  GrContextClipRegionSet(&context, &client_clip);
  GrContextForegroundSet(&context, ClrWhite);
  window(EVENT_WINDOW_PAINT, 0, &context);
  GrFlush(&context);

  window(EVENT_WINDOW_CLOSING, 0, 0);
}
示例#17
0
void TestTriagle(CuTest* tc)
{
  GrContextForegroundSet(&context, ClrBlack);
  GrRectFill(&context, &client_clip);

  GrContextForegroundSet(&context, ClrWhite);

  GrTriagleFill(&context, 82, 68, 79, 80, 80, 80);

  GrTriagleFill(&context, 110, 70, 70, 100, 130, 140);
  GrTriagleFill(&context, 10, 10, 30, 10, 40, 40);
 
  GrFlush(&context);
}
示例#18
0
void configDisplay(void)
{
    // Enable use of external clock crystals
    P5SEL |= (BIT5|BIT4|BIT3|BIT2);

    // Set up LCD -- These function calls are part on a TI supplied library
    Dogs102x64_UC1701Init();
    GrContextInit(&g_sContext, &g_sDogs102x64_UC1701);
    GrContextForegroundSet(&g_sContext, ClrBlack);
    GrContextBackgroundSet(&g_sContext, ClrWhite);
    GrContextFontSet(&g_sContext, &g_sFontFixed6x8);
    GrClearDisplay(&g_sContext);
    GrFlush(&g_sContext);
}
示例#19
0
//*****************************************************************************
//
// Set up the OLED Graphical Display
//
//*****************************************************************************
void
InitGraphics(void)
{
    tRectangle sRect;

    //
    // Initialize the display driver.
    //
    CFAL96x64x16Init();

    //
    // Initialize the graphics context.
    //
    GrContextInit(&g_sContext, &g_sCFAL96x64x16);

    //
    // Fill the top 24 rows of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.i16YMax = 9;
    GrContextForegroundSet(&g_sContext, ClrDarkBlue);
    GrRectFill(&g_sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrRectDraw(&g_sContext, &sRect);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&g_sContext, g_psFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "CAN Example", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 4, 0);

    //
    // Flush any cached drawing operations.
    //
    GrFlush(&g_sContext);
}
/*******************************************************************************
 * @fn          devpkLcdInvert
 *
 * @brief       Inverts the foreground and background colours
 *
 * @return      true if success
 */
bool devpkLcdInvert(void)
{
  if (hLcdPin != NULL)
  {
    uint32_t tmp;

    // Swap background and foreground
    tmp = display.fg;
    display.fg = display.bg;
    display.bg = tmp;

    GrContextForegroundSet(&g_sContext, display.fg);
    GrContextBackgroundSet(&g_sContext, display.bg);
    GrClearDisplay(&g_sContext);

    GrFlush(&g_sContext);
  }

  return hLcdPin != 0;
}
示例#21
0
void draw_well(nstate *state, int forcedraw)
{
	int x, y;

	for(y = WELL_NOTVISIBLE; y < WELL_HEIGHT; y++) {
		for(x = 0; x < WELL_WIDTH; x++) {
			if(forcedraw || (state->blocks[0][y][x] !=
						state->blocks[1][y][x])) {
				state->blocks[1][y][x] = state->blocks[0][y][x];
				GrSetGCForeground(state->wellgc,
							state->blocks[0][y][x]);
				GrFillRect(state->well_window, state->wellgc,
					(BLOCK_SIZE * x),
					(BLOCK_SIZE * (y - WELL_NOTVISIBLE)),
						BLOCK_SIZE, BLOCK_SIZE);
			}
		}
	}

	GrFlush();
}
/*******************************************************************************
 * @fn          devpkLcdOpen
 *
 * @brief       Initialize the LCD
 *
 * @descr       Initializes the pins used by the LCD, creates resource access
 *              protection semaphore, turns on the LCD device, initializes the
 *              frame buffer, initializes to white background/dark foreground,
 *              and finally clears the display.
 *
 * @return      true if success
 */
bool devpkLcdOpen(void)
{
  hLcdPin = PIN_open(&pinState, BoardDevpackLCDPinTable);

  if (hLcdPin != 0)
  {
    display.bg = ClrBlack;
    display.fg = ClrWhite;

    // Open the SPI driver
    bspSpiOpen();

    // Exclusive access
    Semaphore_Params_init(&semParamsLCD);
    semParamsLCD.mode = Semaphore_Mode_BINARY;
    Semaphore_construct(&semLCD, 1, &semParamsLCD);
    hSemLCD = Semaphore_handle(&semLCD);

    // Turn on the display
    PIN_setOutputValue(hLcdPin,Board_DEVPK_LCD_DISP,1);

    // Graphics library init
    GrContextInit(&g_sContext, &g_sharp96x96LCD);

    // Graphics properties
    GrContextForegroundSet(&g_sContext, display.fg);
    GrContextBackgroundSet(&g_sContext, display.bg);
    GrContextFontSet(&g_sContext, &g_sFontFixed6x8);

    // Clear display
    GrClearDisplay(&g_sContext);
    GrFlush(&g_sContext);
  }

  return hLcdPin != 0;
}
int
main(void)
{
    tContext sContext;
    tRectangle sRect;

    //
    // The FPU should be enabled because some compilers will use floating-
    // point registers, even for non-floating-point code.  If the FPU is not
    // enabled this will cause a fault.  This also ensures that floating-
    // point operations could be added to this application and would work
    // correctly and use the hardware floating-point unit.  Finally, lazy
    // stacking is enabled for interrupt handlers.  This allows floating-
    // point instructions to be used within interrupt handlers, but at the
    // expense of extra stack usage.
    //
    FPUEnable();
    FPULazyStackingEnable();

    //
    // Set the clock to 40Mhz derived from the PLL and the external oscillator
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);

    //
    // Initialize the display driver.
    //
    Adafruit320x240x16_ILI9325Init();

    //
    // Initialize the graphics context.
    //
    GrContextInit(&sContext, &g_sAdafruit320x240x16_ILI9325);

    //
    // Configure and enable uDMA
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
    SysCtlDelay(10);
    uDMAControlBaseSet(&sDMAControlTable[0]);
    uDMAEnable();

    //
    // Initialize the touch screen driver and have it route its messages to the
    // widget tree.
    //
    TouchScreenInit();

    //
    // Paint touch calibration targets and collect calibration data
    //
    GrContextForegroundSet(&sContext, ClrWhite);
    GrContextBackgroundSet(&sContext, ClrBlack);
    GrContextFontSet(&sContext, &g_sFontCm20);
    GrStringDraw(&sContext, "Touch center of circles to calibrate", -1, 0, 0, 1);
    GrCircleDraw(&sContext, 32, 24, 10);
    GrFlush(&sContext);
    TouchScreenCalibrationPoint(32, 24, 0);

    GrCircleDraw(&sContext, 280, 200, 10);
    GrFlush(&sContext);
    TouchScreenCalibrationPoint(280, 200, 1);

    GrCircleDraw(&sContext, 200, 40, 10);
    GrFlush(&sContext);
    TouchScreenCalibrationPoint(200, 40, 2);

    //
    // Calculate and set calibration matrix
    //
    long* plCalibrationMatrix = TouchScreenCalibrate();
    
    //
    // Write out calibration data if successful
    //
    if(plCalibrationMatrix)
    {
    	char pcStringBuf[20];
    	usprintf(pcStringBuf, "A %d", plCalibrationMatrix[0]);
    	GrStringDraw(&sContext, pcStringBuf, -1, 0, 20, 1);
    	usprintf(pcStringBuf, "B %d", plCalibrationMatrix[1]);
    	GrStringDraw(&sContext, pcStringBuf, -1, 0, 40, 1);
    	usprintf(pcStringBuf, "C %d", plCalibrationMatrix[2]);
    	GrStringDraw(&sContext, pcStringBuf, -1, 0, 60, 1);
    	usprintf(pcStringBuf, "D %d", plCalibrationMatrix[3]);
    	GrStringDraw(&sContext, pcStringBuf, -1, 0, 80, 1);
    	usprintf(pcStringBuf, "E %d", plCalibrationMatrix[4]);
    	GrStringDraw(&sContext, pcStringBuf, -1, 0, 100, 1);
    	usprintf(pcStringBuf, "F %d", plCalibrationMatrix[5]);
    	GrStringDraw(&sContext, pcStringBuf, -1, 0, 120, 1);
    	usprintf(pcStringBuf, "Div %d", plCalibrationMatrix[6]);
    	GrStringDraw(&sContext, pcStringBuf, -1, 0, 140, 1);
    	TouchScreenCalibrationPoint(0,0,0);	// wait for dummy touch
    }

    //
    // Enable touch screen event handler for grlib widgets
    //
    TouchScreenCallbackSet(WidgetPointerMessage);

    //
    // Fill the top 24 rows of the screen with blue to create the banner.
    //
    sRect.sXMin = 0;
    sRect.sYMin = 0;
    sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1;
    sRect.sYMax = 23;
    GrContextForegroundSet(&sContext, ClrDarkBlue);
    GrRectFill(&sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&sContext, ClrWhite);
    GrRectDraw(&sContext, &sRect);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&sContext, &g_sFontCm20);
    GrStringDrawCentered(&sContext, "grlib demo", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 8, 0);

    //
    // Add the title block and the previous and next buttons to the widget
    // tree.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sPrevious);
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sTitle);
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sNext);

    //
    // Add the first panel to the widget tree.
    //
    g_ulPanel = 0;
    WidgetAdd(WIDGET_ROOT, (tWidget *)g_psPanels);
    CanvasTextSet(&g_sTitle, g_pcPanelNames[0]);

    //
    // Issue the initial paint request to the widgets.
    //
    WidgetPaint(WIDGET_ROOT);

    //
    // Loop forever handling widget messages.
    //
    while(1)
    {
        //
        // Process any messages in the widget message queue.
        //
        WidgetMessageQueueProcess();
    }
}
示例#24
0
static void
MoveTile(int xpos, int ypos)
{
	/* check all possible moves to see if there is the blank (N,E,S,W) */
	if (ypos > 0 && value[xpos][ypos - 1] == MAX_TILES) {
		value[xpos][ypos - 1] = value[xpos][ypos];
		value[xpos][ypos] = MAX_TILES;
		DrawTile(xpos, ypos - 1);
		DrawTile(xpos, ypos);
	}

	if (xpos < (WIDTH_IN_TILES - 1) && value[xpos + 1][ypos] == MAX_TILES) {
		value[xpos + 1][ypos] = value[xpos][ypos];
		value[xpos][ypos] = MAX_TILES;
		DrawTile(xpos + 1, ypos);
		DrawTile(xpos, ypos);
	}

	if (ypos < (HEIGHT_IN_TILES - 1) && value[xpos][ypos + 1] == MAX_TILES) {
		value[xpos][ypos + 1] = value[xpos][ypos];
		value[xpos][ypos] = MAX_TILES;
		DrawTile(xpos, ypos + 1);
		DrawTile(xpos, ypos);
	}

	if (xpos > 0 && value[xpos - 1][ypos] == MAX_TILES) {
		value[xpos - 1][ypos] = value[xpos][ypos];
		value[xpos][ypos] = MAX_TILES;
		DrawTile(xpos - 1, ypos);
		DrawTile(xpos, ypos);
	}

	/* check for a winner */
	if (value[WIDTH_IN_TILES - 1][HEIGHT_IN_TILES - 1] == MAX_TILES) {
		int winner = 0;
		for (ypos=0; ypos< HEIGHT_IN_TILES; ypos++){
			for (xpos=0; xpos< WIDTH_IN_TILES; xpos++){
				if (value[xpos][ypos] == winner + 1)
					winner++;
				else 
					winner=0;
			}
		}
		if (winner == MAX_TILES) {
			/* Do winning screen */
			int loop = MAX_TILES;
			for(loop=0; loop < MAX_TILES; loop++) {
				for(winner=0; winner < (MAX_TILES - loop) ; winner++) {

					/* move tiles around */
					xpos = winner % WIDTH_IN_TILES;
					ypos = (int)(winner/WIDTH_IN_TILES);
					value[xpos][ypos] = loop + winner + 1; 
					DrawTile(winner % WIDTH_IN_TILES, (int)(winner/WIDTH_IN_TILES));
				}
				GrFlush();
				for(winner=0; winner < 10000000 ; winner++);
					/* delay loop */
			}
			/* Print message */
			GrSetGCForeground(gc1, WHITE);
			GrSetGCBackground(gc1, RED);
			GrText(tiles, gc1, ((WIDTH_IN_TILES * tile_width)/2) - 40, (HEIGHT_IN_TILES * tile_height)/2, "Well Done!!", -1, 0);
		}
				
	}
}
//*****************************************************************************
//
// Performs calibration of the touch screen.
//
//*****************************************************************************
int
main(void)
{
    int32_t i32Idx, i32X1, i32Y1, i32X2, i32Y2, i32Count, ppi32Points[3][4];
    uint32_t ui32SysClock;
    char pcBuffer[32];
    tContext sContext;
    tRectangle sRect;

    //
    // Run from the PLL at 120 MHz.
    //
    ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);

    //
    // Configure the device pins.
    //
    PinoutSet();

    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init(ui32SysClock);

    //
    // Initialize the graphics context.
    //
    GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Draw the application frame.
    //
    FrameDraw(&sContext, "calibrate");

    //
    // Print the instructions across the middle of the screen in white with a
    // 20 point small-caps font.
    //
    GrContextForegroundSet(&sContext, ClrWhite);
    GrContextFontSet(&sContext, g_psFontCmsc20);
    GrStringDrawCentered(&sContext, "Touch the box", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         (GrContextDpyHeightGet(&sContext) / 2) - 10, 0);

    //
    // Set the points used for calibration based on the size of the screen.
    //
    ppi32Points[0][0] = GrContextDpyWidthGet(&sContext) / 10;
    ppi32Points[0][1] = (GrContextDpyHeightGet(&sContext) * 2) / 10;
    ppi32Points[1][0] = GrContextDpyWidthGet(&sContext) / 2;
    ppi32Points[1][1] = (GrContextDpyHeightGet(&sContext) * 9) / 10;
    ppi32Points[2][0] = (GrContextDpyWidthGet(&sContext) * 9) / 10;
    ppi32Points[2][1] = GrContextDpyHeightGet(&sContext) / 2;

    //
    // Initialize the touch screen driver.
    //
    TouchScreenInit(ui32SysClock);

    //
    // Loop through the calibration points.
    //
    for(i32Idx = 0; i32Idx < 3; i32Idx++)
    {
        //
        // Fill a white box around the calibration point.
        //
        GrContextForegroundSet(&sContext, ClrWhite);
        sRect.i16XMin = ppi32Points[i32Idx][0] - 5;
        sRect.i16YMin = ppi32Points[i32Idx][1] - 5;
        sRect.i16XMax = ppi32Points[i32Idx][0] + 5;
        sRect.i16YMax = ppi32Points[i32Idx][1] + 5;
        GrRectFill(&sContext, &sRect);

        //
        // Flush any cached drawing operations.
        //
        GrFlush(&sContext);

        //
        // Initialize the raw sample accumulators and the sample count.
        //
        i32X1 = 0;
        i32Y1 = 0;
        i32Count = -5;

        //
        // Loop forever.  This loop is explicitly broken out of when the pen is
        // lifted.
        //
        while(1)
        {
            //
            // Grab the current raw touch screen position.
            //
            i32X2 = g_i16TouchX;
            i32Y2 = g_i16TouchY;

            //
            // See if the pen is up or down.
            //
            if((i32X2 < g_i16TouchMin) || (i32Y2 < g_i16TouchMin))
            {
                //
                // The pen is up, so see if any samples have been accumulated.
                //
                if(i32Count > 0)
                {
                    //
                    // The pen has just been lifted from the screen, so break
                    // out of the controlling while loop.
                    //
                    break;
                }

                //
                // Reset the accumulators and sample count.
                //
                i32X1 = 0;
                i32Y1 = 0;
                i32Count = -5;

                //
                // Grab the next sample.
                //
                continue;
            }

            //
            // Increment the count of samples.
            //
            i32Count++;

            //
            // If the sample count is greater than zero, add this sample to the
            // accumulators.
            //
            if(i32Count > 0)
            {
                i32X1 += i32X2;
                i32Y1 += i32Y2;
            }
        }

        //
        // Save the averaged raw ADC reading for this calibration point.
        //
        ppi32Points[i32Idx][2] = i32X1 / i32Count;
        ppi32Points[i32Idx][3] = i32Y1 / i32Count;

        //
        // Erase the box around this calibration point.
        //
        GrContextForegroundSet(&sContext, ClrBlack);
        GrRectFill(&sContext, &sRect);
    }

    //
    // Clear the screen.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1;
    sRect.i16YMax = GrContextDpyHeightGet(&sContext) - 1;
    GrRectFill(&sContext, &sRect);

    //
    // Indicate that the calibration data is being displayed.
    //
    GrContextForegroundSet(&sContext, ClrWhite);
    GrStringDraw(&sContext, "Calibration data:", -1, 16, 32, 0);

    //
    // Compute and display the M0 calibration value.
    //
    usprintf(pcBuffer, "M0 = %d",
             (((ppi32Points[0][0] - ppi32Points[2][0]) *
               (ppi32Points[1][3] - ppi32Points[2][3])) -
              ((ppi32Points[1][0] - ppi32Points[2][0]) *
               (ppi32Points[0][3] - ppi32Points[2][3]))));
    GrStringDraw(&sContext, pcBuffer, -1, 16, 72, 0);

    //
    // Compute and display the M1 calibration value.
    //
    usprintf(pcBuffer, "M1 = %d",
             (((ppi32Points[0][2] - ppi32Points[2][2]) *
               (ppi32Points[1][0] - ppi32Points[2][0])) -
              ((ppi32Points[0][0] - ppi32Points[2][0]) *
               (ppi32Points[1][2] - ppi32Points[2][2]))));
    GrStringDraw(&sContext, pcBuffer, -1, 16, 92, 0);

    //
    // Compute and display the M2 calibration value.
    //
    usprintf(pcBuffer, "M2 = %d",
             ((((ppi32Points[2][2] * ppi32Points[1][0]) -
                (ppi32Points[1][2] * ppi32Points[2][0])) * ppi32Points[0][3]) +
              (((ppi32Points[0][2] * ppi32Points[2][0]) -
                (ppi32Points[2][2] * ppi32Points[0][0])) * ppi32Points[1][3]) +
              (((ppi32Points[1][2] * ppi32Points[0][0]) -
                (ppi32Points[0][2] * ppi32Points[1][0])) * ppi32Points[2][3])));
    GrStringDraw(&sContext, pcBuffer, -1, 16, 112, 0);

    //
    // Compute and display the M3 calibration value.
    //
    usprintf(pcBuffer, "M3 = %d",
             (((ppi32Points[0][1] - ppi32Points[2][1]) *
               (ppi32Points[1][3] - ppi32Points[2][3])) -
              ((ppi32Points[1][1] - ppi32Points[2][1]) *
               (ppi32Points[0][3] - ppi32Points[2][3]))));
    GrStringDraw(&sContext, pcBuffer, -1, 16, 132, 0);

    //
    // Compute and display the M4 calibration value.
    //
    usprintf(pcBuffer, "M4 = %d",
             (((ppi32Points[0][2] - ppi32Points[2][2]) *
               (ppi32Points[1][1] - ppi32Points[2][1])) -
              ((ppi32Points[0][1] - ppi32Points[2][1]) *
               (ppi32Points[1][2] - ppi32Points[2][2]))));
    GrStringDraw(&sContext, pcBuffer, -1, 16, 152, 0);

    //
    // Compute and display the M5 calibration value.
    //
    usprintf(pcBuffer, "M5 = %d",
             ((((ppi32Points[2][2] * ppi32Points[1][1]) -
                (ppi32Points[1][2] * ppi32Points[2][1])) * ppi32Points[0][3]) +
              (((ppi32Points[0][2] * ppi32Points[2][1]) -
                (ppi32Points[2][2] * ppi32Points[0][1])) * ppi32Points[1][3]) +
              (((ppi32Points[1][2] * ppi32Points[0][1]) -
                (ppi32Points[0][2] * ppi32Points[1][1])) * ppi32Points[2][3])));
    GrStringDraw(&sContext, pcBuffer, -1, 16, 172, 0);

    //
    // Compute and display the M6 calibration value.
    //
    usprintf(pcBuffer, "M6 = %d",
             (((ppi32Points[0][2] - ppi32Points[2][2]) *
               (ppi32Points[1][3] - ppi32Points[2][3])) -
              ((ppi32Points[1][2] - ppi32Points[2][2]) *
               (ppi32Points[0][3] - ppi32Points[2][3]))));
    GrStringDraw(&sContext, pcBuffer, -1, 16, 192, 0);

    //
    // Flush any cached drawing operations.
    //
    GrFlush(&sContext);

    //
    // The calibration is complete.  Sit around and wait for a reset.
    //
    while(1)
    {
    }
}
//*****************************************************************************
//
// This is the main example program.  It checks to see that the interrupts are
// processed in the correct order when they have identical priorities,
// increasing priorities, and decreasing priorities.  This exercises interrupt
// preemption and tail chaining.
//
//*****************************************************************************
int
main(void)
{
    uint_fast8_t ui8Error;
    uint32_t ui32SysClock;

    //
    // Run from the PLL at 120 MHz.
    //
    ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);

    //
    // Configure the device pins.
    //
    PinoutSet();

    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init(ui32SysClock);

    //
    // Initialize the graphics context.
    //
    GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Draw the application frame.
    //
    FrameDraw(&g_sContext, "interrupts");

    //
    // Put the status header text on the display.
    //
    GrContextFontSet(&g_sContext, g_psFontCm20);
    GrStringDrawCentered(&g_sContext, "Active:      Pending:     ", -1,
                 GrContextDpyWidthGet(&g_sContext) / 2, 150, 0);

    //
    // Configure the B3, L1 and L0 to be outputs to indicate entry/exit of one
    // of the interrupt handlers.
    //
    GPIOPinTypeGPIOOutput(GPIO_A_BASE, GPIO_A_PIN);
    GPIOPinTypeGPIOOutput(GPIO_B_BASE, GPIO_B_PIN);
    GPIOPinTypeGPIOOutput(GPIO_C_BASE, GPIO_C_PIN);
    GPIOPinWrite(GPIO_A_BASE, GPIO_A_PIN, 0);
    GPIOPinWrite(GPIO_B_BASE, GPIO_B_PIN, 0);
    GPIOPinWrite(GPIO_C_BASE, GPIO_C_PIN, 0);

    //
    // Set up and enable the SysTick timer.  It will be used as a reference
    // for delay loops in the interrupt handlers.  The SysTick timer period
    // will be set up for 100 times per second.
    //
    ROM_SysTickPeriodSet(ui32SysClock / 100);
    ROM_SysTickEnable();

    //
    // Reset the error indicator.
    //
    ui8Error = 0;

    //
    // Enable interrupts to the processor.
    //
    ROM_IntMasterEnable();

    //
    // Enable the interrupts.
    //
    ROM_IntEnable(INT_GPIOA);
    ROM_IntEnable(INT_GPIOB);
    ROM_IntEnable(INT_GPIOC);

    //
    // Indicate that the equal interrupt priority test is beginning.
    //
    GrStringDrawCentered(&g_sContext, "Equal Priority", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 60, 1);

    //
    // Set the interrupt priorities so they are all equal.
    //
    ROM_IntPrioritySet(INT_GPIOA, 0x00);
    ROM_IntPrioritySet(INT_GPIOB, 0x00);
    ROM_IntPrioritySet(INT_GPIOC, 0x00);

    //
    // Reset the interrupt flags.
    //
    g_ui32GPIOa = 0;
    g_ui32GPIOb = 0;
    g_ui32GPIOc = 0;
    g_ui32Index = 1;

    //
    // Trigger the interrupt for GPIO C.
    //
    HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16;

    //
    // Put the current interrupt state on the LCD.
    //
    DisplayIntStatus();

    //
    // Verify that the interrupts were processed in the correct order.
    //
    if((g_ui32GPIOa != 3) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 1))
    {
        ui8Error |= 1;
    }

    //
    // Wait two seconds.
    //
    Delay(2);

    //
    // Indicate that the decreasing interrupt priority test is beginning.
    //
    GrStringDrawCentered(&g_sContext, " Decreasing Priority ", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 60, 1);

    //
    // Set the interrupt priorities so that they are decreasing (i.e. C > B >
    // A).
    //
    ROM_IntPrioritySet(INT_GPIOA, 0x80);
    ROM_IntPrioritySet(INT_GPIOB, 0x40);
    ROM_IntPrioritySet(INT_GPIOC, 0x00);

    //
    // Reset the interrupt flags.
    //
    g_ui32GPIOa = 0;
    g_ui32GPIOb = 0;
    g_ui32GPIOc = 0;
    g_ui32Index = 1;

    //
    // Trigger the interrupt for GPIO C.
    //
    HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16;

    //
    // Put the current interrupt state on the display.
    //
    DisplayIntStatus();

    //
    // Verify that the interrupts were processed in the correct order.
    //
    if((g_ui32GPIOa != 3) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 1))
    {
        ui8Error |= 2;
    }

    //
    // Wait two seconds.
    //
    Delay(2);

    //
    // Indicate that the increasing interrupt priority test is beginning.
    //
    GrStringDrawCentered(&g_sContext, " Increasing Priority ", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 60, 1);

    //
    // Set the interrupt priorities so that they are increasing (i.e. C < B <
    // A).
    //
    ROM_IntPrioritySet(INT_GPIOA, 0x00);
    ROM_IntPrioritySet(INT_GPIOB, 0x40);
    ROM_IntPrioritySet(INT_GPIOC, 0x80);

    //
    // Reset the interrupt flags.
    //
    g_ui32GPIOa = 0;
    g_ui32GPIOb = 0;
    g_ui32GPIOc = 0;
    g_ui32Index = 1;

    //
    // Trigger the interrupt for GPIO C.
    //
    HWREG(NVIC_SW_TRIG) = INT_GPIOC - 16;

    //
    // Put the current interrupt state on the display.
    //
    DisplayIntStatus();

    //
    // Verify that the interrupts were processed in the correct order.
    //
    if((g_ui32GPIOa != 1) || (g_ui32GPIOb != 2) || (g_ui32GPIOc != 3))
    {
        ui8Error |= 4;
    }

    //
    // Wait two seconds.
    //
    Delay(2);

    //
    // Disable the interrupts.
    //
    ROM_IntDisable(INT_GPIOA);
    ROM_IntDisable(INT_GPIOB);
    ROM_IntDisable(INT_GPIOC);

    //
    // Disable interrupts to the processor.
    //
    ROM_IntMasterDisable();

    //
    // Print out the test results.
    //
    GrStringDrawCentered(&g_sContext, " Interrupt Priority ", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 60, 1);
    if(ui8Error)
    {
        GrStringDrawCentered(&g_sContext, "     Equal: P  Inc: P  Dec: P     ",
                             -1, GrContextDpyWidthGet(&g_sContext) / 2, 150, 1);
        if(ui8Error & 1)
        {
            GrStringDrawCentered(&g_sContext, " F ", -1, 113, 150, 1);
        }
        if(ui8Error & 2)
        {
            GrStringDrawCentered(&g_sContext, " F ", -1, 187, 150, 1);
        }
        if(ui8Error & 4)
        {
            GrStringDrawCentered(&g_sContext, " F ", -1, 272, 150, 1);
        }
    }
    else
    {
        GrStringDrawCentered(&g_sContext, "           Success!           ", -1,
                             GrContextDpyWidthGet(&g_sContext) / 2, 150, 1);
    }

    //
    // Flush the display.
    //
    GrFlush(&g_sContext);

    //
    // Loop forever.
    //
    while(1)
    {
    }
}
示例#27
0
int
main(int ac, char **av)
{
	GR_WINDOW_ID window;
	GR_GC_ID gc;
	GR_FONT_ID fontid;
	int x, y, fnum;
	GR_REGION_ID regionid;
#if CLIP_POLYGON
	GR_POINT points[] = { {20, 20}, {300, 20}, {300, 300}, {20, 300} };
#else
	GR_RECT clip_rect = { 20, 20, 300, 300 };
#endif

	if (GrOpen() < 0)
		exit(1);

	window = GrNewWindowEx(GR_WM_PROPS_APPWINDOW,
		"t1demo loadable fonts (truetype, t1lib, pcf, mgl, hzk)",
		GR_ROOT_WINDOW_ID, 50, 50, WIDTH, HEIGHT, BLACK);
	GrSelectEvents(window, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CLOSE_REQ);
	GrMapWindow(window);

	gc = GrNewGC();
	GrSetGCUseBackground(gc, GR_FALSE);
	GrSetGCBackground(gc, BLACK);

#if CLIP_POLYGON
	/* polygon clip region */
	regionid = GrNewPolygonRegion(MWPOLY_EVENODD, 3, points);
#else
	/* rectangle clip region */
	regionid = GrNewRegion();
	GrUnionRectWithRegion(regionid, &clip_rect);
#endif
	GrSetGCRegion(gc, regionid);

	srand(time(0));
	while (1) {
		GR_EVENT event;

		GrCheckNextEvent(&event);
		if (event.type == GR_EVENT_TYPE_CLOSE_REQ) {
			GrClose();
			exit(0);
		}

		fontid = GrCreateFontEx(names[fnum=RAND(MAXFONTS)], 0, 0, NULL);
		GrSetFontSizeEx(fontid, RAND(80) + 1, RAND(80) + 1);
		GrSetFontRotation(fontid, 330);		/* 33 degrees */
		GrSetFontAttr(fontid, GR_TFKERNING | GR_TFANTIALIAS, 0);
		GrSetGCFont(gc, fontid);

		GrSetGCForeground(gc, rand() & 0xffffff);
		/*GrSetGCBackground(gc, rand() & 0xffffff); */

		x = RAND(WIDTH);
		y = RAND(HEIGHT);

#if HAVE_HZK_SUPPORT
		{
#if HZKBIG5
		/* hzk big5 unicode-16 test*/
		static unsigned short buffer[] = {
		    0x9060, 0x898b, 0x79d1, 0x6280, 0x0061, 0x0041, 0
		};
		GrText(window, gc, x, y, buffer, 7, GR_TFUC16);

		/* hzk big5 dbcs test #1*/
		x = RAND(WIDTH);
		y = RAND(HEIGHT);
		GrText(window, gc, x, y,
		       "Microwindows,Åwªï¨Ï¥Î¤¤­^¤åÂI°}¦rÅé", -1, GR_TFASCII);

		/* hzk big5 dbcs test #2*/
		x = RAND(WIDTH);
		y = RAND(HEIGHT);
		GrText(window, gc, x, y, "£t£u£v£w£¸£¹£º", -1, GR_TFASCII);
#else
	#if 0
		/* hzk test #1*/
		static char buffer[] = {
			0x6c, 0x49, 0x73, 0x8b, 0x79,
			0xd1, 0x62, 0x80, 0x61, 0x00,
			0x41, 0x00, 0x00, 0xa1, 0x00,
			0xa6, 0x6c, 0x49, 0, 0
		};

		/* *static unsigned short buffer[] = {
			0x496c, 0x8b73, 0xd179, 0x8062, 0x0061,
			0x0041, 0xa100, 0xa600, 0x496c, 0
		};***/

		GrText(window, gc, x, y, buffer, 9, GR_TFUC16);
	#endif
		/* HZK Metrix font test, includes Chinese and English */
		x = RAND(WIDTH);
		y = RAND(HEIGHT);
		GrText(window, gc, x, y,
		       "Microwindows,»¶Ó­Ê¹ÓÃÖÐÓ¢ÎĵãÕó×ÖÌå", -1, GR_TFASCII);
#endif /* HZKBIG5*/
		}
#elif HAVE_BIG5_SUPPORT
		/* encoding BIG5 test 61 B1 64 B1 64 61 */
		GrText(window, gc, x, y, "\151\261\144\261\144\151", 6, MWTF_DBCS_BIG5);
#elif HAVE_GB2312_SUPPORT
		/* encoding GB2312 test BD A1 BD A1 */
		GrText(window, gc, x, y, "\275\241\275\241", 4, MWTF_DBCS_GB);
#elif HAVE_EUCJP_SUPPORT
		/* encoding EUC_JP test A2 A1 */
		GrText(window, gc, x, y, "ï¿½Þ¥ï¿½ï¿½ï¿½ï¿½í¥¦ï¿½ï¿½ï¿½ï¿½ï¿½É¥ï¿½ï¿½ï¿½ï¿½Ø¤è¤¦ï¿½ï¿½ï¿½ï¿½!", -1, MWTF_DBCS_EUCJP);
#elif HAVE_JISX0213_SUPPORT
		/* encoding JISX0213 test A2 A1 */
		GrText(window, gc, x, y, "\242\241", 2, MWTF_DBCS_JIS);
#elif HAVE_KSC5601_SUPPORT
		/* encoding KSC5601 test B0 B0 */
		GrText(window, gc, x, y, "\273\273", 2, MWTF_DBCS_EUCKR);
#elif HAVE_FREETYPE_2_SUPPORT
		/* ASCII test */
		GrText(window, gc, x, y, "Microwindows", -1, GR_TFASCII);
#elif HAVE_PCF_SUPPORT
		/* note: large PCF fonts require XCHAR2B, this is not
		   figured out yet for these fonts.  FIXME */
		if (fnum == 3) {
			/* japanese jiskan24*/
			unsigned short text[] =
			    { 0x213a, 0x213b, 0x2170, 0x2276, 0x2339 };
			GrText(window, gc, x,y, text, 5, GR_TFUC16);
		} else if (fnum == 4) {
			/* chinese gb24st*/
			unsigned short text[] =
			    /* FIXME: why doesn't first row index correctly?*/
			    /*{ 0x7765, 0x7766, 0x7767, 0x777a, 0x777e };*/
			    { 0x2129, 0x212a, 0x212b, 0x212c, 0x212d };
			GrText(window, gc, x,y, text, 5, GR_TFUC16);
		} else
			GrText(window, gc, x,y, "Microwindows", -1, GR_TFASCII);
#elif HAVE_FNT_SUPPORT
		/* UC16 test */
		if (fnum == 2 || fnum == 3) {
			/* japanese jiskan24, jiskan16-2000-1*/
			unsigned short text[] =
			    { 0x213a, 0x213b, 0x2170, 0x2276, 0x2339 };
			GrText(window, gc, x,y, text, 5, GR_TFUC16);
		} else if (fnum == 4) {
			/* chinese gbk16-xke*/
			unsigned short text[] =
			    { 0x8144, 0x8147, 0x8148, 0xfe4e, 0xfe4f };
			GrText(window, gc, x,y, text, 5, GR_TFUC16);
		} else
			GrText(window, gc, x,y, "Microwindows", -1, GR_TFASCII);
#else
		/* ASCII test */
		GrText(window, gc, x, y, "Microwindows", -1, GR_TFASCII);
#endif
		GrFlush();
		GrDestroyFont(fontid);
	}
	GrDestroyRegion(regionid);
	GrClose();
	return 0;
}
示例#28
0
//*****************************************************************************
//
// Print "Hello World!" to the display.
//
//*****************************************************************************
int
main(void)
{
    tContext sContext;
    tRectangle sRect;

    //
    // Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    ROM_FPULazyStackingEnable();

    //
    // Set the clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);

    //
    // Initialize the UART.
    //
    ConfigureUART();

    UARTprintf("Hello, world!\n");

    //
    // Initialize the display driver.
    //
    CFAL96x64x16Init();

    //
    // Initialize the graphics context.
    //
    GrContextInit(&sContext, &g_sCFAL96x64x16);

    //
    // Fill the top 24 rows of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1;
    sRect.i16YMax = 23;
    GrContextForegroundSet(&sContext, ClrDarkBlue);
    GrRectFill(&sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&sContext, ClrWhite);
    GrRectDraw(&sContext, &sRect);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&sContext, g_psFontCm12);
    GrStringDrawCentered(&sContext, "hello", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 10, 0);

    //
    // Say hello using the Computer Modern 40 point font.
    //
    GrContextFontSet(&sContext, g_psFontCm12/*g_psFontFixed6x8*/);
    GrStringDrawCentered(&sContext, "Hello World!", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         ((GrContextDpyHeightGet(&sContext) - 24) / 2) + 24,
                         0);

    //
    // Flush any cached drawing operations.
    //
    GrFlush(&sContext);

    //
    // We are finished. Hang around doing nothing.
    //
    while(1) {
    }
}
//*****************************************************************************
//
// Demonstrate the use of the USB stick update example.
//
//*****************************************************************************
int
main(void)
{
    unsigned long ulCount;
    tContext sContext;
    tRectangle sRect;

    //
    // Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    ROM_FPULazyStackingEnable();

    //
    // Set the system clock to run at 50MHz from the PLL.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Initialize the display driver.
    //
    CFAL96x64x16Init();

    //
    // Initialize the graphics context.
    //
    GrContextInit(&sContext, &g_sCFAL96x64x16);

    //
    // Fill the top 24 rows of the screen with blue to create the banner.
    //
    sRect.sXMin = 0;
    sRect.sYMin = 0;
    sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1;
    sRect.sYMax = 9;
    GrContextForegroundSet(&sContext, ClrDarkBlue);
    GrRectFill(&sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&sContext, ClrWhite);
    GrRectDraw(&sContext, &sRect);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&sContext, g_pFontFixed6x8);
    GrStringDrawCentered(&sContext, "usb-stick-demo", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 4, 0);

    //
    // Indicate what is happening.
    //
    GrStringDrawCentered(&sContext, "Press the", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 20, 0);
    GrStringDrawCentered(&sContext, "select button to", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 30, 0);
    GrStringDrawCentered(&sContext, "start the USB", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 40, 0);
    GrStringDrawCentered(&sContext, "stick updater.", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 50, 0);

    //
    // Flush any cached drawing operations.
    //
    GrFlush(&sContext);

    //
    // Enable the GPIO module which the select button is attached to.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM);

    //
    // Enable the GPIO pin to read the user button.
    //
    ROM_GPIODirModeSet(GPIO_PORTM_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN);
    ROM_GPIOPadConfigSet(GPIO_PORTM_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA,
                         GPIO_PIN_TYPE_STD_WPU);

    //
    // Wait for the pullup to take effect or the next loop will exist too soon.
    //
    SysCtlDelay(1000);

    //
    // Wait until the select button has been pressed for ~40ms (in order to
    // debounce the press).
    //
    ulCount = 0;
    while(1)
    {
        //
        // See if the button is pressed.
        //
        if(ROM_GPIOPinRead(GPIO_PORTM_BASE, GPIO_PIN_4) == 0)
        {
            //
            // Increment the count since the button is pressed.
            //
            ulCount++;

            //
            // If the count has reached 4, then the button has been debounced
            // as being pressed.
            //
            if(ulCount == 4)
            {
                break;
            }
        }
        else
        {
            //
            // Reset the count since the button is not pressed.
            //
            ulCount = 0;
        }

        //
        // Delay for approximately 10ms.
        //
        SysCtlDelay(16000000 / (3 * 100));
    }

    //
    // Wait until the select button has been released for ~40ms (in order to
    // debounce the release).
    //
    ulCount = 0;
    while(1)
    {
        //
        // See if the button is pressed.
        //
        if(ROM_GPIOPinRead(GPIO_PORTM_BASE, GPIO_PIN_4) != 0)
        {
            //
            // Increment the count since the button is released.
            //
            ulCount++;

            //
            // If the count has reached 4, then the button has been debounced
            // as being released.
            //
            if(ulCount == 4)
            {
                break;
            }
        }
        else
        {
            //
            // Reset the count since the button is pressed.
            //
            ulCount = 0;
        }

        //
        // Delay for approximately 10ms.
        //
        SysCtlDelay(16000000 / (3 * 100));
    }

    //
    // Indicate that the updater is being called.
    //
    GrStringDrawCentered(&sContext, "The USB stick", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 20, true);
    GrStringDrawCentered(&sContext, "updater is now", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 30, true);
    GrStringDrawCentered(&sContext, "waiting for a", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 40, true);
    GrStringDrawCentered(&sContext, "USB stick.", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 50, true);

    //
    // Flush any cached drawing operations.
    //
    GrFlush(&sContext);

    //
    // Call the updater so that it will search for an update on a memory stick.
    //
    (*((void (*)(void))(*(unsigned long *)0x2c)))();

    //
    // The updater should take control, so this should never be reached.
    // Just in case, loop forever.
    //
    while(1)
    {
    }
}
示例#30
0
文件: main.c 项目: tnapiork/all
void main(void)
{
    // Stop WDT
    WDTCTL = WDTPW + WDTHOLD;

    // Initialize the boards
    boardInit();
    clockInit();
    timerInit();
    flashInit();

    __bis_SR_register(GIE);

    // Set up the LCD
    LCDInit();
    GrContextInit(&g_sContext, &g_sharp96x96LCD);
    GrContextForegroundSet(&g_sContext, ClrBlack);
    GrContextBackgroundSet(&g_sContext, ClrWhite);
    GrContextFontSet(&g_sContext, &g_sFontFixed6x8);
    GrClearDisplay(&g_sContext);
    GrFlush(&g_sContext);

    // Intro Screen
    GrStringDrawCentered(&g_sContext, 
                         "How to use", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         15, 
                         TRANSPARENT_TEXT);
    GrStringDrawCentered(&g_sContext, 
                         "the MSP430", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         35, 
                         TRANSPARENT_TEXT);
    GrStringDraw(&g_sContext, 
                 "Graphics Library", 
                 AUTO_STRING_LENGTH, 
                 1, 
                 51, 
                 TRANSPARENT_TEXT);
    GrStringDrawCentered(&g_sContext, 
                         "Primitives", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         75, 
                         TRANSPARENT_TEXT);
    GrFlush(&g_sContext);
    Delay_long();
    GrClearDisplay(&g_sContext);

    // Draw pixels and lines on the display
    GrStringDrawCentered(&g_sContext, 
                         "Draw Pixels", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         5, 
                         TRANSPARENT_TEXT);
    GrStringDrawCentered(&g_sContext, 
                         "& Lines", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         15, 
                         TRANSPARENT_TEXT);
    GrPixelDraw(&g_sContext, 30, 30);
    GrPixelDraw(&g_sContext, 30, 32);
    GrPixelDraw(&g_sContext, 32, 32);
    GrPixelDraw(&g_sContext, 32, 30);
    GrLineDraw(&g_sContext, 35, 35, 90, 90);
    GrLineDraw(&g_sContext, 5, 80, 80, 20);
    GrLineDraw(&g_sContext, 
               0, 
               GrContextDpyHeightGet(&g_sContext) - 1, 
               GrContextDpyWidthGet(&g_sContext) - 1, 
               GrContextDpyHeightGet(&g_sContext) - 1);
    GrFlush(&g_sContext);
    Delay_long();
    GrClearDisplay(&g_sContext);

    // Draw circles on the display
    GrStringDraw(&g_sContext, 
                 "Draw Circles", 
                 AUTO_STRING_LENGTH, 
                 10, 
                 5, 
                 TRANSPARENT_TEXT);
    GrCircleDraw(&g_sContext, 30, 70, 20);
    GrCircleFill(&g_sContext, 60, 50, 30);
    GrFlush(&g_sContext);
    Delay_long();
    GrClearDisplay(&g_sContext);

    // Draw rectangles on the display
    GrStringDrawCentered(&g_sContext, 
                         "Draw Rectangles", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         5, 
                         TRANSPARENT_TEXT);
    GrRectDraw(&g_sContext, &myRectangle1);
    GrRectFill(&g_sContext, &myRectangle2);
    GrFlush(&g_sContext);
    Delay_long();
    GrClearDisplay(&g_sContext);

    // Combining Primitive screen
    GrStringDrawCentered(&g_sContext, 
                         "Combining", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         15, 
                         TRANSPARENT_TEXT);
    GrStringDrawCentered(&g_sContext, 
                         "Primitives to", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         35, 
                         TRANSPARENT_TEXT);
    GrStringDrawCentered(&g_sContext, 
                         "create menus", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         51, 
                         TRANSPARENT_TEXT);
    GrStringDrawCentered(&g_sContext, 
                         "and animations", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         75, 
                         TRANSPARENT_TEXT);
    GrFlush(&g_sContext);
    Delay_long();
    GrClearDisplay(&g_sContext);

    // Draw a Menu screen
    GrStringDrawCentered(&g_sContext, 
                         "Create a Menu", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         5, 
                         TRANSPARENT_TEXT);
    GrRectDraw(&g_sContext, &myRectangleOption1);
    GrStringDraw(&g_sContext,"Option #1", 10,15,15,TRANSPARENT_TEXT);
    GrRectFill(&g_sContext, &myRectangleOption2);
    GrStringDraw(&g_sContext,"Option #2", 10,15,25,TRANSPARENT_TEXT);
    GrRectDraw(&g_sContext, &myRectangleOption3);
    GrStringDraw(&g_sContext,"Option #3", 10,15,35,TRANSPARENT_TEXT);
    GrRectDraw(&g_sContext, &myRectangleOption4);
    GrStringDraw(&g_sContext,"Option #4", 10,15,45,TRANSPARENT_TEXT);
    GrRectDraw(&g_sContext, &myRectangleOption5);
    GrStringDraw(&g_sContext,"Option #5", 10,15,55,TRANSPARENT_TEXT);
    GrFlush(&g_sContext);
    Delay_long();
    GrClearDisplay(&g_sContext);

    // Show progress bar screen
    // The following animation consist on displaying a progress bar and 
    // updating the progress bar in increments of 25%.
    GrStringDrawCentered(&g_sContext, 
                         "Show progress", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         5, 
                         TRANSPARENT_TEXT);
    GrRectDraw(&g_sContext, &myRectangleFrame);
    GrStringDrawCentered(&g_sContext,
                         "Processing...", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         75, 
                         TRANSPARENT_TEXT);
    GrFlush(&g_sContext);
    Delay_short();

    // Update display with 25 %. Initial value of "myRectangleProgress" are set 
    // to update bar with a 25 % increment.
    GrRectFill(&g_sContext, &myRectangleProgress);
    GrFlush(&g_sContext);
    Delay_short();

    // Set myRectangleProgress values to update progress bar with 50 %
    myRectangleProgress.sXMin = 30;
    myRectangleProgress.sYMin = 40;
    myRectangleProgress.sXMax = 50;
    myRectangleProgress.sYMax = 60;

    GrRectFill(&g_sContext, &myRectangleProgress);
    GrFlush(&g_sContext);
    Delay_short();

    // Set myRectangleProgress values to update progress bar with 75 %
    myRectangleProgress.sXMin = 50;
    myRectangleProgress.sYMin = 40;
    myRectangleProgress.sXMax = 70;
    myRectangleProgress.sYMax = 60;

    GrRectFill(&g_sContext, &myRectangleProgress);
    GrFlush(&g_sContext);
    Delay_short();

    // Set myRectangleProgress values to update progress bar with 100 %
    myRectangleProgress.sXMin = 70;
    myRectangleProgress.sYMin = 40;
    myRectangleProgress.sXMax = 90;
    myRectangleProgress.sYMax = 60;
    GrRectFill(&g_sContext, &myRectangleProgress);

    GrStringDrawCentered(&g_sContext,
                         "DONE!", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         85, 
                         TRANSPARENT_TEXT);
    GrFlush(&g_sContext);
    Delay_long();



    while(1);

}