]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - psdk_cust/pdk_k2g_1_0_1_2_eng/packages/ti/board/diag/lcd_touchscreen/src/lcd_touchscreen_test.c
Modified messaging code after code review.
[processor-sdk/performance-audio-sr.git] / psdk_cust / pdk_k2g_1_0_1_2_eng / packages / ti / board / diag / lcd_touchscreen / src / lcd_touchscreen_test.c
1 /**
2  *  \file   main.c
3  *
4  *  \brief  Example application main file. This application will toggle the led.
5  *          The led toggling will be done inside an callback function, which
6  *          will be called by Interrupt Service Routine. Interrupts are
7  *          triggered manually and no external source is used to trigger
8  *          interrupts.
9  *
10  */
12 /*
13  * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions
17  * are met:
18  *
19  * Redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer.
21  *
22  * Redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in the
24  * documentation and/or other materials provided with the
25  * distribution.
26  *
27  * Neither the name of Texas Instruments Incorporated nor the names of
28  * its contributors may be used to endorse or promote products derived
29  * from this software without specific prior written permission.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  */
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <string.h>
50 #include <ti/drv/i2c/I2C.h>
51 #include <ti/drv/i2c/soc/I2C_v1.h>
52 #include <ti/drv/uart/UART.h>
53 #include <ti/drv/uart/UART_stdio.h>
54 #include <ti/drv/uart/UART.h>
55 #include <ti/drv/uart/UART_stdio.h>
56 #include <ti/csl/soc/am572x/src/cslr_control_core_pad_io.h>
58 #include "include/lcd_touchscreen.h"
60 #include "board.h"
61 #include "board_cfg.h"
63 /**********************************************************************
64  ************************** Internal functions ************************
65  **********************************************************************/
66 void AppDelay(uint32_t delayVal);
67 extern const I2C_Config I2C_config[];
69 /* Board specific definitions */
70 #define SOC_CORE_PAD_IO_REGISTERS_BASE              (0x4a003400U)
71 #define CTRL_CORE_PAD_GPIO6_15                                          (0x28cU)
72 #define CTRL_CORE_PAD_GPIO6_15_PIN                  (0x20000 | 0x0E)
73 #define CM_WKUPAON_GPIO1_CLKCTRL                    (0x4AE07838)
74 #define CM_L4PER_GPIO6_CLKCTRL                                          (0x4A009780)
75 #define CLK_ENABLE_VAL                              (0x00000082)
76 #define HW_WR_REG32(addr, data)   *(unsigned int*)(addr) =(unsigned int)(data)
77 #define GPIO_PIN_VAL_LOW     (0U)
78 #define GPIO_PIN_VAL_HIGH    (1U)
79 #define I2C_INSTANCE           (0U)
81 /**********************************************************************
82  ************************** Global Variables **************************
83  **********************************************************************/
85 int tsCtrlWrite(I2C_Handle h, uint8_t reg, uint8_t val)
86 {
87         int ret = 0;
88         uint8_t tx[2];
89         I2C_Transaction t;
90         t.slaveAddress = TOUCH_SLAVE_ADDR;
91         t.writeBuf = tx;
92         t.writeCount = 2;
93         t.readCount = 0;
94         tx[0] = reg;
95         tx[1] = val;
96         I2C_transfer(h, &t);
97         return ret;
98 }
100 uint8_t tsCtrlRead(I2C_Handle h, uint8_t reg)
102         
103         uint8_t tx[1];
104         uint8_t rx[1];
105         I2C_Transaction t;
106         t.slaveAddress = TOUCH_SLAVE_ADDR;
107         t.writeBuf = tx;
108         t.writeCount = 1;
109         t.readBuf = rx;
110         t.readCount = 1;
111         tx[0] = reg;
112         I2C_transfer(h, &t);
113         return rx[0];
116 int touchInit(I2C_Handle h)
118         int ret = 0;
119     tsCtrlWrite(h, ID_G_AUTO_CLB_MODE, 0x00);   //calibrate
120     AppDelay(100);
121     while(!tsCtrlRead(h, ID_G_AUTO_CLB_MODE));
122     tsCtrlWrite(h, DEVICE_MODE, NORMAL_OPMODE);
123     tsCtrlWrite(h, ID_G_THGROUP, 0x23);
124     tsCtrlWrite(h, ID_G_THPEAK, 0x3c);
125     tsCtrlWrite(h, ID_G_THCAL, 0x1d);
126     tsCtrlWrite(h, ID_G_THWATER, 0xd3);
127     tsCtrlWrite(h, ID_G_TEMP, 0xeb);
128     tsCtrlWrite(h, ID_G_THDIFF, 0xa0);
129     tsCtrlWrite(h, ID_G_TIME_ENTER_MONITOR, 0xc8);
130     tsCtrlWrite(h, ID_G_PERIODACTIVE, 0x06);
131     tsCtrlWrite(h, ID_G_PERIODMONITOR, 0x28);
132     tsCtrlWrite(h, ID_G_MODE, 0x01);
133         return ret;
136 int tsReadAll(I2C_Handle h, uint8_t *rx)
138         uint8_t tx[1] = {0};
139         I2C_Transaction t;
140         t.slaveAddress = TOUCH_SLAVE_ADDR;
141         t.writeBuf = tx;
142         t.writeCount = 1;
143         t.readBuf = rx;
144         t.readCount = 255;
145         I2C_transfer(h, &t);
146         return 0;
149 void touchLoop(I2C_Handle h)
151         uint8_t rx[255] = {0};
152         UART_printf("Input 9 touches to exit test\n");
153         UART_printf("Touch\tt1\t\tt2\t\tt3\t\tt4\t\tt5\t\tt6\t\tt7\t\tt8\t\tt9\n");
154         while(rx[TD_STATUS] != 0x9)
155         {
156                 tsReadAll(h, rx);
157                 if (rx[TD_STATUS] > 0 && rx[TD_STATUS] < 10)
158                 {
159                         UART_printf("%d\t%4d,%4d\t%4d,%4d\t%4d,%4d\t%4d,%4d\t%4d,%4d\t%4d,%4d\t%4d,%4d\t%4d,%4d\t%4d,%4d\n",
160                                         rx[TD_STATUS],
161               (((rx[TOUCH1_XH]&0x0F)<<8) | (rx[TOUCH1_XL])),
162               (((rx[TOUCH1_YH]&0x0F)<<8) | (rx[TOUCH1_YL])),
163               (((rx[TOUCH2_XH]&0x0F)<<8) | (rx[TOUCH2_XL])),
164               (((rx[TOUCH2_YH]&0x0F)<<8) | (rx[TOUCH2_YL])),
165               (((rx[TOUCH3_XH]&0x0F)<<8) | (rx[TOUCH3_XL])),
166               (((rx[TOUCH3_YH]&0x0F)<<8) | (rx[TOUCH3_YL])),
167               (((rx[TOUCH4_XH]&0x0F)<<8) | (rx[TOUCH4_XL])),
168               (((rx[TOUCH4_YH]&0x0F)<<8) | (rx[TOUCH4_YL])),
169               (((rx[TOUCH5_XH]&0x0F)<<8) | (rx[TOUCH5_XL])),
170               (((rx[TOUCH5_YH]&0x0F)<<8) | (rx[TOUCH5_YL])),
171               (((rx[TOUCH6_XH]&0x0F)<<8) | (rx[TOUCH6_XL])),
172               (((rx[TOUCH6_YH]&0x0F)<<8) | (rx[TOUCH6_YL])),
173               (((rx[TOUCH7_XH]&0x0F)<<8) | (rx[TOUCH7_XL])),
174               (((rx[TOUCH7_YH]&0x0F)<<8) | (rx[TOUCH7_YL])),
175               (((rx[TOUCH8_XH]&0x0F)<<8) | (rx[TOUCH8_XL])),
176               (((rx[TOUCH8_YH]&0x0F)<<8) | (rx[TOUCH8_YL])),
177               (((rx[TOUCH9_XH]&0x0F)<<8) | (rx[TOUCH9_XL])),
178               (((rx[TOUCH9_YH]&0x0F)<<8) | (rx[TOUCH9_YL]))
179                         );
180                 }
181                 AppDelay(10000000);
182         }
185 /*
186  *  ======== test function ========
187  */
188 int touchscreen_test()
190     char *ptr;
191         uint8_t messageSize = 4;
192         int ret = 0;
193         int i;
194     I2C_Params i2cParams;
195     I2C_Handle handle = NULL;
197     ptr = (char*)malloc(messageSize);
198     memset(ptr,0,messageSize);
200         for (i=0; I2C_config[i].fxnTablePtr != NULL; i++)
201         {
202                 ((I2C_HwAttrs *)I2C_config[i].hwAttrs)->enableIntr = false;
203         }
205     I2C_init();
207     I2C_Params_init(&i2cParams);
209     handle = I2C_open(I2C_INSTANCE, &i2cParams);
211         UART_printf("\n*********************************************\n"); 
212         UART_printf  ("*             Touchscreen Test              *\n");
213         UART_printf  ("*********************************************\n");
215         touchInit(handle);
216         touchLoop(handle);
217         I2C_close(handle);
218         return ret;
221 /*
222  *  ======== main ========
223  */
224 int main(void)
226     Board_initCfg boardCfg;
227 #ifdef PDK_RAW_BOOT
228     boardCfg = BOARD_INIT_PINMUX_CONFIG | 
229         BOARD_INIT_UART_STDIO;
230 #else
231     boardCfg = BOARD_INIT_UART_STDIO;
232 #endif
233     Board_init(boardCfg);
234         return touchscreen_test();
237 void AppDelay(uint32_t delayVal)
239         uint32_t cnt = 0;
240     while(cnt < delayVal)
241     {
242                 asm("");
243         cnt++;
244     }