You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1141 lines
37 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. /*
  2. This is an example of how to write a library that allows user to pass in an I2C port
  3. Nathan Seidle
  4. SparkFun Electronics
  5. License: Public domain
  6. */
  7. #include "hud.h"
  8. //Initialize the I2C port
  9. bool begin(TwoWire & wirePort) {
  10. _i2cPort = & wirePort; //Grab which port the user wants us to use
  11. _i2cPort - > begin();
  12. initializeHUD231();
  13. }
  14. void AdjustIconLevel(uint16_t IconNo, uint16_t IconLevel) {
  15. uint16_t Temp;
  16. uint16_t Temp_I;
  17. uint8_t StartBytePos;
  18. uint8_t StartRGBPos;
  19. uint8_t EndBytePos;
  20. uint8_t EndRGBPos;
  21. uint8_t BumpNoTemp;
  22. uint8_t Counter;
  23. // uint8_t Result;
  24. if (IconLevel > 31) return; //If the IconLevel parameter is greater than 31, skip this function
  25. BumpNoTemp = IconData[IconNo].BumpNo;
  26. Temp = IconData[IconNo].StartBumpLocation; //Bump Location counts from 0
  27. StartBytePos = Temp / 3;
  28. StartRGBPos = Temp % 3; //A remainder of 0 means that the beginning Bump position is R, 1 means G, and 2 means B
  29. //==================================================================================================================================================================
  30. // Processing the first data
  31. // Maybe it's only this one, maybe there's more
  32. //==================================================================================================================================================================
  33. switch (StartRGBPos) {
  34. case 0: //Location in R
  35. if (BumpNoTemp == 1) {
  36. IconRamMap[IconData[IconNo].DriverNo][StartBytePos] = ChangeRedValue(IconRamMap[IconData[IconNo].DriverNo][StartBytePos], IconLevel);
  37. } else if (BumpNoTemp == 2) {
  38. IconRamMap[IconData[IconNo].DriverNo][StartBytePos] = ChangeRG_Value(IconRamMap[IconData[IconNo].DriverNo][StartBytePos], IconLevel);
  39. } else if (BumpNoTemp >= 3) {
  40. IconRamMap[IconData[IconNo].DriverNo][StartBytePos] = SetRGB_Value(IconLevel);
  41. }
  42. SendDataBuffer[0] = 0x0A;
  43. SendDataBuffer[1] = StartBytePos >> 4; //X Start
  44. SendDataBuffer[2] = StartBytePos & 0x0F;
  45. SendDataBuffer[3] = 0x07; //X End
  46. SendDataBuffer[4] = 0x0F;
  47. SendDataBuffer[5] = 0; //Y Start
  48. SendDataBuffer[6] = 0;
  49. SendDataBuffer[7] = 0; //Y End
  50. SendDataBuffer[8] = 0;
  51. IIC_Write_Command1(IIC_Addr[IconData[IconNo].DriverNo], 9, SendDataBuffer);
  52. SendDataBuffer[0] = (IconRamMap[IconData[IconNo].DriverNo][StartBytePos] & 0xFF00) >> 8;
  53. SendDataBuffer[1] = IconRamMap[IconData[IconNo].DriverNo][StartBytePos] & 0xFF;
  54. if (BumpNoTemp <= 3) {
  55. IIC_Write_Data1(IIC_Addr[IconData[IconNo].DriverNo], 2, SendDataBuffer);
  56. return;
  57. } else {
  58. BumpNoTemp = BumpNoTemp - 3;
  59. }
  60. break;
  61. case 1: //Location in G
  62. if (BumpNoTemp == 1) {
  63. IconRamMap[IconData[IconNo].DriverNo][StartBytePos] = ChangeGreenValue(IconRamMap[IconData[IconNo].DriverNo][StartBytePos], IconLevel);
  64. } else if (BumpNoTemp >= 2) {
  65. IconRamMap[IconData[IconNo].DriverNo][StartBytePos] = ChangeGB_Value(IconRamMap[IconData[IconNo].DriverNo][StartBytePos], IconLevel);
  66. }
  67. //Set the position setting to write
  68. SendDataBuffer[0] = 0x0A;
  69. SendDataBuffer[1] = StartBytePos >> 4; //X Start
  70. SendDataBuffer[2] = StartBytePos & 0x0F;
  71. SendDataBuffer[3] = 0x07; //X End
  72. SendDataBuffer[4] = 0x0F;
  73. SendDataBuffer[5] = 0; //Y Start
  74. SendDataBuffer[6] = 0;
  75. SendDataBuffer[7] = 0; //Y End
  76. SendDataBuffer[8] = 0;
  77. IIC_Write_Command1(IIC_Addr[IconData[IconNo].DriverNo], 9, SendDataBuffer);
  78. SendDataBuffer[0] = (IconRamMap[IconData[IconNo].DriverNo][StartBytePos] & 0xFF00) >> 8;
  79. SendDataBuffer[1] = IconRamMap[IconData[IconNo].DriverNo][StartBytePos] & 0xFF;
  80. IIC_Write_Data1(IIC_Addr[IconData[IconNo].DriverNo], 2, SendDataBuffer);
  81. SendDataBuffer[0] = (IconRamMap[IconData[IconNo].DriverNo][StartBytePos] & 0xFF00) >> 8; //Store the first data in Buffer 0 & 1
  82. SendDataBuffer[1] = IconRamMap[IconData[IconNo].DriverNo][StartBytePos] & 0xFF;
  83. if (BumpNoTemp <= 2) {
  84. IIC_Write_Data1(IIC_Addr[IconData[IconNo].DriverNo], 2, SendDataBuffer);
  85. return;
  86. } else {
  87. BumpNoTemp = BumpNoTemp - 2;
  88. }
  89. break;
  90. case 2: //Location in B
  91. IconRamMap[IconData[IconNo].DriverNo][StartBytePos] = ChangeBlueValue(IconRamMap[IconData[IconNo].DriverNo][StartBytePos], IconLevel);
  92. //Set the position setting to write
  93. SendDataBuffer[0] = 0x0A;
  94. SendDataBuffer[1] = StartBytePos >> 4; //X Start
  95. SendDataBuffer[2] = StartBytePos & 0x0F;
  96. SendDataBuffer[3] = 0x07; //X End
  97. SendDataBuffer[4] = 0x0F;
  98. SendDataBuffer[5] = 0; //Y Start
  99. SendDataBuffer[6] = 0;
  100. SendDataBuffer[7] = 0; //Y End
  101. SendDataBuffer[8] = 0;
  102. IIC_Write_Command1(IIC_Addr[IconData[IconNo].DriverNo], 9, SendDataBuffer);
  103. SendDataBuffer[0] = (IconRamMap[IconData[IconNo].DriverNo][StartBytePos] & 0xFF00) >> 8;
  104. SendDataBuffer[1] = IconRamMap[IconData[IconNo].DriverNo][StartBytePos] & 0xFF;
  105. if (BumpNoTemp == 1) {
  106. IIC_Write_Data1(IIC_Addr[IconData[IconNo].DriverNo], 2, SendDataBuffer);
  107. return;
  108. } else {
  109. BumpNoTemp = BumpNoTemp - 1;
  110. }
  111. break;
  112. }
  113. //==================================================================================================================================================================
  114. //Processing later information
  115. //==================================================================================================================================================================
  116. EndBytePos = BumpNoTemp / 3;
  117. EndRGBPos = BumpNoTemp % 3;
  118. Counter = 1; //Previous [0], [1] store the data of the first SEG
  119. if (EndBytePos >= 1) { // Process complete
  120. //So far there are several complete RGB (16bit) data
  121. for (Temp_I = 1; Temp_I <= EndBytePos; Temp_I++) {
  122. IconRamMap[IconData[IconNo].DriverNo][StartBytePos + Temp_I] = SetRGB_Value(IconLevel);
  123. Counter = Counter + 1;
  124. SendDataBuffer[Counter] = (IconRamMap[IconData[IconNo].DriverNo][StartBytePos + Temp_I] & 0xFF00) >> 8; //Save High byte data in the following Buffer
  125. Counter = Counter + 1;
  126. SendDataBuffer[Counter] = IconRamMap[IconData[IconNo].DriverNo][StartBytePos + Temp_I] & 0xFF; //Save Low byte data in the following Buffer
  127. }
  128. if (EndRGBPos == 0) {
  129. //If there is no remainder, there is no need to process the remaining R, G, B bits. After exiting the entire batch of data, exit.
  130. IIC_Write_Data1(IIC_Addr[IconData[IconNo].DriverNo], Counter + 1, SendDataBuffer);
  131. return;
  132. }
  133. }
  134. //=================================================================================================================================================================
  135. //Check the remaining number of Bits
  136. switch (EndRGBPos) {
  137. case 1: //Location in R
  138. IconRamMap[IconData[IconNo].DriverNo][StartBytePos + EndBytePos + 1] = ChangeRedValue(IconRamMap[IconData[IconNo].DriverNo][StartBytePos + EndBytePos + 1], IconLevel);
  139. break;
  140. case 2: //Location in G
  141. IconRamMap[IconData[IconNo].DriverNo][StartBytePos + EndBytePos + 1] = ChangeRG_Value(IconRamMap[IconData[IconNo].DriverNo][StartBytePos + EndBytePos + 1], IconLevel);
  142. break;
  143. }
  144. Counter = Counter + 1;
  145. //With this last data send out
  146. SendDataBuffer[Counter] = (IconRamMap[IconData[IconNo].DriverNo][StartBytePos + EndBytePos + 1] & 0xFF00) >> 8;
  147. Counter = Counter + 1;
  148. SendDataBuffer[Counter] = IconRamMap[IconData[IconNo].DriverNo][StartBytePos + EndBytePos + 1] & 0xFF;
  149. IIC_Write_Data1(IIC_Addr[IconData[IconNo].DriverNo], Counter + 1, SendDataBuffer);
  150. }
  151. uint16_t ChangeRedValue(uint16_t OriginalValue, uint16_t R_Value) {
  152. uint16_t Temp;
  153. if (R_Value > 31) return 0; //If R value is greater than 31, return 0
  154. Temp = OriginalValue & 0x7FF; //Clear R (high 5 bits) to 0
  155. Temp = Temp | (R_Value << 11); //Set R new value back
  156. return Temp;
  157. }
  158. uint16_t ChangeGreenValue(uint16_t OriginalValue, uint16_t G_Value) {
  159. uint16_t Temp;
  160. if (G_Value > 31) return 0; //If the G value is greater than 31, return 0
  161. Temp = OriginalValue & 0xF81F; //Clear the G value (6 bits) to 0
  162. Temp = Temp | (G_Value << 6); //Set G high 5bit new value back
  163. if (G_Value > 0x0f)
  164. Temp = Temp | 0x20; //Set bit0 of G to 1
  165. else
  166. Temp = Temp & 0xFFDF; //Set bit0 of G to 0
  167. return Temp;
  168. }
  169. uint16_t ChangeBlueValue(uint16_t OriginalValue, uint16_t B_Value) {
  170. uint16_t Temp;
  171. if (B_Value > 31) return 0; //If the B value is greater than 31, then return 0
  172. Temp = OriginalValue & 0xFFE0; //Clear the B value (5 bits) to 0
  173. Temp = Temp | B_Value; //Set the new value of B 5bit back
  174. return Temp;
  175. }
  176. uint16_t ChangeRG_Value(uint16_t OriginalValue, uint16_t RG_Value) {
  177. uint16_t Temp;
  178. if (RG_Value > 31) return 0; //If the value is greater than 31, return 0
  179. Temp = OriginalValue & 0x1F; //Clear the RG value (11 bits) to 0
  180. Temp = Temp | (RG_Value << 11) | (RG_Value << 6); //Set R 5bit, G 6bit new value back
  181. if (RG_Value > 0x0f)
  182. Temp = Temp | 0x20; //Set bit0 of G to 1
  183. else
  184. Temp = Temp & 0xFFDF; //Set bit0 of G to 0
  185. return Temp;
  186. }
  187. uint16_t ChangeGB_Value(uint16_t OriginalValue, uint16_t GB_Value) {
  188. uint16_t Temp;
  189. if (GB_Value > 31) return 0; //If the value is greater than 31, return 0
  190. Temp = OriginalValue & 0xF800; //Clear the GB value (11 bits) to 0
  191. Temp = Temp | (GB_Value << 6) | GB_Value; //Set G 6bit, B 5bit new value back
  192. if (GB_Value > 0x0f)
  193. Temp = Temp | 0x20; //Set bit0 of G to 1
  194. else
  195. Temp = Temp & 0xFFDF; //Set bit0 of G to 0
  196. return Temp;
  197. }
  198. uint16_t SetRGB_Value(uint16_t RGB_Value) {
  199. uint16_t Temp;
  200. if (RGB_Value > 31) return 0; //If the value is greater than 31, return 0
  201. Temp = (RGB_Value << 11) | (RGB_Value << 6) | RGB_Value;
  202. if (RGB_Value > 0x0f)
  203. Temp = Temp | 0x20; //Set bit0 of G to 1
  204. else
  205. Temp = Temp & 0xFFDF; //Set bit0 of G to 0
  206. return Temp;
  207. }
  208. void NumericalTo4BCD(uint16_t S_Number, uint8_t * BCD_Ptr) {
  209. uint8_t i;
  210. uint16_t Quotient;
  211. uint16_t QuotienNav;
  212. Quotient = S_Number;
  213. for (i = 0; i <= 3; i++) {
  214. QuotienNav = Quotient / 10;
  215. BCD_Ptr[i] = Quotient % 10;
  216. Quotient = QuotienNav;
  217. }
  218. }
  219. //=======================================================================================================
  220. //The following for HUD231 standard products
  221. //=======================================================================================================
  222. #define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_A,_B,NAME,...) NAME
  223. #define AdjustIconsOn(...) GET_MACRO(__VA_ARGS__,AIOnB,AIOnA,AIOn9,AIOn8,AIOn7,AIOn6,AIOn5,AIOn4,AIOn3,AIOn2)(__VA_ARGS__)
  224. #define AdjustIconsOfff(...) GET_MACRO(__VA_ARGS__,AIOffB,AIOffA,AIOff9,AIOff8,AIOff7,AIOff6,AIOff5,AIOff4,AIOff3,AIOff2)(__VA_ARGS__)
  225. #define AIOn2(a, b) AIOn(a); AIOn(b)
  226. #define AIOn3(a, b, c) AIOn(a); AIOn(b); AIOn(c)
  227. #define AIOn4(a, b, c, d) AIOn(a); AIOn(b); AIOn(c); AIOn(d)
  228. #define AIOn5(a, b, c, d, e) AIOn(a); AIOn(b); AIOn(c); AIOn(d); AIOn(e)
  229. #define AIOn6(a, b, c, d, e, f) AIOn(a); AIOn(b); AIOn(c); AIOn(d); AIOn(e); AIOn(f)
  230. #define AIOn7(a, b, c, d, e, f, g) AIOn(a); AIOn(b); AIOn(c); AIOn(d); AIOn(e); AIOn(f); AIOn(g)
  231. #define AIOn8(a, b, c, d, e, f, g, h) AIOn(a); AIOn(b); AIOn(c); AIOn(d); AIOn(e); AIOn(f); AIOn(g); AIOn(h)
  232. #define AIOn9(a, b, c, d, e, f, g, h, i) AIOn(a); AIOn(b); AIOn(c); AIOn(d); AIOn(e); AIOn(f); AIOn(g); AIOn(h); AIOn(i)
  233. #define AIOnA(a, b, c, d, e, f, g, h, i, j) AIOn(a); AIOn(b); AIOn(c); AIOn(d); AIOn(e); AIOn(f); AIOn(g); AIOn(h); AIOn(i); AIOn(j)
  234. #define AIOnB(a, b, c, d, e, f, g, h, i, j, k) AIOn(a); AIOn(b); AIOn(c); AIOn(d); AIOn(e); AIOn(f); AIOn(g); AIOn(h); AIOn(i); AIOn(j); AIOn(k)
  235. #define AIOff2(a, b) AIoff(a); AIoff(b)
  236. #define AIOff3(a, b, c) AIoff(a); AIoff(b); AIoff(c)
  237. #define AIOff4(a, b, c, d) AIoff(a); AIoff(b); AIoff(c); AIoff(d)
  238. #define AIOff5(a, b, c, d, e) AIoff(a); AIoff(b); AIoff(c); AIoff(d); AIoff(e)
  239. #define AIOff6(a, b, c, d, e, f) AIoff(a); AIoff(b); AIoff(c); AIoff(d); AIoff(e); AIoff(f)
  240. #define AIOff7(a, b, c, d, e, f, g) AIoff(a); AIoff(b); AIoff(c); AIoff(d); AIoff(e); AIoff(f); AIoff(g)
  241. #define AIOff8(a, b, c, d, e, f, g, h) AIoff(a); AIoff(b); AIoff(c); AIoff(d); AIoff(e); AIoff(f); AIoff(g); AIoff(h)
  242. #define AIOff9(a, b, c, d, e, f, g, h, i) AIoff(a); AIoff(b); AIoff(c); AIoff(d); AIoff(e); AIoff(f); AIoff(g); \AIoff(h); AIoff(i)
  243. #define AIOffA(a, b, c, d, e, f, g, h, i, j) AIoff(a); AIoff(b); AIoff(c); AIoff(d); AIoff(e); AIoff(f); AIoff(g); AIoff(h); AIoff(i); AIoff(j)
  244. #define AIOffB(a, b, c, d, e, f, g, h, i, j, k) AIoff(a); AIoff(b); AIoff(c); AIoff(d); AIoff(e); AIoff(f); AIoff(g); AIoff(h); AIoff(i); AIoff(j); AIoff(k)
  245. void AIOn(uint16_t IconNo) {
  246. AdjustIconLevel(IconNo, IconData[IconNo].Level);
  247. }
  248. void AIoff(uint16_t IconNo) {
  249. AdjustIconLevel(IconNo, 0x00);
  250. }
  251. void AdjustIconAction(uint16_t IconNo, bool Action) {
  252. if (Action) {
  253. AIOn(IconNo);
  254. } else {
  255. AIoff(IconNo);
  256. }
  257. }
  258. #define D01(Action) AdjustIconAction(0, Action)
  259. #define D02(Action) AdjustIconAction(2, Action)
  260. #define D03(Action) AdjustIconAction(4, Action)
  261. #define D04(Action) AdjustIconAction(9, Action)
  262. #define D05(Action) AdjustIconAction(18, Action)
  263. #define D06(Action) AdjustIconAction(26, Action)
  264. #define D07(Action) AdjustIconAction(29, Action)
  265. #define D08(Action) AdjustIconAction(31, Action)
  266. #define D0A(a, b, c, d, e, f, g, h) D01(a); D02(b); D03(c); D04(d); D05(e); D06(f); D07(g); D08(h)
  267. #define CC1(Action) AdjustIconAction(1, Action)
  268. #define CC2(Action) AdjustIconAction(3, Action)
  269. #define CC3(Action) AdjustIconAction(5, Action)
  270. #define CC4(Action) AdjustIconAction(8, Action)
  271. #define CC5(Action) AdjustIconAction(17, Action)
  272. #define CC6(Action) AdjustIconAction(27, Action)
  273. #define CC7(Action) AdjustIconAction(28, Action)
  274. #define CC8(Action) AdjustIconAction(30, Action)
  275. #define CCA(a, b, c, d, e, f, g, h) CC1(a); CC2(b); CC3(c); CC4(d); CC5(e); CC6(f); CC7(g); CC8(h)
  276. //0-9 00-full off 1-8 => specify which CCx goes off 9-all bright 10-17=> specifies which CCx is on (inverse with 1-8)
  277. void compassCircle(uint8_t Select) {
  278. switch (Select) {
  279. case 0: CCA(0, 0, 0, 0, 0, 0, 0, 0); break;
  280. case 1: CCA(1, 0, 0, 0, 0, 0, 0, 0); break;
  281. case 2: CCA(0, 1, 0, 0, 0, 0, 0, 0); break;
  282. case 3: CCA(0, 0, 1, 0, 0, 0, 0, 0); break;
  283. case 4: CCA(0, 0, 0, 1, 0, 0, 0, 0); break;
  284. case 5: CCA(0, 0, 0, 0, 1, 0, 0, 0); break;
  285. case 6: CCA(0, 0, 0, 0, 0, 1, 0, 0); break;
  286. case 7: CCA(0, 0, 0, 0, 0, 0, 1, 0); break;
  287. case 8: CCA(0, 0, 0, 0, 0, 0, 0, 1); break;
  288. case 9: CCA(1, 1, 1, 1, 1, 1, 1, 1); break;
  289. case 10: CCA(0, 1, 1, 1, 1, 1, 1, 1); break;
  290. case 11: CCA(1, 0, 1, 1, 1, 1, 1, 1); break;
  291. case 12: CCA(1, 1, 0, 1, 1, 1, 1, 1); break;
  292. case 13: CCA(1, 1, 1, 0, 1, 1, 1, 1); break;
  293. case 14: CCA(1, 1, 1, 1, 0, 1, 1, 1); break;
  294. case 15: CCA(1, 1, 1, 1, 1, 0, 1, 1); break;
  295. case 16: CCA(1, 1, 1, 1, 1, 1, 0, 1); break;
  296. case 17: CCA(1, 1, 1, 1, 1, 1, 1, 0); break;
  297. }
  298. }
  299. void D0x(uint8_t Action) {
  300. if (Action) {
  301. D01(1); D02(1); D03(1); D04(1); D05(1); D06(1); D07(1); D08(1);
  302. } else {
  303. D01(0); D02(0); D03(0); D04(0); D05(0); D06(0); D07(0); D08(0);
  304. }
  305. }
  306. //0-9 00-full off 1-8 => specify which one is off D0x 9-all bright 10-17=> specify which one D0x is on (inverse with 1-8)
  307. void compassArrows(uint8_t Select) {
  308. switch (Select) {
  309. case 0: D0A(0, 0, 0, 0, 0, 0, 0, 0); break;
  310. case 1: D0A(1, 0, 0, 0, 0, 0, 0, 0); break;
  311. case 2: D0A(0, 1, 0, 0, 0, 0, 0, 0); break;
  312. case 3: D0A(0, 0, 1, 0, 0, 0, 0, 0); break;
  313. case 4: D0A(0, 0, 0, 1, 0, 0, 0, 0); break;
  314. case 5: D0A(0, 0, 0, 0, 1, 0, 0, 0); break;
  315. case 6: D0A(0, 0, 0, 0, 0, 1, 0, 0); break;
  316. case 7: D0A(0, 0, 0, 0, 0, 0, 1, 0); break;
  317. case 8: D0A(0, 0, 0, 0, 0, 0, 0, 1); break;
  318. case 9: D0A(1, 1, 1, 1, 1, 1, 1, 1); break;
  319. case 10: D0A(0, 1, 1, 1, 1, 1, 1, 1); break;
  320. case 11: D0A(1, 0, 1, 1, 1, 1, 1, 1); break;
  321. case 12: D0A(1, 1, 0, 1, 1, 1, 1, 1); break;
  322. case 13: D0A(1, 1, 1, 0, 1, 1, 1, 1); break;
  323. case 14: D0A(1, 1, 1, 1, 0, 1, 1, 1); break;
  324. case 15: D0A(1, 1, 1, 1, 1, 0, 1, 1); break;
  325. case 16: D0A(1, 1, 1, 1, 1, 1, 0, 1); break;
  326. case 17: D0A(1, 1, 1, 1, 1, 1, 1, 0); break;
  327. }
  328. }
  329. #define radarDistanceUnits(Action) AdjustIconAction(80, Action)
  330. #define flag(Action) AdjustIconAction(32, Action)
  331. #define C01(Action) AdjustIconAction(40, Action)
  332. #define C02(Action) AdjustIconAction(48, Action)
  333. #define H01(Action) AdjustIconAction(58, Action)
  334. #define K01(Action) AdjustIconAction(56, Action)
  335. #define M01(Action) AdjustIconAction(57, Action)
  336. #define C03(Action) AdjustIconAction(145, Action)
  337. #define K02(Action) AdjustIconAction(153, Action)
  338. #define M03(Action) AdjustIconAction(154, Action)
  339. #define P01(Action) AdjustIconAction(211, Action)
  340. #define P02(Action) AdjustIconAction(212, Action)
  341. #define P03(Action) AdjustIconAction(213, Action)
  342. #define T01(Action) AdjustIconAction(189, Action)
  343. #define T02(Action) AdjustIconAction(197, Action)
  344. void tirePressureAlert(uint8_t Action) {
  345. switch (Action) {
  346. case 0: // Blank
  347. T01(0); // "tire"
  348. T02(0); // "TPMS"
  349. break;
  350. case 1: // TPMS
  351. T01(0); // "tire"
  352. T02(1); // "TPMS"
  353. break;
  354. case 2: // Tire
  355. T01(1); // "tire"
  356. T02(0); // "TPMS"
  357. break;
  358. case 3: // Both
  359. T01(1); // "tire"
  360. T02(1); // "TPMS"
  361. break;
  362. }
  363. }
  364. #define speedometerUnits(Action) AdjustIconAction(230, Action)
  365. void destinationDistanceUnits(uint8_t iconUnits) {
  366. switch (iconUnits) {
  367. case 0: // Blank
  368. H01(0); // hours
  369. K01(0); // kilo
  370. M01(0); // meters
  371. break;
  372. case 1: // hours
  373. H01(1); // hours
  374. K01(0); // kilo
  375. M01(0); // meters
  376. break;
  377. case 2: // meters
  378. H01(0); // hours
  379. K01(0); // kilo
  380. M01(1); // meters
  381. break;
  382. case 3: // kilometers
  383. H01(0); // hours
  384. K01(1); // kilo
  385. M01(1); // meters
  386. break;
  387. }
  388. }
  389. void turnDistanceUnits(uint8_t iconUnits) {
  390. switch (iconUnits) {
  391. case 0: // Blank
  392. K02(0); // kilo
  393. M03(0); // meters
  394. break;
  395. case 1: // meters
  396. K02(0); // kilo
  397. M03(1); // meters
  398. break;
  399. case 2: // kilometers
  400. K02(1); // kilo
  401. M03(1); // meters
  402. break;
  403. }
  404. }
  405. void leftTunnel(uint8_t Action) {
  406. if (Action) {
  407. AdjustIconsOn(91, 92, 93, 94, 95, 96, 97, 98, 99);
  408. } else {
  409. AdjustIconsOff(91, 92, 93, 94, 95, 96, 97, 98, 99);
  410. }
  411. }
  412. void middleTunnel(uint8_t Action) {
  413. if (Action) {
  414. AdjustIconsOn(89, 90, 100, 101, 102, 198, 199, 209, 210);
  415. } else {
  416. AdjustIconsOff(89, 90, 100, 101, 102, 198, 199, 209, 210);
  417. }
  418. }
  419. void rightTunnel(uint8_t Action) {
  420. if (Action) {
  421. AdjustIconsOn(200, 201, 202, 203, 204, 205, 206, 207, 208);
  422. } else {
  423. AdjustIconsOff(200, 201, 202, 203, 204, 205, 206, 207, 208);
  424. }
  425. }
  426. void leftRoad(uint8_t Action) {
  427. if (Action) {
  428. AdjustIconsOn(91, 94, 95, 99);
  429. } else {
  430. AdjustIconsOff(91, 94, 95, 99);
  431. }
  432. }
  433. void middleRoad(uint8_t Action) {
  434. if (Action) {
  435. AdjustIconsOn(90, 100, 199, 209);
  436. } else {
  437. AdjustIconsOff(90, 100, 199, 209);
  438. }
  439. }
  440. void rightRoad(uint8_t Action) {
  441. if (Action) {
  442. AdjustIconsOn(200, 204, 205, 208);
  443. } else {
  444. AdjustIconsOff(200, 204, 205, 208);
  445. }
  446. }
  447. void nav_Group(uint8_t Action) {
  448. uint8_t i;
  449. if (Action) {
  450. for (i = 103; i <= 130; i++) {
  451. AdjustIconLevel(i, IconData[i].Level);
  452. }
  453. for (i = 155; i <= 181; i++) {
  454. AdjustIconLevel(i, IconData[i].Level);
  455. }
  456. } else {
  457. for (i = 103; i <= 130; i++) {
  458. AdjustIconLevel(i, 0x00);
  459. }
  460. for (i = 155; i <= 181; i++) {
  461. AdjustIconLevel(i, 0x00);
  462. }
  463. }
  464. }
  465. void nav_KeepLeft(uint8_t Action) {
  466. if (Action) {
  467. AdjustIconsOn(107, 108, 109, 106, 111, 112, 105, 128, 129, 155, 130);
  468. } else {
  469. AdjustIconsOff(107, 108, 109, 106, 111, 112, 105, 128, 129, 155, 130);
  470. }
  471. }
  472. void nav_TurnLeft(uint8_t Action) {
  473. if (Action) {
  474. AdjustIconsOn(113, 114, 121, 111, 112, 115, 128, 129, 155, 130);
  475. } else {
  476. AdjustIconsOff(113, 114, 121, 111, 112, 115, 128, 129, 155, 130);
  477. }
  478. }
  479. void nav_TurnRight(uint8_t Action) {
  480. if (Action) {
  481. AdjustIconsOn(171, 170, 163, 173, 172, 169, 156, 129, 155, 130);
  482. } else {
  483. AdjustIconsOff(171, 170, 163, 173, 172, 169, 156, 129, 155, 130);
  484. }
  485. }
  486. void nav_HardRight(uint8_t Action) {
  487. if (Action) {
  488. AdjustIconsOn(165, 159, 163, 160, 158, 166, 156, 129, 155, 130);
  489. } else {
  490. AdjustIconsOff(165, 159, 163, 160, 158, 166, 156, 129, 155, 130);
  491. }
  492. }
  493. void nav_HardLeft(uint8_t Action) {
  494. if (Action) {
  495. AdjustIconsOn(119, 125, 121, 124, 126, 118, 128, 129, 155, 130);
  496. } else {
  497. AdjustIconsOff(119, 125, 121, 124, 126, 118, 128, 129, 155, 130);
  498. }
  499. }
  500. void nav_UTurnLeft(uint8_t Action) {
  501. if (Action) {
  502. AdjustIconLevel(162, IconData[162].Level);
  503. AdjustIconLevel(166, IconData[166].Level);
  504. AdjustIconLevel(167, IconData[167].Level);
  505. AdjustIconLevel(168, IconData[168].Level);
  506. AdjustIconLevel(170, IconData[170].Level);
  507. AdjustIconLevel(174, IconData[174].Level);
  508. AdjustIconLevel(176, IconData[176].Level);
  509. AdjustIconLevel(179, IconData[179].Level);
  510. AdjustIconLevel(180, IconData[180].Level);
  511. AdjustIconLevel(104, IconData[104].Level);
  512. AdjustIconLevel(108, IconData[108].Level);
  513. AdjustIconLevel(110, IconData[110].Level);
  514. AdjustIconLevel(114, IconData[114].Level);
  515. AdjustIconLevel(116, IconData[116].Level);
  516. AdjustIconLevel(117, IconData[117].Level);
  517. AdjustIconLevel(118, IconData[118].Level);
  518. AdjustIconLevel(122, IconData[122].Level);
  519. AdjustIconLevel(123, IconData[123].Level);
  520. } else {
  521. AdjustIconLevel(162, 0x00);
  522. AdjustIconLevel(166, 0x00);
  523. AdjustIconLevel(167, 0x00);
  524. AdjustIconLevel(168, 0x00);
  525. AdjustIconLevel(170, 0x00);
  526. AdjustIconLevel(174, 0x00);
  527. AdjustIconLevel(176, 0x00);
  528. AdjustIconLevel(179, 0x00);
  529. AdjustIconLevel(180, 0x00);
  530. AdjustIconLevel(104, 0x00);
  531. AdjustIconLevel(108, 0x00);
  532. AdjustIconLevel(110, 0x00);
  533. AdjustIconLevel(114, 0x00);
  534. AdjustIconLevel(116, 0x00);
  535. AdjustIconLevel(117, 0x00);
  536. AdjustIconLevel(118, 0x00);
  537. AdjustIconLevel(122, 0x00);
  538. AdjustIconLevel(123, 0x00);
  539. }
  540. }
  541. void nav_UTurnRight(uint8_t Action) {
  542. if (Action) {
  543. AdjustIconLevel(162, IconData[162].Level);
  544. AdjustIconLevel(166, IconData[166].Level);
  545. AdjustIconLevel(167, IconData[167].Level);
  546. AdjustIconLevel(168, IconData[168].Level);
  547. AdjustIconLevel(170, IconData[170].Level);
  548. AdjustIconLevel(174, IconData[174].Level);
  549. AdjustIconLevel(176, IconData[176].Level);
  550. AdjustIconLevel(179, IconData[179].Level);
  551. AdjustIconLevel(180, IconData[180].Level);
  552. AdjustIconLevel(104, IconData[104].Level);
  553. AdjustIconLevel(108, IconData[108].Level);
  554. AdjustIconLevel(110, IconData[110].Level);
  555. AdjustIconLevel(114, IconData[114].Level);
  556. AdjustIconLevel(116, IconData[116].Level);
  557. AdjustIconLevel(117, IconData[117].Level);
  558. AdjustIconLevel(118, IconData[118].Level);
  559. AdjustIconLevel(122, IconData[122].Level);
  560. AdjustIconLevel(161, IconData[161].Level);
  561. } else {
  562. AdjustIconLevel(162, 0x00);
  563. AdjustIconLevel(166, 0x00);
  564. AdjustIconLevel(167, 0x00);
  565. AdjustIconLevel(168, 0x00);
  566. AdjustIconLevel(170, 0x00);
  567. AdjustIconLevel(174, 0x00);
  568. AdjustIconLevel(176, 0x00);
  569. AdjustIconLevel(179, 0x00);
  570. AdjustIconLevel(180, 0x00);
  571. AdjustIconLevel(104, 0x00);
  572. AdjustIconLevel(108, 0x00);
  573. AdjustIconLevel(110, 0x00);
  574. AdjustIconLevel(114, 0x00);
  575. AdjustIconLevel(116, 0x00);
  576. AdjustIconLevel(117, 0x00);
  577. AdjustIconLevel(118, 0x00);
  578. AdjustIconLevel(122, 0x00);
  579. AdjustIconLevel(161, 0x00);
  580. }
  581. }
  582. void nav_ContinueStraight(uint8_t Action) {
  583. // uint8_t i;
  584. if (Action) {
  585. AdjustIconLevel(181, IconData[181].Level);
  586. AdjustIconLevel(180, IconData[180].Level);
  587. AdjustIconLevel(103, IconData[103].Level);
  588. AdjustIconLevel(178, IconData[178].Level);
  589. AdjustIconLevel(105, IconData[105].Level);
  590. AdjustIconLevel(106, IconData[106].Level);
  591. AdjustIconLevel(173, IconData[173].Level);
  592. AdjustIconLevel(111, IconData[111].Level);
  593. AdjustIconLevel(129, IconData[129].Level);
  594. AdjustIconLevel(155, IconData[155].Level);
  595. AdjustIconLevel(130, IconData[130].Level);
  596. } else {
  597. AdjustIconLevel(181, 0x00);
  598. AdjustIconLevel(180, 0x00);
  599. AdjustIconLevel(103, 0x00);
  600. AdjustIconLevel(178, 0x00);
  601. AdjustIconLevel(105, 0x00);
  602. AdjustIconLevel(106, 0x00);
  603. AdjustIconLevel(173, 0x00);
  604. AdjustIconLevel(111, 0x00);
  605. AdjustIconLevel(129, 0x00);
  606. AdjustIconLevel(155, 0x00);
  607. AdjustIconLevel(130, 0x00);
  608. }
  609. }
  610. void nav_KeepRight(uint8_t Action) {
  611. // uint8_t i;
  612. if (Action) {
  613. AdjustIconLevel(105, IconData[105].Level);
  614. AdjustIconLevel(177, IconData[177].Level);
  615. AdjustIconLevel(176, IconData[176].Level);
  616. AdjustIconLevel(175, IconData[175].Level);
  617. AdjustIconLevel(172, IconData[172].Level);
  618. AdjustIconLevel(173, IconData[173].Level);
  619. AdjustIconLevel(178, IconData[178].Level);
  620. AdjustIconLevel(156, IconData[156].Level);
  621. AdjustIconLevel(129, IconData[129].Level);
  622. AdjustIconLevel(155, IconData[155].Level);
  623. AdjustIconLevel(130, IconData[130].Level);
  624. } else {
  625. AdjustIconLevel(105, 0x00);
  626. AdjustIconLevel(177, 0x00);
  627. AdjustIconLevel(176, 0x00);
  628. AdjustIconLevel(175, 0x00);
  629. AdjustIconLevel(172, 0x00);
  630. AdjustIconLevel(173, 0x00);
  631. AdjustIconLevel(178, 0x00);
  632. AdjustIconLevel(156, 0x00);
  633. AdjustIconLevel(129, 0x00);
  634. AdjustIconLevel(155, 0x00);
  635. AdjustIconLevel(130, 0x00);
  636. }
  637. }
  638. void radarDetector(uint8_t Level) //00-08 00-全滅 01-主體 02-08 =>Level
  639. {
  640. switch (Level) {
  641. case 0:
  642. AdjustIconLevel(81, 0x00); //R01
  643. AdjustIconLevel(82, 0x00); //R02
  644. AdjustIconLevel(83, 0x00); //R03
  645. AdjustIconLevel(84, 0x00); //R04
  646. AdjustIconLevel(85, 0x00); //R05
  647. AdjustIconLevel(86, 0x00); //R06
  648. AdjustIconLevel(87, 0x00); //R07
  649. AdjustIconLevel(88, 0x00); //R08
  650. break;
  651. case 1:
  652. AdjustIconLevel(81, IconData[81].Level); //R01
  653. AdjustIconLevel(82, 0x00); //R02
  654. AdjustIconLevel(83, 0x00); //R03
  655. AdjustIconLevel(84, 0x00); //R04
  656. AdjustIconLevel(85, 0x00); //R05
  657. AdjustIconLevel(86, 0x00); //R06
  658. AdjustIconLevel(87, 0x00); //R07
  659. AdjustIconLevel(88, 0x00); //R08
  660. break;
  661. case 2:
  662. AdjustIconLevel(81, IconData[81].Level); //R01
  663. AdjustIconLevel(82, IconData[82].Level); //R02
  664. AdjustIconLevel(83, 0x00); //R03
  665. AdjustIconLevel(84, 0x00); //R04
  666. AdjustIconLevel(85, 0x00); //R05
  667. AdjustIconLevel(86, 0x00); //R06
  668. AdjustIconLevel(87, 0x00); //R07
  669. AdjustIconLevel(88, 0x00); //R08
  670. break;
  671. case 3:
  672. AdjustIconLevel(81, IconData[81].Level); //R01
  673. AdjustIconLevel(82, IconData[82].Level); //R02
  674. AdjustIconLevel(83, IconData[83].Level); //R03
  675. AdjustIconLevel(84, 0x00); //R04
  676. AdjustIconLevel(85, 0x00); //R05
  677. AdjustIconLevel(86, 0x00); //R06
  678. AdjustIconLevel(87, 0x00); //R07
  679. AdjustIconLevel(88, 0x00); //R08
  680. break;
  681. case 4:
  682. AdjustIconLevel(81, IconData[81].Level); //R01
  683. AdjustIconLevel(82, IconData[82].Level); //R02
  684. AdjustIconLevel(83, IconData[83].Level); //R03
  685. AdjustIconLevel(84, IconData[84].Level); //R04
  686. AdjustIconLevel(85, 0x00); //R05
  687. AdjustIconLevel(86, 0x00); //R06
  688. AdjustIconLevel(87, 0x00); //R07
  689. AdjustIconLevel(88, 0x00); //R08
  690. break;
  691. case 5:
  692. AdjustIconLevel(81, IconData[81].Level); //R01
  693. AdjustIconLevel(82, IconData[82].Level); //R02
  694. AdjustIconLevel(83, IconData[83].Level); //R03
  695. AdjustIconLevel(84, IconData[84].Level); //R04
  696. AdjustIconLevel(85, IconData[85].Level); //R05
  697. AdjustIconLevel(86, 0x00); //R06
  698. AdjustIconLevel(87, 0x00); //R07
  699. AdjustIconLevel(88, 0x00); //R08
  700. break;
  701. case 6:
  702. AdjustIconLevel(81, IconData[81].Level); //R01
  703. AdjustIconLevel(82, IconData[82].Level); //R02
  704. AdjustIconLevel(83, IconData[83].Level); //R03
  705. AdjustIconLevel(84, IconData[84].Level); //R04
  706. AdjustIconLevel(85, IconData[85].Level); //R05
  707. AdjustIconLevel(86, IconData[86].Level); //R06
  708. AdjustIconLevel(87, 0x00); //R07
  709. AdjustIconLevel(88, 0x00); //R08
  710. break;
  711. case 7:
  712. AdjustIconLevel(81, IconData[81].Level); //R01
  713. AdjustIconLevel(82, IconData[82].Level); //R02
  714. AdjustIconLevel(83, IconData[83].Level); //R03
  715. AdjustIconLevel(84, IconData[84].Level); //R04
  716. AdjustIconLevel(85, IconData[85].Level); //R05
  717. AdjustIconLevel(86, IconData[86].Level); //R06
  718. AdjustIconLevel(87, IconData[87].Level); //R07
  719. AdjustIconLevel(88, 0x00); //R08
  720. break;
  721. case 8:
  722. AdjustIconLevel(81, IconData[81].Level); //R01
  723. AdjustIconLevel(82, IconData[82].Level); //R02
  724. AdjustIconLevel(83, IconData[83].Level); //R03
  725. AdjustIconLevel(84, IconData[84].Level); //R04
  726. AdjustIconLevel(85, IconData[85].Level); //R05
  727. AdjustIconLevel(86, IconData[86].Level); //R06
  728. AdjustIconLevel(87, IconData[87].Level); //R07
  729. AdjustIconLevel(88, IconData[88].Level); //R08
  730. break;
  731. };
  732. }
  733. void DispNumber(const uint16_t * SegIconPtr, uint8_t DispNo) {
  734. uint8_t Cnt;
  735. uint16_t tmp;
  736. uint32_t DispData;
  737. DispData = NumberSegTable[DispNo];
  738. Cnt = 0;
  739. do {
  740. tmp = SegIconPtr[Cnt];
  741. if ((tmp != 0) && ((DispData & 1) == 1)) {
  742. AdjustIconLevel(tmp, IconData[tmp].Level);
  743. } else {
  744. AdjustIconLevel(tmp, 0x00);
  745. }
  746. DispData >>= 1;
  747. Cnt++;
  748. } while (Cnt <= 6);
  749. }
  750. void setSegmentedDisplay(uint8_t Display, uint8_t SpeedNo, bool Mode) {
  751. uint8_t BCDcode[4];
  752. if (SpeedNo > DisplayLimit[Display])
  753. SpeedNo = DisplayLimit[Display];
  754. NumericalTo4BCD(SpeedNo, BCDcode);
  755. if (BCDcode[2] == 0 && BCDcode[1] == 0 && Mode) {
  756. DispNumber(SegIconTable[Display][0], 10);
  757. } else {
  758. DispNumber(SegIconTable[Display][0], BCDcode[2]);
  759. }
  760. if (BCDcode[2] == 0 && Mode) {
  761. DispNumber(SegIconTable[Display][1], 10);
  762. } else {
  763. DispNumber(SegIconTable[Display][1], BCDcode[1]);
  764. }
  765. DispNumber(SegIconTable[Display][2], BCDcode[0]);
  766. }
  767. void setCallIcon(uint8_t iconStatus) {
  768. switch (iconStatus) {
  769. case 0: // Blank
  770. P01(0); // Call Outline
  771. P02(0); // Call Phone Icon
  772. P03(0); // Call Text
  773. break;
  774. case 1: // Outline Only
  775. P01(1); // Call Outline
  776. P02(0); // Call Phone Icon
  777. P03(0); // Call Text
  778. break;
  779. case 2: // Outline w/ Phone
  780. P01(1); // Call Outline
  781. P02(1); // Call Phone Icon
  782. P03(0); // Call Text
  783. break;
  784. case 3: // All
  785. P01(1); // Call Outline
  786. P02(1); // Call Phone Icon
  787. P03(1); // Call Text
  788. break;
  789. }
  790. }
  791. void SoftReset(unsigned char DriverNo) {
  792. ReceiveData[0] = 0x01; //SoftReset Command No.
  793. IIC_Write_Command1(IIC_Addr[DriverNo], 1, ReceiveData);
  794. }
  795. void SetOscControl(unsigned char DriverNo, unsigned char mode) {
  796. ReceiveData[0] = 0x04; //Set Osc Control Command No.
  797. ReceiveData[1] = mode;
  798. IIC_Write_Command1(IIC_Addr[DriverNo], 2, ReceiveData);
  799. }
  800. void SetGraphicsRAMWritingDirection(unsigned char DriverNo, unsigned char mode) {
  801. ReceiveData[0] = 0x05; //Set Graphics RAM Writing Direction Command No.
  802. ReceiveData[1] = mode;
  803. IIC_Write_Command1(IIC_Addr[DriverNo], 2, ReceiveData);
  804. }
  805. void SetInterface(unsigned char DriverNo, unsigned char mode) {
  806. ReceiveData[0] = 0x08; //Set Interface Command No.
  807. ReceiveData[1] = mode;
  808. IIC_Write_Command1(IIC_Addr[DriverNo], 2, ReceiveData);
  809. }
  810. void DisplayOnOff(unsigned char DriverNo, unsigned char Val) {
  811. ReceiveData[0] = 0x02; //DisplayOnOff Command No.
  812. ReceiveData[1] = Val;
  813. IIC_Write_Command1(IIC_Addr[DriverNo], 2, ReceiveData);
  814. }
  815. void DisplayStandbyOnOff(unsigned char DriverNo, unsigned char Val) {
  816. ReceiveData[0] = 0x03; //DisplayStandbyOnOff Command No.
  817. ReceiveData[1] = Val;
  818. IIC_Write_Command1(IIC_Addr[DriverNo], 2, ReceiveData);
  819. }
  820. void SetDisplaySize(unsigned char DriverNo, unsigned char Xstart, unsigned char Xend, unsigned char Ystart, unsigned char Yend) {
  821. ReceiveData[0] = 0x07; //SetDisplaySize Command No.
  822. ReceiveData[1] = Xstart >> 4;
  823. ReceiveData[2] = Xstart & 0x0f;
  824. ReceiveData[3] = Xend >> 4;
  825. ReceiveData[4] = Xend & 0x0f;
  826. ReceiveData[5] = Ystart >> 4;
  827. ReceiveData[6] = Ystart & 0x0f;
  828. ReceiveData[7] = Yend >> 4;
  829. ReceiveData[8] = Yend & 0x0f;
  830. IIC_Write_Command1(IIC_Addr[DriverNo], 9, ReceiveData);
  831. }
  832. void SetDotCurrent(unsigned char DriverNo, unsigned char Rlevel, unsigned char Glevel, unsigned char Blevel) {
  833. ReceiveData[0] = 0x0e; //SetDotCurrent Level Command No.
  834. ReceiveData[1] = Rlevel >> 4;
  835. ReceiveData[2] = Rlevel & 0x0f;
  836. ReceiveData[3] = Glevel >> 4;
  837. ReceiveData[4] = Glevel & 0x0f;
  838. ReceiveData[5] = Blevel >> 4;
  839. ReceiveData[6] = Blevel & 0x0f;
  840. IIC_Write_Command1(IIC_Addr[DriverNo], 7, ReceiveData);
  841. }
  842. void SetSystemClockDivisionRatio(unsigned char DriverNo, unsigned char mode) {
  843. ReceiveData[0] = 0x10; //Set System Clock Division Ratio Command No.
  844. ReceiveData[1] = mode;
  845. IIC_Write_Command1(IIC_Addr[DriverNo], 2, ReceiveData);
  846. }
  847. void SetPreChargeWidth(unsigned char DriverNo, unsigned char Val) {
  848. ReceiveData[0] = 0x1C; //SetPreChargeWidth Command No.
  849. ReceiveData[1] = Val;
  850. IIC_Write_Command1(IIC_Addr[DriverNo], 2, ReceiveData);
  851. }
  852. void SetPeakPulseWidth(unsigned char DriverNo, unsigned char Rlevel, unsigned char Glevel, unsigned char Blevel) {
  853. ReceiveData[0] = 0x1d; //SetPeakPulseWidthl Command No.
  854. ReceiveData[1] = Rlevel >> 4;
  855. ReceiveData[2] = Rlevel & 0x0f;
  856. ReceiveData[3] = Glevel >> 4;
  857. ReceiveData[4] = Glevel & 0x0f;
  858. ReceiveData[5] = Blevel >> 4;
  859. ReceiveData[6] = Blevel & 0x0f;
  860. IIC_Write_Command1(IIC_Addr[DriverNo], 7, ReceiveData);
  861. }
  862. void SetPeakPulseDelay(unsigned char DriverNo, unsigned char Val) {
  863. ReceiveData[0] = 0x1e; //SetPeakPulseDelay Command No.
  864. ReceiveData[1] = Val;
  865. IIC_Write_Command1(IIC_Addr[DriverNo], 2, ReceiveData);
  866. }
  867. void SetRowScanOperation(unsigned char DriverNo, unsigned char mode) {
  868. ReceiveData[0] = 0x1f; //SetRowScanOperation Command No.
  869. ReceiveData[1] = mode;
  870. IIC_Write_Command1(IIC_Addr[DriverNo], 2, ReceiveData);
  871. }
  872. void SetInternalRegulatorforRowScan(unsigned char DriverNo, unsigned char mode) {
  873. ReceiveData[0] = 0x30; //SetInternalRegulatorforRowScan Command No.
  874. ReceiveData[1] = mode;
  875. IIC_Write_Command1(IIC_Addr[DriverNo], 2, ReceiveData);
  876. }
  877. void DumpDataToDriver(unsigned char DriverNo, unsigned int SData) {
  878. unsigned int Cnt, CnNav;
  879. unsigned char Nav, t2;
  880. // unsigned char tmp;
  881. //Set the position setting to write Row-0
  882. ReceiveData[0] = 0x0a;
  883. ReceiveData[1] = 0x00; //X Start
  884. ReceiveData[2] = 0x00;
  885. ReceiveData[3] = 0x07; //X End
  886. ReceiveData[4] = 0x0f;
  887. ReceiveData[5] = 0x00; //Y Start
  888. ReceiveData[6] = 0x00;
  889. ReceiveData[7] = 0x00; //Y End
  890. ReceiveData[8] = 0x00;
  891. IIC_Write_Command1(IIC_Addr[DriverNo], 9, ReceiveData);
  892. Nav = SData >> 8;
  893. t2 = SData & 0xff;
  894. CnNav = 0;
  895. for (Cnt = 0; Cnt <= 127; Cnt++) {
  896. ReceiveData[CnNav] = Nav;
  897. CnNav++;
  898. ReceiveData[CnNav] = t2;
  899. CnNav++;
  900. }
  901. IIC_Write_Data1(IIC_Addr[DriverNo], CnNav, ReceiveData);
  902. }
  903. //---------------------------------INITIALIZE (HUDBEGIN)-----------------------------------//
  904. void initializeHUD231(void) {
  905. uint8_t i, j;
  906. SoftReset(0);
  907. SoftReset(1);
  908. SetOscControl(0, 3); // Internal OSC. 105hz
  909. SetOscControl(1, 3);
  910. SetGraphicsRAMWritingDirection(0, 2); //RGB, Left->Right, Bottom->Top
  911. SetGraphicsRAMWritingDirection(1, 2);
  912. SetSystemClockDivisionRatio(0, 0x0B); // 1/128
  913. SetSystemClockDivisionRatio(1, 0x0B);
  914. SetInterface(0, 1);
  915. SetInterface(1, 1);
  916. DisplayOnOff(0, 0);
  917. DisplayOnOff(1, 0);
  918. SetDisplaySize(0, 0, 127, 0, 0);
  919. SetDisplaySize(1, 0, 127, 0, 0);
  920. SetDotCurrent(0, 220, 230, 230);
  921. SetDotCurrent(1, 230, 230, 230);
  922. SetPreChargeWidth(0, 1); //1
  923. SetPreChargeWidth(1, 1);
  924. SetPeakPulseWidth(0, 0, 0, 0); //0,0,0
  925. SetPeakPulseWidth(1, 0, 0, 0);
  926. SetPeakPulseDelay(0, 1); //1
  927. SetPeakPulseDelay(1, 1);
  928. SetRowScanOperation(0, 0x2a); //Pre-Charge + Peak Delay Timing,All Row are in GND, Mode3
  929. SetRowScanOperation(1, 0x2a);
  930. SetInternalRegulatorforRowScan(0, 0x10); //Internal scan requlator Enable, VCC_Cx0.85
  931. SetInternalRegulatorforRowScan(1, 0x10);
  932. DisplayStandbyOnOff(0, 1);
  933. DisplayStandbyOnOff(0, 0);
  934. DisplayStandbyOnOff(1, 1);
  935. DisplayStandbyOnOff(1, 0);
  936. DumpDataToDriver(0, 0x0000);
  937. DumpDataToDriver(1, 0x0000);
  938. DisplayOnOff(0, 1);
  939. DisplayOnOff(1, 1);
  940. for (i = 0; i < 2; i++) {
  941. for (j = 0; j < 128; j++) {
  942. IconRamMap[i][j] = 0;
  943. }
  944. }
  945. }
  946. //---------------------------------I2C FUNCTIONS-----------------------------------//
  947. void IIC_Write_Command1(uint8_t IIC_Addr, uint16_t DataLen, uint8_t * DataPtr) {
  948. uint16_t Cnt;
  949. _i2cPort - > beginTransmission(IIC_Addr);
  950. for (Cnt = 0; Cnt < DataLen; Cnt++) {
  951. _i2cPort - > write(DataPtr[Cnt]);
  952. }
  953. _i2cPort - > endTransmission();
  954. }
  955. void IIC_Write_Data1(uint8_t IIC_Addr, uint16_t DataLen, uint8_t * DataPtr) {
  956. uint16_t Cnt;
  957. _i2cPort - > beginTransmission(IIC_Addr);
  958. _i2cPort - > write(0x0C);
  959. for (Cnt = 0; Cnt < DataLen; Cnt++) {
  960. _i2cPort - > write(DataPtr[Cnt]);
  961. }
  962. _i2cPort - > endTransmission();
  963. }
  964. void IIC_Write_Data2(uint8_t IIC_Addr, uint16_t DataLen,
  965. const uint8_t * DataPtr) {
  966. uint16_t Cnt;
  967. uint8_t tmp;
  968. _i2cPort - > beginTransmission(IIC_Addr);
  969. _i2cPort - > write(0x0C);
  970. for (Cnt = 0; Cnt < DataLen; Cnt++) {
  971. tmp = DataPtr[Cnt];
  972. _i2cPort - > write(tmp);
  973. }
  974. _i2cPort - > endTransmission();
  975. }
  976. //---------------------------------CLEAR DISPLAY-----------------------------------//
  977. void clearAll(void) {
  978. for (uint16_t i; i < 230; i++) {
  979. AdjustIconLevel(i, 0x00);
  980. }
  981. }