rendered paste body#define _GNU_SOURCE#include "msm_mdp.h"#define __dev_t_defined#define __gid_t_defined#define __uid_t_defined#define __mode_t_defined#define __timer_t_defined#define __nlink_t_defined#define __blkcnt_t_defined#define __fd_set_defined#define _SYS_SELECT_H#include <sys/types.h>#include <sys/stat.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <sys/mman.h>#include <sys/ioctl.h>#include <fcntl.h>#include <linux/fb.h>#include <linux/input.h>#include <dirent.h>//#include <linux/msm_mdp.h>short *ptr;struct fb_var_screeninfo info;//considering screen is 2048x2048int points[5][2]= { { 128, 128 }, { 1903, 129 }, { 1024, 1024 }, { 128, 1907 }, { 1903, 1907 },};void put_pixel(int rel_x, int rel_y, short rgb) { int x,y; x=rel_x*info.xres; x/=2048; y=rel_y*info.yres; y/=2048; ptr[x+info.xres_virtual*y]=rgb;}int dev_id=-1;int open_input() { /* scan all input drivers and look for "kionix-ksd9" */ int fd = -1; const char *dirname = "/dev/input"; char devname[PATH_MAX]; char *filename; DIR *dir; struct dirent *de; dir = opendir(dirname); if(dir == NULL) return -1; strcpy(devname, dirname); filename = devname + strlen(devname); *filename++ = '/'; while((de = readdir(dir))) { if(de->d_name[0] == '.' && (de->d_name[1] == '\0' || (de->d_name[1] == '.' && de->d_name[2] == '\0'))) continue; strcpy(filename, de->d_name); fd = open(devname, O_RDONLY); if (fd>=0) { char name[80]; if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) { name[0] = '\0'; } if (!strcmp(name, "tssc-manager")) { int i,id; for(i=0;i<strlen(devname);++i) if(isdigit(devname[i])) { dev_id=atoi(devname+i); break; } break; } close(fd); fd = -1; } } closedir(dir); return fd;}int main(int argc, char **argv) { int fd=open("/dev/graphics/fb0", O_RDWR); int i,x,y; char *str; int input_fd=open_input(); struct input_event ev_buf; struct mdp_blit_req_list *req_list; struct mdp_blit_req *req; req_list = calloc(1,sizeof(struct mdp_blit_req_list) + sizeof(struct mdp_blit_req)); req_list->count = 1; req = req_list->req; req->src.format=MDP_RGB_565; req->src.format=MDP_RGB_565; req->src.offset=0; req->dst.offset=0; req->src.memory_id=fd; req->dst.memory_id=fd; req->alpha=MDP_ALPHA_NOP; req->transp_mask=MDP_TRANSP_NOP; req->flags=MDP_ROT_NOP; if(input_fd<0) { perror("Open input device"); return -1; } if(fd<0) { perror("Open fb device"); return -1; } ioctl(fd, FBIOGET_VSCREENINFO, &info); ptr=mmap(0, info.xres_virtual*info.yres_virtual*info.bits_per_pixel/8, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0); if(!ptr) { perror("mapping framebuffer"); return -1; } req->src.width=info.xres; req->src_rect.w=info.xres; req->dst.width=info.xres; req->dst_rect.w=info.xres; req->src.height=info.yres; req->src_rect.h=info.yres; req->dst.height=info.yres; req->dst_rect.h=info.yres; req->src_rect.x=0; req->dst_rect.x=0; req->src_rect.y=0; req->dst_rect.y=0; info.yoffset=0; char *path=0; asprintf(&path, "/sys/class/input/input%d/calibration_screen", dev_id); int calib_fd=open(path, O_WRONLY); free(path);path=NULL; if(calib_fd<0) { perror("opening calibration_screen"); //return -2; } asprintf(&str, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n", points[0][0], points[0][1], points[1][0], points[1][1], points[3][0], points[3][1], points[4][0], points[4][1], points[2][0], points[2][1]); write(calib_fd, str, strlen(str)); free(str); close(calib_fd); str=NULL; asprintf(&path, "/sys/class/input/input%d/calibration", dev_id); for(i=1;i<6;++i) { calib_fd=open(path, O_WRONLY); for(x=points[i-1][0]-70;x<=points[i-1][0]+70;++x) for(y=points[i-1][1]-50;y<=points[i-1][1]+50;++y) put_pixel(x, y, 0xffff); for(x=points[i-1][0]-70;x<=points[i-1][0]+70;++x) put_pixel(x, points[i-1][1], 0x0000); for(y=points[i-1][1]-70;y<=points[i-1][1]+70;++y) put_pixel(points[i-1][0], y, 0x0000); ioctl(fd, MSMFB_BLIT, req_list); ioctl(fd, FBIOPAN_DISPLAY, &info); asprintf(&str, "%d\n", i); write(calib_fd, str, strlen(str)); close(calib_fd); free(str); str=NULL; while(1) { if(read(input_fd, &ev_buf, sizeof(ev_buf))<0) return -1; if(ev_buf.type==EV_KEY && ev_buf.value!=0 && ev_buf.code==BTN_TOUCH) break; } while(1) { if(read(input_fd, &ev_buf, sizeof(ev_buf))<0) return -1; if(ev_buf.type==EV_KEY && ev_buf.value==0 && ev_buf.code==BTN_TOUCH) break; } } calib_fd=open("/sys/class/input/input3/calibration", O_WRONLY); write(calib_fd, "0\n", 2); close(calib_fd); return 0;}