test program for SPI_STMPE610

Dependencies:   SPI_STMPE610 mbed vt100

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* main.cpp to test touch sensor comes with adafruit 2.8" TFT LCD shield 
00002  * Copyright (c) 2014 Motoo Tanaka @ Design Methodology Lab
00003  *
00004  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00005  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00006  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00007  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00008  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00009  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00010  * THE SOFTWARE.
00011  */
00012  /*
00013   * Note: Since the interrupt siganl of the shield was not connected
00014   * to an interrupt pin on my frdm-kl25z, I just used polling mode.
00015   */
00016 #include "mbed.h"
00017 #include "vt100.h"
00018 #include "SPI_STMPE610.h"
00019 
00020 vt100 *tty = 0 ;
00021 
00022 #if   defined (TARGET_KL25Z) 
00023 #define PIN_MOSI        PTD2
00024 #define PIN_MISO        PTD3 
00025 #define PIN_SCLK        PTD1 
00026 #define PIN_CS_TFT      PTD0 
00027 #define PIN_DC_TFT      PTD5 
00028 #define PIN_BL_TFT      PTC9 
00029 #define PIN_CS_SD       PTA4 
00030 #define PIN_CS_TSC      PTA13
00031 #define PIN_TSC_INTR    PTC9
00032 #define DEVICE_NAME     "KL25Z"
00033 
00034 #elif defined (TARGET_KL46Z)
00035 #define PIN_MOSI        PTD6
00036 #define PIN_MISO        PTD7 
00037 #define PIN_SCLK        PTD5 
00038 #define PIN_CS_TFT      PTD4 
00039 #define PIN_DC_TFT      PTD2 
00040 #define PIN_BL_TFT      PTC9 
00041 #define PIN_CS_SD       PTA4 
00042 #define PIN_CS_TSC      PTA13
00043 #define PIN_TSC_INTR    PTC9
00044 #define DEVICE_NAME     "KL46Z"
00045 
00046 #elif defined (TARGET_K64F)
00047 #define PIN_MOSI        PTD2
00048 #define PIN_MISO        PTD3
00049 #define PIN_SCLK        PTD1
00050 #define PIN_CS_TFT      PTD0
00051 #define PIN_DC_TFT      PTC4
00052 #define PIN_BL_TFT      PTC3
00053 #define PIN_CS_SD       PTB23
00054 #define PIN_CS_TSC      PTA0
00055 #define PIN_TSC_INTR    PTC3
00056 #define PIN_RESET_TFT   PTB20
00057 #define PIN_ADC_CH0     PTB2
00058 #define PIN_ADC_CH1     PTB3
00059 #define DEVICE_NAME     "K64F"
00060 
00061 #elif defined (TARGET_NECLEO_F411RE)
00062 #define PIN_MOSI        PA_7
00063 #define PIN_MISO        PA_6  
00064 #define PIN_SCLK        PA_5 
00065 #define PIN_CS_TFT      PB_6 
00066 #define PIN_DC_TFT      PC_7 
00067 #define PIN_BL_TFT      PA_8 
00068 #define PIN_CS_SD       PB_5 
00069 #define PIN_CS_TSC      PA_9 
00070 #define PIN_TSC_INTR    PA_8
00071 #define PIN_RESET_TFT   PC_13 /* place holder */
00072 #define DEVICE_NAME     "F411RE"
00073 
00074 #elif defined (TARGET_MAX32600MBED)
00075 /* I2C */
00076 #define PIN_SCL  P2_7
00077 #define PIN_SDA  P2_6
00078 /* SPI */
00079 #define PIN_SCLK  P2_0
00080 #define PIN_MISO P2_2
00081 #define PIN_MOSI P2_1
00082 // #define PIN_MISO P2_1
00083 // #define PIN_MOSI P2_2
00084 #define PIN_CS0  P2_3
00085 /* Interrupt */
00086 #define PIN_INT0 P2_4
00087 #define PIN_INT1 P2_5
00088 #define PIN_INT2 P1_7
00089 #define PIN_INT3 P1_6
00090 #define PIN_INT4 P1_5
00091 #define PIN_INT5 P1_4
00092 /* Analog In */
00093 #define PIN_AN0  AIN_0P
00094 #define PIN_AN1  AIN_1P
00095 #define PIN_AN2  AIN_2P
00096 #define PIN_AN3  AIN_3P
00097 #define PIN_AN4  AIN_4P
00098 #define PIN_AN5  AIN_5P
00099 #define BOARD_NAME "MAX32600MBED"
00100 #define DEVICE_NAME "MAX32600MBED"
00101 
00102 #define PIN_CS_TFT      P2_3 // D10 PTD0 
00103 #define PIN_DC_TFT      P2_4 // D9  PTD5 
00104 #define PIN_CS_TSC      P2_5 // D8  PTA13
00105 #define PIN_BL_TFT      P1_7 // D7   PTC9 
00106 #define PIN_CS_SD       P1_4 // D4   PTA4 
00107 #define PIN_TSC_INTR    P5_4 // PTC9 /* place holder */
00108 #define PIN_RESET_TFT   P5_5 /// PTB10 /* place holder */
00109 #define PIN_ADC_CH0     AIN_0P // A0 PTB0
00110 #define PIN_ADC_CH1     AIN_2P // A2 PTB2
00111 
00112 #else
00113   #error TARGET NOT DEFINED
00114 #endif
00115 
00116 DigitalOut tft_cs(PIN_CS_TFT, 1) ;
00117 DigitalOut sd_cs(PIN_CS_SD, 1) ;
00118 DigitalOut tsc_cs(PIN_CS_TSC, 1) ;
00119 // DigitalOut tsc_intr(PIN_TSC_INTR) ; // should be input, just for test
00120 // DigitalOut tft_reset(PIN_RESET_TFT, 1) ;
00121 
00122 int main()
00123 {
00124     uint16_t touched, x, y, z ;
00125     SPI_STMPE610 *tsc ;
00126 #if (TARGET_MAX32600MBED)
00127     uint32_t *SPI0_MSTR_CFG = (uint32_t*)0x40030000 ;
00128     tty = new vt100(57600) ;
00129 #else
00130     tty = new vt100() ;
00131 #endif
00132     tty->cls() ;
00133     
00134     tsc = new SPI_STMPE610(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TSC) ;
00135  //   tsc->spi_frequency(1000000) ; 
00136  //   tsc->spi_format(8, 0) ;
00137     printf("Test SPI STMPE610 (%s:%s)\n\r", DEVICE_NAME, __DATE__) ;
00138 
00139     tft_cs = 1 ; /* disable TFT display */
00140     sd_cs = 1 ; /* disable SD */
00141 
00142     while (true) {
00143         touched = tsc->getRAWPoint(&x, &y, &z) ;
00144         if (touched) {
00145             printf("x = %d, y = %d, z = %d\n\r", x, y, z) ;
00146         }
00147         wait(0.1) ;
00148     }
00149 }