summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root@sunyi-pc.(none)>2011-05-23 15:25:42 +0800
committerroot <root@sunyi-pc.(none)>2011-05-23 15:25:42 +0800
commit96a8d55d574a0c713ae7a62e99ab259ddde6879d (patch)
tree22a352b6afd4b7d7620eab30f93d7059f33e6717
Init testedid.
-rw-r--r--Makefile2
-rw-r--r--testedid.c365
2 files changed, 367 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..d6446ba
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,2 @@
+default: testedid.c
+ gcc -std=c99 testedid.c -o testedid
diff --git a/testedid.c b/testedid.c
new file mode 100644
index 0000000..ebdd24f
--- /dev/null
+++ b/testedid.c
@@ -0,0 +1,365 @@
+#include <stdio.h>
+
+#include <stddef.h> /*dir */
+#include <sys/types.h>
+#include <dirent.h>
+
+#include <string.h>
+#include <malloc.h>
+
+#include <fcntl.h> /*open */
+#include <sys/stat.h>
+#include <unistd.h> /*read */
+#include <stdlib.h>
+
+#define EDIDPATH "/sys/class/drm/"
+#define MAXCARD 10
+#define MAXFILENAME 256
+#define MAXEDID 128
+
+int getcardlist(struct dirent *cardlist[])
+{
+ DIR* dp;
+ struct dirent *ep;
+ int cardnum=0;
+
+ dp = opendir(EDIDPATH);
+ if (dp != NULL)
+ {
+ while (ep = readdir(dp))
+ {
+ //puts(ep->d_name);
+ if( strstr(ep->d_name,"card0-")>0 )
+ {
+ memcpy(cardlist[cardnum],ep,sizeof(struct dirent));
+ cardnum++;
+ }
+ }
+ closedir(dp);
+ }
+ else
+ puts("Couldn't open the directory.");
+
+ return cardnum;
+}
+int getedid(char edidfile[],char edid[])
+{
+ int edidfp = open(edidfile,O_RDONLY);
+ if(edidfp < 0)
+ {
+ printf("open edid file error:%s\n",edidfile);
+ return 1;
+ }
+ int cun = read(edidfp, edid, MAXEDID);
+ return cun;
+
+}
+int getconcardlist(struct dirent *concardlist[],char *conedid[])
+{
+ int connum=0;
+ struct dirent *cardlist[MAXCARD];
+ char edid[MAXEDID];
+ char edidfile[MAXFILENAME];
+ for(int i=0; i<MAXCARD; i++)
+ {
+ cardlist[i] = (struct dirent*)malloc(sizeof(struct dirent));
+ }
+
+ int cardnum =getcardlist(cardlist);
+ //printf("The card number is: %d\n",cardnum);
+
+ for (int i=0; i<cardnum;i++)
+ {
+// printf(" %s\n", cardlist[i]->d_name);
+ memset(edidfile,0,MAXFILENAME);
+ memset(edid,0,MAXEDID);
+ strcat(edidfile,EDIDPATH);
+ strcat(edidfile,cardlist[i]->d_name);
+ strcat(edidfile,"/edid");
+// printf("filename:%s\n",edidfile);
+ int cun = getedid(edidfile,edid);
+// printf("%d:",cun);
+ if(cun !=0)
+ {
+ memcpy(concardlist[connum],cardlist[i],sizeof(struct dirent));
+ memcpy(conedid[connum],edid,MAXEDID);
+ connum++;
+ }
+ }
+
+ for(int i=0; i<MAXCARD; i++)
+ {
+ if(cardlist[i] != NULL)
+ free(cardlist[i]);
+ }
+ return connum;
+}
+void printedid(char edid[])
+{
+ printf("%0004hhx: ",0);
+ for(int j=0;j<MAXEDID;j++)
+ {
+ if(j%8 == 0 && j != 0)
+ printf(" ");
+ if(j%16 ==0 && j != 0)
+ printf("\n%0004hhx: ",j);
+ printf("%02hhx ",edid[j]);
+ }
+ printf("\n");
+
+}
+char chrmap(char ch)
+{
+ return 'A'+ch-1;
+}
+void analizeedid(char edid[])
+{
+ char head[]={0x0,0xff,0xff,0xff,0xff,0xff,0xff,0x0};
+ if( memcmp(edid,head,8) !=0)
+ puts("Bad edid file\n");
+ union mfdata
+ {
+ struct
+ {
+ int c:5;
+ int b:5;
+ int a:5;
+ // char b:5;
+ // char c:5;
+ } idchr;
+ struct
+ {
+ int lb:8;
+ int hb:8;
+ }singlechr;
+ } mfid;
+ mfid.singlechr.hb = edid[8];
+ mfid.singlechr.lb = edid[9];
+
+ //printf("ManufactureID: %02hhx %02hhx %02hhx\n",mfid.idchr.a,mfid.idchr.b,mfid.idchr.c);
+ printf("ManufactureID: %c%c%c\n",chrmap(mfid.idchr.a),chrmap(mfid.idchr.b),chrmap(mfid.idchr.c));
+ printf("Monitor ID: %hhx%hhx\n",edid[0xb],edid[0xa]);
+ printf("Monitor SeriesID: %c%c%c%c\n",edid[0xf],edid[0xe],edid[0xd],edid[0xc]);
+ printf("Product Week/year: %d/%d\n",edid[0x10],edid[0x11]+1990);
+ printf("Edid Version: %hhx.%hhx\n",edid[0x12],edid[0x13]);
+ struct
+ {
+ char serrationvsync:1;
+ char syncongreen:1;
+ char compositesync:1;
+ char separatesyncs:1;
+ char blanktoblacksetup:1;
+ char videolevel:2;
+ char analogordigital:1;
+ } inputdef;
+ memcpy(&inputdef,&edid[0x14],1);
+ char msg[256];
+ if(inputdef.analogordigital)
+ strcat(msg,"Digital");
+ else
+ strcat(msg, "Analogor");
+ printf("Monitor Type: %s\n",msg);
+
+ printf("MaxImage size: %hhdcm x %hhdcm\n",edid[0x15],edid[0x16]);
+ printf("Monitor Gamma: %.2f\n",((edid[0x17]+100)*1.0/100.0));
+
+ struct
+ {
+ char GTFSupport:1;
+ char perfertimemod:1;
+ char stdcolorspace:1;
+ char monchrome:2;
+ char activeoff:1;
+ char suspend:1;
+ char standby:1;
+ } powman;
+ memcpy(&powman,&edid[0x18],1);
+ memset(msg,0,256);
+ if(powman.standby) strcat(msg,"standby ");
+ if(powman.suspend) strcat(msg,"suspend ");
+ if(powman.activeoff) strcat(msg,"activeoff ");
+ if(!(powman.monchrome & 3)) strcat(msg,"monochrome ");
+ else if(powman.activeoff & 1) strcat(msg,"RGB ");
+ else if(powman.activeoff & 2) strcat(msg,"Non RGB ");
+ else if(powman.activeoff & 3) strcat(msg,"Undefineed ");
+ printf("MonitorPowerSupport: %s\n",msg);
+
+ printf("Chroma Info: %hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx \n",edid[0x19],edid[0x1a],edid[0x1b],edid[0x1c],edid[0x1d],edid[0x1e],edid[0x1f],edid[0x20],edid[0x21],edid[0x22]);
+
+ char estiming[512];
+ memset(estiming,0,512);
+ if(edid[0x24] & 1) strcat(estiming,"1280x1024@75 ");
+ if(edid[0x24] & 2) strcat(estiming,"1024x768@75 ");
+ if(edid[0x24] & 4) strcat(estiming,"1024x768@70 ");
+ if(edid[0x24] & 8) strcat(estiming,"1024x768@60 ");
+ if(edid[0x24] & 16) strcat(estiming,"1024x768@87 ");
+ if(edid[0x24] & 32) strcat(estiming,"832x624@75 ");
+ if(edid[0x24] & 64) strcat(estiming,"800x600@75 ");
+ if(edid[0x24] & 128) strcat(estiming,"800x600@72 ");
+
+ if(edid[0x23] & 1) strcat(estiming,"800x600@60 ");
+ if(edid[0x23] & 2) strcat(estiming,"800x600@56 ");
+ if(edid[0x23] & 4) strcat(estiming,"640x480@75 ");
+ if(edid[0x23] & 8) strcat(estiming,"640x480@72 ");
+ if(edid[0x23] & 16) strcat(estiming,"640x480@67 ");
+ if(edid[0x23] & 32) strcat(estiming,"640x480@60 ");
+ if(edid[0x23] & 64) strcat(estiming,"720x400@88 ");
+ if(edid[0x23] & 128) strcat(estiming,"720x400@70 ");
+
+ printf("Established Timing: \n");
+ int len=strlen(estiming);
+ for(int i=0;i<len;i++)
+ {
+ if(estiming[i] == ' ')
+ printf("\n");
+ else
+ printf("%c",estiming[i]);
+ }
+ char stdtiming[8][256];
+ struct
+ {
+ int vertfrequency:6;
+ int aspectratio:2;
+ }stdtiminginfo;
+ printf("Stand timing:\n");
+ for(int i=0;i<8;i++)
+ {
+ int tem=0;
+ memcpy(&tem,&edid[38+2*i],1);
+ memcpy(&stdtiminginfo,&edid[39+2*i],1);
+ memset(msg,0,256);
+ if(!(stdtiminginfo.aspectratio & 3)) strcat(msg,"16:10");
+ else if(stdtiminginfo.aspectratio & 1) strcat(msg,"4:3");
+ else if(stdtiminginfo.aspectratio & 2) strcat(msg,"5:4");
+ else if(stdtiminginfo.aspectratio & 3) strcat(msg,"16:9");
+
+ if(tem != 1)
+ printf("%d: %d(H) %d(V) %s\n",i,tem*8+248,stdtiminginfo.vertfrequency+60,msg);
+ }
+ union
+ {
+ struct
+ {
+ int clkl:8;
+ int clkh:8;
+ int :16;
+ }clkchr;
+ int clk;
+ }pixclk;
+ union
+ {
+ struct
+ {
+ int vdispl:8;
+ int vdisph:4;
+ int :0;
+ }vdispchr;
+ int value;
+ }vdisp;
+
+ union
+ {
+ struct
+ {
+ int syncl:8;
+ int synch:2;
+ }syncchr;
+ int value;
+ }sync;
+
+
+ for(int i=0;i<4;i++)
+ {
+ pixclk.clkchr.clkh =edid[0x36 +i*18];
+ pixclk.clkchr.clkl=edid[0x37 + i*18];
+ if(pixclk.clk == 0) continue;
+ printf("pixel clock: %d\n",pixclk.clk*10);
+ union
+ {
+ struct
+ {
+ char blank:4;
+ char disp:4;
+ }h4bitchr;
+ char value;
+ }h4bit;
+ vdisp.vdispchr.vdispl=edid[0x36+ i*18+ 2];
+ h4bit.value = edid[0x36+ i*18+ 4];
+ vdisp.vdispchr.vdispl=edid[0x36+ i*18+ 2];
+ vdisp.vdispchr.vdisph=h4bit.h4bitchr.disp;
+ printf("Hdisplay: %d\n",vdisp.value);
+
+ memset(&h4bit,0,1);
+ memset(&vdisp,0,4);
+ vdisp.vdispchr.vdispl=edid[0x36+ i*18+ 5];
+ h4bit.value = edid[0x36+ i*18+ 7];
+ vdisp.vdispchr.vdispl=edid[0x36+ i*18+ 5];
+ vdisp.vdispchr.vdisph=h4bit.h4bitchr.disp;
+ printf("Vdisplay: %d\n",vdisp.value);
+
+ memset(&h4bit,0,1);
+ memset(&vdisp,0,4);
+ vdisp.vdispchr.vdispl=edid[0x36+ i*18+ 3];
+ h4bit.value = edid[0x36+ i*18+ 4];
+ vdisp.vdispchr.vdispl=edid[0x36+ i*18+ 3];
+ vdisp.vdispchr.vdisph=h4bit.h4bitchr.blank;
+ printf("Hblank:: %d\n",vdisp.value);
+
+ memset(&h4bit,0,1);
+ memset(&vdisp,0,4);
+ vdisp.vdispchr.vdispl=edid[0x36+ i*18+ 6];
+ h4bit.value = edid[0x36+ i*18+ 7];
+ vdisp.vdispchr.vdispl=edid[0x36+ i*18+ 6];
+ vdisp.vdispchr.vdisph=h4bit.h4bitchr.blank;
+ printf("Vblank: %d\n",vdisp.value);
+
+ union
+ {
+ struct
+ {
+ char vsync:2;
+ char dsync:2;
+ char hsync:2;
+ }chr;
+ char value;
+ }h2bit;
+ h2bit.value=edid[0x36+i*18+11];
+ memset(&sync,0,4);
+ sync.syncchr.syncl=edid[0x36+i*18+8];
+ sync.syncchr.synch=h2bit.chr.vsync;
+ printf("VSync: %d\n",sync.value);
+
+ }
+
+}
+int main(void)
+{
+ struct dirent *cardlist[MAXCARD];
+ char *edid[MAXCARD];
+ for(int i=0; i<MAXCARD; i++)
+ {
+ cardlist[i] = (struct dirent*)malloc(sizeof(struct dirent));
+ edid[i] = (char *)malloc(MAXEDID);
+ }
+
+ int connum = getconcardlist(cardlist,edid);
+ printf("The connected monitor number:%d\n",connum);
+
+ for(int i=0;i<connum;i++)
+ {
+ printf("%d Connected monitor card:%s\n",i+1,cardlist[i]->d_name);
+ printedid(edid[i]);
+ analizeedid(edid[i]);
+ }
+
+ for(int i=0; i<MAXCARD; i++)
+ {
+ if(cardlist[i] != NULL)
+ free(cardlist[i]);
+ if(edid[i] != NULL)
+ free(edid[i]);
+ }
+ return 0;
+}
+
+