Iztech Fork
Fork of A2_Interface3_V_0_0 by
Embed:
(wiki syntax)
Show/hide line numbers
Matrix.h
00001 /* 00002 Programmer: Roger McArdell 00003 Date: 03/08/2017 00004 Version 00005 V0.1 First version 00006 */ 00007 00008 static uint8_t MatrixAddWrite = '\x88'; 00009 static uint8_t MatrixAddRead = '\x89'; 00010 00011 // Prototypes 00012 void SwitchMatrix(uint8_t PortA, uint8_t PortB); 00013 void ReadMatrix(char Add,int Bytes); 00014 void WriteMatrix(string Contents); 00015 char GetConnectedStatus(); 00016 00017 bool HDMI1Sync = 0; 00018 bool HDMI2Sync = 0; 00019 bool HDMI3Sync = 0; 00020 bool HDMI4Sync = 0; 00021 bool ExternalSync = 0; 00022 00023 void SwitchMatrix(uint8_t PortA, uint8_t PortB) 00024 { 00025 //Split mode; Reg 02,byte 0 bit 3 = 1; TXA and TXB are the same 00026 //Mux mode; Reg 02,byte 0 bit 3 = 0; TXA and TXB are individually selected, but must not be the same (default) 00027 uint8_t TempA; 00028 uint8_t TempB; 00029 char data[2]; 00030 00031 printf("Switch Matrix, PortA: %d, PortB: %dr\n", PortA, PortB); 00032 aboxPort.printf("MAT%d%d\n", IDNumber, PortA); 00033 00034 TempA = PortA - 49; 00035 00036 switch(PortB) 00037 { 00038 case'1': TempB = 0; // 0000 00039 case'2': TempB = 4; // 0100 00040 case'3': TempB = 8; // 1000 00041 case'4': TempB = 12;// 1100 00042 } 00043 00044 if (PortA == PortB) 00045 { 00046 WriteMatrix("MR0288\x0D"); // select Split mode: Reg02, 10001000 \x88 00047 00048 switch(PortA) 00049 { 00050 case'1': WriteMatrix("MR0700\x0D"); break; 00051 case'2': WriteMatrix("MR0701\x0D"); break; 00052 case'3': WriteMatrix("MR0702\x0D"); break; 00053 case'4': WriteMatrix("MR0703\x0D"); break; 00054 } 00055 } 00056 else 00057 { 00058 WriteMatrix("MR0280\x0D"); // Select Mux mode: Reg02, 1000000 \x80 00059 00060 data[0] = '\x07'; 00061 data[1] = TempA + TempB;; 00062 00063 printf("Register: %d", data[0]); 00064 printf(" With data: %d ",data[1]); 00065 printf(" (numbers in decimal)\r\n"); 00066 00067 I2CHDMI.start(); // Not sure if this is required. 00068 I2CHDMI.write(MatrixAddWrite, data, 2); 00069 I2CHDMI.stop(); 00070 } 00071 } 00072 void ReadMatrix(char SlaveAdd,int Bytes) 00073 { 00074 char TempRead[Bytes]; 00075 I2CHDMI.start(); // Not sure if this is required. 00076 I2CHDMI.write(MatrixAddWrite, &SlaveAdd, 1, true); // "repeated-START condition" required, set by the true statement 00077 I2CHDMI.read(MatrixAddRead, TempRead, Bytes); 00078 I2CHDMI.stop(); 00079 00080 pc.printf("Register %d: \r\n",SlaveAdd); 00081 for (uint8_t I = 0; I < Bytes; I++) 00082 { 00083 pc.printf("Value is %d: \r\n",TempRead[I]); 00084 } 00085 } 00086 00087 void WriteMatrix(string Contents) 00088 { 00089 char data[10]; 00090 uint8_t NoOfBytes = 0; 00091 00092 //printf("1 Length: %d Contents: %s\r\n", Contents.length(), Contents.c_str()); 00093 //printf("\r\n"); 00094 00095 uint8_t I = 0; 00096 uint8_t J = 0; 00097 bool Even = 1; 00098 while (Contents[I] != '\x0D') 00099 { 00100 if (Even) 00101 { 00102 //printf("Even I=%d, Byte = %d ", I, Contents[I+2]); 00103 if (Contents[I+2] >= 48 && Contents[I+2] <= 57) 00104 data[J] = (Contents[I+2] - 48)*16; // move to the most significate nibble 00105 else if (Contents[I+2] >= 65 && Contents[I+2] <= 70) 00106 data[J] = (Contents[I+2] - 55)*16; 00107 else if (Contents[I+2] >= 97 && Contents[I+2] <= 102) 00108 data[J] = (Contents[I+2] - 87)*16; 00109 Even = 0; 00110 //printf("data[J] = %d, J = %d\r\n", data[J], J); 00111 } 00112 else 00113 { 00114 //printf("Odd I=%d, Byte = %d ", I, Contents[I+2]); 00115 if (Contents[I+2] >= 48 && Contents[I+2] <= 57) 00116 data[J] = data[J] + (Contents[I+2] - 48); 00117 else if (Contents[I+2] >= 65 && Contents[I+2] <= 70) 00118 data[J] = data[J] + (Contents[I+2] - 55); 00119 else if (Contents[I+2] >= 97 && Contents[I+2] <= 102) 00120 data[J] = data[J] + (Contents[I+2] - 87); 00121 //printf("data[J] = %d, J = %d\r\n", data[J], J); 00122 00123 NoOfBytes = J; 00124 J++; 00125 Even = 1; 00126 } 00127 I++; 00128 } 00129 pc.printf("Register: %d", data[0]); 00130 pc.printf(" With data:"); 00131 for (I = 1; I < NoOfBytes; I++) 00132 { 00133 printf(" %d ",data[I]); 00134 } 00135 pc.printf(" (numbers in decimal)\r\n"); 00136 00137 I2CHDMI.start(); // Not sure if this is required. 00138 I2CHDMI.write(MatrixAddWrite, data, NoOfBytes); 00139 I2CHDMI.stop(); 00140 } 00141 char GetConnectedStatus() 00142 { 00143 char TempRead[3]; 00144 char SlaveAdd = '\x07'; 00145 I2CHDMI.start(); // Not sure if this is required. 00146 I2CHDMI.write(MatrixAddWrite, &SlaveAdd, 1, true); // "repeated-START condition" required, set by the true statement 00147 I2CHDMI.read(MatrixAddRead, TempRead, 3); 00148 I2CHDMI.stop(); 00149 00150 return TempRead[2]; 00151 } 00152 00153 00154 00155
Generated on Tue Aug 2 2022 20:48:37 by
1.7.2
