/* \brief Main loop. * * Do calibration and then wait for touch events. * Upon a touch or move event we will draw a pixel on that position. */ int main(void) { init_board(); print_dbg("Resistive Touch Example\r\n"); rtouch_init(); rtouch_enable(); rtouch_set_event_handler(event_handler); gpio_clr_gpio_pin(LED0_GPIO); /* Do the calibration */ while(rtouch_calibrate()) ; /* Signal end of calibration */ gpio_set_gpio_pin(LED0_GPIO); while(true) { } }
bool rtouch_calibrate(void) //void * data ) { //int * state = (int *) data; rtouch_event_t event; bool in_progress = true; static int state = 0; static rtouch_event_handler_t oldHandler; switch (state) { case 0: //TFT_SetClipping( 0, 0, TFT_GetWidth(), TFT_GetHeight() ); //TFT_color_t MEM_RAMTYPE * pixmap; //pixmap = MEM_ALLOC_ARRAY( TFT_color_t, (240UL * 320UL) ); tft_print_string( 10, 10, "Touch screen calibration...", RTOUCH_COLOR); points.point1.panelX = 30; points.point1.panelY = 30; points.point2.panelX = 170; points.point2.panelY = 220; points.point3.panelX = 300; points.point3.panelY = 120; tft_draw_filled_circle( points.point1.panelX, points.point1.panelY, 2, RTOUCH_COLOR, TFT_WHOLE ); state = 1; oldHandler = rtouch_get_event_handler(); rtouch_set_event_handler( calibratehandler ); break; case 1: if (rtouch_is_touched() == false) { break; } tft_draw_filled_circle( points.point1.panelX, points.point1.panelY, 2, RTOUCH_COLOR, TFT_WHOLE ); rtouch_get_event(&event); points.point1.rawX = event.rawX; points.point1.rawY = event.rawY; state = 2; break; case 2: if (rtouch_is_touched() == true) { break; } tft_draw_filled_circle( points.point2.panelX, points.point2.panelY, 2, RTOUCH_COLOR, TFT_WHOLE ); state = 3; break; case 3: if (rtouch_is_touched() == false) { break; } tft_draw_filled_circle( points.point2.panelX, points.point2.panelY, 2, RTOUCH_COLOR, TFT_WHOLE ); rtouch_get_event(&event); points.point2.rawX = event.rawX; points.point2.rawY = event.rawY; state = 4; break; case 4: if (rtouch_is_touched() == true) { break; } tft_draw_filled_circle( points.point3.panelX, points.point3.panelY, 2, RTOUCH_COLOR, TFT_WHOLE ); state = 5; break; case 5: if (rtouch_is_touched() == false) { break; } tft_draw_filled_circle( points.point3.panelX, points.point3.panelY, 2, RTOUCH_COLOR, TFT_WHOLE ); rtouch_get_event(&event); points.point3.rawX = event.rawX; points.point3.rawY = event.rawY; state = 6; break; case 6: if (rtouch_is_touched() == true) { break; } rtouch_compute_calibration_matrix(&points, &matrix); rtouch_set_calibration_matrix(&matrix); state = 7; rtouch_set_event_handler(oldHandler); in_progress = false; state = 0; // TODO redraw the background if needed break; default: break; } return in_progress; }
/** * \brief Application entry point for spi_touchscreen example. * * \return Unused (ANSI-C compatibility). */ int main(void) { uint8_t uc_result; sysclk_init(); board_init(); configure_console(); /* Enable clocks for push buttons management */ pmc_enable_periph_clk(ID_PIOA); pmc_enable_periph_clk(ID_PIOB); pmc_enable_periph_clk(ID_PIOC); /* Output example information */ puts(STRING_HEADER); /* Configure systick for 1 ms. */ puts("Configure system tick to get 1ms tick period.\r"); if (SysTick_Config(sysclk_get_cpu_hz() / 1000)) { puts("Systick configuration error\r"); while (1); } /* Switch off backlight */ aat31xx_disable_backlight(); lcd_init(); lcd_set_foreground_color(UNI_COLOR_WHITE); lcd_draw_filled_rectangle(0, 0, LCD_WIDTH, LCD_HEIGHT); /* Turn on LCD */ lcd_display_on(); /* Switch on backlight */ aat31xx_set_backlight(AAT31XX_MAX_BACKLIGHT_LEVEL); /* Initializes the PIO interrupt management for touchscreen driver */ pio_handler_set_priority(PIOA, PIOA_IRQn, IRQ_PRIOR_PIO); pio_handler_set_priority(PIOB, PIOB_IRQn, IRQ_PRIOR_PIO); pio_handler_set_priority(PIOC, PIOC_IRQn, IRQ_PRIOR_PIO); /* Initialize touchscreen without calibration */ rtouch_init(LCD_WIDTH, LCD_HEIGHT); rtouch_enable(); rtouch_set_event_handler(event_handler); while (1) { uc_result = rtouch_calibrate(); if (uc_result == 0) { puts("Calibration successful !\r"); break; } else { puts("Calibration failed; error delta is too big ! Please retry calibration procedure...\r"); } } while (1) { } }
/** \brief Main function. Execution starts here. */ int main(void) { uint8_t uc_result; /* Initialize the sleep manager */ sleepmgr_init(); membag_init(); sysclk_init(); init_specific_board(); /* Initialize the console uart */ configure_console(); /* Output demo infomation. */ printf("-- SAM Toolkit Demo Example --\n\r"); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); /* Configure systick for 1 ms. */ puts("Configure system tick to get 1ms tick period.\r"); if (SysTick_Config(sysclk_get_cpu_hz() / 1000)) { puts("Systick configuration error\r"); while (1) { } } /* Initialize gfx module */ gfx_init(); win_init(); /* Initialize FatFS and bitmap draw interface */ demo_draw_bmpfile_init(); /* Initialize touchscreen without calibration */ rtouch_init(LCD_WIDTH, LCD_HEIGHT); rtouch_enable(); rtouch_set_event_handler(event_handler); /* Initialize demo parameters */ demo_parameters_initialize(); while (g_demo_parameters.calib_points[0].raw.x == 0) { uc_result = rtouch_calibrate(); if (uc_result == 0) { demo_set_special_mode_status(DEMO_LCD_CALIBRATE_MODE, 0); puts("Calibration successful !\r"); break; } else { puts("Calibration failed; error delta is too big ! Please retry calibration procedure...\r"); } } /* Re-caculate the calibration data */ rtouch_compute_calibration( (rtouch_calibration_point_t *)&g_demo_parameters.calib_points[0]); /* Setup root window */ setup_gui_root_window(); gfx_draw_bitmap(&win_startup_bmp, 0, 40); /* Set backlight by the data read from demo parameters */ aat31xx_set_backlight(g_demo_parameters.backlight); /* Default RTC configuration, 24-hour mode */ rtc_set_hour_mode(RTC, 0); rtc_set_time(RTC, g_demo_parameters.hour, g_demo_parameters.minute, g_demo_parameters.second); rtc_set_date( RTC, g_demo_parameters.year, g_demo_parameters.month, g_demo_parameters.day, 1 ); /* Create a semaphore to manage the memories data transfer */ vSemaphoreCreateBinary(main_trans_semphr); /* Turn on main widget */ app_widget_main_on(true); /* Initialize QTouch */ demo_qt_init(); /* Start USB stack to authorize VBus monitoring */ udc_start(); if (!udc_include_vbus_monitoring()) { /* VBUS monitoring is not available on this product * thereby VBUS has to be considered as present */ main_vbus_action(true); } /* Create task to window task */ if (xTaskCreate(task_win, "WIN", TASK_WIN_STACK_SIZE, NULL, TASK_WIN_STACK_PRIORITY, NULL) != pdPASS) { printf("Failed to create test led task\r\n"); } /* Create task to usb mass storage task */ if (xTaskCreate(task_usb, "USB", TASK_USB_STACK_SIZE, NULL, TASK_USB_STACK_PRIORITY, NULL) != pdPASS) { printf("Failed to create test led task\r\n"); } /* Start the scheduler. */ vTaskStartScheduler(); /* Will only get here if there was insufficient memory to create the * idle task. */ return 0; }