u8g_dev_ssd1351_128x128.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. /*
  2. u8g_dev_ssd1351_128x128.c
  3. Universal 8bit Graphics Library
  4. Copyright (c) 2013, jamjardavies@gmail.com
  5. Copyright (c) 2013, 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. History:
  28. Initial version 20 May 2013 jamjardavies@gmail.com
  29. indexed device 22 May 2013 olikraus@gmail.com
  30. */
  31. #include "u8g.h"
  32. #define WIDTH 128
  33. #define HEIGHT 128
  34. #define PAGE_HEIGHT 8
  35. static const uint8_t u8g_dev_ssd1351_128x128_init_seq[] PROGMEM = {
  36. U8G_ESC_CS(0), /* disable chip */
  37. U8G_ESC_DLY(50),
  38. U8G_ESC_ADR(0), /* instruction mode */
  39. U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
  40. U8G_ESC_CS(1), /* enable chip */
  41. U8G_ESC_DLY(50),
  42. 0xfd, /* Command Lock */
  43. U8G_ESC_ADR(1),
  44. 0x12,
  45. U8G_ESC_ADR(0), /* instruction mode */
  46. 0xfd,
  47. U8G_ESC_ADR(1),
  48. 0xb1, /* Command Lock */
  49. U8G_ESC_ADR(0), /* instruction mode */
  50. 0xae, /* Set Display Off */
  51. U8G_ESC_ADR(0), /* instruction mode */
  52. 0xb3,
  53. U8G_ESC_ADR(1),
  54. 0xf1, /* Front Clock Div */
  55. U8G_ESC_ADR(0), /* instruction mode */
  56. 0xca,
  57. U8G_ESC_ADR(1),
  58. 0x7f, /* Set Multiplex Ratio */
  59. U8G_ESC_ADR(0), /* instruction mode */
  60. 0xa0,
  61. U8G_ESC_ADR(1),
  62. 0xb4, /* Set Colour Depth */
  63. U8G_ESC_ADR(0), /* instruction mode */
  64. 0x15,
  65. U8G_ESC_ADR(1),
  66. 0x00, 0x7f, /* Set Column Address */
  67. U8G_ESC_ADR(0), /* instruction mode */
  68. 0x75,
  69. U8G_ESC_ADR(1),
  70. 0x00, 0x7f, /* Set Row Address */
  71. U8G_ESC_ADR(0), /* instruction mode */
  72. 0xa1,
  73. U8G_ESC_ADR(1),
  74. 0x00, /* Set Display Start Line */
  75. U8G_ESC_ADR(0), /* instruction mode */
  76. 0xa2,
  77. U8G_ESC_ADR(1),
  78. 0x00, /* Set Display Offset */
  79. U8G_ESC_ADR(0), /* instruction mode */
  80. 0xb5,
  81. U8G_ESC_ADR(1),
  82. 0x00, /* Set GPIO */
  83. U8G_ESC_ADR(0), /* instruction mode */
  84. 0xab,
  85. U8G_ESC_ADR(1),
  86. 0x01, /* Set Function Selection */
  87. U8G_ESC_ADR(0), /* instruction mode */
  88. 0xb1,
  89. U8G_ESC_ADR(1),
  90. 0x32, /* Set Phase Length */
  91. U8G_ESC_ADR(0), /* instruction mode */
  92. 0xb4,
  93. U8G_ESC_ADR(1),
  94. 0xa0, 0xb5, 0x55, /* Set Segment Low Voltage */
  95. U8G_ESC_ADR(0), /* instruction mode */
  96. 0xbb,
  97. U8G_ESC_ADR(1),
  98. 0x17, /* Set Precharge Voltage */
  99. U8G_ESC_ADR(0), /* instruction mode */
  100. 0xbe,
  101. U8G_ESC_ADR(1),
  102. 0x05, /* Set VComH Voltage */
  103. U8G_ESC_ADR(0), /* instruction mode */
  104. 0xc1,
  105. U8G_ESC_ADR(1),
  106. 0xc8, 0x80, 0xc8, /* Set Contrast */
  107. U8G_ESC_ADR(0), /* instruction mode */
  108. 0xc7,
  109. U8G_ESC_ADR(1),
  110. 0x0f, /* Set Master Contrast */
  111. U8G_ESC_ADR(0), /* instruction mode */
  112. 0xb6,
  113. U8G_ESC_ADR(1),
  114. 0x01, /* Set Second Precharge Period */
  115. U8G_ESC_ADR(0), /* instruction mode */
  116. 0xa6, /* Set Display Mode Reset */
  117. U8G_ESC_ADR(0), /* instruction mode */
  118. 0xb8, /* Set CMD Grayscale Lookup */
  119. U8G_ESC_ADR(1),
  120. 0x05,
  121. 0x06,
  122. 0x07,
  123. 0x08,
  124. 0x09,
  125. 0x0a,
  126. 0x0b,
  127. 0x0c,
  128. 0x0D,
  129. 0x0E,
  130. 0x0F,
  131. 0x10,
  132. 0x11,
  133. 0x12,
  134. 0x13,
  135. 0x14,
  136. 0x15,
  137. 0x16,
  138. 0x18,
  139. 0x1a,
  140. 0x1b,
  141. 0x1C,
  142. 0x1D,
  143. 0x1F,
  144. 0x21,
  145. 0x23,
  146. 0x25,
  147. 0x27,
  148. 0x2A,
  149. 0x2D,
  150. 0x30,
  151. 0x33,
  152. 0x36,
  153. 0x39,
  154. 0x3C,
  155. 0x3F,
  156. 0x42,
  157. 0x45,
  158. 0x48,
  159. 0x4C,
  160. 0x50,
  161. 0x54,
  162. 0x58,
  163. 0x5C,
  164. 0x60,
  165. 0x64,
  166. 0x68,
  167. 0x6C,
  168. 0x70,
  169. 0x74,
  170. 0x78,
  171. 0x7D,
  172. 0x82,
  173. 0x87,
  174. 0x8C,
  175. 0x91,
  176. 0x96,
  177. 0x9B,
  178. 0xA0,
  179. 0xA5,
  180. 0xAA,
  181. 0xAF,
  182. 0xB4,
  183. U8G_ESC_ADR(0),
  184. 0xaf, /* Set Display On */
  185. 0x5c,
  186. U8G_ESC_DLY(50),
  187. U8G_ESC_CS(0), /* disable chip */
  188. U8G_ESC_ADR(1),
  189. U8G_ESC_END /* end of sequence */
  190. };
  191. /* set gpio to high */
  192. static const uint8_t u8g_dev_ssd1351_128x128gh_init_seq[] PROGMEM = {
  193. U8G_ESC_CS(0), /* disable chip */
  194. U8G_ESC_DLY(50),
  195. U8G_ESC_ADR(0), /* instruction mode */
  196. U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */
  197. U8G_ESC_CS(1), /* enable chip */
  198. U8G_ESC_DLY(50),
  199. 0xfd, /* Command Lock */
  200. U8G_ESC_ADR(1),
  201. 0x12,
  202. U8G_ESC_ADR(0), /* instruction mode */
  203. 0xfd,
  204. U8G_ESC_ADR(1),
  205. 0xb1, /* Command Lock */
  206. U8G_ESC_ADR(0), /* instruction mode */
  207. 0xae, /* Set Display Off */
  208. U8G_ESC_ADR(0), /* instruction mode */
  209. 0xb3,
  210. U8G_ESC_ADR(1),
  211. 0xf1, /* Front Clock Div */
  212. U8G_ESC_ADR(0), /* instruction mode */
  213. 0xca,
  214. U8G_ESC_ADR(1),
  215. 0x7f, /* Set Multiplex Ratio */
  216. U8G_ESC_ADR(0), /* instruction mode */
  217. 0xa0,
  218. U8G_ESC_ADR(1),
  219. 0xb4, /* Set Colour Depth */
  220. U8G_ESC_ADR(0), /* instruction mode */
  221. 0x15,
  222. U8G_ESC_ADR(1),
  223. 0x00, 0x7f, /* Set Column Address */
  224. U8G_ESC_ADR(0), /* instruction mode */
  225. 0x75,
  226. U8G_ESC_ADR(1),
  227. 0x00, 0x7f, /* Set Row Address */
  228. U8G_ESC_ADR(0), /* instruction mode */
  229. 0xa1,
  230. U8G_ESC_ADR(1),
  231. 0x00, /* Set Display Start Line */
  232. U8G_ESC_ADR(0), /* instruction mode */
  233. 0xa2,
  234. U8G_ESC_ADR(1),
  235. 0x00, /* Set Display Offset */
  236. U8G_ESC_ADR(0), /* instruction mode */
  237. 0xb5,
  238. U8G_ESC_ADR(1),
  239. 0x03, /* Set GPIO to High Level */
  240. U8G_ESC_ADR(0), /* instruction mode */
  241. 0xab,
  242. U8G_ESC_ADR(1),
  243. 0x01, /* Set Function Selection */
  244. U8G_ESC_ADR(0), /* instruction mode */
  245. 0xb1,
  246. U8G_ESC_ADR(1),
  247. 0x32, /* Set Phase Length */
  248. U8G_ESC_ADR(0), /* instruction mode */
  249. 0xb4,
  250. U8G_ESC_ADR(1),
  251. 0xa0, 0xb5, 0x55, /* Set Segment Low Voltage */
  252. U8G_ESC_ADR(0), /* instruction mode */
  253. 0xbb,
  254. U8G_ESC_ADR(1),
  255. 0x17, /* Set Precharge Voltage */
  256. U8G_ESC_ADR(0), /* instruction mode */
  257. 0xbe,
  258. U8G_ESC_ADR(1),
  259. 0x05, /* Set VComH Voltage */
  260. U8G_ESC_ADR(0), /* instruction mode */
  261. 0xc1,
  262. U8G_ESC_ADR(1),
  263. 0xc8, 0x80, 0xc8, /* Set Contrast */
  264. U8G_ESC_ADR(0), /* instruction mode */
  265. 0xc7,
  266. U8G_ESC_ADR(1),
  267. 0x0f, /* Set Master Contrast */
  268. U8G_ESC_ADR(0), /* instruction mode */
  269. 0xb6,
  270. U8G_ESC_ADR(1),
  271. 0x01, /* Set Second Precharge Period */
  272. U8G_ESC_ADR(0), /* instruction mode */
  273. 0xa6, /* Set Display Mode Reset */
  274. U8G_ESC_ADR(0), /* instruction mode */
  275. 0xb8, /* Set CMD Grayscale Lookup */
  276. U8G_ESC_ADR(1),
  277. 0x05,
  278. 0x06,
  279. 0x07,
  280. 0x08,
  281. 0x09,
  282. 0x0a,
  283. 0x0b,
  284. 0x0c,
  285. 0x0D,
  286. 0x0E,
  287. 0x0F,
  288. 0x10,
  289. 0x11,
  290. 0x12,
  291. 0x13,
  292. 0x14,
  293. 0x15,
  294. 0x16,
  295. 0x18,
  296. 0x1a,
  297. 0x1b,
  298. 0x1C,
  299. 0x1D,
  300. 0x1F,
  301. 0x21,
  302. 0x23,
  303. 0x25,
  304. 0x27,
  305. 0x2A,
  306. 0x2D,
  307. 0x30,
  308. 0x33,
  309. 0x36,
  310. 0x39,
  311. 0x3C,
  312. 0x3F,
  313. 0x42,
  314. 0x45,
  315. 0x48,
  316. 0x4C,
  317. 0x50,
  318. 0x54,
  319. 0x58,
  320. 0x5C,
  321. 0x60,
  322. 0x64,
  323. 0x68,
  324. 0x6C,
  325. 0x70,
  326. 0x74,
  327. 0x78,
  328. 0x7D,
  329. 0x82,
  330. 0x87,
  331. 0x8C,
  332. 0x91,
  333. 0x96,
  334. 0x9B,
  335. 0xA0,
  336. 0xA5,
  337. 0xAA,
  338. 0xAF,
  339. 0xB4,
  340. U8G_ESC_ADR(0),
  341. 0xaf, /* Set Display On */
  342. 0x5c,
  343. U8G_ESC_DLY(50),
  344. U8G_ESC_CS(0), /* disable chip */
  345. U8G_ESC_ADR(1),
  346. U8G_ESC_END /* end of sequence */
  347. };
  348. #define u8g_dev_ssd1351_128x128_init_seq u8g_dev_ssd1351_128x128_init_seq
  349. static const uint8_t u8g_dev_ssd1351_128x128_column_seq[] PROGMEM = {
  350. U8G_ESC_CS(1),
  351. U8G_ESC_ADR(0), 0x15,
  352. U8G_ESC_ADR(1), 0x00, 0x7f,
  353. U8G_ESC_ADR(0), 0x75,
  354. U8G_ESC_ADR(1), 0x00, 0x7f,
  355. U8G_ESC_ADR(0), 0x5c,
  356. U8G_ESC_ADR(1),
  357. U8G_ESC_CS(0),
  358. U8G_ESC_END
  359. };
  360. #define RGB332_STREAM_BYTES 8
  361. static uint8_t u8g_ssd1351_stream_bytes[RGB332_STREAM_BYTES*3];
  362. void u8g_ssd1351_to_stream(uint8_t *ptr)
  363. {
  364. uint8_t cnt = RGB332_STREAM_BYTES;
  365. uint8_t val;
  366. uint8_t *dest = u8g_ssd1351_stream_bytes;
  367. for( cnt = 0; cnt < RGB332_STREAM_BYTES; cnt++ )
  368. {
  369. val = *ptr++;
  370. *dest++ = ((val & 0xe0) >> 2);
  371. *dest++ = ((val & 0x1c) << 1);
  372. *dest++ = ((val & 0x03) << 4);
  373. }
  374. }
  375. #ifdef OBSOLETE
  376. // Convert the internal RGB 332 to R
  377. static uint8_t u8g_ssd1351_get_r(uint8_t colour)
  378. {
  379. //return ((colour & 0xe0) >> 5) * 9;
  380. //return ((colour & 0xe0) >> 5) * 8;
  381. return ((colour & 0xe0) >> 2) ;
  382. }
  383. // Convert the internal RGB 332 to G
  384. static uint8_t u8g_ssd1351_get_g(uint8_t colour)
  385. {
  386. //return ((colour & 0x1c) >> 2) * 9;
  387. //return ((colour & 0x1c) >> 2) * 8;
  388. return ((colour & 0x1c) << 1);
  389. }
  390. // Convert the internal RGB 332 to B
  391. static uint8_t u8g_ssd1351_get_b(uint8_t colour)
  392. {
  393. //return (colour & 0x03) * 21;
  394. return (colour & 0x03) * 16;
  395. }
  396. #endif
  397. uint8_t u8g_dev_ssd1351_128x128_332_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  398. {
  399. // u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  400. switch(msg)
  401. {
  402. case U8G_DEV_MSG_INIT:
  403. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
  404. u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_init_seq);
  405. break;
  406. case U8G_DEV_MSG_STOP:
  407. break;
  408. case U8G_DEV_MSG_PAGE_FIRST:
  409. u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
  410. break;
  411. case U8G_DEV_MSG_PAGE_NEXT:
  412. {
  413. u8g_uint_t x;
  414. uint8_t page_height;
  415. uint8_t i;
  416. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  417. uint8_t *ptr = pb->buf;
  418. u8g_SetChipSelect(u8g, dev, 1);
  419. page_height = pb->p.page_y1;
  420. page_height -= pb->p.page_y0;
  421. page_height++;
  422. for( i = 0; i < page_height; i++ )
  423. {
  424. for (x = 0; x < pb->width; x+=RGB332_STREAM_BYTES)
  425. {
  426. u8g_ssd1351_to_stream(ptr);
  427. u8g_WriteSequence(u8g, dev, RGB332_STREAM_BYTES*3, u8g_ssd1351_stream_bytes);
  428. ptr += RGB332_STREAM_BYTES;
  429. }
  430. }
  431. u8g_SetChipSelect(u8g, dev, 0);
  432. }
  433. break;
  434. case U8G_DEV_MSG_GET_MODE:
  435. return U8G_MODE_R3G3B2;
  436. }
  437. return u8g_dev_pb8h8_base_fn(u8g, dev, msg, arg);
  438. }
  439. uint8_t u8g_dev_ssd1351_128x128gh_332_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  440. {
  441. // u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  442. switch(msg)
  443. {
  444. case U8G_DEV_MSG_INIT:
  445. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
  446. u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128gh_init_seq);
  447. break;
  448. case U8G_DEV_MSG_STOP:
  449. break;
  450. case U8G_DEV_MSG_PAGE_FIRST:
  451. u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
  452. break;
  453. case U8G_DEV_MSG_PAGE_NEXT:
  454. {
  455. u8g_uint_t x;
  456. uint8_t page_height;
  457. uint8_t i;
  458. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  459. uint8_t *ptr = pb->buf;
  460. u8g_SetChipSelect(u8g, dev, 1);
  461. page_height = pb->p.page_y1;
  462. page_height -= pb->p.page_y0;
  463. page_height++;
  464. for( i = 0; i < page_height; i++ )
  465. {
  466. for (x = 0; x < pb->width; x+=RGB332_STREAM_BYTES)
  467. {
  468. u8g_ssd1351_to_stream(ptr);
  469. u8g_WriteSequence(u8g, dev, RGB332_STREAM_BYTES*3, u8g_ssd1351_stream_bytes);
  470. ptr += RGB332_STREAM_BYTES;
  471. }
  472. }
  473. u8g_SetChipSelect(u8g, dev, 0);
  474. }
  475. break;
  476. case U8G_DEV_MSG_GET_MODE:
  477. return U8G_MODE_R3G3B2;
  478. }
  479. return u8g_dev_pb8h8_base_fn(u8g, dev, msg, arg);
  480. }
  481. static uint8_t u8g_dev_ssd1351_128x128_r[256];
  482. static uint8_t u8g_dev_ssd1351_128x128_g[256];
  483. static uint8_t u8g_dev_ssd1351_128x128_b[256];
  484. uint8_t u8g_dev_ssd1351_128x128_idx_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  485. {
  486. // u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  487. switch(msg)
  488. {
  489. case U8G_DEV_MSG_INIT:
  490. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
  491. u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_init_seq);
  492. break;
  493. case U8G_DEV_MSG_STOP:
  494. break;
  495. case U8G_DEV_MSG_SET_COLOR_ENTRY:
  496. u8g_dev_ssd1351_128x128_r[ ((u8g_dev_arg_irgb_t *)arg)->idx ] = ((u8g_dev_arg_irgb_t *)arg)->r;
  497. u8g_dev_ssd1351_128x128_g[ ((u8g_dev_arg_irgb_t *)arg)->idx ] = ((u8g_dev_arg_irgb_t *)arg)->g;
  498. u8g_dev_ssd1351_128x128_b[ ((u8g_dev_arg_irgb_t *)arg)->idx ] = ((u8g_dev_arg_irgb_t *)arg)->b;
  499. break;
  500. case U8G_DEV_MSG_PAGE_FIRST:
  501. u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
  502. break;
  503. case U8G_DEV_MSG_PAGE_NEXT:
  504. {
  505. int x;
  506. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  507. uint8_t *ptr = pb->buf;
  508. u8g_SetChipSelect(u8g, dev, 1);
  509. for (x = 0; x < pb->width; x++)
  510. {
  511. u8g_WriteByte(u8g, dev, u8g_dev_ssd1351_128x128_r[(*ptr)>>2]);
  512. u8g_WriteByte(u8g, dev, u8g_dev_ssd1351_128x128_g[(*ptr)>>2]);
  513. u8g_WriteByte(u8g, dev, u8g_dev_ssd1351_128x128_b[(*ptr)>>2]);
  514. ptr++;
  515. }
  516. u8g_SetChipSelect(u8g, dev, 0);
  517. }
  518. break;
  519. case U8G_DEV_MSG_GET_MODE:
  520. return U8G_MODE_INDEX;
  521. }
  522. return u8g_dev_pb8h8_base_fn(u8g, dev, msg, arg);
  523. }
  524. void u8g_ssd1351_hicolor_to_stream(uint8_t *ptr)
  525. {
  526. register uint8_t cnt = RGB332_STREAM_BYTES;
  527. register uint8_t low, high, r, g, b;
  528. uint8_t *dest = u8g_ssd1351_stream_bytes;
  529. for( cnt = 0; cnt < RGB332_STREAM_BYTES; cnt++ )
  530. {
  531. low = *ptr++;
  532. high = *ptr++;
  533. r = high & ~7;
  534. r >>= 2;
  535. b = low & 31;
  536. b <<= 1;
  537. g = high & 7;
  538. g <<= 3;
  539. g |= (low>>5)&7;
  540. *dest++ = r;
  541. *dest++ = g;
  542. *dest++ = b;
  543. }
  544. }
  545. uint8_t u8g_dev_ssd1351_128x128_hicolor_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  546. {
  547. switch(msg)
  548. {
  549. case U8G_DEV_MSG_INIT:
  550. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
  551. u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_init_seq);
  552. break;
  553. case U8G_DEV_MSG_STOP:
  554. break;
  555. case U8G_DEV_MSG_PAGE_FIRST:
  556. u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
  557. break;
  558. case U8G_DEV_MSG_PAGE_NEXT:
  559. {
  560. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  561. uint8_t i, j;
  562. uint8_t page_height;
  563. uint8_t *ptr = pb->buf;
  564. u8g_SetChipSelect(u8g, dev, 1);
  565. page_height = pb->p.page_y1;
  566. page_height -= pb->p.page_y0;
  567. page_height++;
  568. for( j = 0; j < page_height; j++ )
  569. {
  570. for (i = 0; i < pb->width; i+=RGB332_STREAM_BYTES)
  571. {
  572. u8g_ssd1351_hicolor_to_stream(ptr);
  573. u8g_WriteSequence(u8g, dev, RGB332_STREAM_BYTES*3, u8g_ssd1351_stream_bytes);
  574. ptr += RGB332_STREAM_BYTES*2;
  575. }
  576. }
  577. u8g_SetChipSelect(u8g, dev, 0);
  578. }
  579. break; /* continue to base fn */
  580. case U8G_DEV_MSG_GET_MODE:
  581. return U8G_MODE_HICOLOR;
  582. }
  583. return u8g_dev_pbxh16_base_fn(u8g, dev, msg, arg);
  584. }
  585. uint8_t u8g_dev_ssd1351_128x128gh_hicolor_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  586. {
  587. switch(msg)
  588. {
  589. case U8G_DEV_MSG_INIT:
  590. u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_50NS);
  591. u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128gh_init_seq);
  592. break;
  593. case U8G_DEV_MSG_STOP:
  594. break;
  595. case U8G_DEV_MSG_PAGE_FIRST:
  596. u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1351_128x128_column_seq);
  597. break;
  598. case U8G_DEV_MSG_PAGE_NEXT:
  599. {
  600. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  601. uint8_t i, j;
  602. uint8_t page_height;
  603. uint8_t *ptr = pb->buf;
  604. u8g_SetChipSelect(u8g, dev, 1);
  605. page_height = pb->p.page_y1;
  606. page_height -= pb->p.page_y0;
  607. page_height++;
  608. for( j = 0; j < page_height; j++ )
  609. {
  610. for (i = 0; i < pb->width; i+=RGB332_STREAM_BYTES)
  611. {
  612. u8g_ssd1351_hicolor_to_stream(ptr);
  613. u8g_WriteSequence(u8g, dev, RGB332_STREAM_BYTES*3, u8g_ssd1351_stream_bytes);
  614. ptr += RGB332_STREAM_BYTES*2;
  615. }
  616. }
  617. u8g_SetChipSelect(u8g, dev, 0);
  618. }
  619. break; /* continue to base fn */
  620. case U8G_DEV_MSG_GET_MODE:
  621. return U8G_MODE_HICOLOR;
  622. }
  623. return u8g_dev_pbxh16_base_fn(u8g, dev, msg, arg);
  624. }
  625. uint8_t u8g_dev_ssd1351_128x128_byte_buf[WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ;
  626. u8g_pb_t u8g_dev_ssd1351_128x128_byte_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1351_128x128_byte_buf};
  627. u8g_dev_t u8g_dev_ssd1351_128x128_332_sw_spi = { u8g_dev_ssd1351_128x128_332_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_SW_SPI };
  628. u8g_dev_t u8g_dev_ssd1351_128x128_332_hw_spi = { u8g_dev_ssd1351_128x128_332_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_HW_SPI };
  629. u8g_dev_t u8g_dev_ssd1351_128x128gh_332_sw_spi = { u8g_dev_ssd1351_128x128gh_332_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_SW_SPI };
  630. u8g_dev_t u8g_dev_ssd1351_128x128gh_332_hw_spi = { u8g_dev_ssd1351_128x128gh_332_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_HW_SPI };
  631. //u8g_dev_t u8g_dev_ssd1351_128x128_idx_sw_spi = { u8g_dev_ssd1351_128x128_idx_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_SW_SPI };
  632. //u8g_dev_t u8g_dev_ssd1351_128x128_idx_hw_spi = { u8g_dev_ssd1351_128x128_idx_fn, &u8g_dev_ssd1351_128x128_byte_pb, U8G_COM_HW_SPI };
  633. /* only half of the height, because two bytes are needed for one pixel */
  634. u8g_pb_t u8g_dev_ssd1351_128x128_hicolor_byte_pb = { {PAGE_HEIGHT/2, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1351_128x128_byte_buf};
  635. u8g_dev_t u8g_dev_ssd1351_128x128_hicolor_sw_spi = { u8g_dev_ssd1351_128x128_hicolor_fn, &u8g_dev_ssd1351_128x128_hicolor_byte_pb, U8G_COM_SW_SPI };
  636. u8g_dev_t u8g_dev_ssd1351_128x128_hicolor_hw_spi = { u8g_dev_ssd1351_128x128_hicolor_fn, &u8g_dev_ssd1351_128x128_hicolor_byte_pb, U8G_COM_HW_SPI };
  637. u8g_dev_t u8g_dev_ssd1351_128x128gh_hicolor_sw_spi = { u8g_dev_ssd1351_128x128gh_hicolor_fn, &u8g_dev_ssd1351_128x128_hicolor_byte_pb, U8G_COM_SW_SPI };
  638. u8g_dev_t u8g_dev_ssd1351_128x128gh_hicolor_hw_spi = { u8g_dev_ssd1351_128x128gh_hicolor_fn, &u8g_dev_ssd1351_128x128_hicolor_byte_pb, U8G_COM_HW_SPI };
  639. uint8_t u8g_dev_ssd1351_128x128_4x_byte_buf[WIDTH*PAGE_HEIGHT*4] U8G_NOCOMMON ;
  640. u8g_pb_t u8g_dev_ssd1351_128x128_4x_332_byte_pb = { {PAGE_HEIGHT*4, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1351_128x128_4x_byte_buf};
  641. u8g_dev_t u8g_dev_ssd1351_128x128_4x_332_sw_spi = { u8g_dev_ssd1351_128x128_332_fn, &u8g_dev_ssd1351_128x128_4x_332_byte_pb, U8G_COM_SW_SPI };
  642. u8g_dev_t u8g_dev_ssd1351_128x128_4x_332_hw_spi = { u8g_dev_ssd1351_128x128_332_fn, &u8g_dev_ssd1351_128x128_4x_332_byte_pb, U8G_COM_HW_SPI };
  643. u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_332_sw_spi = { u8g_dev_ssd1351_128x128gh_332_fn, &u8g_dev_ssd1351_128x128_4x_332_byte_pb, U8G_COM_SW_SPI };
  644. u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_332_hw_spi = { u8g_dev_ssd1351_128x128gh_332_fn, &u8g_dev_ssd1351_128x128_4x_332_byte_pb, U8G_COM_HW_SPI };
  645. u8g_pb_t u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb = { {PAGE_HEIGHT/2*4, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_ssd1351_128x128_4x_byte_buf};
  646. u8g_dev_t u8g_dev_ssd1351_128x128_4x_hicolor_sw_spi = { u8g_dev_ssd1351_128x128_hicolor_fn, &u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb, U8G_COM_SW_SPI };
  647. u8g_dev_t u8g_dev_ssd1351_128x128_4x_hicolor_hw_spi = { u8g_dev_ssd1351_128x128_hicolor_fn, &u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb, U8G_COM_HW_SPI };
  648. u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_hicolor_sw_spi = { u8g_dev_ssd1351_128x128gh_hicolor_fn, &u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb, U8G_COM_SW_SPI };
  649. u8g_dev_t u8g_dev_ssd1351_128x128gh_4x_hicolor_hw_spi = { u8g_dev_ssd1351_128x128gh_hicolor_fn, &u8g_dev_ssd1351_128x128_4x_hicolor_byte_pb, U8G_COM_HW_SPI };
  650. /*
  651. U8G_PB_DEV(u8g_dev_ssd1351_128x128_332_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1351_128x128_332_fn, U8G_COM_SW_SPI);
  652. U8G_PB_DEV(u8g_dev_ssd1351_128x128_332_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1351_128x128_332_fn, U8G_COM_HW_SPI);
  653. U8G_PB_DEV(u8g_dev_ssd1351_128x128_idx_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1351_128x128_idx_fn, U8G_COM_SW_SPI);
  654. U8G_PB_DEV(u8g_dev_ssd1351_128x128_idx_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1351_128x128_idx_fn, U8G_COM_HW_SPI);
  655. */