So, here it is with calibrated touch interface:
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using GHIElectronics.NETMF.Hardware;
namespace MFW_EMX_Newhaven
{
public class Program : Microsoft.SPOT.Application
{
// Text Control
private static Text text;
public static void Main()
{
Program myApplication = new Program();
// SET LCD Calibration (Newhaven NHD-4.3-480272EF-ATXL#-T)
SetLCDConfigurations();
// Set touch calibration data. (Newhaven NHD-4.3-480272EF-ATXL#-T)
Touch.Initialize(myApplication);
const int CAL_POINTS = 5;
short[] sx = new short[CAL_POINTS] { 240, 30, 30, 390, 390 };
short[] sy = new short[CAL_POINTS] { 136, 18, 239, 239, 18 };
short[] cx = new short[CAL_POINTS] { 478, 189, 169, 781, 790 };
short[] cy = new short[CAL_POINTS] { 481, 238, 741, 767, 231 };
Microsoft.SPOT.Touch.Touch.ActiveTouchPanel.SetCalibration(CAL_POINTS, sx, sy, cx, cy);
Window mainWindow = myApplication.CreateWindow();
// Start the application
myApplication.Run(mainWindow);
}
private Window mainWindow;
public Window CreateWindow()
{
// Create a window object and set its size to the size of the display.
mainWindow = new Window();
mainWindow.Height = SystemMetrics.ScreenHeight;
mainWindow.Width = SystemMetrics.ScreenWidth;
// Create a single text control.
text = new Text();
text.Font = Resources.GetFont(Resources.FontResources.small);
text.TextContent = Resources.GetString(Resources.StringResources.String1);
text.HorizontalAlignment = Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
text.VerticalAlignment = Microsoft.SPOT.Presentation.VerticalAlignment.Center;
// Add the text control to the window.
mainWindow.Child = text;
// Set the window visibility to visible.
mainWindow.Visibility = Visibility.Visible;
// Touch Events
mainWindow.TouchDown += new TouchEventHandler(mainWindow_TouchDown);
mainWindow.TouchUp += new TouchEventHandler(mainWindow_TouchUp);
return mainWindow;
}
// Set LCD Configuration for Newhaven NHD-4.3-480272EF-ATXL#-T
private static void SetLCDConfigurations()
{
Configuration.LCD.Configurations lcdConfig = new Configuration.LCD.Configurations();
lcdConfig.Width = 480;
lcdConfig.Height = 272;
// Only use if needed, see documentation.
lcdConfig.PriorityEnable = false;
lcdConfig.OutputEnableIsFixed = false;
lcdConfig.OutputEnablePolarity = true;
lcdConfig.HorizontalSyncPolarity = false;
lcdConfig.VerticalSyncPolarity = false;
lcdConfig.PixelPolarity = false;
lcdConfig.HorizontalSyncPulseWidth = 41;
lcdConfig.HorizontalBackPorch = 2;
lcdConfig.HorizontalFrontPorch = 2;
lcdConfig.VerticalSyncPulseWidth = 10;
lcdConfig.VerticalBackPorch = 2;
lcdConfig.VerticalFrontPorch = 2;
// NOTE: This is used for EMX
lcdConfig.PixelClockDivider = 8;
// Set config
if (Configuration.LCD.Set(lcdConfig))
{
// New settings were saved, must reboot
Microsoft.SPOT.Hardware.PowerState.RebootDevice(false);
}
}
private void mainWindow_TouchUp(object sender, TouchEventArgs e)
{
string S = "Touch up: " + e.Touches[0].X + ", " + e.Touches[0].Y;
Debug.Print(S);
text.TextContent = S;
}
private void mainWindow_TouchDown(object sender, TouchEventArgs e)
{
string S = "Touch down: " + e.Touches[0].X + ", " + e.Touches[0].Y;
Debug.Print(S);
text.TextContent = S;
}
}
}
Hardware connections:
Ribbon Function EMX
Pins Pins
1 GND
2 LED+ LED Power Supply
3 GND
4 Vcc Vcc 3.3V
5 GND
6 GND
7 GND
8 R3 LCD_R0
9 R4 LCD_R1
10 R5 LCD_R2
11 R6 LCD_R3
12 R7 LCD_R4
13 GND
14 GND
15 G2 LCD_G0
16 G3 LCD_G1
17 G4 LCD_G2
18 G5 LCD_G3
19 G6 LCD_G4
20 G7 LCD_G5
21 GND
22 GND
23 GND
24 B3 LCD_B0
25 B4 LCD_B1
26 B5 LCD_B2
27 B6 LCD_B3
28 B7 LCS_B4
29 GND
30 PCLK LCD_CLK
31 DISP IO15
32 HSYNC LCD_HT
33 VSYNC LCD_VT
34 Data Enabled LCD_DE
35 NC
36 GND
37 XR IO71
38 YD IO73
39 XL IO8
40 YU IO5
LED Power, use LT3593, in standard configuration
Vcc is 3.3Vdc
Screen ribbon connector is a XF2M-4015 (Not that the pin order can be inverted)
Least significant RGB bits on the screen is grounded.
NOTE !!! This screen cannot be substituted directly with the GHI Screens on PCB 3.5", 4.3" and 7".
You need a LED power supply on your own PCB and the pin out is different.