LibDriver SSD1351  2.0.0
SSD1351 full function driver
driver_ssd1351.c
Go to the documentation of this file.
1 
38 #include "driver_ssd1351.h"
39 #include "driver_ssd1351_font.h"
40 
44 #define CHIP_NAME "Solomon Systech SSD1351"
45 #define MANUFACTURER_NAME "Solomon Systech"
46 #define SUPPLY_VOLTAGE_MIN 2.4f
47 #define SUPPLY_VOLTAGE_MAX 2.6f
48 #define MAX_CURRENT 0.70f
49 #define TEMPERATURE_MIN -40.0f
50 #define TEMPERATURE_MAX 85.0f
51 #define DRIVER_VERSION 2000
56 #define SSD1351_CMD 0
57 #define SSD1351_DATA 1
62 #define SSD1351_CMD_SET_COLUMN_ADDRESS 0x15
63 #define SSD1351_CMD_SET_ROW_ADDRESS 0x75
64 #define SSD1351_CMD_WRITE_RAM 0x5C
65 #define SSD1351_CMD_READ_RAM 0x5D
66 #define SSD1351_CMD_SET_REMAP_COLOR_DEPTH 0xA0
67 #define SSD1351_CMD_SET_DISPLAY_START_LINE 0xA1
68 #define SSD1351_CMD_SET_DISPLAY_OFFSET 0xA2
69 #define SSD1351_CMD_SET_DISPLAY_ALL_OFF 0xA4
70 #define SSD1351_CMD_SET_DISPLAY_ALL_ON 0xA5
71 #define SSD1351_CMD_SET_DISPLAY_NORMAL 0xA6
72 #define SSD1351_CMD_SET_DISPLAY_INVERSE 0xA7
73 #define SSD1351_CMD_FUNCTION_SELECTION 0xAB
74 #define SSD1351_CMD_SET_SLEEP_MODE_ON 0xAE
75 #define SSD1351_CMD_SET_SLEEP_MODE_OFF 0xAF
76 #define SSD1351_CMD_SET_RESET_PRE_CHARGE_PERIOD 0xB1
77 #define SSD1351_CMD_FRONT_CLOCK_DIVIDER_OSC_FREQ 0xB3
78 #define SSD1351_CMD_SET_SEGMENT_LOW_VOLTAGE 0xB4
79 #define SSD1351_CMD_SET_GPIO 0xB5
80 #define SSD1351_CMD_SET_SECOND_PRE_CHARGE_PERIOD 0xB6
81 #define SSD1351_CMD_GRAY_SCALE_PULSE_WIDTH 0xB8
82 #define SSD1351_CMD_USE_BUILT_IN_LINEAR_LUT 0xB9
83 #define SSD1351_CMD_SET_PRE_CHARGE_VOLTAGE 0xBB
84 #define SSD1351_CMD_SET_VCOMH_VOLTAGE 0xBE
85 #define SSD1351_CMD_SET_CONTRAST 0xC1
86 #define SSD1351_CMD_MASTER_CONTRAST_CONTROL 0xC7
87 #define SSD1351_CMD_SET_MUX_RATIO 0xCA
88 #define SSD1351_CMD_SET_COMMAND_LOCK 0xFD
89 #define SSD1351_CMD_HORIZONTAL_SCROLL 0x96
90 #define SSD1351_CMD_STOP_MOVING 0x9E
91 #define SSD1351_CMD_START_MOVING 0x9F
103 static uint8_t a_ssd1351_write_byte(ssd1351_handle_t *handle, uint8_t data, uint8_t cmd)
104 {
105  uint8_t res;
106 
107  res = handle->cmd_data_gpio_write(cmd); /* write gpio */
108  if (res != 0) /* check result */
109  {
110  return 1; /* return error */
111  }
112  res = handle->spi_write_cmd(&data, 1); /* write data command */
113  if (res != 0) /* check result */
114  {
115  return 1; /* return error */
116  }
117  else
118  {
119  return 0; /* success return 0 */
120  }
121 }
122 
137 uint8_t ssd1351_set_column_address(ssd1351_handle_t *handle, uint8_t start_address, uint8_t end_address)
138 {
139  if (handle == NULL) /* check handle */
140  {
141  return 2; /* return error */
142  }
143  if (handle->inited != 1) /* check handle initialization */
144  {
145  return 3; /* return error */
146  }
147  if ((start_address > 127) || (end_address > 127)) /* check range */
148  {
149  handle->debug_print("ssd1351: address is invalid.\n"); /* address is invalid */
150 
151  return 4; /* return error */
152  }
153  if (start_address >= end_address) /* check range */
154  {
155  handle->debug_print("ssd1351: start_address >= end_address.\n"); /* start_address <= end_address */
156 
157  return 5; /* return error */
158  }
159 
160  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_COLUMN_ADDRESS, SSD1351_CMD) != 0) /* write column address command */
161  {
162  handle->debug_print("ssd1351: write command failed.\n"); /* write command failed */
163 
164  return 1; /* return error */
165  }
166  if (a_ssd1351_write_byte(handle, start_address, SSD1351_DATA) != 0) /* set start address */
167  {
168  handle->debug_print("ssd1351: write start address failed.\n"); /* write start address failed */
169 
170  return 1; /* return error */
171  }
172  if (a_ssd1351_write_byte(handle, end_address, SSD1351_DATA) != 0) /* set end address */
173  {
174  handle->debug_print("ssd1351: write end address failed.\n"); /* write end address failed */
175 
176  return 1; /* return error */
177  }
178 
179  return 0; /* success return 0 */
180 }
181 
196 uint8_t ssd1351_set_row_address(ssd1351_handle_t *handle, uint8_t start_address, uint8_t end_address)
197 {
198  if (handle == NULL) /* check handle */
199  {
200  return 2; /* return error */
201  }
202  if (handle->inited != 1) /* check handle initialization */
203  {
204  return 3; /* return error */
205  }
206  if ((start_address > 127) || (end_address > 127)) /* check range */
207  {
208  handle->debug_print("ssd1351: address is invalid.\n"); /* address is invalid */
209 
210  return 4; /* return error */
211  }
212  if (start_address >= end_address) /* check range */
213  {
214  handle->debug_print("ssd1351: start_address >= end_address.\n"); /* start_address >= end_address */
215 
216  return 5; /* return error */
217  }
218 
219  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_ROW_ADDRESS, SSD1351_CMD)!= 0) /* set row address */
220  {
221  handle->debug_print("ssd1351: write command failed.\n"); /* write command failed */
222 
223  return 1; /* return error */
224  }
225  if (a_ssd1351_write_byte(handle, start_address, SSD1351_DATA) != 0) /* set start address */
226  {
227  handle->debug_print("ssd1351: write start address failed.\n"); /* write start address failed */
228 
229  return 1; /* return error */
230  }
231  if (a_ssd1351_write_byte(handle, end_address, SSD1351_DATA) != 0) /* set end address */
232  {
233  handle->debug_print("ssd1351: write end address failed.\n"); /* write end address failed */
234 
235  return 1; /* return error */
236  }
237 
238  return 0; /* success return 0 */
239 }
240 
252 {
253  if (handle == NULL) /* check handle */
254  {
255  return 2; /* return error */
256  }
257  if (handle->inited != 1) /* check handle initialization */
258  {
259  return 3; /* return error */
260  }
261 
262  if (a_ssd1351_write_byte(handle, SSD1351_CMD_WRITE_RAM, SSD1351_CMD) != 0) /* set write ram */
263  {
264  handle->debug_print("ssd1351: write ram failed.\n"); /* write ram failed */
265 
266  return 1; /* return error */
267  }
268 
269  return 0; /* success return 0 */
270 }
271 
283 {
284  if (handle == NULL) /* check handle */
285  {
286  return 2; /* return error */
287  }
288  if (handle->inited != 1) /* check handle initialization */
289  {
290  return 3; /* return error */
291  }
292 
293  if (a_ssd1351_write_byte(handle, SSD1351_CMD_READ_RAM, SSD1351_CMD) != 0) /* set read ram */
294  {
295  handle->debug_print("ssd1351: read command failed.\n"); /* return error */
296 
297  return 1;
298  }
299 
300  return 0; /* success return 0 */
301 }
302 
315 {
316  if (handle == NULL) /* check handle */
317  {
318  return 2; /* return error */
319  }
320  if (handle->inited != 1) /* check handle initialization */
321  {
322  return 3; /* return error */
323  }
324 
325  handle->conf_1 &= ~ (3 << 6); /* clear conf */
326  handle->conf_1 |= color_depth << 6; /* set conf */
327  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_REMAP_COLOR_DEPTH, SSD1351_CMD) != 0) /* set color depth */
328  {
329  handle->debug_print("ssd1351: write color depth failed.\n"); /* write color depth failed */
330 
331  return 1; /* return error */
332  }
333  if (a_ssd1351_write_byte(handle, handle->conf_1, SSD1351_DATA) != 0) /* set conf */
334  {
335  handle->debug_print("ssd1351: write color depth failed.\n"); /* write color depth failed */
336 
337  return 1; /* return error */
338  }
339 
340  return 0; /* success return 0 */
341 }
342 
355 {
356  if (handle == NULL) /* check handle */
357  {
358  return 2; /* return error */
359  }
360  if (handle->inited != 1) /* check handle initialization */
361  {
362  return 3; /* return error */
363  }
364 
365  handle->conf_1 &= ~ (1 << 0); /* clear conf */
366  handle->conf_1 |= increment << 0; /* set conf */
367  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_REMAP_COLOR_DEPTH, SSD1351_CMD) != 0) /* set address increment */
368  {
369  handle->debug_print("ssd1351: write address increment failed.\n"); /* write address increment failed */
370 
371  return 1; /* return error */
372  }
373  if (a_ssd1351_write_byte(handle, handle->conf_1, SSD1351_DATA) != 0) /* set conf */
374  {
375  handle->debug_print("ssd1351: write address increment failed.\n"); /* write address increment failed */
376 
377  return 1; /* return error */
378  }
379 
380  return 0; /* success return 0 */
381 }
382 
395 {
396  if (handle == NULL) /* check handle */
397  {
398  return 2; /* return error */
399  }
400  if (handle->inited != 1) /* check handle initialization */
401  {
402  return 3; /* return error */
403  }
404 
405  handle->conf_1 &= ~ (1 << 1); /* clear conf */
406  handle->conf_1 |= seg0_map << 1; /* set conf */
407  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_REMAP_COLOR_DEPTH, SSD1351_CMD) != 0) /* set seg0 map */
408  {
409  handle->debug_print("ssd1351: write seg0 map failed.\n"); /* write seg0 map failed */
410 
411  return 1; /* return error */
412  }
413  if (a_ssd1351_write_byte(handle, handle->conf_1, SSD1351_DATA) != 0) /* set conf */
414  {
415  handle->debug_print("ssd1351: write seg0 map failed.\n"); /* write seg0 map failed */
416 
417  return 1; /* return error */
418  }
419 
420  return 0; /* success return 0 */
421 }
422 
435 {
436  if (handle == NULL) /* check handle */
437  {
438  return 2; /* return error */
439  }
440  if (handle->inited != 1) /* check handle initialization */
441  {
442  return 3; /* return error */
443  }
444 
445  handle->conf_1 &= ~ (1 << 2); /* clear conf */
446  handle->conf_1 |= color_sequence << 2; /* set conf */
447  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_REMAP_COLOR_DEPTH, SSD1351_CMD) != 0) /* set color sequence */
448  {
449  handle->debug_print("ssd1351: write color sequence failed.\n"); /* write color sequence failed */
450 
451  return 1; /* return error */
452  }
453  if (a_ssd1351_write_byte(handle, handle->conf_1, SSD1351_DATA) != 0) /* set conf */
454  {
455  handle->debug_print("ssd1351: write color sequence failed.\n"); /* write color sequence failed */
456 
457  return 1; /* return error */
458  }
459 
460  return 0; /* success return 0 */
461 }
462 
475 {
476  if (handle == NULL) /* check handle */
477  {
478  return 2; /* return error */
479  }
480  if (handle->inited != 1) /* check handle initialization */
481  {
482  return 3; /* return error */
483  }
484 
485  handle->conf_1 &= ~ (1 << 4); /* clear conf */
486  handle->conf_1 |= mode << 4; /* set conf */
487  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_REMAP_COLOR_DEPTH, SSD1351_CMD) != 0) /* set scan mode */
488  {
489  handle->debug_print("ssd1351: write scan mode failed.\n"); /* write scan mode failed */
490 
491  return 1; /* return error */
492  }
493  if (a_ssd1351_write_byte(handle, handle->conf_1, SSD1351_DATA) != 0) /* set conf */
494  {
495  handle->debug_print("ssd1351: write scan mode failed.\n"); /* write scan mode failed */
496 
497  return 1; /* return error */
498  }
499 
500  return 0; /* success return 0 */
501 }
502 
515 {
516  if (handle == NULL) /* check handle */
517  {
518  return 2; /* return error */
519  }
520  if (handle->inited != 1) /* check handle initialization */
521  {
522  return 3; /* return error */
523  }
524 
525  handle->conf_1 &= ~ (1 << 5); /* clear conf */
526  handle->conf_1 |= enable << 5; /* set conf */
527  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_REMAP_COLOR_DEPTH, SSD1351_CMD) != 0) /* set com split odd even */
528  {
529  handle->debug_print("ssd1351: write com split odd even failed.\n"); /* write com split odd even failed */
530 
531  return 1; /* return error */
532  }
533  if (a_ssd1351_write_byte(handle, handle->conf_1, SSD1351_DATA) != 0) /* set conf */
534  {
535  handle->debug_print("ssd1351: write com split odd even failed.\n"); /* write com split odd even failed */
536 
537  return 1; /* return error */
538  }
539 
540  return 0; /* success return 0 */
541 }
542 
556 {
557  if (handle == NULL) /* check handle */
558  {
559  return 2; /* return error */
560  }
561  if (handle->inited != 1) /* check handle initialization */
562  {
563  return 3; /* return error */
564  }
565  if (l > 127) /* check line */
566  {
567  handle->debug_print("ssd1351: line is over 127.\n"); /* line is over 127 */
568 
569  return 4; /* return error */
570  }
571 
572  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_DISPLAY_START_LINE, SSD1351_CMD) != 0) /* set display start line */
573  {
574  handle->debug_print("ssd1351: write start line failed.\n"); /* write start line failed */
575 
576  return 1; /* return error */
577  }
578  if (a_ssd1351_write_byte(handle, l, SSD1351_DATA) != 0) /* set display start line */
579  {
580  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
581 
582  return 1; /* return error */
583  }
584 
585  return 0; /* success return 0 */
586 }
587 
600 uint8_t ssd1351_set_display_offset(ssd1351_handle_t *handle, uint8_t offset)
601 {
602  if (handle == NULL) /* check handle */
603  {
604  return 2; /* return error */
605  }
606  if (handle->inited != 1) /* check handle initialization */
607  {
608  return 3; /* return error */
609  }
610  if (offset > 127) /* check offset */
611  {
612  handle->debug_print("ssd1351: offset is over 127.\n"); /* offset is over 127 */
613 
614  return 4; /* return error */
615  }
616 
617  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_DISPLAY_OFFSET, SSD1351_CMD) != 0) /* set display offset */
618  {
619  handle->debug_print("ssd1351: write display offset failed.\n"); /* write display offset failed */
620 
621  return 1; /* return error */
622  }
623  if (a_ssd1351_write_byte(handle, offset, SSD1351_DATA) != 0) /* set display offset */
624  {
625  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
626 
627  return 1; /* return error */
628  }
629 
630  return 0; /* success return 0 */
631 }
632 
645 {
646  if (handle == NULL) /* check handle */
647  {
648  return 2; /* return error */
649  }
650  if (handle->inited != 1) /* check handle initialization */
651  {
652  return 3; /* return error */
653  }
654 
655  if (a_ssd1351_write_byte(handle, mode, SSD1351_CMD) != 0) /* set display mode */
656  {
657  handle->debug_print("ssd1351: write display mode failed.\n"); /* write display mode failed */
658 
659  return 1; /* return error */
660  }
661 
662  return 0; /* success return 0 */
663 }
664 
677 {
678  if (handle == NULL) /* check handle */
679  {
680  return 2; /* return error */
681  }
682  if (handle->inited != 1) /* check handle initialization */
683  {
684  return 3; /* return error */
685  }
686 
687  handle->conf_2 &= ~ (1 << 0); /* clear config */
688  handle->conf_2 |= vdd << 0; /* set vdd */
689  if (a_ssd1351_write_byte(handle, SSD1351_CMD_FUNCTION_SELECTION, SSD1351_CMD) != 0) /* set select vdd */
690  {
691  handle->debug_print("ssd1351: write function selection failed.\n"); /* write function selection failed */
692 
693  return 1; /* return error */
694  }
695  if (a_ssd1351_write_byte(handle, handle->conf_2, SSD1351_DATA) != 0) /* set select vdd */
696  {
697  handle->debug_print("ssd1351: write function selection failed.\n"); /* write function selection failed */
698 
699  return 1; /* return error */
700  }
701 
702  return 0; /* success return 0 */
703 }
704 
717 {
718  if (handle == NULL) /* check handle */
719  {
720  return 2; /* return error */
721  }
722  if (handle->inited != 1) /* check handle initialization */
723  {
724  return 3; /* return error */
725  }
726 
727  handle->conf_2 &= ~ (3 << 6); /* clear config */
728  handle->conf_2 |= parallel_bits << 6; /* set bits */
729  if (a_ssd1351_write_byte(handle, SSD1351_CMD_FUNCTION_SELECTION, SSD1351_CMD) != 0) /* set parallel bits */
730  {
731  handle->debug_print("ssd1351: write parallel bits failed.\n"); /* write parallel bits failed */
732 
733  return 1; /* return error */
734  }
735  if (a_ssd1351_write_byte(handle, handle->conf_2, SSD1351_DATA) != 0) /* set parallel bits */
736  {
737  handle->debug_print("ssd1351: write parallel bits failed.\n"); /* write parallel bits failed */
738 
739  return 1; /* return error */
740  }
741 
742  return 0; /* success return 0 */
743 }
744 
757 {
758  if (handle == NULL) /* check handle */
759  {
760  return 2; /* return error */
761  }
762  if (handle->inited != 1) /* check handle initialization */
763  {
764  return 3; /* return error */
765  }
766 
767  if (enable == SSD1351_BOOL_TRUE) /* if sleep mode on */
768  {
769  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_SLEEP_MODE_ON, SSD1351_CMD) != 0) /* set sleep mode on */
770  {
771  handle->debug_print("ssd1351: set sleep mode on failed.\n"); /* set sleep mode on failed */
772 
773  return 1; /* return error */
774  }
775 
776  return 0; /* success return 0 */
777  }
778  else if (enable == SSD1351_BOOL_FALSE) /* if sleep mode off */
779  {
780  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_SLEEP_MODE_OFF, SSD1351_CMD) != 0) /* set sleep mode off */
781  {
782  handle->debug_print("ssd1351: set sleep mode off failed.\n"); /* set sleep mode off failed */
783 
784  return 1; /* return error */
785  }
786 
787  return 0; /* success return 0 */
788  }
789  else
790  {
791  handle->debug_print("ssd1351: param is invalid.\n"); /* param is invalid */
792 
793  return 1; /* return error */
794  }
795 }
796 
813 uint8_t ssd1351_set_phase_period(ssd1351_handle_t *handle, uint8_t phase1_period, uint8_t phase2_period)
814 {
815  if (handle == NULL) /* check handle */
816  {
817  return 2; /* return error */
818  }
819  if (handle->inited != 1) /* check handle initialization */
820  {
821  return 3; /* return error */
822  }
823  if (phase1_period < 2) /* check phase1 */
824  {
825  handle->debug_print("ssd1351: phase1_period is less than 2.\n"); /* phase1_period is less than 2 */
826 
827  return 4; /* return error */
828  }
829  if (phase1_period > 15) /* check phase1 */
830  {
831  handle->debug_print("ssd1351: phase1_period is over 15.\n"); /* phase1_period is over 15 */
832 
833  return 5; /* return error */
834  }
835  if (phase2_period < 3) /* check phase2 */
836  {
837  handle->debug_print("ssd1351: phase2_period is less than 3.\n"); /* phase2_period is less than 3 */
838 
839  return 6; /* return error */
840  }
841  if (phase2_period > 15) /* check phase2 */
842  {
843  handle->debug_print("ssd1351: phase2_period is over 15.\n"); /* phase2_period is over 15 */
844 
845  return 7; /* return error */
846  }
847 
848  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_RESET_PRE_CHARGE_PERIOD, SSD1351_CMD) != 0) /* set reset pre charge period */
849  {
850  handle->debug_print("ssd1351: write reset pre charge period failed.\n"); /* write reset pre-charge period failed */
851 
852  return 1; /* return error */
853  }
854  if (a_ssd1351_write_byte(handle, (phase2_period << 4) | phase1_period, SSD1351_DATA) != 0) /* set phase period */
855  {
856  handle->debug_print("ssd1351: write reset pre charge period failed.\n"); /* write reset pre-charge period failed */
857 
858  return 1; /* return error */
859  }
860 
861  return 0; /* success return 0 */
862 }
863 
878 uint8_t ssd1351_set_front_clock_oscillator_frequency(ssd1351_handle_t *handle, uint8_t d, uint8_t frequency)
879 {
880  if (handle == NULL) /* check handle */
881  {
882  return 2; /* return error */
883  }
884  if (handle->inited != 1) /* check handle initialization */
885  {
886  return 3; /* return error */
887  }
888  if (d >= 11) /* check div */
889  {
890  handle->debug_print("ssd1351: div is over 11.\n"); /* div is over 11 */
891 
892  return 4; /* return error */
893  }
894  if (frequency > 15) /* check frequency */
895  {
896  handle->debug_print("ssd1351: frequency is over 15.\n"); /* frequency is over 15 */
897 
898  return 5; /* return error */
899  }
900 
901  if (a_ssd1351_write_byte(handle, SSD1351_CMD_FRONT_CLOCK_DIVIDER_OSC_FREQ, SSD1351_CMD) != 0) /* set front clock divider osc freq */
902  {
903  handle->debug_print("ssd1351: write front clock divider osc freq failed.\n"); /* write front clock divider osc freq failed */
904 
905  return 1; /* return error */
906  }
907  if (a_ssd1351_write_byte(handle, (frequency << 4) | d, SSD1351_DATA) != 0) /* set front clock divider osc freq */
908  {
909  handle->debug_print("ssd1351: write front clock divider osc freq failed.\n"); /* write front clock divider osc freq failed */
910 
911  return 1; /* return error */
912  }
913 
914  return 0; /* success return 0 */
915 }
916 
929 {
930  if (handle == NULL) /* check handle */
931  {
932  return 2; /* return error */
933  }
934  if (handle->inited != 1) /* check handle initialization */
935  {
936  return 3; /* return error */
937  }
938 
939  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_SEGMENT_LOW_VOLTAGE, SSD1351_CMD) != 0) /* set segment low voltage */
940  {
941  handle->debug_print("ssd1351: write segment low voltage failed.\n"); /* write segment low voltage failed */
942 
943  return 1; /* return error */
944  }
945  if (a_ssd1351_write_byte(handle, (uint8_t)(0xA0 | segment), SSD1351_DATA) != 0) /* set segment low voltage */
946  {
947  handle->debug_print("ssd1351: write segment low voltage failed.\n"); /* write segment low voltage failed */
948 
949  return 1; /* return error */
950  }
951  if (a_ssd1351_write_byte(handle, 0xB5, SSD1351_DATA) != 0) /* set segment low voltage */
952  {
953  handle->debug_print("ssd1351: write segment low voltage failed.\n"); /* write segment low voltage failed */
954 
955  return 1; /* return error */
956  }
957  if (a_ssd1351_write_byte(handle, 0x55, SSD1351_DATA) != 0) /* set segment low voltage */
958  {
959  handle->debug_print("ssd1351: write segment low voltage failed.\n"); /* write segment low voltage failed */
960 
961  return 1; /* return error */
962  }
963 
964  return 0; /* success return 0 */
965 }
966 
980 {
981  if (handle == NULL) /* check handle */
982  {
983  return 2; /* return error */
984  }
985  if (handle->inited != 1) /* check handle initialization */
986  {
987  return 3; /* return error */
988  }
989 
990  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_GPIO, SSD1351_CMD) != 0) /* set gpio */
991  {
992  handle->debug_print("ssd1351: write gpio failed.\n"); /* write gpio failed */
993 
994  return 1; /* return error */
995  }
996  if (a_ssd1351_write_byte(handle,
997  (uint8_t)((gpio1 << 2) | gpio0),
998  SSD1351_DATA) != 0) /* set gpio */
999  {
1000  handle->debug_print("ssd1351: write gpio failed.\n"); /* write gpio failed */
1001 
1002  return 1; /* return error */
1003  }
1004 
1005  return 0; /* success return 0 */
1006 }
1007 
1021 {
1022  if (handle == NULL) /* check handle */
1023  {
1024  return 2; /* return error */
1025  }
1026  if (handle->inited != 1) /* check handle initialization */
1027  {
1028  return 3; /* return error */
1029  }
1030  if (period > 15) /* check period */
1031  {
1032  handle->debug_print("ssd1351: period is over 15.\n"); /* period is over 15 */
1033 
1034  return 4; /* return error */
1035  }
1036 
1037  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_SECOND_PRE_CHARGE_PERIOD, SSD1351_CMD) != 0) /* set second pre-charge period */
1038  {
1039  handle->debug_print("ssd1351: write second pre charge period failed.\n"); /* write second pre-charge period failed */
1040 
1041  return 1; /* return error */
1042  }
1043  if (a_ssd1351_write_byte(handle, period, SSD1351_DATA) != 0) /* set second pre-charge period */
1044  {
1045  handle->debug_print("ssd1351: write second pre charge period failed.\n"); /* write second pre-charge period failed */
1046 
1047  return 1; /* return error */
1048  }
1049 
1050  return 0; /* success return 0 */
1051 }
1052 
1064 uint8_t ssd1351_set_gray_scale_pulse_width(ssd1351_handle_t *handle, uint8_t gamma[63])
1065 {
1066  uint8_t i;
1067 
1068  if (handle == NULL) /* check handle */
1069  {
1070  return 2; /* return error */
1071  }
1072  if (handle->inited != 1) /* check handle initialization */
1073  {
1074  return 3; /* return error */
1075  }
1076 
1077  if (a_ssd1351_write_byte(handle, SSD1351_CMD_GRAY_SCALE_PULSE_WIDTH, SSD1351_CMD) != 0) /* set gray scale pulse width */
1078  {
1079  handle->debug_print("ssd1351: write gray scale pulse width failed.\n"); /* write gray scale pulse width failed */
1080 
1081  return 1; /* return error */
1082  }
1083  for (i = 0; i < 63; i++) /* 64 times */
1084  {
1085  if (a_ssd1351_write_byte(handle, gamma[i], SSD1351_DATA) != 0) /* set gamma */
1086  {
1087  handle->debug_print("ssd1351: write gamma failed.\n"); /* write gamma failed */
1088 
1089  return 1; /* return error */
1090  }
1091  }
1092 
1093  return 0; /* success return 0 */
1094 }
1095 
1107 {
1108  if (handle == NULL) /* check handle */
1109  {
1110  return 2; /* return error */
1111  }
1112  if (handle->inited != 1) /* check handle initialization */
1113  {
1114  return 3; /* return error */
1115  }
1116 
1117  if (a_ssd1351_write_byte(handle, SSD1351_CMD_USE_BUILT_IN_LINEAR_LUT, SSD1351_CMD) != 0) /* set use built in linear lut */
1118  {
1119  handle->debug_print("ssd1351: use built in linear lut failed.\n"); /* write use built in linear lut failed */
1120 
1121  return 1; /* return error */
1122  }
1123 
1124  return 0; /* success return 0 */
1125 }
1126 
1139 uint8_t ssd1351_set_pre_charge_voltage(ssd1351_handle_t *handle, uint8_t voltage_level)
1140 {
1141  if (handle == NULL) /* check handle */
1142  {
1143  return 2; /* return error */
1144  }
1145  if (handle->inited != 1) /* check handle initialization */
1146  {
1147  return 3; /* return error */
1148  }
1149  if (voltage_level > 0x1F) /* check voltage level */
1150  {
1151  handle->debug_print("ssd1351: voltage level is over 0x1F.\n"); /* voltage level is over 0x1F */
1152 
1153  return 4; /* return error */
1154  }
1155 
1156  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_PRE_CHARGE_VOLTAGE, SSD1351_CMD) != 0) /* set pre charge voltage */
1157  {
1158  handle->debug_print("ssd1351: write pre charge voltage failed.\n"); /* write pre-charge voltage failed */
1159 
1160  return 1; /* return error */
1161  }
1162  if (a_ssd1351_write_byte(handle, voltage_level, SSD1351_DATA) != 0) /* set pre charge voltage */
1163  {
1164  handle->debug_print("ssd1351: write pre charge voltage failed.\n"); /* write pre-charge voltage failed */
1165 
1166  return 1; /* return error */
1167  }
1168 
1169  return 0; /* success return 0 */
1170 }
1171 
1184 uint8_t ssd1351_set_vcomh_voltage(ssd1351_handle_t *handle, uint8_t voltage_level)
1185 {
1186  if (handle == NULL) /* check handle */
1187  {
1188  return 2; /* return error */
1189  }
1190  if (handle->inited != 1) /* check handle initialization */
1191  {
1192  return 3; /* return error */
1193  }
1194  if (voltage_level > 0x07) /* check voltage level */
1195  {
1196  handle->debug_print("ssd1351: voltage level is over 0x07.\n"); /* voltage level is over 0x07 */
1197 
1198  return 4; /* return error */
1199  }
1200 
1201  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_VCOMH_VOLTAGE, SSD1351_CMD) != 0) /* set vcomh voltage */
1202  {
1203  handle->debug_print("ssd1351: write vcomh voltage failed.\n"); /* write vcomh voltage failed */
1204 
1205  return 1; /* return error */
1206  }
1207  if (a_ssd1351_write_byte(handle, voltage_level, SSD1351_DATA) != 0) /* set vcomh voltage */
1208  {
1209  handle->debug_print("ssd1351: write vcomh voltage failed.\n"); /* write vcomh voltage failed */
1210 
1211  return 1; /* return error */
1212  }
1213 
1214  return 0; /* success return 0 */
1215 }
1216 
1230 uint8_t ssd1351_set_contrast(ssd1351_handle_t *handle, uint8_t a, uint8_t b, uint8_t c)
1231 {
1232  if (handle == NULL) /* check handle */
1233  {
1234  return 2; /* return error */
1235  }
1236  if (handle->inited != 1) /* check handle initialization */
1237  {
1238  return 3; /* return error */
1239  }
1240 
1241  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_CONTRAST, SSD1351_CMD) != 0) /* set contrast */
1242  {
1243  handle->debug_print("ssd1351: write contrast failed.\n"); /* write contrast failed */
1244 
1245  return 1; /* return error */
1246  }
1247  if (a_ssd1351_write_byte(handle, a, SSD1351_DATA) != 0) /* set a */
1248  {
1249  handle->debug_print("ssd1351: write a failed.\n"); /* write a failed */
1250 
1251  return 1; /* return error */
1252  }
1253  if (a_ssd1351_write_byte(handle, b, SSD1351_DATA) != 0) /* set b */
1254  {
1255  handle->debug_print("ssd1351: write b failed.\n"); /* write b failed */
1256 
1257  return 1; /* return error */
1258  }
1259  if (a_ssd1351_write_byte(handle, c, SSD1351_DATA) != 0) /* set c */
1260  {
1261  handle->debug_print("ssd1351: write c failed.\n"); /* write c failed */
1262 
1263  return 1; /* return error */
1264  }
1265 
1266  return 0; /* success return 0 */
1267 }
1268 
1282 {
1283  if (handle == NULL) /* check handle */
1284  {
1285  return 2; /* return error */
1286  }
1287  if (handle->inited != 1) /* check handle initialization */
1288  {
1289  return 3; /* return error */
1290  }
1291  if (current > 0x0F) /* check master contrast current */
1292  {
1293  handle->debug_print("ssd1351: master contrast current is over 0x0F.\n"); /* master contrast current is over 0x0F */
1294 
1295  return 4; /* return error */
1296  }
1297 
1298  if (a_ssd1351_write_byte(handle, SSD1351_CMD_MASTER_CONTRAST_CONTROL, SSD1351_CMD) != 0) /* set master contrast current */
1299  {
1300  handle->debug_print("ssd1351: write master contrast current failed.\n"); /* write master contrast current failed */
1301 
1302  return 1; /* return error */
1303  }
1304  if (a_ssd1351_write_byte(handle, current, SSD1351_DATA) != 0) /* set master contrast current */
1305  {
1306  handle->debug_print("ssd1351: write master contrast current failed.\n"); /* write master contrast current failed */
1307 
1308  return 1; /* return error */
1309  }
1310 
1311  return 0; /* success return 0 */
1312 }
1313 
1327 uint8_t ssd1351_set_mux_ratio(ssd1351_handle_t *handle, uint8_t ratio)
1328 {
1329  if (handle == NULL) /* check handle */
1330  {
1331  return 2; /* return error */
1332  }
1333  if (handle->inited != 1) /* check handle initialization */
1334  {
1335  return 3; /* return error */
1336  }
1337  if (ratio < 15) /* check ratio */
1338  {
1339  handle->debug_print("ssd1351: ratio < 15.\n"); /* ratio < 15 */
1340 
1341  return 4; /* return error */
1342  }
1343  if (ratio > 127) /* check ratio */
1344  {
1345  handle->debug_print("ssd1351: ratio > 127.\n"); /* ratio > 127 */
1346 
1347  return 5; /* return error */
1348  }
1349 
1350  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_MUX_RATIO, SSD1351_CMD) != 0) /* set mux ratio */
1351  {
1352  handle->debug_print("ssd1351: write mux ratio failed.\n"); /* write mux ratio failed */
1353 
1354  return 1; /* return error */
1355  }
1356  if (a_ssd1351_write_byte(handle, ratio, SSD1351_DATA) != 0) /* set mux ratio */
1357  {
1358  handle->debug_print("ssd1351: write mux ratio failed.\n"); /* write mux ratio failed */
1359 
1360  return 1; /* return error */
1361  }
1362 
1363  return 0; /* success return 0 */
1364 }
1365 
1378 {
1379  if (handle == NULL) /* check handle */
1380  {
1381  return 2; /* return error */
1382  }
1383  if (handle->inited != 1) /* check handle initialization */
1384  {
1385  return 3; /* return error */
1386  }
1387 
1388  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_COMMAND_LOCK, SSD1351_CMD) != 0) /* set command lock */
1389  {
1390  handle->debug_print("ssd1351: write command lock failed.\n"); /* write command lock failed */
1391 
1392  return 1; /* return error */
1393  }
1394  if (a_ssd1351_write_byte(handle, command, SSD1351_DATA) != 0) /* set command lock */
1395  {
1396  handle->debug_print("ssd1351: write command lock failed.\n"); /* write command lock failed */
1397 
1398  return 1; /* return error */
1399  }
1400 
1401  return 0; /* success return 0 */
1402 }
1403 
1420 uint8_t ssd1351_set_scroll(ssd1351_handle_t *handle, int8_t scroll, uint8_t start_row, uint8_t row_len, ssd1351_scroll_mode_t mode)
1421 {
1422  if (handle == NULL) /* check handle */
1423  {
1424  return 2; /* return error */
1425  }
1426  if (handle->inited != 1) /* check handle initialization */
1427  {
1428  return 3; /* return error */
1429  }
1430  if (start_row > 127) /* check start row */
1431  {
1432  handle->debug_print("ssd1351: start row is over 127.\n"); /* start row is over 127 */
1433 
1434  return 4; /* return error */
1435  }
1436  if ((start_row + row_len) > 128) /* check row len */
1437  {
1438  handle->debug_print("ssd1351: start_row + row_len is over 128.\n"); /* start_row + row_len is over 128 */
1439 
1440  return 5; /* return error */
1441  }
1442 
1443  if (a_ssd1351_write_byte(handle, SSD1351_CMD_STOP_MOVING, SSD1351_CMD) != 0) /* set stop moving */
1444  {
1445  handle->debug_print("ssd1351: write stop moving failed.\n"); /* write stop moving failed */
1446 
1447  return 1; /* return error */
1448  }
1449  if (a_ssd1351_write_byte(handle, SSD1351_CMD_HORIZONTAL_SCROLL, SSD1351_CMD) != 0) /* set horizontal scroll */
1450  {
1451  handle->debug_print("ssd1351: write horizontal scroll failed.\n"); /* write horizontal scroll failed */
1452 
1453  return 1; /* return error */
1454  }
1455  if (a_ssd1351_write_byte(handle, scroll, SSD1351_DATA) != 0) /* set scroll */
1456  {
1457  handle->debug_print("ssd1351: write scroll failed.\n"); /* write scroll failed */
1458 
1459  return 1; /* return error */
1460  }
1461  if (a_ssd1351_write_byte(handle, start_row, SSD1351_DATA) != 0) /* set start row */
1462  {
1463  handle->debug_print("ssd1351: write start row failed.\n"); /* write start row failed */
1464 
1465  return 1; /* return error */
1466  }
1467  if (a_ssd1351_write_byte(handle, row_len, SSD1351_DATA) != 0) /* start row len */
1468  {
1469  handle->debug_print("ssd1351: write row len failed.\n"); /* write row len failed */
1470 
1471  return 1; /* return error */
1472  }
1473  if (a_ssd1351_write_byte(handle, 0x00, SSD1351_DATA) != 0) /* set 0x00 */
1474  {
1475  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1476 
1477  return 1; /* return error */
1478  }
1479  if (a_ssd1351_write_byte(handle, mode, SSD1351_DATA) != 0) /* set mode */
1480  {
1481  handle->debug_print("ssd1351: write mode failed.\n"); /* write mode failed */
1482 
1483  return 1; /* return error */
1484  }
1485 
1486  return 0; /* success return 0 */
1487 }
1488 
1500 {
1501  uint8_t i, j;
1502 
1503  if (handle == NULL) /* check handle */
1504  {
1505  return 2; /* return error */
1506  }
1507  if (handle->inited != 1) /* check handle initialization */
1508  {
1509  return 3; /* return error */
1510  }
1511 
1512  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_ROW_ADDRESS, SSD1351_CMD) != 0) /* set row address */
1513  {
1514  handle->debug_print("ssd1351: write command failed.\n"); /* write command failed */
1515 
1516  return 1; /* return error */
1517  }
1518  if (a_ssd1351_write_byte(handle, 0, SSD1351_DATA) != 0) /* set start address */
1519  {
1520  handle->debug_print("ssd1351: write start address failed.\n"); /* write start address failed */
1521 
1522  return 1; /* return error */
1523  }
1524  if (a_ssd1351_write_byte(handle, 127, SSD1351_DATA) != 0) /* set end address */
1525  {
1526  handle->debug_print("ssd1351: write end address failed.\n"); /* write end address failed */
1527 
1528  return 1; /* return error */
1529  }
1530  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_COLUMN_ADDRESS, SSD1351_CMD) != 0) /* set column address */
1531  {
1532  handle->debug_print("ssd1351: write command failed.\n"); /* write command failed */
1533 
1534  return 1; /* return error */
1535  }
1536  if (a_ssd1351_write_byte(handle, 0, SSD1351_DATA) != 0) /* set start address */
1537  {
1538  handle->debug_print("ssd1351: write start address failed.\n"); /* write start address failed */
1539 
1540  return 1; /* return error */
1541  }
1542  if (a_ssd1351_write_byte(handle, 127, SSD1351_DATA) != 0) /* set end address */
1543  {
1544  handle->debug_print("ssd1351: write end address failed.\n"); /* write end address failed */
1545 
1546  return 1; /* return error */
1547  }
1548  if (a_ssd1351_write_byte(handle, SSD1351_CMD_WRITE_RAM, SSD1351_CMD) != 0) /* set write ram */
1549  {
1550  handle->debug_print("ssd1351: write ram failed.\n"); /* write ram failed */
1551 
1552  return 1; /* return error */
1553  }
1554  for (i = 0; i < 128; i++) /* set row */
1555  {
1556  for (j = 0; j < 128; j++) /* set column */
1557  {
1558  if ((handle->conf_1 & 0xC0) == 0) /* if 256 */
1559  {
1560  if (a_ssd1351_write_byte(handle, 0x00, SSD1351_DATA) != 0) /* set data */
1561  {
1562  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1563 
1564  return 1; /* return error */
1565  }
1566  }
1567  else if ((handle->conf_1 & 0xC0) == 0x40) /* if 65K */
1568  {
1569  if (a_ssd1351_write_byte(handle, 0x00, SSD1351_DATA) != 0) /* set data */
1570  {
1571  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1572 
1573  return 1; /* return error */
1574  }
1575  if (a_ssd1351_write_byte(handle, 0x00, SSD1351_DATA) != 0) /* set data */
1576  {
1577  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1578 
1579  return 1; /* return error */
1580  }
1581  }
1582  else /* if 262K */
1583  {
1584  if (a_ssd1351_write_byte(handle, 0x00, SSD1351_DATA) != 0) /* set data */
1585  {
1586  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1587 
1588  return 1; /* return error */
1589  }
1590  if (a_ssd1351_write_byte(handle, 0x00, SSD1351_DATA) != 0) /* set data */
1591  {
1592  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1593 
1594  return 1; /* return error */
1595  }
1596  if (a_ssd1351_write_byte(handle, 0x00, SSD1351_DATA) != 0) /* set data */
1597  {
1598  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1599 
1600  return 1; /* return error */
1601  }
1602  }
1603  }
1604  }
1605 
1606  return 0; /* success return 0 */
1607 }
1608 
1620 static uint8_t a_ssd1351_draw_point(ssd1351_handle_t *handle, uint8_t x, uint8_t y, uint32_t color)
1621 {
1622  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_COLUMN_ADDRESS, SSD1351_CMD) != 0) /* write column address command */
1623  {
1624  handle->debug_print("ssd1351: write command failed.\n"); /* write command failed */
1625 
1626  return 1; /* return error */
1627  }
1628  if (a_ssd1351_write_byte(handle, x, SSD1351_DATA) != 0) /* set start address */
1629  {
1630  handle->debug_print("ssd1351: write start address failed.\n"); /* write start address failed */
1631 
1632  return 1; /* return error */
1633  }
1634  if (a_ssd1351_write_byte(handle, x, SSD1351_DATA) != 0) /* set end address */
1635  {
1636  handle->debug_print("ssd1351: write end address failed.\n"); /* write end address failed */
1637 
1638  return 1; /* return error */
1639  }
1640  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_ROW_ADDRESS, SSD1351_CMD) != 0) /* write column address command */
1641  {
1642  handle->debug_print("ssd1351: write command failed.\n"); /* write command failed */
1643 
1644  return 1; /* return error */
1645  }
1646  if (a_ssd1351_write_byte(handle, y, SSD1351_DATA) != 0) /* set start address */
1647  {
1648  handle->debug_print("ssd1351: write start address failed.\n"); /* write start address failed */
1649 
1650  return 1; /* return error */
1651  }
1652  if (a_ssd1351_write_byte(handle, y, SSD1351_DATA) != 0) /* set end address */
1653  {
1654  handle->debug_print("ssd1351: write end address failed.\n"); /* write end address failed */
1655 
1656  return 1; /* return error */
1657  }
1658  if (a_ssd1351_write_byte(handle, SSD1351_CMD_WRITE_RAM, SSD1351_CMD) != 0) /* set write ram */
1659  {
1660  handle->debug_print("ssd1351: write ram failed.\n"); /* write ram failed */
1661 
1662  return 1; /* return error */
1663  }
1664  if ((handle->conf_1 & 0xC0) == 0) /* if 256 */
1665  {
1666  if (a_ssd1351_write_byte(handle, color & 0xFF, SSD1351_DATA) != 0) /* set data */
1667  {
1668  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1669 
1670  return 1; /* return error */
1671  }
1672 
1673  return 0; /* success return 0 */
1674  }
1675  else if ((handle->conf_1 & 0xC0) == 0x40) /* if 65K */
1676  {
1677  if ((handle->conf_1 & 0x04) != 0) /* CBA */
1678  {
1679  color &= 0x00FFFFU;
1680  if (a_ssd1351_write_byte(handle, (color>>8)&0xFF, SSD1351_DATA) != 0) /* set 1st */
1681  {
1682  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1683 
1684  return 1; /* return error */
1685  }
1686  if (a_ssd1351_write_byte(handle, (color>>0)&0xFF, SSD1351_DATA) != 0) /* set 2nd */
1687  {
1688  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1689 
1690  return 1; /* return error */
1691  }
1692 
1693  return 0; /* success return 0 */
1694  }
1695  else /* ABC */
1696  {
1697  color &= 0x00FFFFU; /* get color */
1698  #if (SSD1351_AUTO_COLOR_CONVERT == 1) /* if auto color convert */
1699  color = ((color&0xF800)>>11) | (color&0x07E0) | ((color&0x001F)<<11); /* blue green red */
1700  #endif
1701  if (a_ssd1351_write_byte(handle, (color>>8)&0xFF, SSD1351_DATA) != 0) /* set 1st */
1702  {
1703  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1704 
1705  return 1; /* return error */
1706  }
1707  if (a_ssd1351_write_byte(handle, (color>>0)&0xFF, SSD1351_DATA) != 0) /* set 2nd */
1708  {
1709  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1710 
1711  return 1; /* return error */
1712  }
1713 
1714  return 0; /* success return 0 */
1715  }
1716  }
1717  else
1718  {
1719  if ((handle->conf_1 & 0x04) != 0) /* CBA */
1720  {
1721  if (a_ssd1351_write_byte(handle, (color>>16)&0x3F, SSD1351_DATA) != 0) /* set red */
1722  {
1723  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1724 
1725  return 1; /* return error */
1726  }
1727  if (a_ssd1351_write_byte(handle, (color>>8)&0x3F, SSD1351_DATA) != 0) /* set green */
1728  {
1729  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1730 
1731  return 1; /* return error */
1732  }
1733  if (a_ssd1351_write_byte(handle, (color>>0)&0x3F, SSD1351_DATA) != 0) /* set blue */
1734  {
1735  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1736 
1737  return 1; /* return error */
1738  }
1739 
1740  return 0; /* success return 0 */
1741  }
1742  else /* ABC */
1743  {
1744  #if (SSD1351_AUTO_COLOR_CONVERT == 1) /* if auto color convert */
1745  if (a_ssd1351_write_byte(handle, (color>>0)&0x3F, SSD1351_DATA) != 0) /* set blue */
1746  {
1747  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1748 
1749  return 1; /* return error */
1750  }
1751  if (a_ssd1351_write_byte(handle, (color>>8)&0x3F, SSD1351_DATA) != 0) /* set green */
1752  {
1753  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1754 
1755  return 1; /* return error */
1756  }
1757  if (a_ssd1351_write_byte(handle, (color>>16)&0x3F, SSD1351_DATA) != 0) /* set red */
1758  {
1759  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1760 
1761  return 1; /* return error */
1762  }
1763  #else
1764  if (a_ssd1351_write_byte(handle, (color>>16)&0x3F, SSD1351_DATA) != 0) /* set blue */
1765  {
1766  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1767 
1768  return 1; /* return error */
1769  }
1770  if (a_ssd1351_write_byte(handle, (color>>8)&0x3F, SSD1351_DATA) != 0) /* set green */
1771  {
1772  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1773 
1774  return 1; /* return error */
1775  }
1776  if (a_ssd1351_write_byte(handle, (color>>0)&0x3F, SSD1351_DATA) != 0) /* set red */
1777  {
1778  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1779 
1780  return 1; /* return error */
1781  }
1782  #endif
1783 
1784  return 0; /* success return 0 */
1785  }
1786  }
1787 }
1788 
1802 static uint8_t a_ssd1351_show_char(ssd1351_handle_t *handle, uint8_t x, uint8_t y, uint8_t chr, uint8_t size, uint32_t color)
1803 {
1804  uint8_t temp, t, t1;
1805  uint8_t y0 = y;
1806  uint8_t csize = (size / 8 + ((size % 8) ? 1 : 0)) * (size / 2); /* get size */
1807 
1808  chr = chr - ' '; /* get index */
1809  for (t = 0; t < csize; t++) /* write size */
1810  {
1811  if (size == 12) /* if size 12 */
1812  {
1813  temp = gsc_ssd1351_ascii_1206[chr][t]; /* get ascii 1206 */
1814  }
1815  else if (size == 16) /* if size 16 */
1816  {
1817  temp = gsc_ssd1351_ascii_1608[chr][t]; /* get ascii 1608 */
1818  }
1819  else if(size == 24) /* if size 24 */
1820  {
1821  temp = gsc_ssd1351_ascii_2412[chr][t]; /* get ascii 2412 */
1822  }
1823  else
1824  {
1825  return 1; /* return error */
1826  }
1827  for (t1 = 0; t1 < 8; t1++) /* write one line */
1828  {
1829  if ((temp & 0x80) != 0) /* if 1 */
1830  {
1831  if (a_ssd1351_draw_point(handle, x, y, color) != 0) /* draw point */
1832  {
1833  return 1; /* return error */
1834  }
1835  }
1836  temp <<= 1; /* left shift 1 */
1837  y++;
1838  if ((y - y0) == size) /* reset size */
1839  {
1840  y = y0; /* set y */
1841  x++; /* x++ */
1842 
1843  break; /* break */
1844  }
1845  }
1846  }
1847 
1848  return 0; /* success return 0 */
1849 }
1850 
1866 static uint8_t a_ssd1351_fill_rect(ssd1351_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint32_t color)
1867 {
1868  uint8_t i, j;
1869 
1870  if (handle == NULL) /* check handle */
1871  {
1872  return 2; /* return error */
1873  }
1874  if (handle->inited != 1) /* check handle initialization */
1875  {
1876  return 3; /* return error */
1877  }
1878  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_COLUMN_ADDRESS, SSD1351_CMD) != 0) /* write column address command */
1879  {
1880  handle->debug_print("ssd1351: write command failed.\n"); /* write command failed */
1881 
1882  return 1; /* return error */
1883  }
1884  if (a_ssd1351_write_byte(handle, left, SSD1351_DATA) != 0) /* set start address */
1885  {
1886  handle->debug_print("ssd1351: write start address failed.\n"); /* write start address failed */
1887 
1888  return 1; /* return error */
1889  }
1890  if (a_ssd1351_write_byte(handle, right, SSD1351_DATA) != 0) /* set end address */
1891  {
1892  handle->debug_print("ssd1351: write end address failed.\n"); /* write end address failed */
1893 
1894  return 1; /* return error */
1895  }
1896  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_ROW_ADDRESS, SSD1351_CMD) != 0) /* write column address command */
1897  {
1898  handle->debug_print("ssd1351: write command failed.\n"); /* write command failed */
1899 
1900  return 1; /* return error */
1901  }
1902  if (a_ssd1351_write_byte(handle, top, SSD1351_DATA) != 0) /* set start address */
1903  {
1904  handle->debug_print("ssd1351: write start address failed.\n"); /* write start address failed */
1905 
1906  return 1; /* return error */
1907  }
1908  if (a_ssd1351_write_byte(handle, bottom, SSD1351_DATA) != 0) /* set end address */
1909  {
1910  handle->debug_print("ssd1351: write end address failed.\n"); /* write end address failed */
1911 
1912  return 1; /* return error */
1913  }
1914  if (a_ssd1351_write_byte(handle, SSD1351_CMD_WRITE_RAM, SSD1351_CMD) != 0) /* set write ram */
1915  {
1916  handle->debug_print("ssd1351: write ram failed.\n"); /* write ram failed */
1917 
1918  return 1; /* return error */
1919  }
1920  if ((handle->conf_1&0xC0) == 0) /* if 256 */
1921  {
1922  for (i = 0; i < (right - left + 1); i++) /* x */
1923  {
1924  for (j = 0; j < (bottom - top + 1); j++) /* y */
1925  {
1926  if (a_ssd1351_write_byte(handle, color&0xFF, SSD1351_DATA) != 0) /* set data */
1927  {
1928  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1929 
1930  return 1; /* return error */
1931  }
1932 
1933  }
1934  }
1935 
1936  return 0; /* success return 0 */
1937  }
1938  else if ((handle->conf_1&0xC0) == 0x40) /* if 65K */
1939  {
1940  for (i = 0; i < (right - left + 1); i++) /* x */
1941  {
1942  for (j = 0; j < (bottom - top + 1); j++) /* y */
1943  {
1944  if ((handle->conf_1 & 0x04) != 0) /* CBA */
1945  {
1946  color &= 0x00FFFFU;
1947  if (a_ssd1351_write_byte(handle, (color>>8)&0xFF, SSD1351_DATA) != 0) /* set 1st */
1948  {
1949  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1950 
1951  return 1; /* return error */
1952  }
1953  if (a_ssd1351_write_byte(handle, (color>>0)&0xFF, SSD1351_DATA) != 0) /* set 2nd */
1954  {
1955  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1956 
1957  return 1; /* return error */
1958  }
1959  }
1960  else /* ABC */
1961  {
1962  color &= 0x00FFFFU; /* get color */
1963  #if (SSD1351_AUTO_COLOR_CONVERT == 1) /* if auto color convert */
1964  color = ((color&0xF800)>>11) | (color&0x07E0) | ((color&0x001F)<<11); /* blue green red */
1965  #endif
1966  if (a_ssd1351_write_byte(handle, (color>>8)&0xFF, SSD1351_DATA) != 0) /* set 1st */
1967  {
1968  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1969 
1970  return 1; /* return error */
1971  }
1972  if (a_ssd1351_write_byte(handle, (color>>0)&0xFF, SSD1351_DATA) != 0) /* set 2nd */
1973  {
1974  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1975 
1976  return 1; /* return error */
1977  }
1978  }
1979  }
1980  }
1981 
1982  return 0; /* success return 0 */
1983  }
1984  else
1985  {
1986  for (i = 0; i < (right - left + 1); i++) /* x */
1987  {
1988  for (j = 0; j < (bottom - top + 1); j++) /* y */
1989  {
1990  if ((handle->conf_1 & 0x04) != 0) /* CBA */
1991  {
1992  if (a_ssd1351_write_byte(handle, (color>>16)&0x3F, SSD1351_DATA) != 0) /* set red */
1993  {
1994  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
1995 
1996  return 1; /* return error */
1997  }
1998  if (a_ssd1351_write_byte(handle, (color>>8)&0x3F, SSD1351_DATA) != 0) /* set green */
1999  {
2000  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2001 
2002  return 1; /* return error */
2003  }
2004  if (a_ssd1351_write_byte(handle, (color>>0)&0x3F, SSD1351_DATA) != 0) /* set blue */
2005  {
2006  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2007 
2008  return 1; /* return error */
2009  }
2010  }
2011  else /* ABC */
2012  {
2013  #if (SSD1351_AUTO_COLOR_CONVERT == 1) /* if auto color convert */
2014  if (a_ssd1351_write_byte(handle, (color>>0)&0x3F, SSD1351_DATA) != 0) /* set blue */
2015  {
2016  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2017 
2018  return 1; /* return error */
2019  }
2020  if (a_ssd1351_write_byte(handle, (color>>8)&0x3F, SSD1351_DATA) != 0) /* set green */
2021  {
2022  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2023 
2024  return 1; /* return error */
2025  }
2026  if (a_ssd1351_write_byte(handle, (color>>16)&0x3F, SSD1351_DATA) != 0) /* set red */
2027  {
2028  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2029 
2030  return 1; /* return error */
2031  }
2032  #else
2033  if (a_ssd1351_write_byte(handle, (color>>16)&0x3F, SSD1351_DATA) != 0) /* set blue */
2034  {
2035  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2036 
2037  return 1; /* return error */
2038  }
2039  if (a_ssd1351_write_byte(handle, (color>>8)&0x3F, SSD1351_DATA) != 0) /* set green */
2040  {
2041  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2042 
2043  return 1; /* return error */
2044  }
2045  if (a_ssd1351_write_byte(handle, (color>>0)&0x3F, SSD1351_DATA) != 0) /* set red */
2046  {
2047  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2048 
2049  return 1; /* return error */
2050  }
2051  #endif
2052  }
2053  }
2054  }
2055 
2056  return 0; /* success return 0 */
2057  }
2058 }
2059 
2075 static uint8_t a_ssd1351_draw_picture(ssd1351_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint32_t *color)
2076 {
2077  uint8_t i, j;
2078  uint32_t p;
2079 
2080  if (handle == NULL) /* check handle */
2081  {
2082  return 2; /* return error */
2083  }
2084  if (handle->inited != 1) /* check handle initialization */
2085  {
2086  return 3; /* return error */
2087  }
2088  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_COLUMN_ADDRESS, SSD1351_CMD) != 0) /* write column address command */
2089  {
2090  handle->debug_print("ssd1351: write command failed.\n"); /* write command failed */
2091 
2092  return 1; /* return error */
2093  }
2094  if (a_ssd1351_write_byte(handle, left, SSD1351_DATA) != 0) /* set start address */
2095  {
2096  handle->debug_print("ssd1351: write start address failed.\n"); /* write start address failed */
2097 
2098  return 1; /* return error */
2099  }
2100  if (a_ssd1351_write_byte(handle, right, SSD1351_DATA) != 0) /* set end address */
2101  {
2102  handle->debug_print("ssd1351: write end address failed.\n"); /* write end address failed */
2103 
2104  return 1; /* return error */
2105  }
2106  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_ROW_ADDRESS, SSD1351_CMD) != 0) /* write column address command */
2107  {
2108  handle->debug_print("ssd1351: write command failed.\n"); /* write command failed */
2109 
2110  return 1; /* return error */
2111  }
2112  if (a_ssd1351_write_byte(handle, top, SSD1351_DATA) != 0) /* set start address */
2113  {
2114  handle->debug_print("ssd1351: write start address failed.\n"); /* write start address failed */
2115 
2116  return 1; /* return error */
2117  }
2118  if (a_ssd1351_write_byte(handle, bottom, SSD1351_DATA) != 0) /* set end address */
2119  {
2120  handle->debug_print("ssd1351: write end address failed.\n"); /* write end address failed */
2121 
2122  return 1; /* return error */
2123  }
2124  if (a_ssd1351_write_byte(handle, SSD1351_CMD_WRITE_RAM, SSD1351_CMD) != 0) /* set write ram */
2125  {
2126  handle->debug_print("ssd1351: write ram failed.\n"); /* write ram failed */
2127 
2128  return 1; /* return error */
2129  }
2130  if ((handle->conf_1 & 0xC0) == 0) /* if 256 */
2131  {
2132  if ((handle->conf_1 & 0x01) != 0) /* if vertical */
2133  {
2134  p = 0; /* set zero */
2135  for (j = 0; j < (bottom - top + 1); j++) /* x */
2136  {
2137  for (i = 0; i < (right - left + 1); i++) /* y */
2138  {
2139  if (a_ssd1351_write_byte(handle, color[p]&0xFF, SSD1351_DATA) != 0) /* set data */
2140  {
2141  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2142 
2143  return 1; /* return error */
2144  }
2145  p++; /* p++ */
2146  }
2147  }
2148  }
2149  else /* if horizontal */
2150  {
2151  p = 0; /* set zero */
2152  for (i = 0; i < (right - left + 1); i++) /* x */
2153  {
2154  for (j = 0; j < (bottom - top + 1); j++) /* y */
2155  {
2156  if (a_ssd1351_write_byte(handle, color[p]&0xFF, SSD1351_DATA) != 0) /* set data */
2157  {
2158  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2159 
2160  return 1; /* return error */
2161  }
2162  p++; /* p++ */
2163  }
2164  }
2165  }
2166 
2167  return 0; /* success return 0 */
2168  }
2169  else if ((handle->conf_1&0xC0) == 0x40) /* if 65K */
2170  {
2171  if ((handle->conf_1 & 0x01) != 0) /* if vertical */
2172  {
2173  p = 0;
2174  for (j = 0; j < (bottom - top + 1); j++) /* x */
2175  {
2176  for (i = 0; i < (right - left + 1); i++) /* y */
2177  {
2178  if ((handle->conf_1 & 0x04) != 0) /* CBA */
2179  {
2180  color[p] &= 0x00FFFFU;
2181  if (a_ssd1351_write_byte(handle, (color[p]>>8)&0xFF, SSD1351_DATA) != 0) /* set 1st */
2182  {
2183  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2184 
2185  return 1; /* return error */
2186  }
2187  if (a_ssd1351_write_byte(handle, (color[p]>>0)&0xFF, SSD1351_DATA) != 0) /* set 2nd */
2188  {
2189  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2190 
2191  return 1; /* return error */
2192  }
2193  }
2194  else /* ABC */
2195  {
2196  color[p] &= 0x00FFFFU; /* get color */
2197  #if (SSD1351_AUTO_COLOR_CONVERT == 1) /* if auto convert */
2198  color[p] = ((color[p]&0xF800)>>11) | (color[p]&0x07E0) | /* convert color */
2199  ((color[p]&0x001F)<<11); /* blue green red */
2200  #endif
2201  if (a_ssd1351_write_byte(handle, (color[p]>>8)&0xFF, SSD1351_DATA) != 0) /* set 1st */
2202  {
2203  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2204 
2205  return 1; /* return error */
2206  }
2207  if (a_ssd1351_write_byte(handle, (color[p]>>0)&0xFF, SSD1351_DATA) != 0) /* set 2nd */
2208  {
2209  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2210 
2211  return 1; /* return error */
2212  }
2213  }
2214  p++; /* p++ */
2215  }
2216  }
2217  }
2218  else /* if horizontal */
2219  {
2220  p = 0;
2221  for (i = 0; i < (right - left + 1); i++) /* x */
2222  {
2223  for (j = 0; j < (bottom - top + 1); j++) /* y */
2224  {
2225  if ((handle->conf_1 & 0x04) != 0) /* CBA */
2226  {
2227  color[p] &= 0x00FFFFU;
2228  if (a_ssd1351_write_byte(handle, (color[p]>>8)&0xFF, SSD1351_DATA) != 0) /* set 1st */
2229  {
2230  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2231 
2232  return 1; /* return error */
2233  }
2234  if (a_ssd1351_write_byte(handle, (color[p]>>0)&0xFF, SSD1351_DATA) != 0) /* set 2nd */
2235  {
2236  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2237 
2238  return 1; /* return error */
2239  }
2240  }
2241  else /* ABC */
2242  {
2243  color[p] &= 0x00FFFFU; /* get color */
2244  #if (SSD1351_AUTO_COLOR_CONVERT == 1) /* if auto convert */
2245  color[p] = ((color[p]&0xF800)>>11) | (color[p]&0x07E0) | /* convert color */
2246  ((color[p]&0x001F)<<11); /* blue green red */
2247  #endif
2248  if (a_ssd1351_write_byte(handle, (color[p]>>8)&0xFF, SSD1351_DATA) != 0) /* set 1st */
2249  {
2250  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2251 
2252  return 1; /* return error */
2253  }
2254  if (a_ssd1351_write_byte(handle, (color[p]>>0)&0xFF, SSD1351_DATA) != 0) /* set 2nd */
2255  {
2256  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2257 
2258  return 1; /* return error */
2259  }
2260  }
2261  p++; /* p++ */
2262  }
2263  }
2264  }
2265 
2266  return 0; /* success return 0 */
2267  }
2268  else
2269  {
2270  if ((handle->conf_1 & 0x01) != 0) /* if vertical */
2271  {
2272  p = 0; /* set zero */
2273  for (j = 0; j < (bottom - top + 1); j++) /* x */
2274  {
2275  for (i = 0; i < (right - left + 1); i++) /* y */
2276  {
2277  if ((handle->conf_1 & 0x04) != 0) /* CBA */
2278  {
2279  if (a_ssd1351_write_byte(handle, (color[p]>>16)&0x3F, SSD1351_DATA) != 0)/* set red */
2280  {
2281  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2282 
2283  return 1; /* return error */
2284  }
2285  if (a_ssd1351_write_byte(handle, (color[p]>>8)&0x3F, SSD1351_DATA) != 0) /* set green */
2286  {
2287  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2288 
2289  return 1; /* return error */
2290  }
2291  if (a_ssd1351_write_byte(handle, (color[p]>>0)&0x3F, SSD1351_DATA) != 0) /* set blue */
2292  {
2293  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2294 
2295  return 1; /* return error */
2296  }
2297  }
2298  else /* ABC */
2299  {
2300  #if (SSD1351_AUTO_COLOR_CONVERT == 1) /* if auto convert */
2301  if (a_ssd1351_write_byte(handle, (color[p]>>0)&0x3F, SSD1351_DATA) != 0) /* set blue */
2302  {
2303  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2304 
2305  return 1; /* return error */
2306  }
2307  if (a_ssd1351_write_byte(handle, (color[p]>>8)&0x3F, SSD1351_DATA) != 0) /* set green */
2308  {
2309  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2310 
2311  return 1; /* return error */
2312  }
2313  if (a_ssd1351_write_byte(handle, (color[p]>>16)&0x3F, SSD1351_DATA) != 0)/* set red */
2314  {
2315  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2316 
2317  return 1; /* return error */
2318  }
2319  #else
2320  if (a_ssd1351_write_byte(handle, (color[p]>>16)&0x3F, SSD1351_DATA) != 0)/* set blue */
2321  {
2322  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2323 
2324  return 1; /* return error */
2325  }
2326  if (a_ssd1351_write_byte(handle, (color[p]>>8)&0x3F, SSD1351_DATA) != 0) /* set green */
2327  {
2328  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2329 
2330  return 1; /* return error */
2331  }
2332  if (a_ssd1351_write_byte(handle, (color[p]>>0)&0x3F, SSD1351_DATA) != 0) /* set red */
2333  {
2334  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2335 
2336  return 1; /* return error */
2337  }
2338  #endif
2339  }
2340  p++; /* p++ */
2341  }
2342  }
2343  }
2344  else /* if horizontal */
2345  {
2346  p = 0; /* set zero */
2347  for (i = 0; i < (right - left + 1); i++) /* x */
2348  {
2349  for (j = 0; j < (bottom - top + 1); j++) /* y */
2350  {
2351  if ((handle->conf_1 & 0x04) != 0) /* CBA */
2352  {
2353  if (a_ssd1351_write_byte(handle, (color[p]>>16)&0x3F, SSD1351_DATA) != 0)/* set red */
2354  {
2355  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2356 
2357  return 1; /* return error */
2358  }
2359  if (a_ssd1351_write_byte(handle, (color[p]>>8)&0x3F, SSD1351_DATA) != 0) /* set green */
2360  {
2361  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2362 
2363  return 1; /* return error */
2364  }
2365  if (a_ssd1351_write_byte(handle, (color[p]>>0)&0x3F, SSD1351_DATA) != 0) /* set blue */
2366  {
2367  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2368 
2369  return 1; /* return error */
2370  }
2371  }
2372  else /* ABC */
2373  {
2374  #if (SSD1351_AUTO_COLOR_CONVERT == 1) /* if auto convert */
2375  if (a_ssd1351_write_byte(handle, (color[p]>>0)&0x3F, SSD1351_DATA) != 0) /* set blue */
2376  {
2377  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2378 
2379  return 1; /* return error */
2380  }
2381  if (a_ssd1351_write_byte(handle, (color[p]>>8)&0x3F, SSD1351_DATA) != 0) /* set green */
2382  {
2383  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2384 
2385  return 1; /* return error */
2386  }
2387  if (a_ssd1351_write_byte(handle, (color[p]>>16)&0x3F, SSD1351_DATA) != 0)/* set red */
2388  {
2389  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2390 
2391  return 1; /* return error */
2392  }
2393  #else
2394  if (a_ssd1351_write_byte(handle, (color[p]>>16)&0x3F, SSD1351_DATA) != 0)/* set blue */
2395  {
2396  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2397 
2398  return 1; /* return error */
2399  }
2400  if (a_ssd1351_write_byte(handle, (color[p]>>8)&0x3F, SSD1351_DATA) != 0) /* set green */
2401  {
2402  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2403 
2404  return 1; /* return error */
2405  }
2406  if (a_ssd1351_write_byte(handle, (color[p]>>0)&0x3F, SSD1351_DATA) != 0) /* set red */
2407  {
2408  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2409 
2410  return 1; /* return error */
2411  }
2412  #endif
2413  }
2414  p++; /* p++ */
2415  }
2416  }
2417  }
2418 
2419  return 0; /* success return 0 */
2420  }
2421 }
2422 
2438 static uint8_t a_ssd1351_draw_picture_16_bits(ssd1351_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint16_t *color)
2439 {
2440  uint8_t i, j;
2441  uint32_t p;
2442 
2443  if (handle == NULL) /* check handle */
2444  {
2445  return 2; /* return error */
2446  }
2447  if (handle->inited != 1) /* check handle initialization */
2448  {
2449  return 3; /* return error */
2450  }
2451  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_COLUMN_ADDRESS, SSD1351_CMD) != 0) /* write column address command */
2452  {
2453  handle->debug_print("ssd1351: write command failed.\n"); /* write command failed */
2454 
2455  return 1; /* return error */
2456  }
2457  if (a_ssd1351_write_byte(handle, left, SSD1351_DATA) != 0) /* set start address */
2458  {
2459  handle->debug_print("ssd1351: write start address failed.\n"); /* write start address failed */
2460 
2461  return 1; /* return error */
2462  }
2463  if (a_ssd1351_write_byte(handle, right, SSD1351_DATA) != 0) /* set end address */
2464  {
2465  handle->debug_print("ssd1351: write end address failed.\n"); /* write end address failed */
2466 
2467  return 1; /* return error */
2468  }
2469  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_ROW_ADDRESS, SSD1351_CMD) != 0) /* write column address command */
2470  {
2471  handle->debug_print("ssd1351: write command failed.\n"); /* write command failed */
2472 
2473  return 1; /* return error */
2474  }
2475  if (a_ssd1351_write_byte(handle, top, SSD1351_DATA) != 0) /* set start address */
2476  {
2477  handle->debug_print("ssd1351: write start address failed.\n"); /* write start address failed */
2478 
2479  return 1; /* return error */
2480  }
2481  if (a_ssd1351_write_byte(handle, bottom, SSD1351_DATA) != 0) /* set end address */
2482  {
2483  handle->debug_print("ssd1351: write end address failed.\n"); /* write end address failed */
2484 
2485  return 1; /* return error */
2486  }
2487  if (a_ssd1351_write_byte(handle, SSD1351_CMD_WRITE_RAM, SSD1351_CMD) != 0) /* set write ram */
2488  {
2489  handle->debug_print("ssd1351: write ram failed.\n"); /* write ram failed */
2490 
2491  return 1; /* return error */
2492  }
2493  if ((handle->conf_1&0xC0) == 0) /* if 256 */
2494  {
2495  if ((handle->conf_1 & 0x01) != 0) /* if vertical */
2496  {
2497  p = 0; /* set zero */
2498  for (j = 0; j < (bottom - top + 1); j++) /* x */
2499  {
2500  for (i = 0; i < (right - left + 1); i++) /* y */
2501  {
2502  if (a_ssd1351_write_byte(handle, color[p]&0xFF, SSD1351_DATA) != 0) /* set data */
2503  {
2504  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2505 
2506  return 1; /* return error */
2507  }
2508  p++; /* p++ */
2509  }
2510  }
2511  }
2512  else /* if horizontal */
2513  {
2514  p = 0; /* set zero */
2515  for (i = 0; i < (right - left + 1); i++) /* x */
2516  {
2517  for (j = 0; j < (bottom - top + 1); j++) /* y */
2518  {
2519  if (a_ssd1351_write_byte(handle, color[p]&0xFF, SSD1351_DATA) != 0) /* set data */
2520  {
2521  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2522 
2523  return 1; /* return error */
2524  }
2525  p++; /* p++ */
2526  }
2527  }
2528  }
2529 
2530  return 0; /* success return 0 */
2531  }
2532  else if ((handle->conf_1&0xC0) == 0x40) /* if 65K */
2533  {
2534  if ((handle->conf_1 & 0x01) != 0) /* if vertical */
2535  {
2536  p = 0;
2537  for (j = 0; j < (bottom - top + 1); j++) /* x */
2538  {
2539  for (i = 0; i < (right - left + 1); i++) /* y */
2540  {
2541  if ((handle->conf_1 & 0x04) != 0) /* CBA */
2542  {
2543  color[p] &= 0x00FFFFU;
2544  if (a_ssd1351_write_byte(handle, (color[p]>>8)&0xFF, SSD1351_DATA) != 0) /* set 1st */
2545  {
2546  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2547 
2548  return 1; /* return error */
2549  }
2550  if (a_ssd1351_write_byte(handle, (color[p]>>0)&0xFF, SSD1351_DATA) != 0) /* set 2nd */
2551  {
2552  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2553 
2554  return 1; /* return error */
2555  }
2556  }
2557  else /* ABC */
2558  {
2559  color[p] &= 0x00FFFFU; /* get color */
2560  #if (SSD1351_AUTO_COLOR_CONVERT == 1) /* if auto convert */
2561  color[p] = ((color[p]&0xF800)>>11) | (color[p]&0x07E0) | /* convert color */
2562  ((color[p]&0x001F)<<11); /* blue green red */
2563  #endif
2564  if (a_ssd1351_write_byte(handle, (color[p]>>8)&0xFF, SSD1351_DATA) != 0) /* set 1st */
2565  {
2566  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2567 
2568  return 1; /* return error */
2569  }
2570  if (a_ssd1351_write_byte(handle, (color[p]>>0)&0xFF, SSD1351_DATA) != 0) /* set 2nd */
2571  {
2572  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2573 
2574  return 1; /* return error */
2575  }
2576  }
2577  p++; /* p++ */
2578  }
2579  }
2580  }
2581  else /* if horizontal */
2582  {
2583  p = 0;
2584  for (i = 0; i < (right - left + 1); i++) /* x */
2585  {
2586  for (j = 0; j < (bottom - top + 1); j++) /* y */
2587  {
2588  if ((handle->conf_1 & 0x04) != 0) /* CBA */
2589  {
2590  color[p] &= 0x00FFFFU; /* get color */
2591  if (a_ssd1351_write_byte(handle, (color[p]>>8)&0xFF, SSD1351_DATA) != 0) /* set 1st */
2592  {
2593  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2594 
2595  return 1; /* return error */
2596  }
2597  if (a_ssd1351_write_byte(handle, (color[p]>>0)&0xFF, SSD1351_DATA) != 0) /* set 2nd */
2598  {
2599  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2600 
2601  return 1; /* return error */
2602  }
2603  }
2604  else /* ABC */
2605  {
2606  color[p] &= 0x00FFFFU; /* get color */
2607  #if (SSD1351_AUTO_COLOR_CONVERT == 1) /* if auto convert */
2608  color[p] = ((color[p]&0xF800)>>11) | (color[p]&0x07E0) | /* convert color */
2609  ((color[p]&0x001F)<<11); /* blue green red */
2610  #endif
2611  if (a_ssd1351_write_byte(handle, (color[p]>>8)&0xFF, SSD1351_DATA) != 0) /* set 1st */
2612  {
2613  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2614 
2615  return 1; /* return error */
2616  }
2617  if (a_ssd1351_write_byte(handle, (color[p]>>0)&0xFF, SSD1351_DATA) != 0) /* set 2nd */
2618  {
2619  handle->debug_print("ssd1351: write data failed.\n"); /* write data failed */
2620 
2621  return 1; /* return error */
2622  }
2623  }
2624  p++; /* p++ */
2625  }
2626  }
2627  }
2628 
2629  return 0; /* success return 0 */
2630  }
2631  else
2632  {
2633  handle->debug_print("ssd1351: 262K color format can't use this function.\n"); /* write data failed */
2634 
2635  return 1; /* success return 0 */
2636  }
2637 }
2638 
2654 uint8_t ssd1351_draw_point(ssd1351_handle_t *handle, uint8_t x, uint8_t y, uint32_t color)
2655 {
2656  if (handle == NULL) /* check handle */
2657  {
2658  return 2; /* return error */
2659  }
2660  if (handle->inited != 1) /* check handle initialization */
2661  {
2662  return 3; /* return error */
2663  }
2664  if (x > 127) /* check x */
2665  {
2666  handle->debug_print("ssd1351: x is over 127.\n"); /* x is over 127 */
2667 
2668  return 4; /* return error */
2669  }
2670  if (y > 127) /* check y */
2671  {
2672  handle->debug_print("ssd1351: y is over 127.\n"); /* y is over 127 */
2673 
2674  return 5; /* return error */
2675  }
2676 
2677  return a_ssd1351_draw_point(handle, x, y, color); /* draw point */
2678 }
2679 
2697 uint8_t ssd1351_write_string(ssd1351_handle_t *handle, uint8_t x, uint8_t y, char *str, uint16_t len, uint32_t color, ssd1351_font_t font)
2698 {
2699  if (handle == NULL) /* check handle */
2700  {
2701  return 2; /* return error */
2702  }
2703  if (handle->inited != 1) /* check handle initialization */
2704  {
2705  return 3; /* return error */
2706  }
2707  if((x > 127) || (y > 127)) /* check x, y */
2708  {
2709  handle->debug_print("ssd1351: x or y is invalid.\n"); /* x or y is invalid */
2710 
2711  return 4; /* return error */
2712  }
2713 
2714  while ((len != 0) && (*str <= '~') && (*str >= ' ')) /* write all string */
2715  {
2716  if (x > (127 - (font / 2))) /* check x point */
2717  {
2718  x = 0; /* set x */
2719  y += (uint8_t)font; /* set next row */
2720  }
2721  if (y > (127 - font)) /* check y pont */
2722  {
2723  y = x = 0; /* reset to 0 */
2724  }
2725  if (a_ssd1351_show_char(handle, x, y, *str, font, color) != 0) /* show a char */
2726  {
2727  return 1; /* return error */
2728  }
2729  x += (uint8_t)(font / 2); /* x + font/2 */
2730  str++; /* str address++ */
2731  len--; /* str length-- */
2732  }
2733 
2734  return 0; /* success return 0 */
2735 }
2736 
2758 uint8_t ssd1351_fill_rect(ssd1351_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint32_t color)
2759 {
2760  if (handle == NULL) /* check handle */
2761  {
2762  return 2; /* return error */
2763  }
2764  if (handle->inited != 1) /* check handle initialization */
2765  {
2766  return 3; /* return error */
2767  }
2768  if (left > 127) /* check left */
2769  {
2770  handle->debug_print("ssd1351: left is over 127.\n"); /* left is over 127 */
2771 
2772  return 4; /* return error */
2773  }
2774  if (right > 127) /* check right */
2775  {
2776  handle->debug_print("ssd1351: right is over 127.\n"); /* right is over 127 */
2777 
2778  return 5; /* return error */
2779  }
2780  if (left >= right) /* check left and right */
2781  {
2782  handle->debug_print("ssd1351: left >= right.\n"); /* left >= right */
2783 
2784  return 6; /* return error */
2785  }
2786  if (top > 127) /* check top */
2787  {
2788  handle->debug_print("ssd1351: top is over 127.\n"); /* top is over 127 */
2789 
2790  return 7; /* return error */
2791  }
2792  if (bottom > 127) /* check bottom */
2793  {
2794  handle->debug_print("ssd1351: bottom is over 127.\n"); /* bottom is over 127 */
2795 
2796  return 8; /* return error */
2797  }
2798  if (top >= bottom) /* check top and bottom */
2799  {
2800  handle->debug_print("ssd1351: top >= bottom.\n"); /* top >= bottom */
2801 
2802  return 9; /* return error */
2803  }
2804 
2805  return a_ssd1351_fill_rect(handle, left, top, right, bottom, color); /* fill rect */
2806 }
2807 
2829 uint8_t ssd1351_draw_picture(ssd1351_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint32_t *image)
2830 {
2831  if (handle == NULL) /* check handle */
2832  {
2833  return 2; /* return error */
2834  }
2835  if (handle->inited != 1) /* check handle initialization */
2836  {
2837  return 3; /* return error */
2838  }
2839  if (left > 127) /* check left */
2840  {
2841  handle->debug_print("ssd1351: left is over 127.\n"); /* left is over 127 */
2842 
2843  return 4; /* return error */
2844  }
2845  if (right > 127) /* check right */
2846  {
2847  handle->debug_print("ssd1351: right is over 127.\n"); /* right is over 127 */
2848 
2849  return 5; /* return error */
2850  }
2851  if (left >= right) /* check left and right */
2852  {
2853  handle->debug_print("ssd1351: left >= right.\n"); /* left >= right */
2854 
2855  return 6; /* return error */
2856  }
2857  if (top > 127) /* check top */
2858  {
2859  handle->debug_print("ssd1351: top is over 127.\n"); /* top is over 127 */
2860 
2861  return 7; /* return error */
2862  }
2863  if (bottom > 127) /* check bottom */
2864  {
2865  handle->debug_print("ssd1351: bottom is over 127.\n"); /* bottom is over 127 */
2866 
2867  return 8; /* return error */
2868  }
2869  if (top >= bottom) /* check top and bottom */
2870  {
2871  handle->debug_print("ssd1351: top >= bottom.\n"); /* top >= bottom */
2872 
2873  return 9; /* return error */
2874  }
2875 
2876  return a_ssd1351_draw_picture(handle, left, top, right, bottom, image); /* draw picture */
2877 }
2878 
2900 uint8_t ssd1351_draw_picture_16bits(ssd1351_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint16_t *image)
2901 {
2902  if (handle == NULL) /* check handle */
2903  {
2904  return 2; /* return error */
2905  }
2906  if (handle->inited != 1) /* check handle initialization */
2907  {
2908  return 3; /* return error */
2909  }
2910  if (left > 127) /* check left */
2911  {
2912  handle->debug_print("ssd1351: left is over 127.\n"); /* left is over 127 */
2913 
2914  return 4; /* return error */
2915  }
2916  if (right > 127) /* check right */
2917  {
2918  handle->debug_print("ssd1351: right is over 127.\n"); /* right is over 127 */
2919 
2920  return 5; /* return error */
2921  }
2922  if (left >= right) /* check left and right */
2923  {
2924  handle->debug_print("ssd1351: left >= right.\n"); /* left >= right */
2925 
2926  return 6; /* return error */
2927  }
2928  if (top > 127) /* check top */
2929  {
2930  handle->debug_print("ssd1351: top is over 127.\n"); /* top is over 127 */
2931 
2932  return 7; /* return error */
2933  }
2934  if (bottom > 127) /* check bottom */
2935  {
2936  handle->debug_print("ssd1351: bottom is over 127.\n"); /* bottom is over 127 */
2937 
2938  return 8; /* return error */
2939  }
2940  if (top >= bottom) /* check top and bottom */
2941  {
2942  handle->debug_print("ssd1351: top >= bottom.\n"); /* top >= bottom */
2943 
2944  return 9; /* return error */
2945  }
2946 
2947  return a_ssd1351_draw_picture_16_bits(handle, left, top, right, bottom, image); /* draw picture */
2948 }
2949 
2960 {
2961  if (handle == NULL) /* check handle */
2962  {
2963  return 2; /* return error */
2964  }
2965  if (handle->inited != 1) /* check handle initialization */
2966  {
2967  return 3; /* return error */
2968  }
2969 
2970  if (a_ssd1351_write_byte(handle, SSD1351_CMD_START_MOVING, SSD1351_CMD) != 0) /* set start moving */
2971  {
2972  handle->debug_print("ssd1351: write start moving failed.\n"); /* write start moving failed */
2973 
2974  return 1; /* return error */
2975  }
2976 
2977  return 0; /* success return 0 */
2978 }
2979 
2990 {
2991  if (handle == NULL) /* check handle */
2992  {
2993  return 2; /* return error */
2994  }
2995  if (handle->inited != 1) /* check handle initialization */
2996  {
2997  return 3; /* return error */
2998  }
2999 
3000  if (a_ssd1351_write_byte(handle, SSD1351_CMD_STOP_MOVING, SSD1351_CMD) != 0) /* set stop moving */
3001  {
3002  handle->debug_print("ssd1351: write stop moving failed.\n"); /* write stop moving failed */
3003 
3004  return 1; /* return error */
3005  }
3006 
3007  return 0; /* success return 0 */
3008 }
3009 
3021 uint8_t ssd1351_write_cmd(ssd1351_handle_t *handle, uint8_t cmd)
3022 {
3023  if (handle == NULL) /* check handle */
3024  {
3025  return 2; /* return error */
3026  }
3027  if (handle->inited != 1) /* check handle initialization */
3028  {
3029  return 3; /* return error */
3030  }
3031 
3032  return a_ssd1351_write_byte(handle, cmd, SSD1351_CMD); /* write command */
3033 }
3034 
3046 uint8_t ssd1351_write_data(ssd1351_handle_t *handle, uint8_t data)
3047 {
3048  if (handle == NULL) /* check handle */
3049  {
3050  return 2; /* return error */
3051  }
3052  if (handle->inited != 1) /* check handle initialization */
3053  {
3054  return 3; /* return error */
3055  }
3056 
3057  return a_ssd1351_write_byte(handle, data, SSD1351_DATA); /* write data */
3058 }
3059 
3073 {
3074  if (handle == NULL) /* check handle */
3075  {
3076  return 2; /* return error */
3077  }
3078  if (handle->debug_print == NULL) /* check debug_print */
3079  {
3080  return 3; /* return error */
3081  }
3082  if (handle->spi_init == NULL) /* check spi_init */
3083  {
3084  handle->debug_print("ssd1351: spi_init is null.\n"); /* spi_init is null */
3085 
3086  return 3; /* return error */
3087  }
3088  if (handle->spi_deinit == NULL) /* check spi_deinit */
3089  {
3090  handle->debug_print("ssd1351: spi_deinit is null.\n"); /* spi_deinit is null */
3091 
3092  return 3; /* return error */
3093  }
3094  if (handle->spi_write_cmd == NULL) /* check spi_write_cmd */
3095  {
3096  handle->debug_print("ssd1351: spi_write_cmd is null.\n"); /* spi_init is null */
3097 
3098  return 3; /* return error */
3099  }
3100  if (handle->cmd_data_gpio_init == NULL) /* check cmd_data_gpio_init */
3101  {
3102  handle->debug_print("ssd1351: cmd_data_gpio_init is null.\n"); /* cmd_data_gpio_init is null */
3103 
3104  return 3; /* return error */
3105  }
3106  if (handle->cmd_data_gpio_deinit == NULL) /* check cmd_data_gpio_deinit */
3107  {
3108  handle->debug_print("ssd1351: cmd_data_gpio_deinit is null.\n"); /* cmd_data_gpio_deinit is null */
3109 
3110  return 3; /* return error */
3111  }
3112  if (handle->cmd_data_gpio_write == NULL) /* check cmd_data_gpio_write */
3113  {
3114  handle->debug_print("ssd1351: cmd_data_gpio_write is null.\n"); /* cmd_data_gpio_write is null */
3115 
3116  return 3; /* return error */
3117  }
3118  if (handle->reset_gpio_init == NULL) /* check reset_gpio_init */
3119  {
3120  handle->debug_print("ssd1351: reset_gpio_init is null.\n"); /* reset_gpio_init is null */
3121 
3122  return 3; /* return error */
3123  }
3124  if (handle->reset_gpio_deinit == NULL) /* check reset_gpio_deinit */
3125  {
3126  handle->debug_print("ssd1351: reset_gpio_deinit is null.\n"); /* reset_gpio_deinit is null */
3127 
3128  return 3; /* return error */
3129  }
3130  if (handle->reset_gpio_write == NULL) /* check reset_gpio_write */
3131  {
3132  handle->debug_print("ssd1351: reset_gpio_write is null.\n"); /* reset_gpio_write is null */
3133 
3134  return 3; /* return error */
3135  }
3136  if (handle->delay_ms == NULL) /* check delay_ms */
3137  {
3138  handle->debug_print("ssd1351: delay_ms is null.\n"); /* delay_ms is null */
3139 
3140  return 3; /* return error */
3141  }
3142 
3143  if (handle->cmd_data_gpio_init() != 0) /* check cmd_data_gpio_init */
3144  {
3145  handle->debug_print("ssd1351: cmd data gpio init failed.\n"); /* cmd data gpio init failed */
3146 
3147  return 5; /* return error */
3148  }
3149  if (handle->reset_gpio_init() != 0) /* reset gpio init */
3150  {
3151  handle->debug_print("ssd1351: reset gpio init failed.\n"); /* reset gpio init failed */
3152  (void)handle->cmd_data_gpio_deinit(); /* cmd_data_gpio_deinit */
3153 
3154  return 4; /* return error */
3155  }
3156  if (handle->reset_gpio_write(0) != 0) /* write 0 */
3157  {
3158  handle->debug_print("ssd1351: reset gpio write failed.\n"); /* reset gpio write failed */
3159  (void)handle->cmd_data_gpio_deinit(); /* cmd_data_gpio_deinit */
3160  (void)handle->reset_gpio_deinit(); /* reset_gpio_deinit */
3161 
3162  return 4; /* return error */
3163  }
3164  handle->delay_ms(100); /* delay 100 ms */
3165  if (handle->reset_gpio_write(1) != 0) /* write 1 */
3166  {
3167  handle->debug_print("ssd1351: reset gpio write failed.\n"); /* reset gpio write failed */
3168  (void)handle->cmd_data_gpio_deinit(); /* cmd_data_gpio_deinit */
3169  (void)handle->reset_gpio_deinit(); /* reset_gpio_deinit */
3170 
3171  return 4; /* return error */
3172  }
3173  if (handle->spi_init() != 0) /* spi init */
3174  {
3175  handle->debug_print("ssd1351: spi init failed.\n"); /* spi init failed */
3176  (void)handle->cmd_data_gpio_deinit(); /* cmd_data_gpio_deinit */
3177  (void)handle->reset_gpio_deinit(); /* reset_gpio_deinit */
3178 
3179  return 1; /* return error */
3180  }
3181  handle->inited = 1; /* flag inited */
3182 
3183  return 0; /* success return 0 */
3184 }
3185 
3200 {
3201  if (handle == NULL) /* check handle */
3202  {
3203  return 2; /* return error */
3204  }
3205  if (handle->inited != 1) /* check handle initialization */
3206  {
3207  return 3; /* return error */
3208  }
3209 
3210  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_SLEEP_MODE_ON, SSD1351_CMD) != 0) /* set sleep mode on */
3211  {
3212  handle->debug_print("ssd1351: write sleep mode on failed.\n"); /* write sleep mode on failed */
3213 
3214  return 4; /* return error */
3215  }
3216  if (a_ssd1351_write_byte(handle, SSD1351_CMD_SET_DISPLAY_ALL_OFF, SSD1351_CMD) != 0) /* set display all off */
3217  {
3218  handle->debug_print("ssd1351: write display all off failed.\n"); /* write display all off failed */
3219 
3220  return 4; /* return error */
3221  }
3222  if (handle->reset_gpio_deinit() != 0) /* reset gpio deinit */
3223  {
3224  handle->debug_print("ssd1351: reset gpio deinit failed.\n"); /* reset gpio deinit failed */
3225 
3226  return 5; /* return error */
3227  }
3228  if (handle->cmd_data_gpio_deinit() != 0) /* cmd data gpio deinit */
3229  {
3230  handle->debug_print("ssd1351: cmd data gpio deinit failed.\n"); /* cmd data gpio deinit failed */
3231 
3232  return 6; /* return error */
3233  }
3234  if (handle->spi_deinit() != 0) /* spi deinit */
3235  {
3236  handle->debug_print("ssd1351: spi deinit failed.\n"); /* spi deinit failed */
3237 
3238  return 1; /* return error */
3239  }
3240  handle->inited = 0; /* flag close */
3241 
3242  return 0; /* success return 0 */
3243 }
3244 
3254 {
3255  if (info == NULL) /* check handle */
3256  {
3257  return 2; /* return error */
3258  }
3259 
3260  memset(info, 0, sizeof(ssd1351_info_t)); /* initialize ssd1351 info structure */
3261  strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
3262  strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
3263  strncpy(info->interface, "SPI", 8); /* copy interface name */
3264  info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
3265  info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
3266  info->max_current_ma = MAX_CURRENT; /* set maximum current */
3267  info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
3268  info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
3269  info->driver_version = DRIVER_VERSION; /* set driver version */
3270 
3271  return 0; /* success return 0 */
3272 }
#define SSD1351_CMD
command data type definition
#define SSD1351_CMD_MASTER_CONTRAST_CONTROL
#define SSD1351_CMD_START_MOVING
#define SSD1351_CMD_USE_BUILT_IN_LINEAR_LUT
#define MAX_CURRENT
#define SSD1351_CMD_SET_COLUMN_ADDRESS
command definition
#define SSD1351_CMD_SET_SLEEP_MODE_ON
#define SSD1351_CMD_SET_DISPLAY_ALL_OFF
#define SSD1351_CMD_SET_PRE_CHARGE_VOLTAGE
#define SSD1351_CMD_SET_SLEEP_MODE_OFF
#define SSD1351_CMD_SET_COMMAND_LOCK
#define SUPPLY_VOLTAGE_MAX
#define SSD1351_CMD_SET_CONTRAST
#define SSD1351_CMD_SET_DISPLAY_OFFSET
#define SSD1351_CMD_WRITE_RAM
#define SSD1351_CMD_FUNCTION_SELECTION
#define TEMPERATURE_MAX
#define SSD1351_CMD_SET_DISPLAY_START_LINE
#define SSD1351_CMD_SET_REMAP_COLOR_DEPTH
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define SSD1351_DATA
#define SSD1351_CMD_READ_RAM
#define SSD1351_CMD_SET_GPIO
#define SSD1351_CMD_STOP_MOVING
#define SSD1351_CMD_SET_SEGMENT_LOW_VOLTAGE
#define SSD1351_CMD_HORIZONTAL_SCROLL
#define SSD1351_CMD_FRONT_CLOCK_DIVIDER_OSC_FREQ
#define SSD1351_CMD_SET_RESET_PRE_CHARGE_PERIOD
#define CHIP_NAME
chip information definition
#define SSD1351_CMD_GRAY_SCALE_PULSE_WIDTH
#define SSD1351_CMD_SET_ROW_ADDRESS
#define DRIVER_VERSION
#define SSD1351_CMD_SET_MUX_RATIO
#define SSD1351_CMD_SET_VCOMH_VOLTAGE
#define SSD1351_CMD_SET_SECOND_PRE_CHARGE_PERIOD
driver ssd1351 header file
driver ssd1351 font header file
uint8_t ssd1351_set_master_contrast_current(ssd1351_handle_t *handle, uint8_t current)
set the master contrast current
uint8_t ssd1351_set_scan_mode(ssd1351_handle_t *handle, ssd1351_scan_mode_t mode)
set the scan mode
uint8_t ssd1351_fill_rect(ssd1351_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint32_t color)
fill the rect
uint8_t ssd1351_set_color_sequence(ssd1351_handle_t *handle, ssd1351_color_sequence_t color_sequence)
set the color sequence
ssd1351_select_vdd_t
ssd1351 select vdd enumeration definition
ssd1351_seg0_mapped_t
ssd1351 seg0 mapped enumeration definition
uint8_t ssd1351_read_ram(ssd1351_handle_t *handle)
sent the read ram command
ssd1351_color_sequence_t
ssd1351 color sequence enumeration definition
uint8_t ssd1351_write_ram(ssd1351_handle_t *handle)
sent the write ram command
uint8_t ssd1351_set_contrast(ssd1351_handle_t *handle, uint8_t a, uint8_t b, uint8_t c)
set the display contrast
ssd1351_command_t
ssd1351 command enumeration definition
ssd1351_scroll_mode_t
ssd1351 scroll mode enumeration definition
ssd1351_gpio_pin_t
ssd1351 gpio pin enumeration definition
uint8_t ssd1351_clear(ssd1351_handle_t *handle)
clear the display
uint8_t ssd1351_set_display_offset(ssd1351_handle_t *handle, uint8_t offset)
set the display offset
uint8_t ssd1351_set_command(ssd1351_handle_t *handle, ssd1351_command_t command)
set the command
uint8_t ssd1351_set_color_depth(ssd1351_handle_t *handle, ssd1351_color_depth_t color_depth)
set the display color depth
ssd1351_segment_low_voltage_t
ssd1351 segment low voltage enumeration definition
uint8_t ssd1351_init(ssd1351_handle_t *handle)
initialize the chip
uint8_t ssd1351_set_use_built_in_linear_lut(ssd1351_handle_t *handle)
use built in linear lut
uint8_t ssd1351_set_parallel_bits(ssd1351_handle_t *handle, ssd1351_select_parallel_bits_t parallel_bits)
set the interface parallel bits
ssd1351_font_t
ssd1351 font size enumeration definition
uint8_t ssd1351_set_column_address(ssd1351_handle_t *handle, uint8_t start_address, uint8_t end_address)
set the display column address
uint8_t ssd1351_set_gpio(ssd1351_handle_t *handle, ssd1351_gpio_pin_t gpio0, ssd1351_gpio_pin_t gpio1)
set the gpio pin
uint8_t ssd1351_set_com_split_odd_even(ssd1351_handle_t *handle, ssd1351_bool_t enable)
set the com split odd or even
ssd1351_scan_mode_t
ssd1351 scan mode enumeration definition
uint8_t ssd1351_set_second_pre_charge_period(ssd1351_handle_t *handle, uint8_t period)
set the second pre charge period
uint8_t ssd1351_set_front_clock_oscillator_frequency(ssd1351_handle_t *handle, uint8_t d, uint8_t frequency)
set the front clock oscillator frequency
ssd1351_display_mode_t
ssd1351 display mode enumeration definition
uint8_t ssd1351_set_pre_charge_voltage(ssd1351_handle_t *handle, uint8_t voltage_level)
set the pre charge voltage
uint8_t ssd1351_set_vcomh_voltage(ssd1351_handle_t *handle, uint8_t voltage_level)
set the vcomh voltage
uint8_t ssd1351_set_phase_period(ssd1351_handle_t *handle, uint8_t phase1_period, uint8_t phase2_period)
set the phase period
uint8_t ssd1351_draw_picture_16bits(ssd1351_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint16_t *image)
draw a 16 bits picture
ssd1351_select_parallel_bits_t
ssd1351 select parallel enumeration definition
uint8_t ssd1351_set_display_start_line(ssd1351_handle_t *handle, uint8_t l)
set the display start line
uint8_t ssd1351_write_string(ssd1351_handle_t *handle, uint8_t x, uint8_t y, char *str, uint16_t len, uint32_t color, ssd1351_font_t font)
write a string in the display
uint8_t ssd1351_info(ssd1351_info_t *info)
get chip's information
uint8_t ssd1351_set_display_mode(ssd1351_handle_t *handle, ssd1351_display_mode_t mode)
set the display mode
ssd1351_bool_t
ssd1351 bool enumeration definition
uint8_t ssd1351_set_row_address(ssd1351_handle_t *handle, uint8_t start_address, uint8_t end_address)
set the row address
ssd1351_address_increment_t
ssd1351 address increment enumeration definition
uint8_t ssd1351_set_select_vdd(ssd1351_handle_t *handle, ssd1351_select_vdd_t vdd)
set the select vdd
ssd1351_color_depth_t
ssd1351 color depth enumeration definition
uint8_t ssd1351_set_seg0_map(ssd1351_handle_t *handle, ssd1351_seg0_mapped_t seg0_map)
set the seg0 map
uint8_t ssd1351_set_sleep_mode(ssd1351_handle_t *handle, ssd1351_bool_t enable)
set the sleep mode
uint8_t ssd1351_set_scroll(ssd1351_handle_t *handle, int8_t scroll, uint8_t start_row, uint8_t row_len, ssd1351_scroll_mode_t mode)
set the scroll
uint8_t ssd1351_set_mux_ratio(ssd1351_handle_t *handle, uint8_t ratio)
set the mux ratio
uint8_t ssd1351_set_address_increment(ssd1351_handle_t *handle, ssd1351_address_increment_t increment)
set the address increment
uint8_t ssd1351_start_moving(ssd1351_handle_t *handle)
start the display moving
uint8_t ssd1351_draw_point(ssd1351_handle_t *handle, uint8_t x, uint8_t y, uint32_t color)
draw a point in the display
uint8_t ssd1351_draw_picture(ssd1351_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint32_t *image)
draw a picture
uint8_t ssd1351_stop_moving(ssd1351_handle_t *handle)
stop the display moving
uint8_t ssd1351_set_gray_scale_pulse_width(ssd1351_handle_t *handle, uint8_t gamma[63])
set the gray scale pulse width
uint8_t ssd1351_set_segment_low_voltage(ssd1351_handle_t *handle, ssd1351_segment_low_voltage_t segment)
set the segment low voltage
uint8_t ssd1351_deinit(ssd1351_handle_t *handle)
close the chip
@ SSD1351_BOOL_TRUE
@ SSD1351_BOOL_FALSE
uint8_t ssd1351_write_data(ssd1351_handle_t *handle, uint8_t data)
write the data
uint8_t ssd1351_write_cmd(ssd1351_handle_t *handle, uint8_t cmd)
write the command
ssd1351 handle structure definition
uint8_t(* spi_init)(void)
uint8_t(* cmd_data_gpio_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* cmd_data_gpio_deinit)(void)
uint8_t(* reset_gpio_deinit)(void)
void(* debug_print)(const char *const fmt,...)
uint8_t(* spi_deinit)(void)
uint8_t(* reset_gpio_init)(void)
uint8_t(* cmd_data_gpio_write)(uint8_t value)
uint8_t(* spi_write_cmd)(uint8_t *buf, uint16_t len)
uint8_t(* reset_gpio_write)(uint8_t value)
ssd1351 information structure definition
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]