Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Mini-DK mbed SDFileSystem
Revision 3:fb4d62b5ffb3, committed 2013-01-03
- Comitter:
- frankvnk
- Date:
- Thu Jan 03 16:16:24 2013 +0000
- Parent:
- 2:d0acbd263ec7
- Child:
- 4:067633a7dfa5
- Commit message:
- Changes - see modifs.h
Changed in this revision
--- a/Mini-DK/TouchADS7843/Touch.cpp Thu Jan 03 10:54:09 2013 +0000
+++ b/Mini-DK/TouchADS7843/Touch.cpp Thu Jan 03 16:16:24 2013 +0000
@@ -18,8 +18,8 @@
#define THRESHOLD 2
-TouchScreenADS7843::TouchScreenADS7843(PinName tp_mosi, PinName tp_miso, PinName tp_sclk, PinName tp_cs, PinName tp_irq)
- : _tp_spi(tp_mosi, tp_miso, tp_sclk), _tp_cs(tp_cs), _tp_irq(tp_irq)
+TouchScreenADS7843::TouchScreenADS7843(PinName tp_mosi, PinName tp_miso, PinName tp_sclk, PinName tp_cs, PinName tp_irq, SPI_TFT *_LCD)
+ : _tp_spi(tp_mosi, tp_miso, tp_sclk), _tp_cs(tp_cs), _tp_irq(tp_irq), LCD(_LCD)
{
DisplaySample[0].x=45;
DisplaySample[0].y=45;
@@ -73,17 +73,17 @@
void TouchScreenADS7843::TP_DrawPoint(unsigned int Xpos,unsigned int Ypos, unsigned int color)
{
-/* LCD->wr_reg(0x03, 0x1030);
+ LCD->wr_reg(0x03, 0x1030);
LCD->WindowMax();
LCD->pixel(Xpos,Ypos,color);
LCD->pixel(Xpos+1,Ypos,color);
LCD->pixel(Xpos,Ypos+1,color);
- LCD->pixel(Xpos+1,Ypos+1,color);*/
+ LCD->pixel(Xpos+1,Ypos+1,color);
}
void TouchScreenADS7843::DrawCross(unsigned int Xpos,unsigned int Ypos)
{
-/* LCD->line(Xpos-15,Ypos,Xpos-2,Ypos,White);
+ LCD->line(Xpos-15,Ypos,Xpos-2,Ypos,White);
LCD->line(Xpos+2,Ypos,Xpos+15,Ypos,White);
LCD->line(Xpos,Ypos-15,Xpos,Ypos-2,White);
LCD->line(Xpos,Ypos+2,Xpos,Ypos+15,White);
@@ -98,7 +98,7 @@
LCD->line(Xpos+15,Ypos+7,Xpos+15,Ypos+15,DarkGrey);
LCD->line(Xpos+7,Ypos-15,Xpos+15,Ypos-15,DarkGrey);
- LCD->line(Xpos+15,Ypos-15,Xpos+15,Ypos-7,DarkGrey);*/
+ LCD->line(Xpos+15,Ypos-15,Xpos+15,Ypos-7,DarkGrey);
}
unsigned char TouchScreenADS7843::Read_Ads7846(Coordinate * screenPtr)
@@ -106,6 +106,7 @@
int m0,m1,m2,TP_X[1],TP_Y[1],temp[3];
uint8_t count=0;
int buffer[2][9]={{0},{0}};
+ if (screenPtr == NULL) screenPtr = &screen;
do
{
TP_GetAdXY(TP_X,TP_Y);
@@ -244,18 +245,18 @@
uint8_t i;
Coordinate screen_cal;
setCalibrationMatrix( &DisplaySample[0],&ScreenSample[0],&matrix) ;
-// LCD->set_font((unsigned char*) Arial12x12);
+ LCD->set_font((unsigned char*) Arial12x12);
for(i=0;i<3;i++)
{
-// LCD->cls();
-// LCD->locate(10,10);
-// LCD->printf("Touch crosshair to calibrate");
+ LCD->cls();
+ LCD->locate(10,10);
+ LCD->printf("Touch crosshair to calibrate");
wait_ms(500);
DrawCross(DisplaySample[i].x,DisplaySample[i].y);
do {} while (!Read_Ads7846(&screen_cal));
ScreenSample[i].x= screen_cal.x;ScreenSample[i].y= screen_cal.y;
}
setCalibrationMatrix( &DisplaySample[0],&ScreenSample[0],&matrix) ;
-// LCD->cls();
+ LCD->cls();
}
--- a/Mini-DK/TouchADS7843/Touch.h Thu Jan 03 10:54:09 2013 +0000
+++ b/Mini-DK/TouchADS7843/Touch.h Thu Jan 03 16:16:24 2013 +0000
@@ -24,17 +24,22 @@
class TouchScreenADS7843 {
public:
- Coordinate DisplaySample[3];
- Coordinate ScreenSample[3];
- Matrix matrix;
Coordinate display;
Coordinate screen;
- TouchScreenADS7843(PinName tp_mosi,PinName tp_miso,PinName tp_sclk,PinName tp_cs,PinName tp_irq);
+ /*
+ * Create a Touchscreen object connected to SPI and two pins
+ *
+ * @param mosi,miso,sclk SPI
+ * @param cs pin connected to CS of ADS7843
+ * @param irq pin connected to IRQ of ADS7843
+ * @param pointer to SPI_TFT constructor
+ *
+ */
+ TouchScreenADS7843(PinName tp_mosi, PinName tp_miso, PinName tp_sclk, PinName tp_cs, PinName tp_irq, SPI_TFT *_LCD);
- void TP_GetAdXY(int *x,int *y);
void TP_DrawPoint(unsigned int Xpos,unsigned int Ypos,unsigned int color);
- unsigned char Read_Ads7846(Coordinate * screenPtr);
+ unsigned char Read_Ads7846(Coordinate * screenPtr = NULL);
void TouchPanel_Calibrate(void);
unsigned char getDisplayPoint(void);
@@ -45,10 +50,15 @@
protected:
-#define SPI_RD_DELAY 1
-#define CHX 0xd0 // 12 bit mode
-#define CHY 0x90
+ #define SPI_RD_DELAY 1
+ #define CHX 0xd0 // 12 bit mode
+ #define CHY 0x90
+ Coordinate DisplaySample[3];
+ Coordinate ScreenSample[3];
+ Matrix matrix;
+
+ void TP_GetAdXY(int *x,int *y);
int Read_XY(unsigned char XY);
void DrawCross(unsigned int Xpos,unsigned int Ypos);
unsigned char setCalibrationMatrix( Coordinate * displayPtr,Coordinate * screenPtr,Matrix * matrixPtr);
--- a/main.cpp Thu Jan 03 10:54:09 2013 +0000
+++ b/main.cpp Thu Jan 03 16:16:24 2013 +0000
@@ -9,13 +9,8 @@
DigitalOut led(DK_LED1);
// TFT -> mosi, miso, sclk, cs
SPI_TFT TFT(LCD_SDI, LCD_SDO, LCD_SCK, LCD_CS,"TFT");
-// ADS7843 -> mosi, miso, sclk, cs, irq
-TouchScreenADS7843 TP(TP_SDI ,TP_SDO ,TP_SCK ,TP_CS ,TP_IRQ);
-
-// (To be modified) put these global vars back in Touch.cpp/Touch.h
-//Matrix matrix;
-//Coordinate display;
-//Coordinate screen;
+// ADS7843 -> mosi, miso, sclk, cs, irq, SPI_TFT
+TouchScreenADS7843 TP(TP_SDI ,TP_SDO ,TP_SCK ,TP_CS ,TP_IRQ, &TFT);
int main()
{
@@ -129,7 +124,7 @@
TP.TouchPanel_Calibrate();
TFT.set_font((unsigned char*) Arial12x12);
TFT.set_orientation(0);
- TFT.cls();
+// TFT.cls();
TFT.locate(0,0);
TFT.printf(" X:");
TFT.locate(70,0);
@@ -138,12 +133,12 @@
{
if (!TP._tp_irq)
{
- Ads7846_status = TP.Read_Ads7846(&TP.screen);
+ Ads7846_status = TP.Read_Ads7846();
if (Ads7846_status)
{
TP.getDisplayPoint() ;
-// TP.TP_DrawPoint(display.x,display.y, Blue);
- TFT.rect(TP.display.x,TP.display.y,1,1,Red);
+ TP.TP_DrawPoint(TP.display.x,TP.display.y, Blue);
+// TFT.rect(TP.display.x,TP.display.y,1,1,Red);
TFT.locate(25,0);
printf("%03d",TP.display.x);
TFT.locate(95,0);
--- a/modifs.h Thu Jan 03 10:54:09 2013 +0000
+++ b/modifs.h Thu Jan 03 16:16:24 2013 +0000
@@ -1,35 +1,18 @@
/*
-Date : 31.12.12
-Author : Erik Olieman
----------------------
-Code readability and speed
-1. created separate structure for mini-DK (base for library)
-2. Removed wr_dat_only routine (uses 8 bit transfer = slow)
- Replaced each wr_dat_only with
- _spi.format(16,3);
- .....
- _spi.write(...);
- .....
- _spi.format(8,3);
-3. Creation of Mini-DK.h with all declarations specific to the mini-DK board.
-
+Date : 31.12.12
+Authors : Erik Olieman/Frank Vannieuwkerke
+-----------------------------------------
+ Code readability and speed
+ 1. created separate structure for mini-DK (base for library)
+ 2. Removed wr_dat_only routine (uses 8 bit transfer = slow) in SPI_TFT
+ Replaced each wr_dat_only with
+ _spi.format(16,3);
+ .....
+ _spi.write(...);
+ .....
+ _spi.format(8,3);
+ 3. Creation of Mini-DK.h with all declarations specific to the mini-DK board.
-Date : 31.12.12
-Author : Frank Vannieuwkerke
-----------------------------
- NOTE : Current code contains SPI_TFT *LCD; in Touch.h
- TouchPanel_Calibrate, TP_DrawPoint and DrawCross in Touch.cpp use LCD->...
- These are currently commented out since using them locks up the system although
- the compiler does not show any errors. Current code works but the calibration
- crosshairs do not show - touching their approximate position still allows you to
- calibrate and draw (TP.TP_DrawPoint in main.cpp temporarily replaced with TFT.rect).
-
- ??Other solution : see TODOs below??
- Possible advantage of this solution :
- Touch library fully independent of LCD library.
- Perhaps do Calibration with a printed template when LCD is not used (less accurate).
- This would only be useful when a touchpanel without LCD is used.
-
Removed reset pin from SPI_TFT (not needed - pin is connected to main reset).
@@ -37,14 +20,10 @@
In main.cpp
-----------
- TODO: before TP.TouchPanel_Calibrate()
- cls
- draw 3 crosses with numbers according to DisplaySample in touch.cpp
- Use following text : Calibration - Touch each crosshair in the numbered sequence.
- after TP.TouchPanel_Calibrate()
- cls
- Moved following global touch var declarations (at top of main.cpp) to touch.cpp/.h
+ TouchScreenADS7843 initialisation: pointer to SPI_TFT needed for calibration, drawcross and drawpoint routines.
+
+ Moved following global touch var declarations from main.cpp back to touch.cpp/.h
Matrix matrix;
Coordinate display;
Coordinate screen;
@@ -56,27 +35,26 @@
In Touch.cpp/.h
---------------
- Removed TP_Init - moved TP_init code to constructor.
+ TouchScreenADS7843 constructor: added pointer to SPI_TFT - needed for calibration, drawcross and drawpoint routines.
+ If LCD calls are not needed, initialise TouchScreenADS7843 with NULL pointer for LCD.
- TODO : Avoid using TFT_LCD library : remove all references to LCD driving
- remove Drawpoint and Drawcross
- remove #include Arial12x12
+ Removed TP_Init - moved TP_init code to constructor.
Variables in call to TouchPanel_Calibrate, Read_Ads7846, getDisplayPoint are no longer needed.
Modified these routines accordingly in touch.cpp/.h (pointers no longer needed)
*** TouchPanel_Calibrate and getDisplayPoint already modified.
- TODO: Problem with Read_Ads7846 -> is also called in TouchPanel_Calibrate (Touch.cpp) with other var.
- Solution : in TouchPanel_Calibrate, change screen_cal to screen_tmp and copy (TP.)screen to this
- variable. Put screen_tmp back to (TP.)screen after setCalibrationMatrix.
-
+ Read_Ads7846: is also called in TouchPanel_Calibrate (Touch.cpp) with other var.
+ Modified Read_Ads7846 to allow call with/without (parameter).
+ If called without (parameter) - screen variable is used, otherwise (parameter) is used.
+ in Touch.h - unsigned char Read_Ads7846(Coordinate * screenPtr); replaced with
+ unsigned char Read_Ads7846(Coordinate * screenPtr = NULL);
+ in Touch.cpp - if (screenPtr == NULL) screenPtr = &screen; added.
General notes
-------------
-lpc1768 SPI port - problem with using SD and TFT simultaneously
+lpc1768 SPI port - problem when using SD and TFT simultaneously - solution provided by Erik Olieman
see note http://mbed.org/comments/cr/83/2654/#c4768
-google search : lpc1768 ssp ssp0 ssp1
-perhaps use softspi (eg http://arduino.cc/forum/index.php?topic=117356.0)
-Ignore above notes - use Erik Olieman's solution.
+Even faster SPI write : http://mbed.org/users/Sissors/code/BurstSPI/docs/600eecd89a78/BurstSPI_8cpp_source.html
*/
\ No newline at end of file
