/* * TOUCH_EVENT.c * * Created on: 1/04/2014 * Author: Holguer A. Becerra * Adrizcorp@gmail.com */ // INCLUDES TOUCH #include #include // usleep (unix standard?) #include "io.h" // I/O access #include "system.h" // HAL system #include "./touch_driver/TOUCH_EVENT.h" // INCLUDES VIDEO #include "terasic_includes.h" #include "vip_fr.h" #include "./graphic_lib/simple_graphics.h" #include "./graphic_lib/gimp_bmp.h" #include "./graphic_lib/draw_gimps.h" #define FRAME_WIDTH 480 #define FRAME_HEIGHT 272 #define FR_FRAME_0 (SDRAM_BASE) // vector de colores unsigned int colors[10]={GREEN_24,AQUAMARINE_24,BROWN_24,BLUEVIOLET_24,INDIGO_24, LEMONCHIFFON_24,OLIVE_24,SILVER_24, DIMGRAY_24,GOLD_24}; typedef alt_32 fixed428; typedef alt_64 fixed856; // subfuncion calcular fractal int calc_frac_point( fixed428 cx, fixed428 cy, alt_u16 max_itr) { fixed428 x, y, xx, yy, xy2; fixed856 xx_raw, yy_raw, xy_raw; int itr; x = cx; y = cy; itr=0; do { /* Q4.Z8 multiplications */ xx_raw= (fixed856)(x) * (fixed856)(x); xx = (fixed428)(xx_raw >> 28); yy_raw = (fixed856)(y) * (fixed856)(y); yy = (fixed428)(yy_raw >> 28); xy_raw=(fixed856)(x) * (fixed856)(y); xy2 = (fixed428)(xy_raw>>27); // 2* is same as «1 /* iteration equation */ x = xx - yy + cx; y = xy2 + cy; itr++; } while (((xx+yy)<0x40000000) && ( itr < max_itr ) ) ; return(itr); } int assign_color(int iter,int max_iter ) { int p; int color; if(iter==max_iter) { color=0x0000; } else { p=iter%10; color=colors[p]; } return(color); } int main(){ //***** INICIALIZANDO DRIVERS ****// // init Touch int result; int event=0; int pos_x,pos_y; alt_touchscreen touchscreen_global; result=alt_touchscreen_init( &touchscreen_global, TOUCH_PANEL_SPI_BASE, TOUCH_PANEL_SPI_IRQ, TOUCH_PANEL_PENIRQ_N_BASE, 60, ALT_TOUCHSCREEN_SWAP_XY); if(result==0){ printf("Touch Inicializado\n"); alt_touchscreen_calibrate_upper_right (&touchscreen_global, 3975, 4032, // ADC readings 479, 0 ); // pixel coords alt_touchscreen_calibrate_lower_left (&touchscreen_global, 112, 110, // ADC readings 0, 271 ); // pixel coords } else{ printf("Touch Fallo\n"); return 0; } // init video VIP_FRAME_READER *pReader; ////////Se inicializa el HW del sistema////////////// // frame reader pReader = VIPFR_Init(ALT_VIP_VFR_0_BASE, (void *)FR_FRAME_0, (void *)FR_FRAME_0, FRAME_WIDTH, FRAME_HEIGHT); // se activa el frame de video VIPFR_ActiveDrawFrame(pReader); // clean screen vid_clean_screen(pReader, BLACK_24); printf("Video Inicializado\n"); //***** PROGRAMA PRINCIPAL ****// fixed428 cy; fixed428 cy0; fixed428 cx0; fixed428 cx; int j; int i; int HPIX; int VPIX; fixed428 deltax; fixed428 deltay; int itr; alt_u16 max_itr; int color; fixed428 xn; fixed428 yn; // resolución de la pantalla HPIX=480; VPIX=272; // Area de dibujo del fractal cx0=0xe0000000; cy0=0xf0000000; xn=0x10000000; yn=0x10000000; // cálculo de delta deltax=( fixed428)(xn-cx0)/HPIX; deltay=( fixed428)(yn-cy0)/VPIX; max_itr=100; while(1){ cy = cy0; for(j=0; j