implemented functions to get x and y coordinates and a test function
This commit is contained in:
@@ -19,7 +19,7 @@ void app_init() {
|
|||||||
void app_process() {
|
void app_process() {
|
||||||
|
|
||||||
system_process(); //Let the system handle it's pending events
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -49,8 +49,11 @@ bool ll_system_init(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void touch_test(void);
|
||||||
|
|
||||||
void ll_system_process() {
|
void ll_system_process() {
|
||||||
USBH_Process(&USB_OTG_Core, &USB_Host);
|
USBH_Process(&USB_OTG_Core, &USB_Host);
|
||||||
|
touch_test();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ll_system_delay(uint32_t msec) {
|
void ll_system_delay(uint32_t msec) {
|
||||||
|
|||||||
@@ -2,8 +2,78 @@
|
|||||||
#include<stm32f4xx_spi.h>
|
#include<stm32f4xx_spi.h>
|
||||||
#include<stm32f4xx_rcc.h>
|
#include<stm32f4xx_rcc.h>
|
||||||
|
|
||||||
|
#include<tft.h>
|
||||||
|
#include<stdio.h>
|
||||||
|
#include<stdlib.h>
|
||||||
|
|
||||||
|
/* Defines ---------------------------------------------------------- */
|
||||||
#define CLEAR_CS GPIO_ResetBits(GPIOB,GPIO_Pin_9)
|
#define CLEAR_CS GPIO_ResetBits(GPIOB,GPIO_Pin_9)
|
||||||
#define SET_CS GPIO_SetBits(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)
|
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);
|
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()
|
bool ll_touch_init()
|
||||||
{
|
{
|
||||||
//We have a ADS7843 Touch controller
|
//We have a ADS7843 Touch controller
|
||||||
@@ -73,22 +161,6 @@ bool ll_touch_init()
|
|||||||
// enable spi
|
// enable spi
|
||||||
SPI_Cmd(SPI2, ENABLE);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user