Touch recognition working
This commit is contained in:
@@ -186,7 +186,7 @@ static void init_exti()
|
|||||||
EXTI_StructInit(&exti);
|
EXTI_StructInit(&exti);
|
||||||
exti.EXTI_Line = EXTI_Line0;
|
exti.EXTI_Line = EXTI_Line0;
|
||||||
exti.EXTI_Mode = EXTI_Mode_Interrupt;
|
exti.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||||
exti.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
exti.EXTI_Trigger = EXTI_Trigger_Falling; // Trigger on falling edge (PENIRQ)
|
||||||
exti.EXTI_LineCmd = ENABLE;
|
exti.EXTI_LineCmd = ENABLE;
|
||||||
EXTI_Init(&exti);
|
EXTI_Init(&exti);
|
||||||
|
|
||||||
@@ -207,8 +207,8 @@ static void init_timer()
|
|||||||
|
|
||||||
/* Timer 7 configuration */
|
/* Timer 7 configuration */
|
||||||
TIM_TimeBaseStructInit(&t); // Init TimeBaseStruct
|
TIM_TimeBaseStructInit(&t); // Init TimeBaseStruct
|
||||||
t.TIM_Prescaler = APB1_CLK / 1000 - 1; // 0..41999 prescaler
|
t.TIM_Prescaler = APB1_CLK / 1000 - 1; // 41999 prescaler
|
||||||
t.TIM_Period = 20- 1; // 10ms cycle time
|
t.TIM_Period = 50 - 1; // 50ms count time
|
||||||
TIM_TimeBaseInit(TIM7, &t); // Init TIM7
|
TIM_TimeBaseInit(TIM7, &t); // Init TIM7
|
||||||
TIM_ITConfig(TIM7, TIM_IT_Update, ENABLE); // Enable update IRQ for TIM7
|
TIM_ITConfig(TIM7, TIM_IT_Update, ENABLE); // Enable update IRQ for TIM7
|
||||||
NVIC_EnableIRQ(TIM7_IRQn); // Enable IRQs for TIM7
|
NVIC_EnableIRQ(TIM7_IRQn); // Enable IRQs for TIM7
|
||||||
@@ -217,20 +217,8 @@ static void init_timer()
|
|||||||
/* Interrupt service routines ------------------------------------------ */
|
/* Interrupt service routines ------------------------------------------ */
|
||||||
void EXTI0_IRQHandler()
|
void EXTI0_IRQHandler()
|
||||||
{
|
{
|
||||||
if (EXTI_GetITStatus(EXTI_Line0) == SET) { // Make sure the interrupt flag is set
|
if (EXTI_GetITStatus(EXTI_Line0) == SET) { // If the right interrupt flag is set
|
||||||
|
|
||||||
if(!pen_state){ // Check if PENDOWN or PENUP
|
|
||||||
TIM_Cmd(TIM7, ENABLE); // Start the timer
|
TIM_Cmd(TIM7, ENABLE); // Start the timer
|
||||||
while(!tim_flag); // Wait for the sampling to finish
|
|
||||||
touch_add_raw_event(avg_vals(x_samples, NSAMPLE), avg_vals(y_samples, NSAMPLE), TOUCH_DOWN);
|
|
||||||
}else{
|
|
||||||
TIM_Cmd(TIM7, ENABLE); // Start the timer
|
|
||||||
while(!tim_flag); // Wait for the sampling to finish
|
|
||||||
touch_add_raw_event(avg_vals(x_samples, NSAMPLE), avg_vals(y_samples, NSAMPLE), TOUCH_UP);
|
|
||||||
}
|
|
||||||
|
|
||||||
pen_state = !pen_state; // Toggle penstate
|
|
||||||
tim_flag = false; // Clear timer flag
|
|
||||||
EXTI_ClearITPendingBit(EXTI_Line0); // Clear interrupt flag
|
EXTI_ClearITPendingBit(EXTI_Line0); // Clear interrupt flag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,14 +226,25 @@ void EXTI0_IRQHandler()
|
|||||||
void TIM7_IRQHandler()
|
void TIM7_IRQHandler()
|
||||||
{
|
{
|
||||||
if(TIM_GetFlagStatus(TIM7, TIM_IT_Update) == SET){ // Make sure the interrupt flag is set
|
if(TIM_GetFlagStatus(TIM7, TIM_IT_Update) == SET){ // Make sure the interrupt flag is set
|
||||||
|
|
||||||
|
TIM_Cmd(TIM7, DISABLE); // Disable the timer during the measuring
|
||||||
|
|
||||||
|
if(!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)){ // Only do this if the PENIRQ line is still low
|
||||||
|
/* Sample 16 times and submit */
|
||||||
for(i = 0; i < (NSAMPLE-1); i++){
|
for(i = 0; i < (NSAMPLE-1); i++){
|
||||||
/* get x and y coordinate and apply calibration */
|
/* Apply some calibration to the measured positions */
|
||||||
x_samples[i] = (((long)(DWIDTH - 2 * CCENTER) * 2 * (long)((long)touch_get_x_coord() - x1) / dx + 1) >> 1) + CCENTER;
|
x_samples[i] = (((long)(DWIDTH - 2 * CCENTER) * 2 * (long)((long)touch_get_x_coord() - x1) / dx + 1) >> 1) + CCENTER;
|
||||||
y_samples[i] = (((long)(DHEIGHT -2 * CCENTER) * 2 * (long)((long)touch_get_y_coord() - y1) / dy + 1) >> 1) + CCENTER;
|
y_samples[i] = (((long)(DHEIGHT -2 * CCENTER) * 2 * (long)((long)touch_get_y_coord() - y1) / dy + 1) >> 1) + CCENTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
tim_flag = true; // Set the global timer flag
|
touch_add_raw_event(avg_vals(x_samples, NSAMPLE), avg_vals(y_samples, NSAMPLE), TOUCH_DOWN);
|
||||||
TIM_Cmd(TIM7, DISABLE); // Count only once
|
TIM_Cmd(TIM7, ENABLE);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
touch_add_raw_event(avg_vals(x_samples, NSAMPLE), avg_vals(y_samples, NSAMPLE), TOUCH_UP);
|
||||||
|
TIM_Cmd(TIM7, DISABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TIM_ClearFlag(TIM7, TIM_IT_Update);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
Hallo Test 1241
|
|
||||||
Reference in New Issue
Block a user