ucg_dev_oled_128x128_univision.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. ucg_dev_oled_128x128_univision.c
  3. Specific code for the Univision 1.5" OLED (UG2828, 128x128 pixel, 65K Colors, SEPS225)
  4. Note: Only 65K color support, because 262K mode is not possible with 8 Bit SPI.
  5. Universal uC Color Graphics Library
  6. Copyright (c) 2015, olikraus@gmail.com
  7. All rights reserved.
  8. Redistribution and use in source and binary forms, with or without modification,
  9. are permitted provided that the following conditions are met:
  10. * Redistributions of source code must retain the above copyright notice, this list
  11. of conditions and the following disclaimer.
  12. * Redistributions in binary form must reproduce the above copyright notice, this
  13. list of conditions and the following disclaimer in the documentation and/or other
  14. materials provided with the distribution.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  16. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  17. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  20. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  21. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  25. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  27. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #include "ucg.h"
  30. /* the following code is from the UG2828GDEAF02 Datasheet */
  31. static const ucg_pgm_uint8_t aaa_ucg_univision_seps225_init_seq[] = {
  32. UCG_CFG_CD(0,1), /* First arg: level for commands, Second arg: level for command arguments */
  33. UCG_RST(1),
  34. UCG_CS(1), /* disable chip */
  35. UCG_DLY_MS(1),
  36. UCG_RST(0),
  37. UCG_DLY_MS(1),
  38. UCG_RST(1),
  39. UCG_DLY_MS(50),
  40. UCG_CS(0), /* enable chip */
  41. UCG_C11(0x002, 0x001), /* OSC_CTL: external resistor, internal OSC */
  42. UCG_C11(0x004, 0x000), /* REDUCE_CURRENT: normal operation, no current reduction */
  43. UCG_C11(0x003, 0x030), /* CLK_DIV: 90Hz, ratio 1 */
  44. UCG_C11(0x008, 0x000), /* Precharge time red */
  45. UCG_C11(0x009, 0x000), /* Precharge time green */
  46. UCG_C11(0x00a, 0x000), /* Precharge time blue */
  47. UCG_C11(0x00b, 0x000), /* Precharge current red */
  48. UCG_C11(0x00c, 0x000), /* Precharge current green */
  49. UCG_C11(0x00d, 0x000), /* Precharge current blue */
  50. UCG_C11(0x010, 0x04a), /* Driving current red */
  51. UCG_C11(0x011, 0x025), /* Driving current green, original value 0x011 replaced by 0x025 */
  52. UCG_C11(0x012, 0x02f), /* Driving current blue */
  53. UCG_C11(0x013, 0x000), /* Display mode: RGB,column=0..127,column data display control=Normal Dispaly */
  54. UCG_C11(0x014, 0x001), /* External interface: 18 bit, MPU, Bit size does not matter if MPU is selected*/
  55. //UCG_C11(0x016, 0x076), /* Memory Mode: 6bits triple transfer (would require 6bit words on SPI, 262K support, horizontal inc., vertical inc., data continuously written horizontally */
  56. UCG_C11(0x016, 0x066), /* Memory Mode: dual transfer (2x 8Bit), 65K support, horizontal inc., vertical inc., data continuously written horizontally */
  57. /* memory window */
  58. UCG_C11(0x017, 0x000), /* x0 */
  59. UCG_C11(0x018, 0x07f), /* x1 */
  60. UCG_C11(0x019, 0x000), /* y0 */
  61. UCG_C11(0x01a, 0x07f), /* y1 */
  62. /* memory start */
  63. UCG_C11(0x020, 0x000), /* x */
  64. UCG_C11(0x021, 0x000), /* y */
  65. UCG_C11(0x028, 0x07f), /* Duty */
  66. UCG_C11(0x029, 0x000), /* Display start line */
  67. /* DDRAM start */
  68. UCG_C11(0x02e, 0x000), /* x */
  69. UCG_C11(0x02f, 0x000), /* y */
  70. UCG_C11(0x033, 0x000), /* Display Screen Saver x0 */
  71. UCG_C11(0x034, 0x07f), /* Display Screen Saver x1 */
  72. UCG_C11(0x035, 0x000), /* Display Screen Saver y0 */
  73. UCG_C11(0x036, 0x07f), /* Display Screen Saver y1 */
  74. UCG_C11(0x080, 0x000), /* IREF: External */
  75. UCG_DLY_MS(100), /* as suggested in the Univision manual */
  76. UCG_C11(0x006, 0x001), /* Display on */
  77. UCG_CS(1), /* disable chip */
  78. UCG_END(), /* end of sequence */
  79. };
  80. /* init seq. from the .ino example from ZhangFeng, PRC. http://vfdclock.jimdo.com */
  81. static const ucg_pgm_uint8_t ucg_univision_seps225_init_seq[] = {
  82. UCG_CFG_CD(0,1), /* First arg: level for commands, Second arg: level for command arguments */
  83. UCG_RST(1),
  84. UCG_CS(1), /* disable chip */
  85. UCG_DLY_MS(1),
  86. UCG_RST(0),
  87. UCG_DLY_MS(1),
  88. UCG_RST(1),
  89. UCG_DLY_MS(50),
  90. UCG_CS(0), /* enable chip */
  91. UCG_C11(0x006, 0x000), /* Display off */
  92. UCG_C11(0x002, 0x001), /* OSC_CTL: external resistor, internal OSC */
  93. UCG_C11(0x004, 0x000), /* REDUCE_CURRENT: normal operation, no current reduction */
  94. UCG_C11(0x003, 0x030), /* CLK_DIV: 90Hz, ratio 1 */
  95. UCG_C11(0x005, 0x000), /* Software Reset */
  96. UCG_C11(0x008, 0x003), /* Precharge time red */
  97. UCG_C11(0x009, 0x004), /* Precharge time green */
  98. UCG_C11(0x00a, 0x005), /* Precharge time blue */
  99. UCG_C11(0x00b, 0x00b), /* Precharge current red */
  100. UCG_C11(0x00c, 0x00b), /* Precharge current green */
  101. UCG_C11(0x00d, 0x00e), /* Precharge current blue */
  102. UCG_C11(0x010, 0x03e), /* Driving current red */
  103. UCG_C11(0x011, 0x032), /* Driving current green, original value 0x011 replaced by 0x025 */
  104. UCG_C11(0x012, 0x03d), /* Driving current blue */
  105. UCG_C11(0x013, 0x000), /* Display mode: RGB,column=0..127,column data display control=Normal Dispaly */
  106. UCG_C11(0x014, 0x001), /* External interface: 18 bit, MPU, Bit size does not matter if MPU is selected*/
  107. //UCG_C11(0x016, 0x076), /* Memory Mode: 6bits triple transfer (would require 6bit words on SPI, 262K support, horizontal inc., vertical inc., data continuously written horizontally */
  108. UCG_C11(0x015, 0x000),
  109. UCG_C11(0x016, 0x066), /* Memory Mode: dual transfer (2x 8Bit), 65K support, horizontal inc., vertical inc., data continuously written horizontally */
  110. /* memory window */
  111. UCG_C11(0x017, 0x000), /* x0 */
  112. UCG_C11(0x018, 0x07f), /* x1 */
  113. UCG_C11(0x019, 0x000), /* y0 */
  114. UCG_C11(0x01a, 0x07f), /* y1 */
  115. /* memory start */
  116. UCG_C11(0x020, 0x000), /* x */
  117. UCG_C11(0x021, 0x000), /* y */
  118. UCG_C11(0x028, 0x07f), /* Duty */
  119. UCG_C11(0x029, 0x000), /* Display start line */
  120. /* DDRAM start */
  121. UCG_C11(0x02e, 0x000), /* x */
  122. UCG_C11(0x02f, 0x000), /* y */
  123. UCG_C11(0x031, 0x000),
  124. UCG_C11(0x032, 0x000),
  125. UCG_C11(0x033, 0x000), /* Display Screen Saver x0 */
  126. UCG_C11(0x034, 0x07f), /* Display Screen Saver x1 */
  127. UCG_C11(0x035, 0x000), /* Display Screen Saver y0 */
  128. UCG_C11(0x036, 0x07f), /* Display Screen Saver y1 */
  129. UCG_C11(0x080, 0x000), /* IREF: External */
  130. UCG_DLY_MS(100), /* as suggested in the Univision manual */
  131. UCG_C11(0x006, 0x001), /* Display on */
  132. //UCG_C10(0x022),
  133. UCG_CS(1), /* disable chip */
  134. //UCG_DATA(),
  135. UCG_END(), /* end of sequence */
  136. };
  137. static const ucg_pgm_uint8_t ucg_seps255_pos_dir0_seq[] =
  138. {
  139. UCG_CS(0), /* enable chip */
  140. UCG_C11(0x016, 0x066), /* Memory Mode */
  141. UCG_C11(0x020, 0), /* set x position */
  142. UCG_C11(0x021, 0), /* set y position */
  143. UCG_C10(0x022), /* prepare for data */
  144. UCG_DATA(), /* change to data mode */
  145. UCG_END()
  146. };
  147. ucg_int_t ucg_dev_seps225_16x128x128_univision(ucg_t *ucg, ucg_int_t msg, void *data)
  148. {
  149. switch(msg)
  150. {
  151. case UCG_MSG_DEV_POWER_UP:
  152. /* 1. Call to the controller procedures to setup the com interface */
  153. if ( ucg_dev_ic_seps225_16(ucg, msg, data) == 0 )
  154. return 0;
  155. /* 2. Send specific init sequence for this display module */
  156. ucg_com_SendCmdSeq(ucg, ucg_univision_seps225_init_seq);
  157. /* demonstration of the OLED error */
  158. /*
  159. {
  160. uint8_t r,g,b, i;
  161. uint8_t c[3];
  162. ucg_com_SendCmdSeq(ucg, ucg_seps255_pos_dir0_seq);
  163. r = 0;
  164. g = 0;
  165. b = 80;
  166. c[0] = (r&0x0f8) | (((g) >>5));
  167. c[1] = ((((g))<<3)&0x0e0) | (((b) >>3));
  168. ucg_com_SendRepeat2Bytes(ucg, 128, c);
  169. r = 0;
  170. g = 0;
  171. b = 0;
  172. c[0] = (r&0x0f8) | (((g) >>5));
  173. c[1] = ((((g))<<3)&0x0e0) | (((b) >>3));
  174. for( i = 0; i < 126; i++ )
  175. {
  176. ucg_com_SendRepeat2Bytes(ucg, 128, c);
  177. }
  178. r = 0;
  179. g = 0;
  180. b = 255;
  181. c[0] = (r&0x0f8) | (((g) >>5));
  182. c[1] = ((((g))<<3)&0x0e0) | (((b) >>3));
  183. ucg_com_SendRepeat2Bytes(ucg, 40, c);
  184. for(;;)
  185. ;
  186. }
  187. */
  188. return 1;
  189. case UCG_MSG_DEV_POWER_DOWN:
  190. /* let do power down by the controller procedures */
  191. return ucg_dev_ic_seps225_16(ucg, msg, data);
  192. case UCG_MSG_GET_DIMENSION:
  193. ((ucg_wh_t *)data)->w = 128;
  194. ((ucg_wh_t *)data)->h = 128;
  195. return 1;
  196. }
  197. /* all other messages are handled by the controller procedures */
  198. return ucg_dev_ic_seps225_16(ucg, msg, data);
  199. }