From 5bda699f7906b44af7c52dc9c4db943ca7f6890e Mon Sep 17 00:00:00 2001 From: id101010 Date: Thu, 28 May 2015 16:07:26 +0200 Subject: [PATCH] implemented functions to get x and y coordinates and a test function --- common/app/app.c | 2 +- discovery/src/ll_system.c | 3 ++ discovery/src/ll_touch.c | 108 +++++++++++++++++++++++++++++++------- 3 files changed, 94 insertions(+), 19 deletions(-) diff --git a/common/app/app.c b/common/app/app.c index cd593d7..61c1d0f 100644 --- a/common/app/app.c +++ b/common/app/app.c @@ -19,7 +19,7 @@ void app_init() { void app_process() { system_process(); //Let the system handle it's pending events - gui_screen_update(); //update the currently active screen + //gui_screen_update(); //update the currently active screen } diff --git a/discovery/src/ll_system.c b/discovery/src/ll_system.c index 5858d64..4feddca 100644 --- a/discovery/src/ll_system.c +++ b/discovery/src/ll_system.c @@ -49,8 +49,11 @@ bool ll_system_init(void) return true; } +void touch_test(void); + void ll_system_process() { USBH_Process(&USB_OTG_Core, &USB_Host); + touch_test(); } void ll_system_delay(uint32_t msec) { diff --git a/discovery/src/ll_touch.c b/discovery/src/ll_touch.c index 7192661..267a52c 100644 --- a/discovery/src/ll_touch.c +++ b/discovery/src/ll_touch.c @@ -2,8 +2,78 @@ #include #include -#define CLEAR_CS GPIO_ResetBits(GPIOB,GPIO_Pin_9) -#define SET_CS GPIO_SetBits(GPIOB,GPIO_Pin_9) +#include +#include +#include + +/* Defines ---------------------------------------------------------- */ +#define CLEAR_CS GPIO_ResetBits(GPIOB,GPIO_Pin_9) +#define SET_CS GPIO_SetBits(GPIOB,GPIO_Pin_9) +#define REQ_X_COORD 0x90 // Request x coordinate +#define REQ_Y_COORD 0xD0 // Request y coordinate +#define REQ_1_DATAB 0x00 // Request one databyte + + +/* Prototypes -------------------------------------------------------- */ +bool ll_touch_init(); +static uint8_t touch_send(uint8_t dat); +static uint16_t touch_get_y_coord(); +static uint16_t touch_get_y_coord(); +void touch_test(); + +/* +void touch_test() +{ + tft_clear(BLACK); + //test + CLEAR_CS; + touch_send(0xD0); + + uint16_t buf = ((uint16_t) touch_send(0x00))<<5; + buf|= touch_send(0x00) >> 3; + + int test = 3; + + SET_CS; + + char b[10]; + + itoa(buf, b, 10); + + tft_print_line(10,10,WHITE,TRANSPARENT,0,(const char*)b); + tft_print_formatted(10,50,WHITE,TRANSPARENT,0,"XCoord %d", test); +} +*/ + +/* Functions --------------------------------------------------------- */ +static uint16_t touch_get_x_coord() +{ + uint16_t buf_x = 0; + CLEAR_CS; // clear chipselect + touch_send(REQ_X_COORD); // request x coordinate + + buf_x = ((uint16_t) touch_send(REQ_1_DATAB)) << 5; + buf_x |= touch_send(REQ_1_DATAB) >> 3; + + SET_CS; // set chipselect + + return buf_x; +} + +static uint16_t touch_get_y_coord() +{ + uint16_t buf_y = 0; + + CLEAR_CS; // clear chipselect + touch_send(REQ_Y_COORD); // request y coordinate + + buf_y = ((uint16_t) touch_send(REQ_1_DATAB)) << 5; + buf_y |= touch_send(REQ_1_DATAB) >> 3; + + SET_CS; // set chipselect + + return buf_y; +} static uint8_t touch_send(uint8_t dat) { @@ -13,6 +83,24 @@ static uint8_t touch_send(uint8_t dat) return SPI_I2S_ReceiveData(SPI2); } +void touch_test() +{ + uint16_t x = 0, y = 0; + char xs[10]; + char ys[10]; + + tft_clear(BLACK); + + x = touch_get_x_coord(); + y = touch_get_y_coord(); + + itoa(x, xs, 10); + itoa(y, ys, 10); + + tft_print_line(10, 10, WHITE, TRANSPARENT, 0, (const char*)xs); + tft_print_line(10, 30, WHITE, TRANSPARENT, 0, (const char*)ys); +} + bool ll_touch_init() { //We have a ADS7843 Touch controller @@ -73,22 +161,6 @@ bool ll_touch_init() // enable spi SPI_Cmd(SPI2, ENABLE); - - /* - * TEST ahead ... - */ - - CLEAR_CS; - touch_send(0x90); - - for(long i=0; i<1000; i++); - - uint16_t buf = ((uint16_t) touch_send(0x00))<<5; - buf|= touch_send(0x00) >> 3; - - SET_CS; - - return true; }