Example #1
0
File: main.c Project: DaviWei/uGFX
int main(void) {
	coord_t		width;
	font_t		font1, font2, font3, font4;
	const char	*msg;

    /* Initialize and clear the display */
    gfxInit();

    // Get the screen size
    width = gdispGetWidth();

    // Get the fonts we want to use
	font1 = gdispOpenFont("UI2");
	font2 = gdispOpenFont("UI2 Double");
	font3 = gdispOpenFont("UI2 Narrow");
	font4 = gdispOpenFont("LargeNumbers");

	// Display large numbers on the right (measuring the string)
	msg = "123456";
	gdispDrawString(width-gdispGetStringWidth(msg, font4)-3, 3, msg, font4, Green);
	
	// Display the font name under it.
	msg = gdispGetFontName(font4);
	gdispDrawString(width-gdispGetStringWidth(msg, font1)-3, 20, msg, font1, Green);

	// Demonstrate our other fonts
	gdispDrawString(10, 10, "Writing with Font 'UI2'", font1, Yellow);
	gdispFillString(10, 35, "Writing with Font 'UI2 Double'", font2, Red, White);
	gdispDrawStringBox(0, 50, width, 40, "Writing with Font 'UI2 Narrow'", font3, Red, justifyCenter);
	gdispFillStringBox(0, 90, width, 40, "Filled Centered", font3, Pink, Gray, justifyCenter);

	// Clean up the fonts
	gdispCloseFont(font1);
	gdispCloseFont(font2);
	gdispCloseFont(font3);
	gdispCloseFont(font4);

	// Wait forever
    while(TRUE) {
    	gfxSleepMilliseconds(500);
    }   
}
Example #2
0
	LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) {
		netPriv	*	priv;
		uint16_t	buf[4];

		#if GDISP_DONT_WAIT_FOR_NET_DISPLAY
			if (!(g->flags & GDISP_FLG_CONNECTED))
				return;
		#else
			while(!(g->flags & GDISP_FLG_CONNECTED))
				gfxSleepMilliseconds(200);
		#endif

		priv = g->priv;
		buf[0] = GNETCODE_PIXEL;
		buf[1] = g->p.x;
		buf[2] = g->p.y;
		buf[3] = gdispColor2Native(g->p.color);
		MUTEX_ENTER;
		sendpkt(priv->netfd, buf, 4);
		MUTEX_EXIT;
	}
Example #3
0
int main(void) {
	GHandle		gh;
	uint16_t 	i;
	
	gfxInit();
	
	{
		GWindowInit wi;

		gwinClearInit(&wi);
		wi.show = TRUE;
		wi.x = wi.y = 0;
		wi.width = gdispGetWidth();
		wi.height = gdispGetHeight();
		gh = gwinGraphCreate(&g, &wi);
	}

	gwinGraphSetOrigin(gh, gwinGetWidth(gh)/2, gwinGetHeight(gh)/2);
	gwinGraphSetStyle(gh, &GraphStyle1);
	gwinGraphDrawAxis(gh);
	
	for(i = 0; i < gwinGetWidth(gh); i++)
		gwinGraphDrawPoint(gh, i-gwinGetWidth(gh)/2, 80*fsin(2*i/5));	//sin(2*0.2*M_PI*i/180));

	gwinGraphStartSet(gh);
	GraphStyle1.point.color = uGreen;
	gwinGraphSetStyle(gh, &GraphStyle1);
	
	for(i = 0; i < gwinGetWidth(gh)*5; i++)
		gwinGraphDrawPoint(gh, i/5-gwinGetWidth(gh)/2, 95*fsin(2*i/5));	//sin(2*0.2*M_PI*i/180));

	gwinGraphStartSet(gh);
	gwinGraphSetStyle(gh, &GraphStyle2);

	gwinGraphDrawPoints(gh, data, sizeof(data)/sizeof(data[0]));

	while(TRUE) {
		gfxSleepMilliseconds(100);
	}
}
Example #4
0
File: main.c Project: DaviWei/uGFX
int main(void) {
	coord_t		width, height;

    /* Initialize and clear the display */
    gfxInit();

    // Get the screen size
    width = gdispGetWidth();
    height = gdispGetHeight();

    // Code Here
	gdispFillArc(width/2, height/2, width/4, -10, -45, White);
	gdispDrawCircle(width/2+width/8, height/2-height/8, 13, Green);
	gdispFillCircle (width/2+width/8, height/2-height/8, 10, Red);
	gdispDrawArc(width/2+width/8, height/2-height/8, 20, 25, 115, Gray);
	gdispFillEllipse (width-width/6, height-height/6, width/8, height/16, Blue);
	gdispDrawEllipse (width-width/6, height-height/6, width/16, height/8, Yellow);

    while(TRUE) {
    	gfxSleepMilliseconds(500);
    }   
}
Example #5
0
int main(void) {
	coord_t		width, height;
	coord_t		i, j;

    // Initialize and clear the display
    gfxInit();

    // Get the screen size
    width = gdispGetWidth();
    height = gdispGetHeight();

    // Code Here
	gdispDrawBox(10, 10, width/2, height/2, Yellow);
    gdispFillArea(width/2, height/2, width/2-10, height/2-10, Blue);
    gdispDrawLine(5, 30, width-50, height-40, Red);
    
	for(i = 5, j = 0; i < width && j < height; i += 7, j += i/20)
    	gdispDrawPixel(i, j, White);

    while(TRUE) {
    	gfxSleepMilliseconds(500);
    }   
}
Example #6
0
	LLDSPEC void gdisp_lld_vertical_scroll(GDisplay *g) {
		netPriv	*	priv;
		uint16_t	buf[6];

		#if GDISP_DONT_WAIT_FOR_NET_DISPLAY
			if (!(g->flags & GDISP_FLG_CONNECTED))
				return;
		#else
			while(!(g->flags & GDISP_FLG_CONNECTED))
				gfxSleepMilliseconds(200);
		#endif

		priv = g->priv;
		buf[0] = GNETCODE_SCROLL;
		buf[1] = g->p.x;
		buf[2] = g->p.y;
		buf[3] = g->p.cx;
		buf[4] = g->p.cy;
		buf[5] = g->p.y1;
		MUTEX_ENTER;
		sendpkt(priv->netfd, buf, 6);
		MUTEX_EXIT;
	}
Example #7
0
bool_t ginputGetMouseStatus(uint16_t instance, GEventMouse *pe) {
	// Win32 threads don't seem to recognise priority and/or pre-emption
	// so we add a sleep here to prevent 100% polled applications from locking up.
	gfxSleepMilliseconds(1);

	if (instance || (MouseConfig.flags & (FLG_INIT_DONE|FLG_IN_CAL)) != FLG_INIT_DONE)
		return FALSE;

	pe->type = GINPUT_MOUSE_EVENT_TYPE;
	pe->instance = instance;
	pe->x = MouseConfig.t.x;
	pe->y = MouseConfig.t.y;
	pe->z = MouseConfig.t.z;
	pe->current_buttons = MouseConfig.t.buttons;
	pe->last_buttons = MouseConfig.last_buttons;
	if (pe->current_buttons & ~pe->last_buttons & GINPUT_MOUSE_BTN_LEFT)
		pe->meta = GMETA_MOUSE_DOWN;
	else if (~pe->current_buttons & pe->last_buttons & GINPUT_MOUSE_BTN_LEFT)
		pe->meta = GMETA_MOUSE_UP;
	else
		pe->meta = GMETA_NONE;
	return TRUE;
}
Example #8
0
bool_t ginputCalibrateMouse(uint16_t instance) {
	#if !GINPUT_MOUSE_NEED_CALIBRATION
		(void) instance;
		
		return FALSE;
	#else

		const coord_t height  =  gdispGGetHeight(MouseConfig.display);
		const coord_t width  =  gdispGGetWidth(MouseConfig.display);
		#if GINPUT_MOUSE_CALIBRATE_EXTREMES
			const MousePoint cross[]  =  {{0, 0},
									{(width - 1) , 0},
									{(width - 1) , (height - 1)},
									{(width / 2), (height / 2)}}; /* Check point */
		#else
			const MousePoint cross[]  =  {{(width / 4), (height / 4)},
									{(width - (width / 4)) , (height / 4)},
									{(width - (width / 4)) , (height - (height / 4))},
									{(width / 2), (height / 2)}}; /* Check point */
		#endif
		MousePoint points[GINPUT_MOUSE_CALIBRATION_POINTS];
		const MousePoint	*pc;
		MousePoint *pt;
		int32_t px, py;
		unsigned i, j;
		font_t	font1, font2;
		#if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0
			unsigned	err;
		#endif

		if (instance || (MouseConfig.flags & FLG_IN_CAL))
			return FALSE;

		font1 = gdispOpenFont(GINPUT_MOUSE_CALIBRATION_FONT);
		font2 = gdispOpenFont(GINPUT_MOUSE_CALIBRATION_FONT2);

		MouseConfig.flags |= FLG_IN_CAL;
		gtimerStop(&MouseTimer);
		MouseConfig.flags &= ~(FLG_CAL_OK|FLG_CAL_SAVED|FLG_CAL_RAW);

		#if GDISP_NEED_CLIP
			gdispGSetClip(MouseConfig.display, 0, 0, width, height);
		#endif

		#if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0
			while(1) {
		#endif
				gdispGClear(MouseConfig.display, Blue);

				gdispGFillStringBox(MouseConfig.display, 0, 5, width, 30, GINPUT_MOUSE_CALIBRATION_TEXT, font1,  White, Blue, justifyCenter);

				for(i = 0, pt = points, pc = cross; i < GINPUT_MOUSE_CALIBRATION_POINTS; i++, pt++, pc++) {
					_tsDrawCross(pc);

					do {

						/* Wait for the mouse to be pressed */
						while(get_raw_reading(&MouseConfig.t), !(MouseConfig.t.buttons & GINPUT_MOUSE_BTN_LEFT))
							gfxSleepMilliseconds(20);

						/* Average all the samples while the mouse is down */
						for(px = py = 0, j = 0;
								gfxSleepMilliseconds(20),			/* Settling time between readings */
								get_raw_reading(&MouseConfig.t),
								(MouseConfig.t.buttons & GINPUT_MOUSE_BTN_LEFT);
								j++) {
							px += MouseConfig.t.x;
							py += MouseConfig.t.y;
						}

					} while(!j);

					pt->x = px / j;
					pt->y = py / j;

					_tsClearCross(pc);

					if (i >= 1 && pt->x == (pt-1)->x && pt->y == (pt-1)->y) {
						gdispGFillStringBox(MouseConfig.display, 0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_SAME_TEXT, font2,  Red, Yellow, justifyCenter);
						gfxSleepMilliseconds(5000);
						gdispGFillArea(MouseConfig.display, 0, 35, width, 40, Blue);
					}

				}

				/* Apply 3 point calibration algorithm */
				_tsDo3PointCalibration(cross, points, MouseConfig.display, &MouseConfig.caldata);

				 /* Verification of correctness of calibration (optional) :
				 *  See if the 4th point (Middle of the screen) coincides with the calibrated
				 *  result. If point is within +/- Squareroot(ERROR) pixel margin, then successful calibration
				 *  Else, start from the beginning.
				 */
		#if GINPUT_MOUSE_MAX_CALIBRATION_ERROR >= 0
				/* Transform the co-ordinates */
				MouseConfig.t.x = points[3].x;
				MouseConfig.t.y = points[3].y;
				_tsTransform(&MouseConfig.t, &MouseConfig.caldata);
				_tsOrientClip(&MouseConfig.t, MouseConfig.display, FALSE);

				/* Calculate the delta */
				err = (MouseConfig.t.x - cross[3].x) * (MouseConfig.t.x - cross[3].x) +
					(MouseConfig.t.y - cross[3].y) * (MouseConfig.t.y - cross[3].y);

				if (err <= GINPUT_MOUSE_MAX_CALIBRATION_ERROR * GINPUT_MOUSE_MAX_CALIBRATION_ERROR)
					break;

				gdispGFillStringBox(MouseConfig.display, 0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_ERROR_TEXT, font2,  Red, Yellow, justifyCenter);
				gfxSleepMilliseconds(5000);
			}
		#endif

		// Restart everything
		gdispCloseFont(font1);
		gdispCloseFont(font2);
		MouseConfig.flags |= FLG_CAL_OK;
		MouseConfig.last_buttons = 0;
		get_calibrated_reading(&MouseConfig.t);
		MouseConfig.flags &= ~FLG_IN_CAL;
		if ((MouseConfig.flags & FLG_INIT_DONE))
			gtimerStart(&MouseTimer, MousePoll, 0, TRUE, GINPUT_MOUSE_POLL_PERIOD);
		
		// Save the calibration data (if possible)
		if (MouseConfig.fnsavecal) {
			MouseConfig.fnsavecal(instance, (const uint8_t *)&MouseConfig.caldata, sizeof(MouseConfig.caldata));
			MouseConfig.flags |= FLG_CAL_SAVED;
		}

		// Clear the screen using the GWIN default background color
		#if GFX_USE_GWIN
			gdispGClear(MouseConfig.display, gwinGetDefaultBgColor());
		#else
			gdispGClear(MouseConfig.display, Black);
		#endif
	
		return TRUE;
	#endif
}
LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
	// The private area is the display surface.
	g->priv = gfxAlloc(GDISP_SCREEN_HEIGHT/8 * SSD1306_PAGE_WIDTH);

	// Fill in the prefix command byte on each page line of the display buffer
	// We can do it during initialisation as this byte is never overwritten.
	#ifdef SSD1306_PAGE_PREFIX
		{
			unsigned	i;

			for(i=0; i < GDISP_SCREEN_HEIGHT/8 * SSD1306_PAGE_WIDTH; i+=SSD1306_PAGE_WIDTH)
				RAM(g)[i] = SSD1306_PAGE_PREFIX;
		}
	#endif

	// Initialise the board interface
	init_board(g);

	// Hardware reset
	setpin_reset(g, TRUE);
	gfxSleepMilliseconds(20);
	setpin_reset(g, FALSE);
	gfxSleepMilliseconds(20);

	acquire_bus(g);

	write_cmd(g, SSD1306_DISPLAYOFF);
	write_cmd2(g, SSD1306_SETDISPLAYCLOCKDIV, 0x80);
	write_cmd2(g, SSD1306_SETMULTIPLEX, GDISP_SCREEN_HEIGHT-1);
	write_cmd2(g, SSD1306_SETPRECHARGE, 0x1F);
	write_cmd2(g, SSD1306_SETDISPLAYOFFSET, 0);
	write_cmd(g, SSD1306_SETSTARTLINE | 0);
	write_cmd2(g, SSD1306_ENABLE_CHARGE_PUMP, 0x14);
	write_cmd2(g, SSD1306_MEMORYMODE, 0);
	write_cmd(g, SSD1306_COLSCANDEC);
	write_cmd(g, SSD1306_ROWSCANDEC);
	#if GDISP_SCREEN_HEIGHT == 64
		write_cmd2(g, SSD1306_SETCOMPINS, 0x12);
	#else
		write_cmd2(g, SSD1306_SETCOMPINS, 0x22);
	#endif
	write_cmd2(g, SSD1306_SETCONTRAST, (uint8_t)(GDISP_INITIAL_CONTRAST*256/101));	// Set initial contrast.
	write_cmd2(g, SSD1306_SETVCOMDETECT, 0x10);
	write_cmd(g, SSD1306_DISPLAYON);
	write_cmd(g, SSD1306_NORMALDISPLAY);
	write_cmd3(g, SSD1306_HV_COLUMN_ADDRESS, 0, GDISP_SCREEN_WIDTH-1);
	write_cmd3(g, SSD1306_HV_PAGE_ADDRESS, 0, GDISP_SCREEN_HEIGHT/8-1);

    // Finish Init
    post_init_board(g);

 	// Release the bus
	release_bus(g);

	/* Initialise the GDISP structure */
	g->g.Width = GDISP_SCREEN_WIDTH;
	g->g.Height = GDISP_SCREEN_HEIGHT;
	g->g.Orientation = GDISP_ROTATE_0;
	g->g.Powermode = powerOn;
	g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
	g->g.Contrast = GDISP_INITIAL_CONTRAST;
	return TRUE;
}
LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
	// No private area for this controller
	g->priv = 0;

	// Initialise the board interface
	init_board(g);

	// Hardware reset
	setpin_reset(g, TRUE);
	gfxSleepMilliseconds(20);
	setpin_reset(g, FALSE);
	gfxSleepMilliseconds(20);

	// Get the bus for the following initialisation commands
	acquire_bus(g);

  write_cmd(g, SSD1327_MAST_CODE); //Master code
  write_data(g, 0x00);
  write_cmd(g, SSD1327_SET_SLEEP_ON);  // set display off

  write_cmd(g, SSD1327_SET_REMAP);
  write_data(g, 0x52); 
  write_cmd(g, SSD1327_SET_DISPLAY_START);
  write_data(g, 0x00);
  write_cmd(g, SSD1327_SET_DISPLAY_OFFSET);
  write_data(g, 0x20);
  write_cmd(g, SSD1327_SET_DISPLAY_MODE_RESET);

  write_cmd(g, SSD1327_SET_MUX_RATIO);
  write_data(g, 0x5F);
  write_cmd(g, SSD1327_SET_FUNCTION_SELECT);
  write_data(g, 0x01);
  write_cmd(g, SSD1327_SET_CONTRAST);
  write_data(g, 0x5F);
  write_cmd(g, SSD1327_USE_LINEAR_GREY);

  write_cmd(g, SSD1327_SET_PHASE_LENGTH);
  write_data(g, 0x31);
  write_cmd(g, SSD1327_CLOCKDIV_OSCFREQ);
  write_data(g, 0x41);
  write_cmd(g, SSD1327_DISPLAY_ENHANCEMENT);
  write_data(g, 0xB5);
  write_cmd(g, SSD1327_SET_SECOND_PRECHARGE);
  write_data(g, 0x04);
  write_cmd(g, SSD1327_SET_PRECHARGE_VOLTAGE);
  write_data(g, 0x05);
  write_cmd(g, SSD1327_SET_VCOMH);
  write_data(g, 0x07);
  write_cmd(g, SSD1327_SET_FUNCTION_SELECT_B);
  write_data(g, 0x02);

//i2c restart
  write_cmd(g, SSD1327_MAST_CODE); //Master code
  write_data(g, 0x00);
  write_cmd(g, SSD1327_SET_COLUMN_ADDRESS); //Master code
  write_data(g, 0x00); //COLUMN START
  write_data(g, 0x3F); //COLUMN END
  write_cmd(g, SSD1327_SET_ROW_ADDRESS); //Master code
  write_data(g, 0x00); //ROW START
  write_data(g, 0x7F); //ROW END

  write_cmd(g, SSD1327_MAST_CODE); //Master code
  write_data(g, 0x40);

	uint16_t i = 0;
	for (i = 0; i < 128*128; i++)
  {
    write_data(g, 0);
  }

	release_bus(g);

    // Finish Init
    post_init_board(g);

 	// Release the bus
//	release_bus(g);

	/* Turn on the back-light */
	set_backlight(g, GDISP_INITIAL_BACKLIGHT);

	/* Initialise the GDISP structure */
	g->g.Width = GDISP_SCREEN_WIDTH;
	g->g.Height = GDISP_SCREEN_HEIGHT;
	g->g.Orientation = GDISP_ROTATE_0;
	g->g.Powermode = powerOn;
	g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
	g->g.Contrast = GDISP_INITIAL_CONTRAST;
	return TRUE;
}
Example #11
0
LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
	// No private area for this controller
	g->priv = 0;

	// Initialise the board interface
	init_board(g);

	// Hardware reset
	setpin_reset(g, TRUE);
	gfxSleepMilliseconds(20);
	setpin_reset(g, FALSE);
	gfxSleepMilliseconds(20);

	// Get the bus for the following initialisation commands
	acquire_bus(g);

	// Soft reset
	write_reg8x2(g, 0x01, 0x01, 0x00);	gfxSleepMilliseconds(1);

	// PLL config
	write_reg8(g, 0x88, 0x08);			gfxSleepMilliseconds(1);
	write_reg8(g, 0x89, 0x02);			gfxSleepMilliseconds(1);

	write_reg8(g, 0x10, 0x0F);			//SYSR   bit[4:3]=00 256 color  bit[2:1]=  00 8bit MPU interface
										//		 0x0F = 16bit MCU interface and 65k color display

	write_reg8(g, 0x04, 0x82);			gfxSleepMilliseconds(1);	//set PCLK inverse

	// Horizontal set
	write_reg8(g, 0x14, GDISP_SCREEN_WIDTH/8-1);	//HDWR: Horizontal Display Width Setting Bit[6:0] - pixels = (HDWR + 1)*8
    write_reg8(g, 0x15, 0x00);						//Horizontal Non-Display Period Fine Tuning Option Register (HNDFTR) - HNDFT = [3:0]
    write_reg8(g, 0x16, 0x01);						//HNDR: Horizontal Non-Display Period Bit[4:0] - pixels = (HNDR + 1)*8
    write_reg8(g, 0x17, 0x00);						//HSTR: HSYNC Start Position[4:0] - Position(PCLK) = (HSTR + 1)*8
    write_reg8(g, 0x18, 0x05);						//HPWR: HSYNC Polarity, The period width of HSYNC. Width [4:0] width(PCLK) = (HPWR + 1)*8

    // Vertical set
    write_reg16(g, 0x19, GDISP_SCREEN_HEIGHT-1);	//VDHR0,1: Vertical Display Height = VDHR + 1
    write_reg16(g, 0x1b, 0x0002);					//VNDR0,1: Vertical Non-Display Period Bit = (VSTR + 1)
    write_reg16(g, 0x1d, 0x0007);					//VSTR0,1: VSYNC Start Position = (VSTR + 1)
    write_reg8(g, 0x1f, 0x09);						//VPWR: VSYNC Polarity, VSYNC Pulse Width[6:0] - Width(PCLK) = (VPWR + 1)

	// Active window  set
	write_reg16(g, 0x30, 0);						//HSAW0 & HSAW1
	write_reg16(g, 0x34, GDISP_SCREEN_WIDTH-1);		//HEAW0 & HEAW1
	write_reg16(g, 0x32, 0);						//VSAW0 & VSAW1
	write_reg16(g, 0x36, GDISP_SCREEN_HEIGHT-1);	//VEAW0 & VEAW1

	// Display ON
	write_reg8(g, 0x01, 0x80);						//PWRR

	// GPO0 DISP high
	write_reg8(g, 0x13, 0x01);						//GPO

	// Set initial back-light
	set_backlight(g, GDISP_INITIAL_BACKLIGHT);
	
	// Change timings for faster access
	post_init_board(g);

 	// Release the bus
	release_bus(g);

	/* Initialise the GDISP structure */
	g->g.Width = GDISP_SCREEN_WIDTH;
	g->g.Height = GDISP_SCREEN_HEIGHT;
	g->g.Orientation = GDISP_ROTATE_0;
	g->g.Powermode = powerOn;
	g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
	g->g.Contrast = GDISP_INITIAL_CONTRAST;
	return TRUE;
}
Example #12
0
/*------------------------------------------------------------------------*
 * GINPUT Touch Driver Calibrator.                                        *
 *------------------------------------------------------------------------*/
int main(void) {
	GSourceHandle			gs;
	GEventMouse				*pem;
	GMouse *				m;
	GMouseVMT *				vmt;

	gfxInit();		// Initialize the display

	// Get the display dimensions
	swidth = gdispGetWidth();
	sheight = gdispGetHeight();

	// Create our title
	font = gdispOpenFont("UI2");
	gwinSetDefaultFont(font);
	bHeight = gdispGetFontMetric(font, fontHeight)+4;
	gdispFillStringBox(0, 0, swidth, bHeight, "Raw Touch Readings", font, Red, White, justifyCenter);

	// Create our main display writing window
	{
		GWindowInit				wi;

		gwinClearInit(&wi);
		wi.show = TRUE; wi.x = 0; wi.y = bHeight; wi.width = swidth; wi.height = sheight-bHeight;
		ghc = gwinConsoleCreate(&gc, &wi);
	}

	// Initialize the listener
	geventListenerInit(&gl);

	// Copy the current mouse's VMT so we can play with it.
	m = (GMouse *)gdriverGetInstance(GDRIVER_TYPE_MOUSE, 0);
	if (!m) gfxHalt("No mouse instance 0");
	vmt = gfxAlloc(sizeof(GMouseVMT));
	if (!vmt) gfxHalt("Could not allocate memory for mouse VMT");
	memcpy(vmt, m->d.vmt, sizeof(GMouseVMT));

	// Swap VMT's on the current mouse to our RAM copy
	m->d.vmt = (const GDriverVMT *)vmt;

	// Listen for events
	gs = ginputGetMouse(0);
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);

	// Make sure we are in uncalibrated pen mode
	m->flags &= ~(GMOUSE_FLG_CALIBRATE|GMOUSE_FLG_CLIP|GMOUSE_FLG_FINGERMODE);

	// Pretend we are a mouse, turn off all touch processing, turn off move and click filtering
	vmt->d.flags &= ~(GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN);
	vmt->pen_jitter.move = 0;
	vmt->pen_jitter.click = 0;

	// For this test turn on ALL mouse movement events
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEUPMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER);

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		gwinPrintf(ghc, "%u, %u z=%u b=0x%04x\n", pem->x, pem->y, pem->z, pem->buttons & ~GINPUT_MISSED_MOUSE_EVENT);

		// Always sleep a bit first to enable other events. We actually don't mind missing events.
		gfxSleepMilliseconds(100);
	}
}
Example #13
0
LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
	LCD_Parameters *	lcdp;

	// The private area for this controller is the LCD timings
	lcdp = (void *)&DisplayTimings[g->controllerdisplay];
	g->priv = lcdp;

	// Initialise the board interface
	init_board(g);

	// Hardware reset
	setpin_reset(g, TRUE);
	gfxSleepMilliseconds(20);
	setpin_reset(g, FALSE);
	gfxSleepMilliseconds(20);

	// Get the bus for the following initialisation commands
	acquire_bus(g);
	
	write_index(g, SSD1963_SOFT_RESET);
	gfxSleepMilliseconds(5);

	/* Driver PLL config */
	write_index(g, SSD1963_SET_PLL_MN);
	write_data(g, 35);								// PLLclk = REFclk (10Mhz) * 36 (360Mhz)
	write_data(g, 2);								// SYSclk = PLLclk / 3  (120MHz)
	write_data(g, 4);								// Apply calculation bit, else it is ignored
	write_reg(g, SSD1963_SET_PLL, 0x01);			// Enable PLL
	gfxSleepMilliseconds(5);
	write_reg(g, SSD1963_SET_PLL, 0x03);			// Use PLL
	gfxSleepMilliseconds(5);
	write_index(g, SSD1963_SOFT_RESET);
	gfxSleepMilliseconds(5);

	/* Screen size */
	write_index(g, SSD1963_SET_GDISP_MODE);
	write_data(g, 0x18);							//Enabled dithering
	write_data(g, 0x00);
	write_data16(g, lcdp->width-1);
	write_data16(g, lcdp->height-1);
	write_data(g, 0x00);							// RGB

	write_reg(g, SSD1963_SET_PIXEL_DATA_INTERFACE, SSD1963_PDI_16BIT565);

	/* LCD Clock specs */
	write_index(g, SSD1963_SET_LSHIFT_FREQ);
	write_data(g, (lcdp->fpr >> 16) & 0xFF);
	write_data(g, (lcdp->fpr >> 8) & 0xFF);
	write_data(g, lcdp->fpr & 0xFF);

	write_index(g, SSD1963_SET_HORI_PERIOD);
	write_data16(g, lcdp->hperiod);
	write_data16(g, lcdp->hpulse + lcdp->hbporch);
	write_data(g, lcdp->hpulse);
	write_data(g, 0x00);
	write_data(g, 0x00);
	write_data(g, 0x00);

	write_index(g, SSD1963_SET_VERT_PERIOD);
	write_data16(g, lcdp->vperiod);
	write_data16(g, lcdp->vpulse + lcdp->vbporch);
	write_data(g, lcdp->vpulse);
	write_data(g, 0x00);
	write_data(g, 0x00);

	/* Tear effect indicator ON. This is used to tell the host MCU when the driver is not refreshing the panel (during front/back porch) */
	write_reg(g, SSD1963_SET_TEAR_ON, 0x00);

	/* Turn on */
	write_index(g, SSD1963_SET_DISPLAY_ON);
	
	/* Turn on the back-light */
	set_backlight(g, GDISP_INITIAL_BACKLIGHT);

	// Finish Init
	post_init_board(g);

	// Release the bus
	release_bus(g);

	/* Initialise the GDISP structure */
	g->g.Width = lcdp->width;
	g->g.Height = lcdp->height;
	g->g.Orientation = GDISP_ROTATE_0;
	g->g.Powermode = powerOn;
	g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
	g->g.Contrast = GDISP_INITIAL_CONTRAST;
	return TRUE;
}
Example #14
0
	LLDSPEC void gdisp_lld_control(GDisplay *g) {
		switch(g->p.x) {
		case GDISP_CONTROL_POWER:
			if (g->g.Powermode == (powermode_t)g->p.ptr)
				return;
			switch((powermode_t)g->p.ptr) {
				case powerOff:
					acquire_bus(g);
					write_index(g, SSD1963_EXIT_SLEEP_MODE); // leave sleep mode
					gfxSleepMilliseconds(5);
					write_index(g, SSD1963_SET_DISPLAY_OFF);
					write_index(g, SSD1963_SET_DEEP_SLEEP); // enter deep sleep mode
					release_bus(g);
					break;
				case powerOn:
					acquire_bus(g);
					read_reg(0x0000); gfxSleepMilliseconds(5); // 2x Dummy reads to wake up from deep sleep
					read_reg(0x0000); gfxSleepMilliseconds(5);
					write_index(g, SSD1963_SET_DISPLAY_ON);
					release_bus(g);
					break;
				case powerSleep:
					acquire_bus(g);
					write_index(g, SSD1963_SET_DISPLAY_OFF);
					write_index(g, SSD1963_ENTER_SLEEP_MODE); // enter sleep mode
					release_bus(g);
					break;
				default:
					return;
			}
			g->g.Powermode = (powermode_t)g->p.ptr;
			return;

		case GDISP_CONTROL_ORIENTATION:
			if (g->g.Orientation == (orientation_t)g->p.ptr)
				return;
			case GDISP_ROTATE_0:
				acquire_bus(g);
				/* 	Code here */
				release_bus(g);
				g->g.Height = ((LCD_Parameters *)g->priv)->height;
				g->g.Width = ((LCD_Parameters *)g->priv)->width;
				break;
			case GDISP_ROTATE_90:
				acquire_bus(g);
				/* 	Code here */
				release_bus(g);
				g->g.Height = ((LCD_Parameters *)g->priv)->width;
				g->g.Width = ((LCD_Parameters *)g->priv)->height;
				break;
			case GDISP_ROTATE_180:
				acquire_bus(g);
				/* 	Code here */
				release_bus(g);
				g->g.Height = ((LCD_Parameters *)g->priv)->height;
				g->g.Width = ((LCD_Parameters *)g->priv)->width;
				break;
			case GDISP_ROTATE_270:
				acquire_bus(g);
				/* 	Code here */
				release_bus(g);
				g->g.Height = ((LCD_Parameters *)g->priv)->width;
				g->g.Width = ((LCD_Parameters *)g->priv)->height;
				break;
			default:
				return;
			}
		g->g.Orientation = (orientation_t)g->p.ptr;
			return;

		case GDISP_CONTROL_BACKLIGHT:
			if ((unsigned)g->p.ptr > 100)
				g->p.ptr = (void *)100;
			set_backlight(g, (unsigned)g->p.ptr);
			g->g.Backlight = (unsigned)g->p.ptr;
			return;

		//case GDISP_CONTROL_CONTRAST:
		default:
			return;
		}
Example #15
0
File: main.c Project: bhdminh/uGFX
int main(void) {
	uint8_t i;
	font_t	font1, font2;

	/* initialize and clear the display */
	gfxInit();

	/* Set some fonts */
	font1 = gdispOpenFont("UI2");
	font2 = gdispOpenFont("DejaVu Sans 12");
	gwinSetDefaultFont(font1);

	/* create the three console windows */
	{
		GWindowInit		wi;

		gwinClearInit(&wi);
		wi.show = TRUE;
		wi.x = 0; wi.y = 0; wi.width = gdispGetWidth(); wi.height = gdispGetHeight()/2;
		GW1 = gwinConsoleCreate(0, &wi);
		wi.y = gdispGetHeight()/2; wi.width = gdispGetWidth()/2; wi.height = gdispGetHeight();
		GW2 = gwinConsoleCreate(0, &wi);
		wi.x = gdispGetWidth()/2; wi.height = gdispGetHeight();
		GW3 = gwinConsoleCreate(0, &wi);
	}

	/* Use a special font for GW1 */
	gwinSetFont(GW1, font2);

	/* Set the fore- and background colors for each console */
	gwinSetColor(GW1, Green);
	gwinSetBgColor(GW1, Black);
	gwinSetColor(GW2, White);
	gwinSetBgColor(GW2, Blue);
	gwinSetColor(GW3, Black);
	gwinSetBgColor(GW3, Red);

	/* clear all console windows - to set background */
	gwinClear(GW1);
	gwinClear(GW2);
	gwinClear(GW3);

	/* Output some data on the first console */
	for(i = 0; i < 10; i++) {
		gwinPrintf(GW1, "Hello \033buGFX\033B!\n");
	}

	/* Output some data on the second console - Fast */
	for(i = 0; i < 32; i++) {
		gwinPrintf(GW2, "Message Nr.: \0331\033b%d\033B\033C\n", i+1);
	}

	/* Output some data on the third console - Slowly */
	for(i = 0; i < 32; i++) {
		gwinPrintf(GW3, "Message Nr.: \033u%d\033U\n", i+1);
		gfxSleepMilliseconds(500);
	}

	/* Make console 3 invisible and then visible again to demonstrate the history buffer */
	gwinPrintf(GW2, "Making red window \033uinvisible\033U\n");
	gwinSetVisible(GW3, FALSE);
	gfxSleepMilliseconds(1000);
	gwinPrintf(GW2, "Making red window \033uvisible\033U\n");
	gwinSetVisible(GW3, TRUE);
	gwinPrintf(GW3, "\033bI'm back!!!\033B\n", i+1);

	while(TRUE) {
		gfxSleepMilliseconds(500);
	}
}
Example #16
0
LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
	XSizeHints				*pSH;
	XSetWindowAttributes	xa;
	XTextProperty			WindowTitle;
	char *					WindowTitleText;
	xPriv					*priv;

	if (!initdone) {
		gfxThreadHandle			hth;

		initdone = TRUE;
		#if GFX_USE_OS_LINUX || GFX_USE_OS_OSX
			XInitThreads();
		#endif

		dis = XOpenDisplay(0);
		scr = DefaultScreen(dis);
		cxt = XUniqueContext();
		wmDelete = XInternAtom(dis, "WM_DELETE_WINDOW", False);
		XSetIOErrorHandler(FatalXIOError);

		#if GDISP_FORCE_24BIT
			if (!XMatchVisualInfo(dis, scr, 24, TrueColor, &vis)) {
				fprintf(stderr, "Your display has no TrueColor mode\n");
				XCloseDisplay(dis);
				return FALSE;
			}
			cmap = XCreateColormap(dis, RootWindow(dis, scr),
					vis.visual, AllocNone);
		#else
			vis.visual = CopyFromParent;
			vis.depth = DefaultDepth(dis, scr);
			cmap = DefaultColormap(dis, scr);
		#endif
		fprintf(stderr, "Running GFX Window in %d bit color\n", vis.depth);

		if (!(hth = gfxThreadCreate(waXThread, sizeof(waXThread), HIGH_PRIORITY, ThreadX, 0))) {
			fprintf(stderr, "Cannot start X Thread\n");
			XCloseDisplay(dis);
			exit(0);
		}
		#if GFX_USE_OS_LINUX || GFX_USE_OS_OSX
			pthread_detach(hth);
		#endif
		gfxThreadClose(hth);
	}

	g->priv = gfxAlloc(sizeof(xPriv));
	priv = (xPriv *)g->priv;
	g->board = 0;					// No board interface for this driver

	xa.colormap = cmap;
	xa.border_pixel = 0xFFFFFF;
	xa.background_pixel = 0x000000;

	priv->win = XCreateWindow(dis, RootWindow(dis, scr), 16, 16,
			GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT,
			0, vis.depth, InputOutput, vis.visual,
			CWBackPixel|CWColormap|CWBorderPixel, &xa);
	XSync(dis, TRUE);

	XSaveContext(dis, priv->win, cxt, (XPointer)g);
	XSetWMProtocols(dis, priv->win, &wmDelete, 1);

	{
		char					buf[132];
		sprintf(buf, "uGFX - %u", g->systemdisplay+1);
		WindowTitleText = buf;
		XStringListToTextProperty(&WindowTitleText, 1, &WindowTitle);
		XSetWMName(dis, priv->win, &WindowTitle);
		XSetWMIconName(dis, priv->win, &WindowTitle);
		XSync(dis, TRUE);
	}

	pSH = XAllocSizeHints();
	pSH->flags = PSize | PMinSize | PMaxSize;
	pSH->min_width = pSH->max_width = pSH->base_width = GDISP_SCREEN_WIDTH;
	pSH->min_height = pSH->max_height = pSH->base_height = GDISP_SCREEN_HEIGHT;
	XSetWMNormalHints(dis, priv->win, pSH);
	XFree(pSH);
	XSync(dis, TRUE);

	priv->pix = XCreatePixmap(dis, priv->win,
				GDISP_SCREEN_WIDTH, GDISP_SCREEN_HEIGHT, vis.depth);
	XSync(dis, TRUE);

	priv->gc = XCreateGC(dis, priv->win, 0, 0);
	XSetBackground(dis, priv->gc, BlackPixel(dis, scr));
	XSync(dis, TRUE);

	// Create the associated mouse before the map
	#if GINPUT_NEED_MOUSE
		priv->mouse = (GMouse *)gdriverRegister((const GDriverVMT const *)GMOUSE_DRIVER_VMT, g);
	#endif

	XSelectInput(dis, priv->win, StructureNotifyMask);
	XMapWindow(dis, priv->win);

	// Wait for the window creation to complete (for safety)
	while(!(((volatile GDisplay *)g)->flags & GDISP_FLG_READY))
		gfxSleepMilliseconds(100);

	/* Initialise the GDISP structure to match */
    g->g.Orientation = GDISP_ROTATE_0;
    g->g.Powermode = powerOn;
    g->g.Backlight = 100;
    g->g.Contrast = 50;
    g->g.Width = GDISP_SCREEN_WIDTH;
    g->g.Height = GDISP_SCREEN_HEIGHT;

    return TRUE;
}
Example #17
0
File: main.c Project: DaviWei/uGFX
int main(void) {
	GEvent *			pe;

	// Initialize the display
	gfxInit();

	// Set the widget defaults
	gwinSetDefaultFont(gdispOpenFont("*"));
	gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE);
	gdispClear(White);

	// Connect the mouse
	#if GINPUT_NEED_MOUSE
		gwinAttachMouse(0);
	#endif

	// Create the gwin windows/widgets
	createWidgets();

    // Assign toggles and dials to specific buttons & sliders etc.
	#if GINPUT_NEED_TOGGLE
		gwinAttachToggle(ghButton1, 0, 0);
		gwinAttachToggle(ghButton2, 0, 1);
	#endif
	#if GINPUT_NEED_DIAL
		gwinAttachDial(ghSlider1, 0, 0);
		gwinAttachDial(ghSlider3, 0, 1);
	#endif

	// Make the console visible
	gwinSetVisible(ghConsole, TRUE);
	gwinClear(ghConsole);

    // We want to listen for widget events
	geventListenerInit(&gl);
	gwinAttachListener(&gl);

	// Press the Tab we want visible
	gwinRadioPress(ghTabButtons);

	while(1) {
		// Get an Event
		pe = geventEventWait(&gl, TIME_INFINITE);

		switch(pe->type) {
		case GEVENT_GWIN_BUTTON:
			gwinPrintf(ghConsole, "Button %s\n", gwinGetText(((GEventGWinButton *)pe)->button));
			break;

		case GEVENT_GWIN_SLIDER:
			gwinPrintf(ghConsole, "Slider %s=%d\n", gwinGetText(((GEventGWinSlider *)pe)->slider), ((GEventGWinSlider *)pe)->position);
			break;

		case GEVENT_GWIN_CHECKBOX:
			gwinPrintf(ghConsole, "Checkbox %s=%s\n", gwinGetText(((GEventGWinCheckbox *)pe)->checkbox), ((GEventGWinCheckbox *)pe)->isChecked ? "Checked" : "UnChecked");

			// If it is the Disable All checkbox then do that.
			if (((GEventGWinCheckbox *)pe)->checkbox == ghCheckDisableAll) {
				gwinPrintf(ghConsole, "%s All\n", ((GEventGWinCheckbox *)pe)->isChecked ? "Disable" : "Enable");
				setEnabled(!((GEventGWinCheckbox *)pe)->isChecked);
			}
			break;

		case GEVENT_GWIN_LIST:
			gwinPrintf(ghConsole, "List %s Item %d %s\n", gwinGetText(((GEventGWinList *)pe)->list), ((GEventGWinList *)pe)->item,
					gwinListItemIsSelected(((GEventGWinList *)pe)->list, ((GEventGWinList *)pe)->item) ? "Selected" : "Unselected");
			break;

		case GEVENT_GWIN_RADIO:
			gwinPrintf(ghConsole, "Radio Group %u=%s\n", ((GEventGWinRadio *)pe)->group, gwinGetText(((GEventGWinRadio *)pe)->radio));

			switch(((GEventGWinRadio *)pe)->group) {
			case GROUP_TABS:

				// Set control visibility depending on the tab selected
				setTab(((GEventGWinRadio *)pe)->radio);

				// Do some special animation for Label1 to demonstrate auto width sizing
				if (((GEventGWinRadio *)pe)->radio == ghTabLabels) {
					gwinPrintf(ghConsole, "Change Label Text\n");
					gfxSleepMilliseconds(1000);
					gwinSetText(ghLabel1, "Very Big Label", FALSE);

					gfxSleepMilliseconds(1000);
					gwinSetText(ghLabel1, "Label", FALSE);
				}
				break;

			case GROUP_COLORS:
				{
					const GWidgetStyle	*pstyle;

					gwinPrintf(ghConsole, "Change Color Scheme\n");

					if (((GEventGWinRadio *)pe)->radio == ghRadioYellow)
						pstyle = &YellowWidgetStyle;
					else if (((GEventGWinRadio *)pe)->radio == ghRadioBlack)
						pstyle = &BlackWidgetStyle;
					else
						pstyle = &WhiteWidgetStyle;

					// Clear the screen to the new color - we avoid the console area as it can't redraw itself
					#if GDISP_NEED_CLIP
						gdispUnsetClip();
					#endif
					gdispFillArea(0, 0, ScrWidth, ScrHeight/2, pstyle->background);
					gdispFillArea(0, ScrHeight/2, ScrWidth/2, ScrHeight/2, pstyle->background);

					// Update the style on all controls
					gwinSetDefaultStyle(pstyle, TRUE);
				}
				break;
			}
			break;

		default:
			gwinPrintf(ghConsole, "Unknown %d\n", pe->type);
			break;
		}
	}
	return 0;
}
Example #18
0
static DECLARE_THREAD_FUNCTION(NetThread, param) {
	SOCKET_TYPE			listenfd, fdmax, i, clientfd;
	socklen_t			len;
	int					leni;
	fd_set				master, read_fds;
    struct sockaddr_in	addr;
    GDisplay *			g;
    netPriv *			priv;
	(void)param;

	// Start the sockets layer
	StartSockets();
	gfxSleepMilliseconds(100);					// Make sure the thread has time to start.

	/* clear the master and temp sets */
	FD_ZERO(&master);
	FD_ZERO(&read_fds);

	if ((listenfd = socket(AF_INET, SOCK_STREAM, 0)) == (SOCKET_TYPE)-1)
		gfxHalt("GDISP: uGFXnet - Socket failed");

	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = htonl(INADDR_ANY);
	addr.sin_port = htons(GDISP_GFXNET_PORT);

	if (bind(listenfd, (struct sockaddr*)&addr, sizeof(addr)) == -1)
		gfxHalt("GDISP: uGFXnet - Bind failed");

    if (listen(listenfd, 10) == -1)
		gfxHalt("GDISP: uGFXnet - Listen failed");


    /* add the listener to the master set */
    FD_SET(listenfd, &master);

    /* keep track of the biggest file descriptor */
    fdmax = listenfd; /* so far, it's this one*/

	#if GDISP_GFXNET_BROKEN_LWIP_ACCEPT
    {
		#warning "Using GDISP_GFXNET_BROKEN_LWIP_ACCEPT limits the number of displays and the use of GFXNET. Avoid if possible!"
		len = sizeof(addr);
		if((clientfd = accept(listenfd, (struct sockaddr *)&addr, &len)) == (SOCKET_TYPE)-1)
			gfxHalt("GDISP: uGFXnet - Accept failed");

		// Look for a display that isn't connected
		for(g = 0; (g = (GDisplay *)gdriverGetNext(GDRIVER_TYPE_DISPLAY, (GDriver *)g));) {
            // Ignore displays for other controllers
            #ifdef GDISP_DRIVER_LIST
                if (gvmt(g) != &GDISPVMT_uGFXnet)
                    continue;
            #endif
			if (!(g->flags & GDISP_FLG_CONNECTED))
				break;
		}

		// Was anything found?
		if (!g) {
			// No Just close the connection
			closesocket(clientfd);
			gfxHalt("GDISP: uGFXnet - Can't find display for connection");
			return 0;
		}

		// Save the descriptor
		FD_SET(clientfd, &master);
		if (clientfd > fdmax) fdmax = clientfd;
		priv = g->priv;
		memset(priv, 0, sizeof(netPriv));
		priv->netfd = clientfd;
		//printf(New connection from %s on socket %d allocated to display %u\n", inet_ntoa(addr.sin_addr), clientfd, disp+1);

		// Send the initialisation data (2 words at a time)
		priv->data[0] = GNETCODE_INIT;
		priv->data[1] = GNETCODE_VERSION;
		sendpkt(priv->netfd, priv->data, 2);
		priv->data[0] = GDISP_SCREEN_WIDTH;
		priv->data[1] = GDISP_SCREEN_HEIGHT;
		sendpkt(priv->netfd, priv->data, 2);
		priv->data[0] = GDISP_LLD_PIXELFORMAT;
		priv->data[1] = (g->flags & GDISP_FLG_HASMOUSE) ? 1 : 0;
		MUTEX_ENTER;
		sendpkt(priv->netfd, priv->data, 2);
		MUTEX_EXIT;

		// The display is now working
		g->flags |= GDISP_FLG_CONNECTED;

		// Send a redraw all
		#if GFX_USE_GWIN && GWIN_NEED_WINDOWMANAGER
			gdispGClear(g, gwinGetDefaultBgColor());
			gwinRedrawDisplay(g, FALSE);
		#endif
    }
	#endif

    /* loop */
    for(;;) {
		/* copy it */
		read_fds = master;
		if (select(fdmax+1, &read_fds, 0, 0, 0) == -1)
			gfxHalt("GDISP: uGFXnet - Select failed");

		// Run through the existing connections looking for data to be read
		for(i = 0; i <= fdmax; i++) {
			if(!FD_ISSET(i, &read_fds))
				continue;

			// Handle new connections
			if(i == listenfd) {
				len = sizeof(addr);
				if((clientfd = accept(listenfd, (struct sockaddr *)&addr, &len)) == (SOCKET_TYPE)-1)
					gfxHalt("GDISP: uGFXnet - Accept failed");

                // Look for a display that isn't connected
                for(g = 0; (g = (GDisplay *)gdriverGetNext(GDRIVER_TYPE_DISPLAY, (GDriver *)g));) {
                    // Ignore displays for other controllers
                    #ifdef GDISP_DRIVER_LIST
                        if (gvmt(g) != &GDISPVMT_uGFXnet)
                            continue;
                    #endif
                    if (!(g->flags & GDISP_FLG_CONNECTED))
                        break;
                }

				// Was anything found?
				if (!g) {
					// No Just close the connection
					closesocket(clientfd);
					//printf(New connection from %s on socket %d rejected as all displays are already connected\n", inet_ntoa(addr.sin_addr), clientfd);
					continue;
				}

				// Save the descriptor
				FD_SET(clientfd, &master);
				if (clientfd > fdmax) fdmax = clientfd;
				priv = g->priv;
				memset(priv, 0, sizeof(netPriv));
				priv->netfd = clientfd;
				//printf(New connection from %s on socket %d allocated to display %u\n", inet_ntoa(addr.sin_addr), clientfd, disp+1);

				// Send the initialisation data (2 words at a time)
				priv->data[0] = GNETCODE_INIT;
				priv->data[1] = GNETCODE_VERSION;
				sendpkt(priv->netfd, priv->data, 2);
				priv->data[0] = GDISP_SCREEN_WIDTH;
				priv->data[1] = GDISP_SCREEN_HEIGHT;
				sendpkt(priv->netfd, priv->data, 2);
				priv->data[0] = GDISP_LLD_PIXELFORMAT;
				priv->data[1] = (g->flags & GDISP_FLG_HASMOUSE) ? 1 : 0;
				MUTEX_ENTER;
				sendpkt(priv->netfd, priv->data, 2);
				MUTEX_EXIT;

				// The display is now working
				g->flags |= GDISP_FLG_CONNECTED;

				// Send a redraw all
				#if GFX_USE_GWIN && GWIN_NEED_WINDOWMANAGER
					gdispGClear(g, gwinGetDefaultBgColor());
					gwinRedrawDisplay(g, FALSE);
				#endif

				continue;
			}

			// Handle data from a client

			// Look for a display that is connected and the socket descriptor matches
            for(g = 0; (g = (GDisplay *)gdriverGetNext(GDRIVER_TYPE_DISPLAY, (GDriver *)g));) {
                // Ignore displays for other controllers
                #ifdef GDISP_DRIVER_LIST
                    if (gvmt(g) != &GDISPVMT_uGFXnet)
                        continue;
                #endif
				priv = g->priv;
				if ((g->flags & GDISP_FLG_CONNECTED) && priv->netfd == i)
					break;
            }
			if (!g)
				gfxHalt("GDISP: uGFXnet - Got data from unrecognized connection");

			if ((g->flags & GDISP_FLG_HAVEDATA)) {
				// The higher level is still processing the previous data.
				//	Give it a chance to run by coming back to this data.
				gfxSleepMilliseconds(1);
				continue;
			}

			/* handle data from a client */
			MUTEX_ENTER;
			if ((leni = recv(i, ((char *)priv->data)+priv->databytes, sizeof(priv->data)-priv->databytes, 0)) <= 0) {
				// Socket closed or in error state
				MUTEX_EXIT;
				g->flags &= ~GDISP_FLG_CONNECTED;
				memset(priv, 0, sizeof(netPriv));
				closesocket(i);
				FD_CLR(i, &master);
				continue;
			}
			MUTEX_EXIT;

			// Do we have a full reply yet
			priv->databytes += leni;
			if (priv->databytes < sizeof(priv->data))
				continue;
			priv->databytes = 0;

			// Convert network byte or to host byte order
			priv->data[0] = ntohs(priv->data[0]);
			priv->data[1] = ntohs(priv->data[1]);

			// Process the data received
			switch(priv->data[0]) {
			#if GINPUT_NEED_MOUSE
				case GNETCODE_MOUSE_X:		priv->mousex = priv->data[1];		break;
				case GNETCODE_MOUSE_Y:		priv->mousey = priv->data[1];		break;
				case GNETCODE_MOUSE_B:
					priv->mousebuttons = priv->data[1];
					// Treat the button event as the sync signal
					#if GINPUT_MOUSE_POLL_PERIOD == TIME_INFINITE
						ginputMouseWakeup();
					#endif
					break;
			#endif
			case GNETCODE_CONTROL:
			case GNETCODE_READ:
				g->flags |= GDISP_FLG_HAVEDATA;
				break;
			case GNETCODE_KILL:
				gfxHalt("GDISP: uGFXnet - Display sent KILL command");
				break;

			default:
				// Just ignore unrecognised data
				break;
			}
		}
	}
    return 0;
}
Example #19
0
File: main.c Project: bhdminh/uGFX
/*------------------------------------------------------------------------*
 * GINPUT Touch Driver Calibrator.                                        *
 *------------------------------------------------------------------------*/
int main(void) {
	GSourceHandle			gs;
	GEventMouse				*pem;
	coord_t					swidth, sheight;
	GHandle					ghc;
	GEventType				deviceType;
	bool_t					calibrated;
	coord_t					bWidth, bHeight;

	gfxInit();		// Initialize the display

	// Get the display dimensions
	swidth = gdispGetWidth();
	sheight = gdispGetHeight();
	calibrated = FALSE;

	// Create our title
	font = gdispOpenFont("UI2");
	gwinSetDefaultFont(font);
	bWidth = gdispGetStringWidth("Next", font);
	bHeight = gdispGetStringWidth("Prev", font);
	if (bHeight > bWidth) bWidth = bHeight;
	bWidth += 4;
	bHeight = gdispGetFontMetric(font, fontHeight)+2;
	gdispFillStringBox(0, 0, swidth, bHeight, "Touch Calibration", font, Red, White, justifyLeft);

	// Create our main display window
	{
		GWindowInit				wi;

		gwinClearInit(&wi);
		wi.show = TRUE; wi.x = 0; wi.y = bHeight; wi.width = swidth; wi.height = sheight-bHeight;
		ghc = gwinConsoleCreate(&gc, &wi);
	}
	gwinClear(ghc);

	// Initialize the mouse in our special no calibration mode.
	geventListenerInit(&gl);
	gs = ginputGetMouse(9999);
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);

	/*
	 * Test: Device Type
	 */

StepDeviceType:
	gwinClear(ghc);
	gwinSetColor(ghc, Yellow);
	gwinPrintf(ghc, "\n1. DEVICE TYPE\n\n");

	pem = (GEventMouse *)&gl.event;
	ginputGetMouseStatus(0, pem);
	deviceType = pem->type;

	gwinSetColor(ghc, White);
	gwinPrintf(ghc, "This is detected as a %s device\n\n",
		deviceType == GEVENT_MOUSE ? "MOUSE" : (pem->type == GEVENT_TOUCH ? "TOUCH" : "UNKNOWN"));

	if (calibrated)
		gwinPrintf(ghc, "Press Next or Back to continue.\n");
	else if (deviceType == GEVENT_MOUSE)
		gwinPrintf(ghc, "Click the mouse button to move on to the next test.\n");
	else
		gwinPrintf(ghc, "Press and release your finger to move on to the next test.\n");

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (calibrated) {
			if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
				if ((pem->meta & GMETA_MOUSE_UP)) {
					if (pem->x >= swidth-bWidth)
						break;
					goto StepClickJitter;
				}
			}
		} else if ((pem->meta & GMETA_MOUSE_UP))
			break;
	}

	/*
	 * Test: Mouse raw reading jitter
	 */

StepRawJitter:
	gwinClear(ghc);
	gwinSetColor(ghc, Yellow);
	gwinPrintf(ghc, "\n2. GINPUT_MOUSE_READ_CYCLES\n\n");

	gwinSetColor(ghc, White);
	if (deviceType == GEVENT_MOUSE)
		gwinPrintf(ghc, "Press and hold the mouse button.\n\n");
	else
		gwinPrintf(ghc, "Press and hold on the surface.\n\n");
	gwinPrintf(ghc, "Numbers will display in this window.\n"
			"Ensure that values don't jump around very much when your finger is stationary.\n\n"
			"Increasing GINPUT_MOUSE_READ_CYCLES helps reduce jitter but increases CPU usage.\n\n");

	if (calibrated)
		gwinPrintf(ghc, "Press Next or Back to continue.\n");
	else if (deviceType == GEVENT_MOUSE)
		gwinPrintf(ghc, "Release the mouse button to move on to the next test.\n");
	else
		gwinPrintf(ghc, "Release your finger to move on to the next test.\n");

	// For this test turn on ALL mouse movement events
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEUPMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER);

	while(1) {
		// Always sleep a bit first to enable other events. We actually don't
		// mind missing events for this test.
		gfxSleepMilliseconds(100);
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (calibrated) {
			if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
				if ((pem->meta & GMETA_MOUSE_UP)) {
					if (pem->x >= swidth-bWidth)
						break;
					goto StepDeviceType;
				}
			}
		} else if ((pem->meta & GMETA_MOUSE_UP))
			break;
		gwinPrintf(ghc, "%u:%u z=%u b=0x%04x m=%04x\n", pem->x, pem->y, pem->z, pem->current_buttons, pem->meta);
	}

	// Reset to just changed movements.
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);

	/*
	 * Test: Calibration
	 */

StepCalibrate:
	gwinClear(ghc);
	gwinSetColor(ghc, Yellow);
	gwinPrintf(ghc, "\n3. GINPUT_MOUSE_CALIBRATION_ERROR\n\n");
	gwinSetColor(ghc, Gray);
	gwinPrintf(ghc, "Ensure GINPUT_MOUSE_NEED_CALIBRATION = TRUE and GINPUT_MOUSE_CALIBRATION_ERROR is >= 0\n\n");
	gwinSetColor(ghc, White);
	gwinPrintf(ghc, "You will be presented with a number of points to touch.\nPress them in turn.\n\n"
			"If the calibration repeatedly fails, increase GINPUT_MOUSE_CALIBRATION_ERROR and try again.\n\n");

	if (calibrated)
		gwinPrintf(ghc, "Press Next to start the calibration.\n");
	else if (deviceType == GEVENT_MOUSE)
		gwinPrintf(ghc, "Click the mouse button to start the calibration.\n");
	else
		gwinPrintf(ghc, "Press and release your finger to start the calibration.\n");

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (calibrated) {
			if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
				if ((pem->meta & GMETA_MOUSE_UP)) {
					if (pem->x >= swidth-bWidth)
						break;
					goto StepRawJitter;
				}
			}
		} else if ((pem->meta & GMETA_MOUSE_UP))
			break;
	}

	// Calibrate
	ginputCalibrateMouse(0);
	calibrated = TRUE;

	// Calibration used the whole screen - re-establish our title and Next and Previous Buttons
	gdispFillStringBox(0, 0, swidth, bHeight, "Touch Calibration", font, Green, White, justifyLeft);
	gdispFillStringBox(swidth-2*bWidth, 0, bWidth-1, bHeight, "Prev", font, Black, Gray, justifyCenter);
	gdispFillStringBox(swidth-1*bWidth, 0, bWidth  , bHeight, "Next", font, Black, Gray, justifyCenter);

	/*
	 * Test: Mouse coords
	 */

StepMouseCoords:
	gwinClear(ghc);
	gwinSetColor(ghc, Yellow);
	gwinPrintf(ghc, "\n4. Show Mouse Coordinates\n\n");

	gwinSetColor(ghc, White);
	if (deviceType == GEVENT_MOUSE)
		gwinPrintf(ghc, "Press and hold the mouse button.\n\n");
	else
		gwinPrintf(ghc, "Press and hold on the surface.\n\n");
	gwinPrintf(ghc, "Numbers will display in this window.\n"
			"Check the coordinates against where it should be on the screen.\n\n");

	gwinPrintf(ghc, "Press Next or Back to continue.\n");

	// For this test normal mouse movement events
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);

	while(1) {
		// Always sleep a bit first to enable other events. We actually don't
		// mind missing events for this test.
		gfxSleepMilliseconds(100);
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
			if ((pem->meta & GMETA_MOUSE_UP)) {
				if (pem->x >= swidth-bWidth)
					break;
				goto StepCalibrate;
			}
		}
		if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT))
			gwinPrintf(ghc, "%u:%u z=%u\n", pem->x, pem->y, pem->z);
	}

	// Reset to just changed movements.
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);

	/*
	 * Test: Mouse movement jitter
	 */

StepJitter:
	gwinClear(ghc);
	gwinSetColor(ghc, Yellow);
	gwinPrintf(ghc, "\n4. GINPUT_MOUSE_MOVE_JITTER\n\n");

	gwinSetColor(ghc, White);
	if (deviceType == GEVENT_MOUSE)
		gwinPrintf(ghc, "Press and hold the mouse button and move around as if to draw.\n\n");
	else
		gwinPrintf(ghc, "Press firmly on the surface and move around as if to draw.\n\n");

	gwinPrintf(ghc, "Dots will display in this window. Ensure that when you stop moving your finger that "
			"new dots stop displaying.\nNew dots should only display when your finger is moving.\n\n"
			"Adjust GINPUT_MOUSE_MOVE_JITTER to the smallest value that this reliably works for.\n\n");
	gwinPrintf(ghc, "Press Next or Back to continue.\n\n");

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
			if ((pem->meta & GMETA_MOUSE_UP)) {
				if (pem->x >= swidth-bWidth)
					break;
				goto StepMouseCoords;
			}
		}
		if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT))
			gwinPrintf(ghc, ".");
	}

	/*
	 * Test: Polling frequency
	 */

StepPolling:
	gwinClear(ghc);
	gwinSetColor(ghc, Yellow);
	gwinPrintf(ghc, "\n5. GINPUT_MOUSE_POLL_PERIOD\n\n");

	gwinSetColor(ghc, White);
	gwinPrintf(ghc, "Press firmly on the surface (or press and hold the mouse button) and move around as if to draw.\n\n");
	gwinPrintf(ghc, "A green line will follow your finger.\n"
			"Adjust GINPUT_MOUSE_POLL_PERIOD to the highest value that provides a line without "
			"gaps that are too big.\nDecreasing the value increases CPU usage.\n"
			"About 25 (millisecs) normally produces good results."
			"This test can be ignored for interrupt driven drivers.\n\n");
	gwinPrintf(ghc, "Press Next or Back to continue.\n\n");

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
			if ((pem->meta & GMETA_MOUSE_UP)) {
				if (pem->x >= swidth-bWidth)
					break;
				goto StepJitter;
			}
		}
		if ((pem->current_buttons & GINPUT_MOUSE_BTN_LEFT))
			gdispDrawPixel(pem->x, pem->y, Green);
	}
	
	/*
	 * Test: Click Jitter
	 */

StepClickJitter:
	gwinClear(ghc);
	gwinSetColor(ghc, Yellow);
	gwinPrintf(ghc, "\n6. GINPUT_MOUSE_MAX_CLICK_JITTER\n\n");

	gwinSetColor(ghc, White);
	gwinPrintf(ghc, "Press and release the touch surface to \"click\".\nTry both short and long presses.\n");
	gwinPrintf(ghc, "For a mouse click with the left and right buttons.\n\n");
	gwinPrintf(ghc, "Dots will display in this window. A yellow dash is a left (or short) click. "
			"A red x is a right (or long) click.\n\n"
			"Adjust GINPUT_MOUSE_CLICK_JITTER to the smallest value that this reliably works for.\n"
			"Adjust GINPUT_MOUSE_CLICK_TIME to adjust distinguishing short vs long presses.\n"
			"TIME_INFINITE means there are no long presses (although a right mouse button will still work).\n\n"
			"Note: moving your finger (mouse) during a click cancels it.\n\n");
	gwinPrintf(ghc, "This is the last test but you can press Next or Back to continue.\n\n");

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
			if ((pem->meta & GMETA_MOUSE_UP)) {
				if (pem->x >= swidth-bWidth)
					break;
				goto StepPolling;
			}
		}
		if ((pem->meta & GMETA_MOUSE_CLICK)) {
			gwinSetColor(ghc, Yellow);
			gwinPrintf(ghc, "-");
		}
		if ((pem->meta & GMETA_MOUSE_CXTCLICK)) {
			gwinSetColor(ghc, Red);
			gwinPrintf(ghc, "x");
		}
	}

	// Can't let this really exit
	goto StepDeviceType;
}
Example #20
0
LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
	// No private area for this controller
	g->priv = 0;

	// Initialise the board interface
	init_board(g);

	// Hardware reset
	setpin_reset(g, TRUE);
	gfxSleepMilliseconds(20);
	setpin_reset(g, FALSE);
	gfxSleepMilliseconds(20);

	// Get the bus for the following initialisation commands
	acquire_bus(g);
	
	write_reg(g, 0x00, 0x0001);		gfxSleepMicroseconds(5);
	write_reg(g, 0x03, 0xA8A4);    	gfxSleepMicroseconds(5);
	write_reg(g, 0x0C, 0x0000);    	gfxSleepMicroseconds(5);
	write_reg(g, 0x0D, 0x080C);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x0E, 0x2B00);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x1E, 0x00B0);    	gfxSleepMicroseconds(5);
	write_reg(g, 0x01, 0x2B3F);		gfxSleepMicroseconds(5);
    write_reg(g, 0x02, 0x0600);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x10, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x11, 0x6070);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x05, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x06, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x16, 0xEF1C);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x17, 0x0003);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x07, 0x0133);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x0B, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x0F, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x41, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x42, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x48, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x49, 0x013F);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x4A, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x4B, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x44, 0xEF00);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x45, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x46, 0x013F);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x30, 0x0707);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x31, 0x0204);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x32, 0x0204);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x33, 0x0502);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x34, 0x0507);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x35, 0x0204);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x36, 0x0204);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x37, 0x0502);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x3A, 0x0302);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x3B, 0x0302);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x23, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x24, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x25, 0x8000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x4f, 0x0000);		gfxSleepMicroseconds(5);
    write_reg(g, 0x4e, 0x0000);		gfxSleepMicroseconds(5);

    // Finish Init
    post_init_board(g);

 	// Release the bus
	release_bus(g);
	
	/* Turn on the back-light */
	set_backlight(g, GDISP_INITIAL_BACKLIGHT);

	/* Initialise the GDISP structure */
	g->g.Width = GDISP_SCREEN_WIDTH;
	g->g.Height = GDISP_SCREEN_HEIGHT;
	g->g.Orientation = GDISP_ROTATE_0;
	g->g.Powermode = powerOn;
	g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
	g->g.Contrast = GDISP_INITIAL_CONTRAST;
	return TRUE;
}
Example #21
0
	LLDSPEC void gdisp_lld_control(GDisplay *g) {
		netPriv	*	priv;
		uint16_t	buf[3];
		bool_t		allgood;

		#if GDISP_DONT_WAIT_FOR_NET_DISPLAY
			if (!(g->flags & GDISP_FLG_CONNECTED))
				return;
		#else
			while(!(g->flags & GDISP_FLG_CONNECTED))
				gfxSleepMilliseconds(200);
		#endif

		// Check if we might support the code
		switch(g->p.x) {
		case GDISP_CONTROL_ORIENTATION:
			if (g->g.Orientation == (orientation_t)g->p.ptr)
				return;
			break;
		case GDISP_CONTROL_POWER:
			if (g->g.Powermode == (powermode_t)g->p.ptr)
				return;
			break;
		case GDISP_CONTROL_BACKLIGHT:
			if (g->g.Backlight == (uint16_t)(int)g->p.ptr)
				return;
			if ((uint16_t)(int)g->p.ptr > 100)
				g->p.ptr = (void *)100;
			break;
		default:
			return;
		}

		// Send the command
		priv = g->priv;
		buf[0] = GNETCODE_CONTROL;
		buf[1] = g->p.x;
		buf[2] = (uint16_t)(int)g->p.ptr;
		MUTEX_ENTER;
		sendpkt(priv->netfd, buf, 3);
		MUTEX_EXIT;

		// Now wait for a reply
		while(!(g->flags & GDISP_FLG_HAVEDATA) || priv->data[0] != GNETCODE_CONTROL)
			gfxSleepMilliseconds(1);

		// Extract the return status
		allgood = priv->data[1] ? TRUE : FALSE;
		g->flags &= ~GDISP_FLG_HAVEDATA;

		// Do nothing more if the operation failed
		if (!allgood) return;

		// Update the local stuff
		switch(g->p.x) {
		case GDISP_CONTROL_ORIENTATION:
			switch((orientation_t)g->p.ptr) {
				case GDISP_ROTATE_0:
				case GDISP_ROTATE_180:
					g->g.Width = GDISP_SCREEN_WIDTH;
					g->g.Height = GDISP_SCREEN_HEIGHT;
					break;
				case GDISP_ROTATE_90:
				case GDISP_ROTATE_270:
					g->g.Height = GDISP_SCREEN_WIDTH;
					g->g.Width = GDISP_SCREEN_HEIGHT;
					break;
				default:
					return;
			}
			g->g.Orientation = (orientation_t)g->p.ptr;
			break;
		case GDISP_CONTROL_POWER:
			g->g.Powermode = (powermode_t)g->p.ptr;
			break;
		case GDISP_CONTROL_BACKLIGHT:
			g->g.Backlight = (uint16_t)(int)g->p.ptr;
			break;
		}
	}
Example #22
0
LLDSPEC bool_t gdisp_lld_init(GDisplay* g) {
	// no private area for this controller
	g->priv = 0;

	// initialise the board interface
	init_board(g);

	// Hardware reset
	setpin_reset(g, TRUE);
	gfxSleepMilliseconds(20);
	setpin_reset(g, FALSE);
	gfxSleepMilliseconds(20);

	// Get the bus for the following initialisation commands
	acquire_bus(g);

	// Enter sleep mode (if we are not already there).
	write_reg(g, SSD2119_REG_SLEEP_MODE_1, 0x0001);
	gfxSleepMicroseconds(5);

	// Set initial power parameters.
	write_reg(g, SSD2119_REG_PWR_CTRL_5, 0x00B2);
	gfxSleepMicroseconds(5);
	write_reg(g, SSD2119_REG_VCOM_OTP_1, 0x0006);
	gfxSleepMicroseconds(5);

	// Start the oscillator.
	write_reg(g, SSD2119_REG_OSC_START, 0x0001);
	gfxSleepMicroseconds(5);

	// Set pixel format and basic display orientation (scanning direction).
	write_reg(g, SSD2119_REG_OUTPUT_CTRL, 0x30EF);
	gfxSleepMicroseconds(5);
	write_reg(g, SSD2119_REG_LCD_DRIVE_AC_CTRL, 0x0600);
	gfxSleepMicroseconds(5);

	// Exit sleep mode.
	write_reg(g, SSD2119_REG_SLEEP_MODE_1, 0x0000);
	gfxSleepMicroseconds(5);

	// Configure pixel color format and MCU interface parameters.
	write_reg(g, SSD2119_REG_ENTRY_MODE, 0x6830); // ENTRY_MODE_DEFAULT
	gfxSleepMicroseconds(5);

	// Set analog parameters.
	write_reg(g, SSD2119_REG_SLEEP_MODE_2, 0x0999);
	gfxSleepMicroseconds(5);
	write_reg(g, SSD2119_REG_ANALOG_SET, 0x3800);
	gfxSleepMicroseconds(5);

	// Enable the display.
	write_reg(g, SSD2119_REG_DISPLAY_CTRL, 0x0033);
	gfxSleepMicroseconds(5);

	// Set VCIX2 voltage to 6.1V.
	write_reg(g, SSD2119_REG_PWR_CTRL_2, 0x0005);
	gfxSleepMicroseconds(5);

	// Configure gamma correction.
	write_reg(g, SSD2119_REG_GAMMA_CTRL_1, 0x0000);
	gfxSleepMicroseconds(5);
	write_reg(g, SSD2119_REG_GAMMA_CTRL_2, 0x0303);
	gfxSleepMicroseconds(5);
	write_reg(g, SSD2119_REG_GAMMA_CTRL_3, 0x0407);
	gfxSleepMicroseconds(5);
	write_reg(g, SSD2119_REG_GAMMA_CTRL_4, 0x0301);
	gfxSleepMicroseconds(5);
	write_reg(g, SSD2119_REG_GAMMA_CTRL_5, 0x0301);
	gfxSleepMicroseconds(5);
	write_reg(g, SSD2119_REG_GAMMA_CTRL_6, 0x0403);
	gfxSleepMicroseconds(5);
	write_reg(g, SSD2119_REG_GAMMA_CTRL_7, 0x0707);
	gfxSleepMicroseconds(5);
	write_reg(g, SSD2119_REG_GAMMA_CTRL_8, 0x0400);
	gfxSleepMicroseconds(5);
	write_reg(g, SSD2119_REG_GAMMA_CTRL_9, 0x0a00);
	gfxSleepMicroseconds(5);
	write_reg(g, SSD2119_REG_GAMMA_CTRL_10, 0x1000);
	gfxSleepMicroseconds(5);

	// Configure Vlcd63 and VCOMl.
	write_reg(g, SSD2119_REG_PWR_CTRL_3, 0x000A);
	gfxSleepMicroseconds(5);
	write_reg(g, SSD2119_REG_PWR_CTRL_4, 0x2E00);
	gfxSleepMicroseconds(5);

	// Set the display size and ensure that the GRAM window is set to allow access to the full display buffer.
	write_reg(g, SSD2119_REG_V_RAM_POS, (GDISP_SCREEN_HEIGHT - 1) << 8);
	gfxSleepMicroseconds(5);
	write_reg(g, SSD2119_REG_H_RAM_START, 0x0000);
	gfxSleepMicroseconds(5);
	write_reg(g, SSD2119_REG_H_RAM_END, GDISP_SCREEN_WIDTH - 1);
	gfxSleepMicroseconds(5);

	write_reg(g, SSD2119_REG_X_RAM_ADDR, 0x00);
	gfxSleepMicroseconds(5);
	write_reg(g, SSD2119_REG_Y_RAM_ADDR, 0x00);
	gfxSleepMicroseconds(5);

    // Finish Init
    post_init_board(g);

 	// Release the bus
	release_bus(g);

	/* Turn on the back-light */
	set_backlight(g, GDISP_INITIAL_BACKLIGHT);

	/* Initialise the GDISP structure */
	g->g.Width = GDISP_SCREEN_WIDTH;
	g->g.Height = GDISP_SCREEN_HEIGHT;
	g->g.Orientation = GDISP_ROTATE_0;
	g->g.Powermode = powerOn;
	g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
	g->g.Contrast = GDISP_INITIAL_CONTRAST;
	return TRUE;
}
Example #23
0
LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
	// No private area for this controller
	g->priv = 0;

	// Initialise the board interface
	init_board(g);

	// Hardware reset
	setpin_reset(g, TRUE);
	gfxSleepMilliseconds(20);
	setpin_reset(g, FALSE);
	gfxSleepMilliseconds(20);

	// Get the bus for the following initialisation commands
	acquire_bus(g);

	write_index(g, 0x01); //software reset
	chThdSleepMilliseconds(5);
	write_index(g, 0x28);
	// display off
	//---------------------------------------------------------
	// magic?
	write_index(g, 0xcf);
	write_data(g, 0x00);
	write_data(g, 0x83);
	write_data(g, 0x30);

	write_index(g, 0xed);
	write_data(g, 0x64);
	write_data(g, 0x03);
	write_data(g, 0x12);
	write_data(g, 0x81);
	write_index(g, 0xe8);
	write_data(g, 0x85);
	write_data(g, 0x01);
	write_data(g, 0x79);
	write_index(g, 0xcb);
	write_data(g, 0x39);
	write_data(g, 0x2c);
	write_data(g, 0x00);
	write_data(g, 0x34);
	write_data(g, 0x02);
	write_index(g, 0xf7);
	write_data(g, 0x20);
	write_index(g, 0xea);
	write_data(g, 0x00);
	write_data(g, 0x00);
	//------------power control------------------------------
	write_index(g, 0xc0); //power control
	write_data(g, 0x26);
	write_index(g, 0xc1); //power control
	write_data(g, 0x11);
	//--------------VCOM
	write_index(g, 0xc5); //vcom control
	write_data(g, 0x35);//35
	write_data(g, 0x3e);//3E
	write_index(g, 0xc7); //vcom control
	write_data(g, 0xbe); // 0x94
	//------------memory access control------------------------
	write_index(g, 0x36);
	// memory access control
	write_data(g, 0x48); //0048 my,mx,mv,ml,BGR,mh,0.0
	write_index(g, 0x3a); // pixel format set
	write_data(g, 0x55);//16bit /pixel
	//----------------- frame rate------------------------------
	write_index(g, 0xb1);
	// frame rate
	write_data(g, 0x00);
	write_data(g, 0x1B); //70
	//----------------Gamma---------------------------------
	write_index(g, 0xf2); // 3Gamma Function Disable
	write_data(g, 0x08);
	write_index(g, 0x26);
	write_data(g, 0x01); // gamma set 4 gamma curve 01/02/04/08

	write_index(g, 0xE0); //positive gamma correction
	write_data(g, 0x1f);
	write_data(g, 0x1a);
	write_data(g, 0x18);
	write_data(g, 0x0a);
	write_data(g, 0x0f);
	write_data(g, 0x06);
	write_data(g, 0x45);
	write_data(g, 0x87);
	write_data(g, 0x32);
	write_data(g, 0x0a);
	write_data(g, 0x07);
	write_data(g, 0x02);
	write_data(g, 0x07);
	write_data(g, 0x05);
	write_data(g, 0x00);
	write_index(g, 0xE1); //negamma correction
	write_data(g, 0x00);
	write_data(g, 0x25);
	write_data(g, 0x27);
	write_data(g, 0x05);
	write_data(g, 0x10);
	write_data(g, 0x09);
	write_data(g, 0x3a);
	write_data(g, 0x78);
	write_data(g, 0x4d);
	write_data(g, 0x05);
	write_data(g, 0x18);
	write_data(g, 0x0d);
	write_data(g, 0x38);
	write_data(g, 0x3a);
	write_data(g, 0x1f);
	//--------------ddram ---------------------
	write_index(g, 0x2a);
	// column set
	// size = 239
	write_data(g, 0x00);
	write_data(g, 0x00);
	write_data(g, 0x00);
	write_data(g, 0xEF);
	write_index(g, 0x2b);
	// page address set
	// size = 319
	write_data(g, 0x00);
	write_data(g, 0x00);
	write_data(g, 0x01);
	write_data(g, 0x3F);
	// write_index(g, 0x34);
	//write_index(g, 0x35);
	// tearing effect off
	// tearing effect on
	// write_index(g, 0xb4); // display inversion
	// write_data(g, 0x00);
	write_index(g, 0xb7); //entry mode set
	write_data(g, 0x07);
	//-----------------display---------------------
	write_index(g, 0xb6);
	// display function control
	write_data(g, 0x0a);
	write_data(g, 0x82);
	write_data(g, 0x27);
	write_data(g, 0x00);
	write_index(g, 0x11); //sleep out
	chThdSleepMilliseconds(100);
	write_index(g, 0x29); // display on
	chThdSleepMilliseconds(100);

    // Finish Init
    post_init_board(g);

 	// Release the bus
	release_bus(g);
	
	/* Turn on the back-light */
	set_backlight(g, GDISP_INITIAL_BACKLIGHT);

	/* Initialise the GDISP structure */
	g->g.Width = GDISP_SCREEN_WIDTH;
	g->g.Height = GDISP_SCREEN_HEIGHT;
	g->g.Orientation = GDISP_ROTATE_0;
	g->g.Powermode = powerOn;
	g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
	g->g.Contrast = GDISP_INITIAL_CONTRAST;
	return TRUE;
}
Example #24
0
void I_WaitVBL(int count)
{
    gfxSleepMilliseconds(1000/TICRATE);
}
Example #25
0
/*------------------------------------------------------------------------*
 * GINPUT Touch Driver Calibrator.                                        *
 *------------------------------------------------------------------------*/
int main(void) {
	GSourceHandle			gs;
	GEventMouse				*pem;
	bool_t					isFirstTime;
	bool_t					isCalibrated;
	bool_t					isTouch;
	bool_t					isFinger;
	const char *			isFingerText;
	const char *			deviceText;
	GMouse *				m;
	GMouseVMT *				vmt;
	GMouseJitter *			pjit;
	uint32_t				calerr;

	gfxInit();		// Initialize the display

	// Get the display dimensions
	swidth = gdispGetWidth();
	sheight = gdispGetHeight();

	// Create our title
	font = gdispOpenFont("UI2");
	gwinSetDefaultFont(font);
	bWidth = gdispGetStringWidth("Next", font);
	bHeight = gdispGetStringWidth("Prev", font);
	if (bHeight > bWidth) bWidth = bHeight;
	bWidth += 4;
	bWidth2 = gdispGetStringWidth("+", font)*2;
	bHeight = gdispGetStringWidth("-", font)*2;
	if (bHeight > bWidth2) bWidth2 = bHeight;
	bWidth2 += 4;
	bHeight = gdispGetFontMetric(font, fontHeight)*2+2;

	// Create our main display window
	{
		GWindowInit				wi;

		gwinClearInit(&wi);
		wi.show = TRUE; wi.x = 0; wi.y = bHeight; wi.width = swidth; wi.height = sheight-bHeight;
		ghc = gwinConsoleCreate(&gc, &wi);
	}

	// Initialize the listener
	geventListenerInit(&gl);

	// Copy the current mouse's VMT so we can play with it.
	m = (GMouse *)gdriverGetInstance(GDRIVER_TYPE_MOUSE, 0);
	if (!m) gfxHalt("No mouse instance 0");
	vmt = gfxAlloc(sizeof(GMouseVMT));
	if (!vmt) gfxHalt("Could not allocate memory for mouse VMT");
	memcpy(vmt, m->d.vmt, sizeof(GMouseVMT));

	// Swap VMT's on the current mouse to our RAM copy
	m->d.vmt = (const GDriverVMT *)vmt;

	// Listen for events
	gs = ginputGetMouse(0);
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);

	// Get initial display settings for buttons
	isFirstTime = TRUE;
	isCalibrated = (vmt->d.flags & GMOUSE_VFLG_CALIBRATE) ? FALSE : TRUE;
	calerr = 0;

	/*
	 * Test: Device Type
	 */

StepDeviceType:
	DrawHeader("1. Device Type", isCalibrated, isCalibrated && !isFirstTime, isCalibrated);

	// Get the type of device and the current mode
	isTouch = (vmt->d.flags & GMOUSE_VFLG_TOUCH) ? TRUE : FALSE;
	isFinger = (m->flags & GMOUSE_FLG_FINGERMODE) ? TRUE : FALSE;
	pjit = isFinger ? &vmt->finger_jitter : &vmt->pen_jitter;
	isFingerText = isFinger ? "finger" : "pen";
	deviceText = isTouch ? isFingerText : "mouse";

	gwinPrintf(ghc, "This is detected as a %s device\n\n", isTouch ? "TOUCH" : "MOUSE");
	gwinPrintf(ghc, "It is currently in %s mode\n\n", isFinger ? "FINGER" : "PEN");

	if (!isCalibrated)
		gwinPrintf(ghc, "Press and release your %s to move on to the next test.\n", deviceText);
	else {
		gwinPrintf(ghc, "Press + for pen or - for finger.\n");
		if (isFirstTime)
			gwinPrintf(ghc, "Press Next to continue.\n");
		else
			gwinPrintf(ghc, "Press Next or Back to continue.\n");
	}

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (isCalibrated) {
			switch (CheckButtons(pem)) {
			case BTN_NEXT:
				break;
			case BTN_PREV:
				if (!isFirstTime)
					goto StepDrawing;
				continue;
			case BTN_PLUS:
				m->flags &= ~GMOUSE_FLG_FINGERMODE;
				goto StepDeviceType;
			case BTN_MINUS:
				m->flags |= GMOUSE_FLG_FINGERMODE;
				goto StepDeviceType;
			default:
				continue;
			}
			break;
		}
		if ((pem->buttons & GMETA_MOUSE_UP))
			break;
	}

	/*
	 * Test: Mouse raw reading
	 */

StepRawReading:
	DrawHeader("2. Raw Mouse Output", FALSE, FALSE, FALSE);
	if (isTouch)
		gwinPrintf(ghc, "Press and hold on the surface.\n\n");
	else
		gwinPrintf(ghc, "Press and hold the mouse button.\n\n");
	gwinPrintf(ghc, "The raw values coming from your mouse driver will display.\n\n");
	gwinPrintf(ghc, "Make sure the x and y values change as you move.\n\n");

	gwinPrintf(ghc, "Release your %s to move on to the next test.\n", deviceText);

	// Make sure we are in uncalibrated mode
	m->flags &= ~(GMOUSE_FLG_CALIBRATE|GMOUSE_FLG_CLIP);

	// For this test turn on ALL mouse movement events
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEUPMOVES|GLISTEN_MOUSEMETA|GLISTEN_MOUSENOFILTER);

	while(1) {
		// Always sleep a bit first to enable other events. We actually don't
		// mind missing events for this test.
		gfxSleepMilliseconds(100);
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		gwinPrintf(ghc, "%u, %u z=%u b=0x%04x\n", pem->x, pem->y, pem->z, pem->buttons & ~GINPUT_MISSED_MOUSE_EVENT);
		if ((pem->buttons & GMETA_MOUSE_UP))
			break;
	}

	// Reset to calibrated condition
	if (isCalibrated) {
		m->flags |= GMOUSE_FLG_CLIP;
		if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE))
			m->flags |= GMOUSE_FLG_CALIBRATE;
	}

	// Reset to just changed movements.
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);

	/*
	 * Test: Calibration
	 */

StepCalibrate:
	DrawHeader("3. Calibration Jitter", isCalibrated, isCalibrated, isCalibrated);
	if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE)) {
		gwinPrintf(ghc, "You will be presented with a number of points to touch.\nPress them in turn.\n\n"
				"If the calibration repeatedly fails, increase the jitter for %s calibration and try again.\n\n", isFingerText);
		gwinPrintf(ghc, "Pressing the surface for longer gives more accurate results.\n\n");
		if (calerr)
			gwinPrintf(ghc, "Last calibration error ^ 2 = %u\n", calerr);
		gwinPrintf(ghc, "Calibration jitter (%s) = %u\n", isFingerText, pjit->calibrate);
		if (isCalibrated)
			gwinPrintf(ghc, "Press + or - to adjust.\n");
	} else {
		gwinPrintf(ghc, "This device does not need calibration.\n\n");
	}
	if (isCalibrated)
		gwinPrintf(ghc, "Press Next or Back to continue.\n");
	else
		gwinPrintf(ghc, "Press and release your %s to move on to start calibration.\n", deviceText);

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (isCalibrated) {
			switch (CheckButtons(pem)) {
			case BTN_NEXT:
				break;
			case BTN_PREV:
				goto StepRawReading;
			case BTN_PLUS:
				gwinPrintf(ghc, "Calibration jitter (%s) = %u", isFingerText, ++pjit->calibrate);
				continue;
			case BTN_MINUS:
				gwinPrintf(ghc, "Calibration jitter (%s) = %u", isFingerText, --pjit->calibrate);
				continue;
			default:
				continue;
			}
			break;
		}
		if ((pem->buttons & GMETA_MOUSE_UP))
			break;
	}

	// Calibrate
	if ((vmt->d.flags & GMOUSE_VFLG_CALIBRATE)) {
		calerr = ginputCalibrateMouse(0);
		if (calerr)
			goto StepCalibrate;
		isCalibrated = TRUE;
	}

	/*
	 * Test: Mouse coords
	 */

StepMouseCoords:
	DrawHeader("4. Show Mouse Coordinates", TRUE, TRUE, TRUE);
	if (isTouch)
		gwinPrintf(ghc, "Press and hold on the surface.\n\n");
	else
		gwinPrintf(ghc, "Press and hold the mouse button.\n\n");
	gwinPrintf(ghc, "Check the coordinates against where it should be on the screen.\n\n");
	gwinPrintf(ghc, "X should be 0 to %u\nY should be 0 to %u\n\n", swidth-1, sheight-1);
	gwinPrintf(ghc, "Press + to retry using extremes or - for normal calibration.\n");
	gwinPrintf(ghc, "Press Next or Back to continue.\n");

	// For this test normal mouse movement events
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);

	while(1) {
		// Always sleep a bit first to enable other events. We actually don't
		// mind missing events for this test.
		gfxSleepMilliseconds(100);
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);

		switch (CheckButtons(pem)) {
		case BTN_NEXT:
			break;
		case BTN_PREV:
			goto StepCalibrate;
		case BTN_PLUS:
			vmt->d.flags |= GMOUSE_VFLG_CAL_EXTREMES;
			goto StepCalibrate;
		case BTN_MINUS:
			vmt->d.flags &= ~GMOUSE_VFLG_CAL_EXTREMES;
			goto StepCalibrate;
		default:
			gwinPrintf(ghc, "%u, %u\n", pem->x, pem->y);
			continue;
		}
		break;
	}

	// Reset to just changed movements.
	geventAttachSource(&gl, gs, GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA);

	/*
	 * Test: Mouse movement jitter
	 */

StepMovementJitter:
	DrawHeader("5. Movement Jitter", TRUE, TRUE, TRUE);
	if (isTouch)
		gwinPrintf(ghc, "Press firmly on the surface and move around as if to draw.\n\n");
	else
		gwinPrintf(ghc, "Press and hold the mouse button and move around as if to draw.\n\n");

	gwinPrintf(ghc, "Dots will display in this window. Ensure that when you stop moving your %s that "
			"new dots stop displaying.\nNew dots should only display when your %s is moving.\n\n"
			"Adjust %s movement jitter to the smallest value that this reliably works for.\n\n", deviceText, deviceText, isFingerText);
	gwinPrintf(ghc, "Movement jitter (%s) = %u\n", isFingerText, pjit->move);
	gwinPrintf(ghc, "Press + or - to adjust.\n");
	gwinPrintf(ghc, "Press Next or Back to continue.\n\n");

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		switch (CheckButtons(pem)) {
		case BTN_NEXT:
			break;
		case BTN_PREV:
			goto StepMouseCoords;
		case BTN_PLUS:
			gwinPrintf(ghc, "Movement jitter (%s) = %u", isFingerText, ++pjit->move);
			continue;
		case BTN_MINUS:
			gwinPrintf(ghc, "Movement jitter (%s) = %u", isFingerText, --pjit->move);
			continue;
		default:
			if ((pem->buttons & GINPUT_MOUSE_BTN_LEFT))
				gwinPrintf(ghc, ".");
			continue;
		}
		break;
	}

	/*
	 * Test: Click Jitter
	 */

StepClickJitter:
	gwinClear(ghc);
	gwinSetColor(ghc, Yellow);
	gwinPrintf(ghc, "\n6. Click Jitter\n\n");

	gwinSetColor(ghc, White);
	if (isTouch)
		gwinPrintf(ghc, "Press and release the touch surface to \"click\".\nTry both short and long presses.\n");
	else
		gwinPrintf(ghc, "Click the mouse with the left and right buttons.\n\n");
	gwinPrintf(ghc, "A yellow dash is a left (or short) click.\n"
			"A red x is a right (or long) click.\n\n"
			"Adjust %s click jitter to the smallest value that this reliably works for.\n"
			"Note: moving your %s during a click cancels it.\n\n", isFingerText, deviceText);
	gwinPrintf(ghc, "Click jitter (%s) = %u\n", isFingerText, pjit->click);
	gwinPrintf(ghc, "Press + or - to adjust.\n");
	gwinPrintf(ghc, "Press Next or Back to continue.\n\n");

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		switch (CheckButtons(pem)) {
		case BTN_NEXT:
			break;
		case BTN_PREV:
			goto StepMovementJitter;
		case BTN_PLUS:
			gwinPrintf(ghc, "Click jitter (%s) = %u", isFingerText, ++pjit->click);
			continue;
		case BTN_MINUS:
			gwinPrintf(ghc, "Click jitter (%s) = %u", isFingerText, --pjit->click);
			continue;
		default:
			if ((pem->buttons & GMETA_MOUSE_CLICK)) {
				gwinSetColor(ghc, Yellow);
				gwinPrintf(ghc, "-");
			}
			if ((pem->buttons & GMETA_MOUSE_CXTCLICK)) {
				gwinSetColor(ghc, uRed);
				gwinPrintf(ghc, "x");
			}
			continue;
		}
		break;
	}

	/*
	 * Test: Polling frequency
	 */

StepDrawing:
	gwinClear(ghc);
	gwinSetColor(ghc, Yellow);
	gwinPrintf(ghc, "\n7. Drawing\n\n");

	gwinSetColor(ghc, White);
	gwinPrintf(ghc, "Press firmly on the surface (or press and hold the mouse button) and move around as if to draw.\n\n");
	gwinPrintf(ghc, "A green line will follow your %s.\n\n", deviceText);
	gwinPrintf(ghc, "Pressing Next will start the tests again but with the option of changing pen/finger mode.\n\n");
	gwinPrintf(ghc, "Press Next or Back to continue.\n\n");

	while(1) {
		pem = (GEventMouse *)geventEventWait(&gl, TIME_INFINITE);
		if (pem->y < bHeight && pem->x >= swidth-2*bWidth) {
			if ((pem->buttons & GMETA_MOUSE_UP)) {
				if (pem->x >= swidth-bWidth)
					break;
				goto StepClickJitter;
			}
		}
		gdispDrawPixel(pem->x, pem->y, uGreen);
	}

	// Can't let this really exit
	isFirstTime = FALSE;
	goto StepDeviceType;
}
Example #26
0
LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {

   unsigned short DeviceCode;

   // No private area for this controller
   g->priv = 0;

   // Initialise the board interface
   init_board(g);

   /* Hardware reset */
   setpin_reset(g, TRUE);
   gfxSleepMilliseconds(1);
   setpin_reset(g, FALSE);
   gfxSleepMilliseconds(10);
   setpin_reset(g, TRUE);
   gfxSleepMilliseconds(50);

   acquire_bus(g);
   setreadmode(g);
   DeviceCode = read_reg(g, 0x00);
   setwritemode(g);

   if( DeviceCode == 0x9320 || DeviceCode == 0x9300 )
   {
      write_reg(g, 0x00, 0x0000);
      write_reg(g, 0x01, 0x0100); /* Driver Output Contral */
      write_reg(g, 0x02, 0x0700); /* LCD Driver Waveform Contral */
      write_reg(g, 0x03, 0x1038); /* Set the scan mode */
      write_reg(g, 0x04, 0x0000); /* Scalling Contral */
      write_reg(g, 0x08, 0x0202); /* Display Contral 2 */
      write_reg(g, 0x09, 0x0000); /* Display Contral 3 */
      write_reg(g, 0x0a, 0x0000); /* Frame Cycle Contal */
      write_reg(g, 0x0c, (1<<0)); /* Extern Display Interface Contral 1 */
      write_reg(g, 0x0d, 0x0000); /* Frame Maker Position */
      write_reg(g, 0x0f, 0x0000); /* Extern Display Interface Contral 2 */
      gfxSleepMilliseconds(50);
      write_reg(g, 0x07, 0x0101); /* Display Contral */
      gfxSleepMilliseconds(50);
      write_reg(g, 0x10, (1<<12)|(0<<8)|(1<<7)|(1<<6)|(0<<4)); /* Power Control 1 */
      write_reg(g, 0x11, 0x0007);                              /* Power Control 2 */
      write_reg(g, 0x12, (1<<8)|(1<<4)|(0<<0));                /* Power Control 3 */
      write_reg(g, 0x13, 0x0b00);                              /* Power Control 4 */
      write_reg(g, 0x29, 0x0000);                              /* Power Control 7 */
      write_reg(g, 0x2b, (1<<14)|(1<<4));
      write_reg(g, 0x50, 0);       /* Set X Start */
      write_reg(g, 0x51, 239);     /* Set X End */
      write_reg(g, 0x52, 0);       /* Set Y Start */
      write_reg(g, 0x53, 319);     /* Set Y End */
      gfxSleepMilliseconds(50);

      write_reg(g, 0x60, 0x2700); /* Driver Output Control */
      write_reg(g, 0x61, 0x0001); /* Driver Output Control */
      write_reg(g, 0x6a, 0x0000); /* Vertical Srcoll Control */

      write_reg(g, 0x80, 0x0000); /* Display Position? Partial Display 1 */
      write_reg(g, 0x81, 0x0000); /* RAM Address Start? Partial Display 1 */
      write_reg(g, 0x82, 0x0000); /* RAM Address End-Partial Display 1 */
      write_reg(g, 0x83, 0x0000); /* Displsy Position? Partial Display 2 */
      write_reg(g, 0x84, 0x0000); /* RAM Address Start? Partial Display 2 */
      write_reg(g, 0x85, 0x0000); /* RAM Address End? Partial Display 2 */

      write_reg(g, 0x90, (0<<7)|(16<<0)); /* Frame Cycle Contral */
      write_reg(g, 0x92, 0x0000);         /* Panel Interface Contral 2 */
      write_reg(g, 0x93, 0x0001);         /* Panel Interface Contral 3 */
      write_reg(g, 0x95, 0x0110);         /* Frame Cycle Contral */
      write_reg(g, 0x97, (0<<8));
      write_reg(g, 0x98, 0x0000);         /* Frame Cycle Contral */
      write_reg(g, 0x07, 0x0133);
   } 
   else if( DeviceCode == 0x9325 || DeviceCode == 0x9328)
   {

      write_reg(g, 0x00e7, 0x0010);
      write_reg(g, 0x0000, 0x0001);    /* start internal osc */
      write_reg(g, 0x0001, 0x0100);
      write_reg(g, 0x0002, 0x0700);    /* power on sequence */
      write_reg(g, 0x0003, (1<<12)|(1<<5)|(1<<4)|(0<<3) );     /* importance */
      write_reg(g, 0x0004, 0x0000);
      write_reg(g, 0x0008, 0x0207);
      write_reg(g, 0x0009, 0x0000);
      write_reg(g, 0x000a, 0x0000);    /* display setting */
      write_reg(g, 0x000c, 0x0001);    /* display setting */
      write_reg(g, 0x000d, 0x0000);
      write_reg(g, 0x000f, 0x0000);
      /* Power On sequence */
      write_reg(g, 0x0010, 0x0000);
      write_reg(g, 0x0011, 0x0007);
      write_reg(g, 0x0012, 0x0000);
      write_reg(g, 0x0013, 0x0000);
      gfxSleepMilliseconds(50);  /* delay 50 ms */
      write_reg(g, 0x0010, 0x1590);
      write_reg(g, 0x0011, 0x0227);
      gfxSleepMilliseconds(50);  /* delay 50 ms */
      write_reg(g, 0x0012, 0x009c);
      gfxSleepMilliseconds(50);  /* delay 50 ms */
      write_reg(g, 0x0013, 0x1900);
      write_reg(g, 0x0029, 0x0023);
      write_reg(g, 0x002b, 0x000e);
      gfxSleepMilliseconds(50);  /* delay 50 ms */
      write_reg(g, 0x0020, 0x0000);
      write_reg(g, 0x0021, 0x0000);
      gfxSleepMilliseconds(50);  /* delay 50 ms */
      write_reg(g, 0x0030, 0x0007);
      write_reg(g, 0x0031, 0x0707);
      write_reg(g, 0x0032, 0x0006);
      write_reg(g, 0x0035, 0x0704);
      write_reg(g, 0x0036, 0x1f04);
      write_reg(g, 0x0037, 0x0004);
      write_reg(g, 0x0038, 0x0000);
      write_reg(g, 0x0039, 0x0706);
      write_reg(g, 0x003c, 0x0701);
      write_reg(g, 0x003d, 0x000f);
      gfxSleepMilliseconds(50);  /* delay 50 ms */
      write_reg(g, 0x0050, 0x0000);
      write_reg(g, 0x0051, 0x00ef);
      write_reg(g, 0x0052, 0x0000);
      write_reg(g, 0x0053, 0x013f);
      write_reg(g, 0x0060, 0xa700);
      write_reg(g, 0x0061, 0x0001);
      write_reg(g, 0x006a, 0x0000);
      write_reg(g, 0x0080, 0x0000);
      write_reg(g, 0x0081, 0x0000);
      write_reg(g, 0x0082, 0x0000);
      write_reg(g, 0x0083, 0x0000);
      write_reg(g, 0x0084, 0x0000);
      write_reg(g, 0x0085, 0x0000);

      write_reg(g, 0x0090, 0x0010);
      write_reg(g, 0x0092, 0x0000);
      write_reg(g, 0x0093, 0x0003);
      write_reg(g, 0x0095, 0x0110);
      write_reg(g, 0x0097, 0x0000);
      write_reg(g, 0x0098, 0x0000);
      /* display on sequence */
      write_reg(g, 0x0007, 0x0133);

      write_reg(g, 0x0020, 0x0000);
      write_reg(g, 0x0021, 0x0000);
   }

   gfxSleepMilliseconds(100);   /* delay 50 ms */


   // Finish Init
   post_init_board(g);

   // Release the bus
   release_bus(g);

   // Turn on the backlight
   set_backlight(g, GDISP_INITIAL_BACKLIGHT);

   /* Initialise the GDISP structure */
   g->g.Width = GDISP_SCREEN_WIDTH;
   g->g.Height = GDISP_SCREEN_HEIGHT;
   g->g.Orientation = GDISP_ROTATE_0;
   g->g.Powermode = powerOn;
   g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
   g->g.Contrast = GDISP_INITIAL_CONTRAST;

   return TRUE;
}
	static uint32_t CalibrateMouse(GMouse *m) {
		coord_t		w, h;
		point		cross[4];		// The locations of the test points on the display
		point		points[4];		// The x, y readings obtained from the mouse for each test point
		uint32_t	err;
		#if GDISP_NEED_TEXT
			font_t		font1, font2;
		#endif

		#if GDISP_NEED_TEXT
			font1 = gdispOpenFont(CALIBRATION_FONT);
			if (!font1) font1 = gdispOpenFont("*");
			font2 = gdispOpenFont(CALIBRATION_FONT2);
			if (!font2) font2 = gdispOpenFont("*");
		#endif
		err = 0;
		w  =  gdispGGetWidth(m->display);
		h  =  gdispGGetHeight(m->display);
		#if GDISP_NEED_CLIP
			gdispGSetClip(m->display, 0, 0, w, h);
		#endif

		// Ensure we get minimaly processed readings for the calibration
		m->flags |= GMOUSE_FLG_IN_CAL;

		// Set up our calibration locations
        if ((gmvmt(m)->d.flags & GMOUSE_VFLG_CAL_EXTREMES)) {
            cross[0].x = 0;		cross[0].y = 0;
            cross[1].x = w-1;	cross[1].y = 0;
            cross[2].x = w-1;	cross[2].y = h-1;
            cross[3].x = w/2;	cross[3].y = h/2;
        } else {
            cross[0].x = w/4;	cross[0].y = h/4;
            cross[1].x = w-w/4;	cross[1].y = h/4;
            cross[2].x = w-w/4;	cross[2].y = h-h/4;
            cross[3].x = w/2;	cross[3].y = h/2;
        }

		// Set up the calibration display
		gdispGClear(m->display, Blue);
		#if GDISP_NEED_TEXT
			gdispGFillStringBox(m->display,
								0, CALIBRATION_TITLE_Y, w, CALIBRATION_TITLE_HEIGHT,
								CALIBRATION_TITLE, font1,  CALIBRATION_TITLE_COLOR, CALIBRATION_TITLE_BACKGROUND,
								justifyCenter);
		#endif

		// Calculate the calibration
		{
			unsigned	i, maxpoints;

			maxpoints = (gmvmt(m)->d.flags & GMOUSE_VFLG_CAL_TEST) ? 4 : 3;

			// Loop through the calibration points
			for(i = 0; i < maxpoints; i++) {
				int32_t		px, py;
				unsigned	j;

				// Draw the current calibration point
				CalibrationCrossDraw(m, &cross[i]);

				// Get a valid "point pressed" average reading
				do {
					// Wait for the mouse to be pressed
					while(!(m->r.buttons & GINPUT_MOUSE_BTN_LEFT))
						gfxSleepMilliseconds(CALIBRATION_POLL_PERIOD);

					// Sum samples taken every CALIBRATION_POLL_PERIOD milliseconds while the mouse is down
					px = py = j = 0;
					while((m->r.buttons & GINPUT_MOUSE_BTN_LEFT)) {
						// Limit sampling period to prevent overflow
						if (j < CALIBRATION_MAXPRESS_PERIOD/CALIBRATION_POLL_PERIOD) {
							px += m->r.x;
							py += m->r.y;
							j++;
						}
						gfxSleepMilliseconds(CALIBRATION_POLL_PERIOD);
					}

					// Ignore presses less than CALIBRATION_MAXPRESS_PERIOD milliseconds
				} while(j < CALIBRATION_MINPRESS_PERIOD/CALIBRATION_POLL_PERIOD);
				points[i].x = px / j;
				points[i].y = py / j;

				// Clear the current calibration point
				CalibrationCrossClear(m, &cross[i]);
			}
		}

		// Apply 3 point calibration algorithm
		CalibrationCalculate(m, cross, points);

		 /* Verification of correctness of calibration (optional) :
		 *  See if the 4th point (Middle of the screen) coincides with the calibrated
		 *  result. If point is within +/- Squareroot(ERROR) pixel margin, then successful calibration
		 *  Else return the error.
		 */
		if ((gmvmt(m)->d.flags & GMOUSE_VFLG_CAL_TEST)) {
			const GMouseJitter	*pj;

			// Are we in pen or finger mode
			pj = (m->flags & GMOUSE_FLG_FINGERMODE) ? &gmvmt(m)->finger_jitter : &gmvmt(m)->pen_jitter;

			// Transform the co-ordinates
			CalibrationTransform((GMouseReading *)&points[3], &m->caldata);

			// Do we need to rotate the reading to match the display
			#if GDISP_NEED_CONTROL
				if (!(gmvmt(m)->d.flags & GMOUSE_VFLG_SELFROTATION)) {
					coord_t		t;

					switch(gdispGGetOrientation(m->display)) {
						case GDISP_ROTATE_0:
							break;
						case GDISP_ROTATE_90:
							t = points[3].x;
							points[3].x = w - 1 - points[3].y;
							points[3].y = t;
							break;
						case GDISP_ROTATE_180:
							points[3].x = w - 1 - points[3].x;
							points[3].y = h - 1 - points[3].y;
							break;
						case GDISP_ROTATE_270:
							t = points[3].y;
							points[3].y = h - 1 - points[3].x;
							points[3].x = t;
							break;
						default:
							break;
					}
				}
			#endif

			// Is this accurate enough?
			err = (points[3].x - cross[3].x) * (points[3].x - cross[3].x) + (points[3].y - cross[3].y) * (points[3].y - cross[3].y);
			if (err > (uint32_t)pj->calibrate * (uint32_t)pj->calibrate) {
				#if GDISP_NEED_TEXT
					// No - Display error and return
					gdispGFillStringBox(m->display,
											0, CALIBRATION_ERROR_Y, w, CALIBRATION_ERROR_HEIGHT,
											CALIBRATION_ERROR_TEXT, font2,  CALIBRATION_ERROR_COLOR, CALIBRATION_ERROR_BACKGROUND,
											justifyCenter);
					gfxSleepMilliseconds(CALIBRATION_ERROR_DELAY);
				#endif
			} else
				err = 0;
		}

		// We are done calibrating
		#if GDISP_NEED_TEXT
			gdispCloseFont(font1);
			gdispCloseFont(font2);
		#endif
		m->flags &= ~GMOUSE_FLG_IN_CAL;
		m->flags |= GMOUSE_FLG_CLIP;

		// Save the calibration data (if possible)
		if (!err) {
			m->flags |= GMOUSE_FLG_CALIBRATE;

			#if GINPUT_TOUCH_USER_CALIBRATION_SAVE
				SaveMouseCalibration(gdriverGetDriverInstanceNumber((GDriver *)m), &m->caldata, sizeof(GMouseCalibration));
			#endif
			if (gmvmt(m)->calsave)
				gmvmt(m)->calsave(m, &m->caldata, sizeof(GMouseCalibration));
		}

		// Force an initial reading
		m->r.buttons = 0;
		GetMouseReading(m);

		// Clear the screen using the GWIN default background color
		#if GFX_USE_GWIN
			gdispGClear(m->display, gwinGetDefaultBgColor());
		#else
			gdispGClear(m->display, GDISP_STARTUP_COLOR);
		#endif

		return err;
	}
Example #28
0
	LLDSPEC void gdisp_lld_control(GDisplay *g) {
		switch(g->p.x) {
		case GDISP_CONTROL_POWER:
			if (g->g.Powermode == (powermode_t)g->p.ptr)
				return;
			switch((powermode_t)g->p.ptr) {
			case powerOff:
				acquire_bus(g);
				write_reg(g, 0x07, 0x0000);
				write_reg(g, 0x10, 0x0000);
				write_reg(g, 0x11, 0x0000);
				write_reg(g, 0x12, 0x0000);
				write_reg(g, 0x13, 0x0000);
				release_bus(g);
				set_backlight(g, 0);
				break;

			case powerOn:
				//*************Power On sequence ******************//
				acquire_bus(g);
				write_reg(g, 0x10, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
				write_reg(g, 0x11, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
				write_reg(g, 0x12, 0x0000); /* VREG1OUT voltage */
				write_reg(g, 0x13, 0x0000); /* VDV[4:0] for VCOM amplitude */
				gfxSleepMilliseconds(200);            /* Dis-charge capacitor power voltage */
				write_reg(g, 0x10, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
				write_reg(g, 0x11, 0x0147); /* DC1[2:0], DC0[2:0], VC[2:0] */
				gfxSleepMilliseconds(50);
				write_reg(g, 0x12, 0x013C); /* VREG1OUT voltage */
				gfxSleepMilliseconds(50);
				write_reg(g, 0x13, 0x0E00); /* VDV[4:0] for VCOM amplitude */
				write_reg(g, 0x29, 0x0009); /* VCM[4:0] for VCOMH */
				gfxSleepMilliseconds(50);
				write_reg(g, 0x07, 0x0173); /* 262K color and display ON */
				release_bus(g);
				set_backlight(g, g->g.Backlight);
				break;

			case powerSleep:
				acquire_bus(g);
				write_reg(g, 0x07, 0x0000); /* display OFF */
				write_reg(g, 0x10, 0x0000); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
				write_reg(g, 0x11, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
				write_reg(g, 0x12, 0x0000); /* VREG1OUT voltage */
				write_reg(g, 0x13, 0x0000); /* VDV[4:0] for VCOM amplitude */
				gfxSleepMilliseconds(200); /* Dis-charge capacitor power voltage */
				write_reg(g, 0x10, 0x0002); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
				release_bus(g);
				set_backlight(g, g->g.Backlight);
				break;

			case powerDeepSleep:
				acquire_bus(g);
				write_reg(g, 0x07, 0x0000); /* display OFF */
				write_reg(g, 0x10, 0x0000); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
				write_reg(g, 0x11, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
				write_reg(g, 0x12, 0x0000); /* VREG1OUT voltage */
				write_reg(g, 0x13, 0x0000); /* VDV[4:0] for VCOM amplitude */
				gfxSleepMilliseconds(200); /* Dis-charge capacitor power voltage */
				write_reg(g, 0x10, 0x0004); /* SAP, BT[3:0], APE, AP, DSTB, SLP */
				release_bus(g);
				set_backlight(g, g->g.Backlight);
				break;

			default:
				return;
			}
			g->g.Powermode = (powermode_t)g->p.ptr;
			return;
			
		case GDISP_CONTROL_ORIENTATION:
			if (g->g.Orientation == (orientation_t)g->p.ptr)
				return;
			switch((orientation_t)g->p.ptr) {
				case GDISP_ROTATE_0:
					acquire_bus(g);
					write_reg(g, 0x01, 0x0100);
					write_reg(g, 0x03, 0x1030);
					write_reg(g, 0x60, 0xa700);
					release_bus(g);
					g->g.Height = GDISP_SCREEN_HEIGHT;
					g->g.Width = GDISP_SCREEN_WIDTH;
					break;

				case GDISP_ROTATE_90:
					acquire_bus(g);
					write_reg(g, 0x01, 0x0100);
					write_reg(g, 0x03, 0x1038);
					write_reg(g, 0x60, 0x2700);
					release_bus(g);
					g->g.Height = GDISP_SCREEN_WIDTH;
					g->g.Width = GDISP_SCREEN_HEIGHT;
					break;

				case GDISP_ROTATE_180:
					acquire_bus(g);
					write_reg(g, 0x01, 0x0000);
					write_reg(g, 0x03, 0x1030);
					write_reg(g, 0x60, 0x2700);
					release_bus(g);
					g->g.Height = GDISP_SCREEN_HEIGHT;
					g->g.Width = GDISP_SCREEN_WIDTH;
					break;
	
				case GDISP_ROTATE_270:
					acquire_bus(g);
					write_reg(g, 0x01, 0x0000);
					write_reg(g, 0x03, 0x1038);
					write_reg(g, 0x60, 0xa700);
					release_bus(g);
					g->g.Height = GDISP_SCREEN_WIDTH;
					g->g.Width = GDISP_SCREEN_HEIGHT;
					break;

				default:
					return;
			}

			g->g.Orientation = (orientation_t)g->p.ptr;
			return;
			
        case GDISP_CONTROL_BACKLIGHT:
            if ((unsigned)g->p.ptr > 100)
            	g->p.ptr = (void *)100;
            set_backlight(g, (unsigned)g->p.ptr);
            g->g.Backlight = (unsigned)g->p.ptr;
            return;
		
	default:
	    return;
		}
	}
Example #29
0
bool_t tdisp_lld_init(void) { 
	/* initialise hardware */
	init_board();
	
	/* The first part is the initialing code.
	 * In this part only the lower nibble of the
	 * byte is written directly to the display, thus
	 * without write_cmd, which sends both high and
	 * low nibble.
	 */
	
	/* Give the LCD a little time to wake up */
	gfxSleepMilliseconds(15);
	
	/* clear the RS-line to the display */
	palClearPad(PORT_CTRL, PIN_RS);
// 	#if BUS_4BITS
		/* write three times 0x03 to display (4-bit mode only)
		* with RS = low.
		*/
		writeToLCD(0x03); // 1x
		gfxSleepMilliseconds(20);
		writeToLCD(0x03); // 2x
// 		gfxSleepMilliseconds(20);
		writeToLCD(0x03); // 3x
// 		gfxSleepMilliseconds(20);
		/* Put display in 4-bit mode by
		* write 0x02 to display.
		*/
		writeToLCD(0x02); // 4bit-modus
// 		gfxSleepMilliseconds(20);
// 	#else
		/* write three times 0x30 to display (8-bit mode only)
		* with RS = low.
		*/
// 		writeToLCD(0x30); // 1x
// 		writeToLCD(0x30); // 2x
// 		writeToLCD(0x30); // 3x
// 	#endif	

	/* From this point on, the LCD accepts
	 * bytes sent with highnibbel first and than
	 *the lownibble if working in 4-bit mode.
	 * In 8-bit mode bytes are written in 1 action.
	 */
	
	/* 4-bit modus, 2 lines en 5x7 characters */
	write_cmd(0x28);
// 	gfxSleepMilliseconds(20);
	
	/* set display on, cursor off and no blinking */
	write_cmd(0x0C);
// 	gfxSleepMilliseconds(20);
	/* set cursor increase and direction */
	write_cmd(0x06);
// 	gfxSleepMilliseconds(20);
	
	displaycontrol = TDISP_DISPLAY_ON;
	cursorcontrol = TDISP_CURSOR_INC;
	/* END OF INITIALISATION */

	return TRUE;
}
Example #30
0
LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
	uint16_t i = 0, f = 0;
	// No private area for this controller
	g->priv = 0;

	// Initialise the board interface
	init_board(g);

	// Hardware reset
	setpin_reset(g, TRUE);
	gfxSleepMilliseconds(120);
	setpin_reset(g, FALSE);
	gfxSleepMilliseconds(120);

	// Get the bus for the following initialisation commands
	acquire_bus(g);

	write_reg(g, 0x01, 0x0100);		gfxSleepMicroseconds(5);
	write_reg(g, 0x02, 0x0700);    	gfxSleepMicroseconds(5);
	write_reg(g, 0x03, 0x1030);    	gfxSleepMicroseconds(5);
	write_reg(g, 0x04, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x08, 0x0302);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x09, 0x0000);    	gfxSleepMicroseconds(5);
	write_reg(g, 0x0A, 0x0008);		gfxSleepMicroseconds(5);
    write_reg(g, 0x0C, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x0D, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x0F, 0x6070);    	gfxSleepMicroseconds(5);

	gfxSleepMilliseconds(100);

  	//*******POWER CONTROL REGISTER INITIAL*******//
    write_reg(g, 0x10, 0x0790);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x11, 0x0005);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x12, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x13, 0x0000);    	gfxSleepMicroseconds(5);

	gfxSleepMilliseconds(50);

  	//********POWER SUPPPLY STARTUP 1 SETTING*******//
    write_reg(g, 0x10, 0x12B0);    	gfxSleepMicroseconds(5);
	gfxSleepMilliseconds(50);
    write_reg(g, 0x11, 0x0007);    	gfxSleepMicroseconds(5);
	gfxSleepMilliseconds(50);

  	//********POWER SUPPLY STARTUP 2 SETTING******//
    write_reg(g, 0x12, 0x008C);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x13, 0x1700);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x29, 0x0022);    	gfxSleepMicroseconds(5);

	gfxSleepMilliseconds(50);

  	//******GAMMA CLUSTER SETTING******//
    write_reg(g, 0x30, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x31, 0x0505);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x32, 0x0205);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x35, 0x0206);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x36, 0x0408);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x37, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x38, 0x0504);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x39, 0x0206);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x3C, 0x0206);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x3D, 0x0408);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x20, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x21, 0x0000);    	gfxSleepMicroseconds(5);

  	// -----------DISPLAY WINDOWS 240*320-------------//
    write_reg(g, 0x50, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x51, 0x00EF);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x52, 0x0000);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x53, 0x013F);    	gfxSleepMicroseconds(5); 	//RTNI setting

	gfxSleepMilliseconds(50);

  	//-----FRAME RATE SETTING-------//
    write_reg(g, 0x60, 0xA700);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x61, 0x0001);    	gfxSleepMicroseconds(5);
    write_reg(g, 0x90, 0x0033);    	gfxSleepMicroseconds(5);

  	//-------DISPLAY ON------//
    write_reg(g, 0x07, 0x0133);    	gfxSleepMicroseconds(5);

	gfxSleepMilliseconds(50);

	// -------EXIT STANDBY----//
    write_reg(g, 0x10, 0x14E0);    	gfxSleepMicroseconds(5);
	gfxSleepMilliseconds(100);
    write_reg(g, 0x07, 0x0133);    	gfxSleepMicroseconds(5);

    //  ------Start Write Data To RAM-----//
    write_index(g, 0x0022);
    //paint screen black
    for(i=0;i<2;i++)
    {
    	for(f=0;f<38400;f++)
    	{
    		write_data(g, 0xFFFF);
    	}
    }

    // Finish Init
    post_init_board(g);

 	// Release the bus
	release_bus(g);
	
	/* Turn on the back-light */
	set_backlight(g, GDISP_INITIAL_BACKLIGHT);

	/* Initialise the GDISP structure */
	g->g.Width = GDISP_SCREEN_WIDTH;
	g->g.Height = GDISP_SCREEN_HEIGHT;
	g->g.Orientation = GDISP_ROTATE_0;
	g->g.Powermode = powerOn;
	g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
	g->g.Contrast = GDISP_INITIAL_CONTRAST;
	return TRUE;
}