u8g_dev_st7687_c144mvgd.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. /*
  2. u8g_dev_st7687_c144mvgd.c (1.44" TFT)
  3. Status: Started, but not finished
  4. Universal 8bit Graphics Library
  5. Copyright (c) 2012, olikraus@gmail.com
  6. All rights reserved.
  7. Redistribution and use in source and binary forms, with or without modification,
  8. are permitted provided that the following conditions are met:
  9. * Redistributions of source code must retain the above copyright notice, this list
  10. of conditions and the following disclaimer.
  11. * Redistributions in binary form must reproduce the above copyright notice, this
  12. list of conditions and the following disclaimer in the documentation and/or other
  13. materials provided with the distribution.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  15. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  16. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  17. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  19. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  24. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  26. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #include "u8g.h"
  29. #define WIDTH 128
  30. #define HEIGHT 128
  31. #define PAGE_HEIGHT 8
  32. #ifdef FIRST_VERSION
  33. /*
  34. see also: read.pudn.com/downloads115/sourcecode/app/484503/LCM_Display.c__.htm
  35. http://en.pudn.com/downloads115/sourcecode/app/detail484503_en.html
  36. */
  37. static const uint8_t u8g_dev_st7687_c144mvgd_init_seq[] PROGMEM = {
  38. U8G_ESC_CS(0), /* disable chip */
  39. U8G_ESC_ADR(0), /* instruction mode */
  40. U8G_ESC_CS(1), /* enable chip */
  41. U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
  42. 0x001, /* A0=0, SW reset */
  43. U8G_ESC_DLY(200), /* delay 200 ms */
  44. 0x0d7, /* EEPROM data auto re-load control */
  45. U8G_ESC_ADR(1), /* data mode */
  46. 0x09f, /* ARD = 1 */
  47. U8G_ESC_ADR(0), /* instruction mode */
  48. U8G_ESC_DLY(100), /* delay 100 ms */
  49. 0x0e0, /* EEPROM control in */
  50. U8G_ESC_ADR(1), /* data mode */
  51. 0x000, /* */
  52. U8G_ESC_ADR(0), /* instruction mode */
  53. U8G_ESC_DLY(100), /* delay 100 ms */
  54. #ifdef NOT_REQUIRED
  55. 0x0fa, /* EEPROM function selection 8.1.66 */
  56. U8G_ESC_ADR(1), /* data mode */
  57. 0x000, /* */
  58. U8G_ESC_ADR(0), /* instruction mode */
  59. U8G_ESC_DLY(100), /* delay 100 ms */
  60. #endif
  61. 0x0e3, /* Read from EEPROM, 8.1.55 */
  62. U8G_ESC_DLY(100), /* delay 100 ms */
  63. 0x0e1, /* EEPROM control out, 8.1.53 */
  64. U8G_ESC_DLY(100), /* delay 100 ms */
  65. //0x028, /* display off */
  66. 0x011, /* Sleep out & booster on */
  67. U8G_ESC_DLY(100), /* delay 100 ms */
  68. 0x0c0, /* Vop setting, 8.1.42 */
  69. U8G_ESC_ADR(1), /* data mode */
  70. 0x000, /* */
  71. 0x001, /* 3.6 + 256*0.04 = 13.84 Volt */
  72. U8G_ESC_ADR(0), /* instruction mode */
  73. U8G_ESC_DLY(100), /* delay 100 ms */
  74. 0x0c3, /* Bias selection, 8.1.45 */
  75. U8G_ESC_ADR(1), /* data mode */
  76. 0x003,
  77. U8G_ESC_ADR(0), /* instruction mode */
  78. 0x0c4, /* Booster setting 8.1.46 */
  79. U8G_ESC_ADR(1), /* data mode */
  80. 0x007,
  81. U8G_ESC_ADR(0), /* instruction mode */
  82. 0x0c5, /* ??? */
  83. U8G_ESC_ADR(1), /* data mode */
  84. 0x001,
  85. U8G_ESC_ADR(0), /* instruction mode */
  86. 0x0cb, /* FV3 with Booster x2 control, 8.1.47 */
  87. U8G_ESC_ADR(1), /* data mode */
  88. 0x001,
  89. U8G_ESC_ADR(0), /* instruction mode */
  90. 0x036, /* Memory data access control, 8.1.28 */
  91. U8G_ESC_ADR(1), /* data mode */
  92. 0x080,
  93. U8G_ESC_ADR(0), /* instruction mode */
  94. 0x0b5, /* N-line control, 8.1.37 */
  95. U8G_ESC_ADR(1), /* data mode */
  96. 0x089,
  97. U8G_ESC_ADR(0), /* instruction mode */
  98. 0x0d0, /* Analog circuit setting, 8.1.49 */
  99. U8G_ESC_ADR(1), /* data mode */
  100. 0x01d,
  101. U8G_ESC_ADR(0), /* instruction mode */
  102. 0x0b7, /* Com/Seg Scan Direction, 8.1.38 */
  103. U8G_ESC_ADR(1), /* data mode */
  104. 0x040,
  105. U8G_ESC_ADR(0), /* instruction mode */
  106. 0x025, /* Write contrast, 8.1.17 */
  107. U8G_ESC_ADR(1), /* data mode */
  108. 0x03f,
  109. U8G_ESC_ADR(0), /* instruction mode */
  110. 0x03a, /* Interface pixel format, 8.1.32 */
  111. U8G_ESC_ADR(1), /* data mode */
  112. 0x004, /* 3: 12 bit per pixel Type A, 4: 12 bit Type B, 5: 16bit per pixel */
  113. U8G_ESC_ADR(0), /* instruction mode */
  114. 0x0b0, /* Display Duty setting, 8.1.34 */
  115. U8G_ESC_ADR(1), /* data mode */
  116. 0x07f,
  117. U8G_ESC_ADR(0), /* instruction mode */
  118. 0x0f0, /* Frame Freq. in Temp range A,B,C and D, 8.1.59 */
  119. U8G_ESC_ADR(1), /* data mode */
  120. 0x007,
  121. 0x00c,
  122. 0x00c,
  123. 0x015,
  124. U8G_ESC_ADR(0), /* instruction mode */
  125. 0x0f9, /* Frame RGB Value, 8.1.65 */
  126. U8G_ESC_ADR(1), /* data mode */
  127. 0x000,
  128. 0x005,
  129. 0x008,
  130. 0x00a,
  131. 0x00c,
  132. 0x00e,
  133. 0x010,
  134. 0x011,
  135. 0x012,
  136. 0x013,
  137. 0x014,
  138. 0x015,
  139. 0x016,
  140. 0x018,
  141. 0x01a,
  142. 0x01b,
  143. U8G_ESC_ADR(0), /* instruction mode */
  144. 0x0f9, /* Frame RGB Value, 8.1.65 */
  145. U8G_ESC_ADR(1), /* data mode */
  146. 0x000,
  147. 0x000,
  148. 0x000,
  149. 0x000,
  150. 0x033,
  151. 0x055,
  152. 0x055,
  153. 0x055,
  154. U8G_ESC_ADR(0), /* instruction mode */
  155. 0x029, /* display on */
  156. U8G_ESC_CS(0), /* disable chip */
  157. U8G_ESC_END /* end of sequence */
  158. };
  159. #else
  160. /*
  161. http://www.waitingforfriday.com/images/e/e3/FTM144D01N_test.zip
  162. */
  163. static const uint8_t u8g_dev_st7687_c144mvgd_init_seq[] PROGMEM = {
  164. U8G_ESC_CS(0), /* disable chip */
  165. U8G_ESC_ADR(0), /* instruction mode */
  166. U8G_ESC_CS(1), /* enable chip */
  167. U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/
  168. 0x011, /* Sleep out & booster on */
  169. U8G_ESC_DLY(5), /* delay 5 ms */
  170. 0x03a, /* Interface pixel format, 8.1.32 */
  171. U8G_ESC_ADR(1), /* data mode */
  172. 0x004, /* 3: 12 bit per pixel Type A, 4: 12 bit Type B, 5: 16bit per pixel */
  173. U8G_ESC_ADR(0), /* instruction mode */
  174. 0x026, /* SET_GAMMA_CURVE */
  175. U8G_ESC_ADR(1), /* data mode */
  176. 0x004,
  177. U8G_ESC_ADR(0), /* instruction mode */
  178. 0x0f2, /* GAM_R_SEL */
  179. U8G_ESC_ADR(1), /* data mode */
  180. 0x001, /* enable gamma adj */
  181. U8G_ESC_ADR(0), /* instruction mode */
  182. 0x0e0, /* POSITIVE_GAMMA_CORRECT */
  183. U8G_ESC_ADR(1), /* data mode */
  184. 0x3f,
  185. 0x25,
  186. 0x1c,
  187. 0x1e,
  188. 0x20,
  189. 0x12,
  190. 0x2a,
  191. 0x90,
  192. 0x24,
  193. 0x11,
  194. 0x00,
  195. 0x00,
  196. 0x00,
  197. 0x00,
  198. 0x00,
  199. U8G_ESC_ADR(0), /* instruction mode */
  200. 0x0e1, /* NEGATIVE_GAMMA_CORRECT */
  201. U8G_ESC_ADR(1), /* data mode */
  202. 0x20,
  203. 0x20,
  204. 0x20,
  205. 0x20,
  206. 0x05,
  207. 0x00,
  208. 0x15,
  209. 0xa7,
  210. 0x3d,
  211. 0x18,
  212. 0x25,
  213. 0x2a,
  214. 0x2b,
  215. 0x2b,
  216. 0x3a,
  217. U8G_ESC_ADR(0), /* instruction mode */
  218. 0x0b1, /* FRAME_RATE_CONTROL1 */
  219. U8G_ESC_ADR(1), /* data mode */
  220. 0x008, /* DIVA = 8 */
  221. 0x008, /* VPA = 8 */
  222. U8G_ESC_ADR(0), /* instruction mode */
  223. 0x0b4, /* DISPLAY_INVERSION */
  224. U8G_ESC_ADR(1), /* data mode */
  225. 0x007, /* NLA = 1, NLB = 1, NLC = 1 (all on Frame Inversion) */
  226. U8G_ESC_ADR(0), /* instruction mode */
  227. 0x0c0, /* POWER_CONTROL1 */
  228. U8G_ESC_ADR(1), /* data mode */
  229. 0x00a, /* VRH = 10: GVDD = 4.30 */
  230. 0x002, /* VC = 2: VCI1 = 2.65 */
  231. U8G_ESC_ADR(0), /* instruction mode */
  232. 0x0c1, /* POWER_CONTROL2 */
  233. U8G_ESC_ADR(1), /* data mode */
  234. 0x002, /* BT = 2: AVDD = 2xVCI1, VCL = -1xVCI1, VGH = 5xVCI1, VGL = -2xVCI1 */
  235. U8G_ESC_ADR(0), /* instruction mode */
  236. 0x0c5, /* VCOM_CONTROL1 */
  237. U8G_ESC_ADR(1), /* data mode */
  238. 0x050, /* VMH = 80: VCOMH voltage = 4.5 */
  239. 0x05b, /* VML = 91: VCOML voltage = -0.225 */
  240. U8G_ESC_ADR(0), /* instruction mode */
  241. 0x0c7, /* VCOM_OFFSET_CONTROL */
  242. U8G_ESC_ADR(1), /* data mode */
  243. 0x040, /* nVM = 0, VMF = 64: VCOMH output = VMH, VCOML output = VML */
  244. U8G_ESC_ADR(0), /* instruction mode */
  245. 0x02a, /* SET_COLUMN_ADDRESS */
  246. U8G_ESC_ADR(1), /* data mode */
  247. 0x000, /* */
  248. 0x000, /* */
  249. 0x000, /* */
  250. 0x07f, /* */
  251. U8G_ESC_ADR(0), /* instruction mode */
  252. 0x02b, /* SET_PAGE_ADDRESS */
  253. U8G_ESC_ADR(1), /* data mode */
  254. 0x000, /* */
  255. 0x000, /* */
  256. 0x000, /* */
  257. 0x07f, /* */
  258. U8G_ESC_ADR(0), /* instruction mode */
  259. 0x036, /* SET_ADDRESS_MODE */
  260. U8G_ESC_ADR(1), /* data mode */
  261. 0x000, /* Select display orientation */
  262. U8G_ESC_ADR(0), /* instruction mode */
  263. 0x029, /* display on */
  264. 0x02c, /* write start */
  265. U8G_ESC_CS(0), /* disable chip */
  266. U8G_ESC_END /* end of sequence */
  267. };
  268. #endif
  269. /* calculate bytes for Type B 4096 color display */
  270. static uint8_t get_byte_1(uint8_t v)
  271. {
  272. v >>= 4;
  273. v &= 0x0e;
  274. return v;
  275. }
  276. static uint8_t get_byte_2(uint8_t v)
  277. {
  278. uint8_t w;
  279. w = v;
  280. w &= 3;
  281. w = (w<<2) | w;
  282. v <<= 3;
  283. v &= 0x0e0;
  284. w |= v;
  285. return w;
  286. }
  287. uint8_t u8g_dev_st7687_c144mvgd_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  288. {
  289. switch(msg)
  290. {
  291. case U8G_DEV_MSG_INIT:
  292. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS);
  293. u8g_WriteEscSeqP(u8g, dev, u8g_dev_st7687_c144mvgd_init_seq);
  294. break;
  295. case U8G_DEV_MSG_STOP:
  296. break;
  297. case U8G_DEV_MSG_PAGE_NEXT:
  298. {
  299. uint8_t y, i, j;
  300. uint8_t *ptr;
  301. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  302. u8g_SetAddress(u8g, dev, 0); /* cmd mode */
  303. u8g_SetChipSelect(u8g, dev, 1);
  304. y = pb->p.page_y0;
  305. ptr = pb->buf;
  306. u8g_SetAddress(u8g, dev, 0); /* cmd mode */
  307. u8g_WriteByte(u8g, dev, 0x02a ); /* Column address set 8.1.20 */
  308. u8g_SetAddress(u8g, dev, 1); /* data mode */
  309. u8g_WriteByte(u8g, dev, 0x000 ); /* x0 */
  310. u8g_WriteByte(u8g, dev, WIDTH-1 ); /* x1 */
  311. u8g_SetAddress(u8g, dev, 0); /* cmd mode */
  312. u8g_WriteByte(u8g, dev, 0x02b ); /* Row address set 8.1.21 */
  313. u8g_SetAddress(u8g, dev, 1); /* data mode */
  314. u8g_WriteByte(u8g, dev, y ); /* y0 */
  315. u8g_WriteByte(u8g, dev, y+PAGE_HEIGHT-1 ); /* y1 */
  316. u8g_SetAddress(u8g, dev, 0); /* cmd mode */
  317. u8g_WriteByte(u8g, dev, 0x02c ); /* Memory write 8.1.22 */
  318. u8g_SetAddress(u8g, dev, 1); /* data mode */
  319. for( i = 0; i < PAGE_HEIGHT; i ++ )
  320. {
  321. for( j = 0; j < WIDTH; j ++ )
  322. {
  323. u8g_WriteByte(u8g, dev, get_byte_1(*ptr) );
  324. u8g_WriteByte(u8g, dev, get_byte_2(*ptr) );
  325. ptr++;
  326. }
  327. }
  328. u8g_SetAddress(u8g, dev, 0); /* cmd mode */
  329. u8g_SetChipSelect(u8g, dev, 0);
  330. }
  331. break;
  332. }
  333. return u8g_dev_pb8h8_base_fn(u8g, dev, msg, arg);
  334. }
  335. uint8_t u8g_st7687_c144mvgd_8h8_buf[WIDTH*8] U8G_NOCOMMON ;
  336. u8g_pb_t u8g_st7687_c144mvgd_8h8_pb = { {8, HEIGHT, 0, 0, 0}, WIDTH, u8g_st7687_c144mvgd_8h8_buf};
  337. u8g_dev_t u8g_dev_st7687_c144mvgd_sw_spi = { u8g_dev_st7687_c144mvgd_fn, &u8g_st7687_c144mvgd_8h8_pb, u8g_com_arduino_sw_spi_fn };
  338. u8g_dev_t u8g_dev_st7687_c144mvgd_8bit = { u8g_dev_st7687_c144mvgd_fn, &u8g_st7687_c144mvgd_8h8_pb, U8G_COM_PARALLEL };