bsp/stm32f10x: calibrate touch screen before starting GUI
If we do not calibrate the touch screen, GUI is unusable. This patch use a semaphore to block GUI thread until calibration finish. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1791 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
065c3fb834
commit
4e8d6639f0
|
@ -45,6 +45,8 @@
|
||||||
|
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
|
|
||||||
|
extern rt_sem_t touch_screen_calibrated;
|
||||||
|
|
||||||
ALIGN(RT_ALIGN_SIZE)
|
ALIGN(RT_ALIGN_SIZE)
|
||||||
static rt_uint8_t led_stack[ 512 ];
|
static rt_uint8_t led_stack[ 512 ];
|
||||||
static struct rt_thread led_thread;
|
static struct rt_thread led_thread;
|
||||||
|
@ -151,6 +153,17 @@ void rt_init_thread_entry(void* parameter)
|
||||||
/* set lcd device as rtgui graphic driver */
|
/* set lcd device as rtgui graphic driver */
|
||||||
rtgui_graphic_set_device(lcd);
|
rtgui_graphic_set_device(lcd);
|
||||||
|
|
||||||
|
/* without calibration, the position we got from the touch screen is
|
||||||
|
* useless raw value and the GUI is unusable. */
|
||||||
|
calibration_init();
|
||||||
|
if (touch_screen_calibrated != RT_NULL)
|
||||||
|
{
|
||||||
|
rt_sem_take(touch_screen_calibrated, RT_WAITING_FOREVER);
|
||||||
|
/* NOTE: no other thread use this semaphore, so we can delete it.
|
||||||
|
* If this is not your case, comment this line. */
|
||||||
|
rt_sem_delete(touch_screen_calibrated);
|
||||||
|
}
|
||||||
|
|
||||||
/* startup rtgui */
|
/* startup rtgui */
|
||||||
rtgui_startup();
|
rtgui_startup();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,9 @@ struct calibration_session
|
||||||
};
|
};
|
||||||
static struct calibration_session* calibration_ptr = RT_NULL;
|
static struct calibration_session* calibration_ptr = RT_NULL;
|
||||||
|
|
||||||
|
/* a semaphore that will become avaible when calibration finished. */
|
||||||
|
rt_sem_t touch_screen_calibrated = RT_NULL;
|
||||||
|
|
||||||
static void calibration_data_post(rt_uint16_t x, rt_uint16_t y)
|
static void calibration_data_post(rt_uint16_t x, rt_uint16_t y)
|
||||||
{
|
{
|
||||||
if (calibration_ptr != RT_NULL)
|
if (calibration_ptr != RT_NULL)
|
||||||
|
@ -254,6 +257,8 @@ void calibration_entry(void* parameter)
|
||||||
/* release memory */
|
/* release memory */
|
||||||
rt_free(calibration_ptr);
|
rt_free(calibration_ptr);
|
||||||
calibration_ptr = RT_NULL;
|
calibration_ptr = RT_NULL;
|
||||||
|
/* tell other thread that we finished calibration */
|
||||||
|
rt_sem_release(touch_screen_calibrated);
|
||||||
}
|
}
|
||||||
|
|
||||||
void calibration_init()
|
void calibration_init()
|
||||||
|
@ -261,7 +266,12 @@ void calibration_init()
|
||||||
rt_device_t device;
|
rt_device_t device;
|
||||||
|
|
||||||
device = rt_device_find("touch");
|
device = rt_device_find("touch");
|
||||||
if (device == RT_NULL) return; /* no this device */
|
if (device == RT_NULL)
|
||||||
|
return; /* no such device */
|
||||||
|
|
||||||
|
touch_screen_calibrated = rt_sem_create("tc_cali", 0, RT_IPC_FLAG_FIFO);
|
||||||
|
if (touch_screen_calibrated == RT_NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
calibration_ptr = (struct calibration_session*)rt_malloc(sizeof(struct calibration_session));
|
calibration_ptr = (struct calibration_session*)rt_malloc(sizeof(struct calibration_session));
|
||||||
rt_memset(calibration_ptr, 0, sizeof(struct calibration_data));
|
rt_memset(calibration_ptr, 0, sizeof(struct calibration_data));
|
||||||
|
@ -271,7 +281,8 @@ void calibration_init()
|
||||||
|
|
||||||
calibration_ptr->tid = rt_thread_create("cali", calibration_entry, RT_NULL,
|
calibration_ptr->tid = rt_thread_create("cali", calibration_entry, RT_NULL,
|
||||||
2048, 20, 5);
|
2048, 20, 5);
|
||||||
if (calibration_ptr->tid != RT_NULL) rt_thread_startup(calibration_ptr->tid);
|
if (calibration_ptr->tid != RT_NULL)
|
||||||
|
rt_thread_startup(calibration_ptr->tid);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RT_USING_FINSH
|
#ifdef RT_USING_FINSH
|
||||||
|
|
Loading…
Reference in New Issue