LibDriver SSD1681
Loading...
Searching...
No Matches
driver_ssd1681.c
Go to the documentation of this file.
1
36
37#include "driver_ssd1681.h"
38#include "driver_ssd1681_font.h"
39
43#define CHIP_NAME "Solomon Systech SSD1681"
44#define MANUFACTURER_NAME "Solomon Systech"
45#define SUPPLY_VOLTAGE_MIN 2.2f
46#define SUPPLY_VOLTAGE_MAX 3.7f
47#define MAX_CURRENT 500.00f
48#define TEMPERATURE_MIN -40.0f
49#define TEMPERATURE_MAX 85.0f
50#define DRIVER_VERSION 1000
51
55#define SSD1681_CMD 0
56#define SSD1681_DATA 1
57
61#define SSD1681_CMD_DRIVER_OUTPUT_CONTROL 0x01
62#define SSD1681_CMD_GATE_DRIVING_VOLTAGE_CONTROL 0x03
63#define SSD1681_CMD_SOURCE_DRIVING_VOLTAGE_CONTROL 0x04
64#define SSD1681_CMD_INITIAL_CODE_SETTING_OTP_PROGRAM 0x08
65#define SSD1681_CMD_WRITE_REGISTER_FOR_INITIAL_CODE_SETTING 0x09
66#define SSD1681_CMD_READ_REGISTER_FOR_INITIAL_CODE_SETTING 0x0A
67#define SSD1681_CMD_BOOSTER_SOFT_START_CONTROL 0x0C
68#define SSD1681_CMD_DEEP_SLEEP_MODE 0x10
69#define SSD1681_CMD_DATA_ENTRY_MODE_SETTING 0x11
70#define SSD1681_CMD_SW_RESET 0x12
71#define SSD1681_CMD_HV_READY_DETECTION 0x14
72#define SSD1681_CMD_VCI_DETECTION 0x15
73#define SSD1681_CMD_TEMPERATURE_SENSOR_CONTROL 0x18
74#define SSD1681_CMD_TEMPERATURE_SENSOR_CONTROL_WRITE 0x1A
76#define SSD1681_CMD_TEMPERATURE_SENSOR_CONTROL_READ 0x1B
78#define SSD1681_CMD_TEMPERATURE_SENSOR_CONTROL_WRITE_EXT 0x1C
80#define SSD1681_CMD_MASTER_ACTIVATION 0x20
81#define SSD1681_CMD_DISPLAY_UPDATA_CONTROL_1 0x21
82#define SSD1681_CMD_DISPLAY_UPDATA_CONTROL_2 0x22
83#define SSD1681_CMD_WRITE_RAM_BLACK 0x24
84#define SSD1681_CMD_WRITE_RAM_RED 0x26
85#define SSD1681_CMD_READ_RAM 0x27
86#define SSD1681_CMD_VCOM_SENSE 0x28
87#define SSD1681_CMD_VCOM_SENSE_DURATION 0x29
88#define SSD1681_CMD_PROGRAM_VCOM_OTP 0x2A
89#define SSD1681_CMD_WRITE_REGISTER_FOR_VCOM_CONTROL 0x2B
90#define SSD1681_CMD_WRITE_VCOM_REGISTER 0x2C
91#define SSD1681_CMD_OTP_REGISTER_READ_FOR_DISPLAY_OPTION 0x2D
92#define SSD1681_CMD_USER_ID_READ 0x2E
93#define SSD1681_CMD_STATUS_BIT_READ 0x2F
94#define SSD1681_CMD_PROGRAM_WS_OTP 0x30
95#define SSD1681_CMD_LOAD_WS_OTP 0x31
96#define SSD1681_CMD_WRITE_LUT_REGISTER 0x32
97#define SSD1681_CMD_CRC_CALCULATION 0x34
98#define SSD1681_CMD_CRC_STATUS_READ 0x35
99#define SSD1681_CMD_PROGRAM_OTP_SELECTION 0x36
100#define SSD1681_CMD_WRITE_REGISTER_FOR_DISPLAY_OPTION 0x37
101#define SSD1681_CMD_WRITE_REGISTER_FOR_USER_ID 0x38
102#define SSD1681_CMD_OTP_PROGRAM_MODE 0x39
103#define SSD1681_CMD_BORDER_WAVEFORM_CONTROL 0x3C
104#define SSD1681_CMD_END_OPTION 0x3F
105#define SSD1681_CMD_READ_RAM_OPTION 0x41
106#define SSD1681_CMD_SET_RAM_X 0x44
107#define SSD1681_CMD_SET_RAM_Y 0x45
108#define SSD1681_CMD_AUTO_WRITE_RED_RAM_FOR_REGULAR_PATTERN 0x46
109#define SSD1681_CMD_AUTO_WRITE_BW_RAM_FOR_REGULAR_PATTERN 0x47
110#define SSD1681_CMD_SET_RAM_X_ADDRESS_COUNTER 0x4E
111#define SSD1681_CMD_SET_RAM_Y_ADDRESS_COUNTER 0x4F
112#define SSD1681_CMD_NOP 0x7F
113
125static uint8_t a_ssd1681_multiple_write_byte(ssd1681_handle_t *handle, uint8_t command, uint8_t *data, uint16_t len)
126{
127 uint8_t res;
128 uint8_t value;
129 uint16_t i;
130
131 value = 1; /* set value 1 */
132 for (i = 0; i < SSD1681_BUSY_MAX_RETRY_TIMES; i++) /* SSD1681_BUSY_MAX_RETRY_TIMES times */
133 {
134 res = handle->busy_gpio_read(&value); /* read the busy */
135 if (res != 0) /* check error */
136 {
137 return 1; /* return error */
138 }
139 if (value == 1) /* if busy */
140 {
141 handle->delay_ms(SSD1681_BUSY_MAX_DELAY_MS); /* delay SSD1681_BUSY_MAX_DELAY_MS */
142 }
143 else
144 {
145 break; /* break */
146 }
147 }
148 if (value == 1) /* check the value */
149 {
150 return 1; /* return error */
151 }
152
153 res = handle->spi_cmd_data_gpio_write(SSD1681_CMD); /* write command */
154 if (res != 0) /* check error */
155 {
156 return 1; /* return error */
157 }
158 res = handle->spi_write_cmd(&command, 1); /* write command */
159 if (res != 0) /* check error */
160 {
161 return 1; /* return error */
162 }
163 if (len != 0) /* check the length */
164 {
165 res = handle->spi_cmd_data_gpio_write(SSD1681_DATA); /* write data */
166 if (res != 0) /* check error */
167 {
168 return 1; /* return error */
169 }
170 for (i = 0; i < len; i++) /* len times */
171 {
172 if (handle->spi_write_cmd(data + i, 1) != 0) /* write command */
173 {
174 return 1; /* return error */
175 }
176 }
177 }
178
179 return 0; /* success return 0 */
180}
181
193static uint8_t a_ssd1681_multiple_read_byte(ssd1681_handle_t *handle, uint8_t command, uint8_t *data, uint16_t len)
194{
195 uint8_t res;
196 uint8_t value;
197 uint16_t i;
198
199 value = 1; /* set value 1 */
200 for (i = 0; i < SSD1681_BUSY_MAX_RETRY_TIMES; i++) /* SSD1681_BUSY_MAX_RETRY_TIMES times */
201 {
202 res = handle->busy_gpio_read(&value); /* read the busy */
203 if (res != 0) /* check error */
204 {
205 return 1; /* return error */
206 }
207 if (value == 1) /* if busy */
208 {
209 handle->delay_ms(SSD1681_BUSY_MAX_DELAY_MS); /* delay SSD1681_BUSY_MAX_DELAY_MS */
210 }
211 else
212 {
213 break; /* break */
214 }
215 }
216 if (value == 1) /* check the value */
217 {
218 return 1; /* return error */
219 }
220
221 res = handle->spi_cmd_data_gpio_write(SSD1681_CMD); /* write command */
222 if (res != 0) /* check error */
223 {
224 return 1; /* return error */
225 }
226 res = handle->spi_write_cmd(&command, 1); /* write command */
227 if (res != 0) /* check error */
228 {
229 return 1; /* return error */
230 }
231 if (len != 0) /* check the length */
232 {
233 res = handle->spi_cmd_data_gpio_write(SSD1681_DATA); /* write data */
234 if (res != 0) /* check error */
235 {
236 return 1; /* return error */
237 }
238 for (i = 0; i < len; i++) /* len times */
239 {
240 if (handle->spi_read_cmd(data + i, 1) != 0) /* read command */
241 {
242 return 1; /* return error */
243 }
244 }
245 }
246
247 return 0; /* success return 0 */
248}
249
266{
267 uint8_t res;
268 uint8_t b;
269 uint8_t buf[3];
270
271 if (handle == NULL) /* check handle */
272 {
273 return 2; /* return error */
274 }
275 if (handle->inited != 1) /* check handle initialization */
276 {
277 return 3; /* return error */
278 }
279 if (mux > 0x1FF) /* check mux */
280 {
281 handle->debug_print("ssd1681: mux is invalid.\n"); /* mux is invalid */
282
283 return 4; /* return error */
284 }
285
286 buf[0] = (mux >> 0) & 0xFF; /* set mux */
287 buf[1] = (mux >> 8) & 0x01; /* set mux */
288 b = 0; /* init 0 */
289 if (gd != 0) /* check the gd */
290 {
291 b |= 1 << 2; /* set the gd */
292 }
293 if (sm != 0) /* check the sm */
294 {
295 b |= 1 << 1; /* set the sm */
296 }
297 if (tb != 0) /* check the tb */
298 {
299 b |= 1 << 0; /* set the tb */
300 }
301 buf[2] = b; /* set the b */
302
303 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_DRIVER_OUTPUT_CONTROL, (uint8_t *)buf, 3); /* write byte */
304 if (res != 0) /* check the result */
305 {
306 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
307
308 return 1; /* return error */
309 }
310
311 return 0; /* success return 0 */
312}
313
326{
327 uint8_t res;
328 uint8_t buf[1];
329
330 if (handle == NULL) /* check handle */
331 {
332 return 2; /* return error */
333 }
334 if (handle->inited != 1) /* check handle initialization */
335 {
336 return 3; /* return error */
337 }
338
339 buf[0] = voltage; /* set the voltage */
340 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_GATE_DRIVING_VOLTAGE_CONTROL, (uint8_t *)buf, 1); /* write byte */
341 if (res != 0) /* check the result */
342 {
343 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
344
345 return 1; /* return error */
346 }
347
348 return 0; /* success return 0 */
349}
350
365{
366 uint8_t res;
367 uint8_t buf[3];
368
369 if (handle == NULL) /* check handle */
370 {
371 return 2; /* return error */
372 }
373 if (handle->inited != 1) /* check handle initialization */
374 {
375 return 3; /* return error */
376 }
377
378 buf[0] = vsh1; /* set vsh1 */
379 buf[1] = vsh2; /* set vsh2 */
380 buf[2] = vsl; /* set vsl */
381 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_SOURCE_DRIVING_VOLTAGE_CONTROL, (uint8_t *)buf, 3); /* write byte */
382 if (res != 0) /* check the result */
383 {
384 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
385
386 return 1; /* return error */
387 }
388
389 return 0; /* success return 0 */
390}
391
403{
404 uint8_t res;
405
406 if (handle == NULL) /* check handle */
407 {
408 return 2; /* return error */
409 }
410 if (handle->inited != 1) /* check handle initialization */
411 {
412 return 3; /* return error */
413 }
414
415 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_INITIAL_CODE_SETTING_OTP_PROGRAM, NULL, 0); /* write byte */
416 if (res != 0) /* check the result */
417 {
418 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
419
420 return 1; /* return error */
421 }
422
423 return 0; /* success return 0 */
424}
425
437uint8_t ssd1681_otp_initial_write(ssd1681_handle_t *handle, uint8_t param[4])
438{
439 uint8_t res;
440
441 if (handle == NULL) /* check handle */
442 {
443 return 2; /* return error */
444 }
445 if (handle->inited != 1) /* check handle initialization */
446 {
447 return 3; /* return error */
448 }
449
450 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_WRITE_REGISTER_FOR_INITIAL_CODE_SETTING, param, 4); /* write byte */
451 if (res != 0) /* check the result */
452 {
453 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
454
455 return 1; /* return error */
456 }
457
458 return 0; /* success return 0 */
459}
460
472{
473 uint8_t res;
474
475 if (handle == NULL) /* check handle */
476 {
477 return 2; /* return error */
478 }
479 if (handle->inited != 1) /* check handle initialization */
480 {
481 return 3; /* return error */
482 }
483
484 res = a_ssd1681_multiple_read_byte(handle, SSD1681_CMD_READ_REGISTER_FOR_INITIAL_CODE_SETTING, NULL, 0); /* read byte */
485 if (res != 0) /* check the result */
486 {
487 handle->debug_print("ssd1681: multiple read byte failed.\n"); /* multiple read byte failed */
488
489 return 1; /* return error */
490 }
491
492 return 0; /* success return 0 */
493}
494
510 uint8_t phase1, uint8_t phase2,
511 uint8_t phase3, uint8_t duration)
512{
513 uint8_t res;
514 uint8_t buf[4];
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 buf[0] = 0x80 | phase1; /* set the phase1 */
526 buf[1] = 0x80 | phase2; /* set the phase2 */
527 buf[2] = 0x80 | phase3; /* set the phase3 */
528 buf[3] = duration; /* set the duration */
529 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_BOOSTER_SOFT_START_CONTROL, buf, 4); /* write byte */
530 if (res != 0) /* check the result */
531 {
532 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
533
534 return 1; /* return error */
535 }
536
537 return 0; /* success return 0 */
538}
539
552{
553 uint8_t res;
554 uint8_t buf[1];
555
556 if (handle == NULL) /* check handle */
557 {
558 return 2; /* return error */
559 }
560 if (handle->inited != 1) /* check handle initialization */
561 {
562 return 3; /* return error */
563 }
564
565 buf[0] = mode; /* set the mode */
566 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_DEEP_SLEEP_MODE, buf, 1); /* write byte */
567 if (res != 0) /* check the result */
568 {
569 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
570
571 return 1; /* return error */
572 }
573
574 return 0; /* success return 0 */
575}
576
590{
591 uint8_t res;
592 uint8_t buf[1];
593
594 if (handle == NULL) /* check handle */
595 {
596 return 2; /* return error */
597 }
598 if (handle->inited != 1) /* check handle initialization */
599 {
600 return 3; /* return error */
601 }
602
603 buf[0] = (uint8_t)((mode << 0) | (direction << 2)); /* set the config */
604 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_DATA_ENTRY_MODE_SETTING, buf, 1); /* write byte */
605 if (res != 0) /* check the result */
606 {
607 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
608
609 return 1; /* return error */
610 }
611
612 return 0; /* success return 0 */
613}
614
626{
627 uint8_t res;
628
629 if (handle == NULL) /* check handle */
630 {
631 return 2; /* return error */
632 }
633 if (handle->inited != 1) /* check handle initialization */
634 {
635 return 3; /* return error */
636 }
637
638 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_SW_RESET, NULL, 0); /* write byte */
639 if (res != 0) /* check the result */
640 {
641 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
642
643 return 1; /* return error */
644 }
645
646 return 0; /* success return 0 */
647}
648
665uint8_t ssd1681_set_hv_ready_detection(ssd1681_handle_t *handle, uint8_t cool_down_duration, uint8_t cool_down_loop_num)
666{
667 uint8_t res;
668 uint8_t buf[1];
669
670 if (handle == NULL) /* check handle */
671 {
672 return 2; /* return error */
673 }
674 if (handle->inited != 1) /* check handle initialization */
675 {
676 return 3; /* return error */
677 }
678 if (cool_down_duration > 0x7) /* check the cool_down_duration */
679 {
680 handle->debug_print("ssd1681: cool_down_duration is over 7.\n"); /* cool_down_duration is over 7 */
681
682 return 4; /* return error */
683 }
684 if (cool_down_loop_num > 0x7) /* check the cool_down_loop_num */
685 {
686 handle->debug_print("ssd1681: cool_down_loop_num is over 7.\n"); /* cool_down_loop_num is over 7 */
687
688 return 5; /* return error */
689 }
690
691 buf[0] = (cool_down_duration << 4) | (cool_down_loop_num << 0); /* set the config */
692 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_HV_READY_DETECTION, buf, 1); /* write byte */
693 if (res != 0) /* check the result */
694 {
695 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
696
697 return 1; /* return error */
698 }
699
700 return 0; /* success return 0 */
701}
702
715{
716 uint8_t res;
717 uint8_t buf[1];
718
719 if (handle == NULL) /* check handle */
720 {
721 return 2; /* return error */
722 }
723 if (handle->inited != 1) /* check handle initialization */
724 {
725 return 3; /* return error */
726 }
727
728 buf[0] = level; /* set the level */
729 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_VCI_DETECTION, buf, 1); /* write byte */
730 if (res != 0) /* check the result */
731 {
732 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
733
734 return 1; /* return error */
735 }
736
737 return 0; /* success return 0 */
738}
739
752{
753 uint8_t res;
754 uint8_t buf[1];
755
756 if (handle == NULL) /* check handle */
757 {
758 return 2; /* return error */
759 }
760 if (handle->inited != 1) /* check handle initialization */
761 {
762 return 3; /* return error */
763 }
764
765 buf[0] = sensor; /* set the temperature sensor */
766 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_TEMPERATURE_SENSOR_CONTROL, buf, 1); /* write byte */
767 if (res != 0) /* check the result */
768 {
769 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
770
771 return 1; /* return error */
772 }
773
774 return 0; /* success return 0 */
775}
776
789uint8_t ssd1681_write_temperature_sensor(ssd1681_handle_t *handle, uint16_t control)
790{
791 uint8_t res;
792 uint8_t buf[2];
793
794 if (handle == NULL) /* check handle */
795 {
796 return 2; /* return error */
797 }
798 if (handle->inited != 1) /* check handle initialization */
799 {
800 return 3; /* return error */
801 }
802 if (control > 0xFFF) /* check the control */
803 {
804 handle->debug_print("ssd1681: control is over 0xFFF.\n"); /* control is over 0xFFF */
805
806 return 4; /* return error */
807 }
808
809 buf[0] = (control >> 4) & 0xFF; /* set the temperature data */
810 buf[1] = ((control >> 0) << 4) & 0xFF; /* set the temperature data */
811 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_TEMPERATURE_SENSOR_CONTROL_WRITE, buf, 2); /* write byte */
812 if (res != 0) /* check the result */
813 {
814 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
815
816 return 1; /* return error */
817 }
818
819 return 0; /* success return 0 */
820}
821
833uint8_t ssd1681_read_temperature_sensor(ssd1681_handle_t *handle, uint16_t *control)
834{
835 uint8_t res;
836 uint8_t buf[2];
837
838 if (handle == NULL) /* check handle */
839 {
840 return 2; /* return error */
841 }
842 if (handle->inited != 1) /* check handle initialization */
843 {
844 return 3; /* return error */
845 }
846
847 res = a_ssd1681_multiple_read_byte(handle, SSD1681_CMD_TEMPERATURE_SENSOR_CONTROL_READ, buf, 2); /* read byte */
848 if (res != 0) /* check the result */
849 {
850 handle->debug_print("ssd1681: multiple read byte failed.\n"); /* multiple read byte failed */
851
852 return 1; /* return error */
853 }
854 *control = (((uint16_t)buf[0]) << 4) | ((buf[1] >> 4) & 0xFF); /* set the control */
855
856 return 0; /* success return 0 */
857}
858
871{
872 uint8_t res;
873
874 if (handle == NULL) /* check handle */
875 {
876 return 2; /* return error */
877 }
878 if (handle->inited != 1) /* check handle initialization */
879 {
880 return 3; /* return error */
881 }
882
883 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_TEMPERATURE_SENSOR_CONTROL_WRITE_EXT, param, 3); /* write byte */
884 if (res != 0) /* check the result */
885 {
886 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
887
888 return 1; /* return error */
889 }
890
891 return 0; /* success return 0 */
892}
893
905{
906 uint8_t res;
907
908 if (handle == NULL) /* check handle */
909 {
910 return 2; /* return error */
911 }
912 if (handle->inited != 1) /* check handle initialization */
913 {
914 return 3; /* return error */
915 }
916
917 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_MASTER_ACTIVATION, NULL, 0); /* write byte */
918 if (res != 0) /* check the result */
919 {
920 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
921
922 return 1; /* return error */
923 }
924
925 return 0; /* success return 0 */
926}
927
941{
942 uint8_t res;
943 uint8_t buf[1];
944
945 if (handle == NULL) /* check handle */
946 {
947 return 2; /* return error */
948 }
949 if (handle->inited != 1) /* check handle initialization */
950 {
951 return 3; /* return error */
952 }
953
954 buf[0] = (uint8_t)((red_control << 4) | (black_control << 0)); /* set the display update control */
955 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_DISPLAY_UPDATA_CONTROL_1, buf, 1); /* write byte */
956 if (res != 0) /* check the result */
957 {
958 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
959
960 return 1; /* return error */
961 }
962
963 return 0; /* success return 0 */
964}
965
978{
979 uint8_t res;
980 uint8_t buf[1];
981
982 if (handle == NULL) /* check handle */
983 {
984 return 2; /* return error */
985 }
986 if (handle->inited != 1) /* check handle initialization */
987 {
988 return 3; /* return error */
989 }
990
991 buf[0] = sequence; /* set the display sequence */
992 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_DISPLAY_UPDATA_CONTROL_2, buf, 1); /* write byte */
993 if (res != 0) /* check the result */
994 {
995 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
996
997 return 1; /* return error */
998 }
999
1000 return 0; /* success return 0 */
1001}
1002
1014{
1015 uint8_t res;
1016
1017 if (handle == NULL) /* check handle */
1018 {
1019 return 2; /* return error */
1020 }
1021 if (handle->inited != 1) /* check handle initialization */
1022 {
1023 return 3; /* return error */
1024 }
1025
1026 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_WRITE_RAM_BLACK, NULL, 0); /* write byte */
1027 if (res != 0) /* check the result */
1028 {
1029 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1030
1031 return 1; /* return error */
1032 }
1033
1034 return 0; /* success return 0 */
1035}
1036
1048{
1049 uint8_t res;
1050
1051 if (handle == NULL) /* check handle */
1052 {
1053 return 2; /* return error */
1054 }
1055 if (handle->inited != 1) /* check handle initialization */
1056 {
1057 return 3; /* return error */
1058 }
1059
1060 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_WRITE_RAM_RED, NULL, 0); /* write byte */
1061 if (res != 0) /* check the result */
1062 {
1063 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1064
1065 return 1; /* return error */
1066 }
1067
1068 return 0; /* success return 0 */
1069}
1070
1082{
1083 uint8_t res;
1084
1085 if (handle == NULL) /* check handle */
1086 {
1087 return 2; /* return error */
1088 }
1089 if (handle->inited != 1) /* check handle initialization */
1090 {
1091 return 3; /* return error */
1092 }
1093
1094 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_READ_RAM, NULL, 0); /* write byte */
1095 if (res != 0) /* check the result */
1096 {
1097 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1098
1099 return 1; /* return error */
1100 }
1101
1102 return 0; /* success return 0 */
1103}
1104
1116{
1117 uint8_t res;
1118
1119 if (handle == NULL) /* check handle */
1120 {
1121 return 2; /* return error */
1122 }
1123 if (handle->inited != 1) /* check handle initialization */
1124 {
1125 return 3; /* return error */
1126 }
1127
1128 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_VCOM_SENSE, NULL, 0); /* write byte */
1129 if (res != 0) /* check the result */
1130 {
1131 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1132
1133 return 1; /* return error */
1134 }
1135
1136 return 0; /* success return 0 */
1137}
1138
1150uint8_t ssd1681_set_vcom_sense_duration(ssd1681_handle_t *handle, uint8_t duration)
1151{
1152 uint8_t res;
1153 uint8_t buf[1];
1154
1155 if (handle == NULL) /* check handle */
1156 {
1157 return 2; /* return error */
1158 }
1159 if (handle->inited != 1) /* check handle initialization */
1160 {
1161 return 3; /* return error */
1162 }
1163
1164 buf[0] = duration; /* set the duration */
1165 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_VCOM_SENSE_DURATION, buf, 1); /* write byte */
1166 if (res != 0) /* check the result */
1167 {
1168 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1169
1170 return 1; /* return error */
1171 }
1172
1173 return 0; /* success return 0 */
1174}
1175
1187{
1188 uint8_t res;
1189
1190 if (handle == NULL) /* check handle */
1191 {
1192 return 2; /* return error */
1193 }
1194 if (handle->inited != 1) /* check handle initialization */
1195 {
1196 return 3; /* return error */
1197 }
1198
1199 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_PROGRAM_VCOM_OTP, NULL, 0); /* write byte */
1200 if (res != 0) /* check the result */
1201 {
1202 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1203
1204 return 1; /* return error */
1205 }
1206
1207 return 0; /* success return 0 */
1208}
1209
1221{
1222 uint8_t res;
1223 uint8_t buf[2];
1224
1225 if (handle == NULL) /* check handle */
1226 {
1227 return 2; /* return error */
1228 }
1229 if (handle->inited != 1) /* check handle initialization */
1230 {
1231 return 3; /* return error */
1232 }
1233
1234 buf[0] = 0x04; /* command 1 */
1235 buf[1] = 0x63; /* command 2 */
1236 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_WRITE_REGISTER_FOR_VCOM_CONTROL, buf, 2); /* write byte */
1237 if (res != 0) /* check the result */
1238 {
1239 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1240
1241 return 1; /* return error */
1242 }
1243
1244 return 0; /* success return 0 */
1245}
1246
1259{
1260 uint8_t res;
1261 uint8_t buf[1];
1262
1263 if (handle == NULL) /* check handle */
1264 {
1265 return 2; /* return error */
1266 }
1267 if (handle->inited != 1) /* check handle initialization */
1268 {
1269 return 3; /* return error */
1270 }
1271
1272 buf[0] = vcom; /* set the vcom */
1273 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_WRITE_VCOM_REGISTER, buf, 1); /* write byte */
1274 if (res != 0) /* check the result */
1275 {
1276 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1277
1278 return 1; /* return error */
1279 }
1280
1281 return 0; /* success return 0 */
1282}
1283
1295uint8_t ssd1681_otp_read_register(ssd1681_handle_t *handle, uint8_t param[11])
1296{
1297 uint8_t res;
1298
1299 if (handle == NULL) /* check handle */
1300 {
1301 return 2; /* return error */
1302 }
1303 if (handle->inited != 1) /* check handle initialization */
1304 {
1305 return 3; /* return error */
1306 }
1307
1308 res = a_ssd1681_multiple_read_byte(handle, SSD1681_CMD_OTP_REGISTER_READ_FOR_DISPLAY_OPTION, param, 11); /* read byte */
1309 if (res != 0) /* check the result */
1310 {
1311 handle->debug_print("ssd1681: multiple read byte failed.\n"); /* multiple read byte failed */
1312
1313 return 1; /* return error */
1314 }
1315
1316 return 0; /* success return 0 */
1317}
1318
1330uint8_t ssd1681_get_user_id(ssd1681_handle_t *handle, uint8_t id[10])
1331{
1332 uint8_t res;
1333
1334 if (handle == NULL) /* check handle */
1335 {
1336 return 2; /* return error */
1337 }
1338 if (handle->inited != 1) /* check handle initialization */
1339 {
1340 return 3; /* return error */
1341 }
1342
1343 res = a_ssd1681_multiple_read_byte(handle, SSD1681_CMD_USER_ID_READ, id, 10); /* read byte */
1344 if (res != 0) /* check the result */
1345 {
1346 handle->debug_print("ssd1681: multiple read byte failed.\n"); /* multiple read byte failed */
1347
1348 return 1; /* return error */
1349 }
1350
1351 return 0; /* success return 0 */
1352}
1353
1365uint8_t ssd1681_get_status(ssd1681_handle_t *handle, uint8_t *status)
1366{
1367 uint8_t res;
1368
1369 if (handle == NULL) /* check handle */
1370 {
1371 return 2; /* return error */
1372 }
1373 if (handle->inited != 1) /* check handle initialization */
1374 {
1375 return 3; /* return error */
1376 }
1377
1378 res = a_ssd1681_multiple_read_byte(handle, SSD1681_CMD_STATUS_BIT_READ, status, 1); /* read byte */
1379 if (res != 0) /* check the result */
1380 {
1381 handle->debug_print("ssd1681: multiple read byte failed.\n"); /* multiple read byte failed */
1382
1383 return 1; /* return error */
1384 }
1385
1386 return 0; /* success return 0 */
1387}
1388
1400{
1401 uint8_t res;
1402
1403 if (handle == NULL) /* check handle */
1404 {
1405 return 2; /* return error */
1406 }
1407 if (handle->inited != 1) /* check handle initialization */
1408 {
1409 return 3; /* return error */
1410 }
1411
1412 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_PROGRAM_WS_OTP, NULL, 0); /* write byte */
1413 if (res != 0) /* check the result */
1414 {
1415 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1416
1417 return 1; /* return error */
1418 }
1419
1420 return 0; /* success return 0 */
1421}
1422
1434{
1435 uint8_t res;
1436
1437 if (handle == NULL) /* check handle */
1438 {
1439 return 2; /* return error */
1440 }
1441 if (handle->inited != 1) /* check handle initialization */
1442 {
1443 return 3; /* return error */
1444 }
1445
1446 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_LOAD_WS_OTP, NULL, 0); /* write byte */
1447 if (res != 0) /* check the result */
1448 {
1449 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1450
1451 return 1; /* return error */
1452 }
1453
1454 return 0; /* success return 0 */
1455}
1456
1469uint8_t ssd1681_set_lut_register(ssd1681_handle_t *handle, uint8_t *reg, uint16_t len)
1470{
1471 uint8_t res;
1472
1473 if (handle == NULL) /* check handle */
1474 {
1475 return 2; /* return error */
1476 }
1477 if (handle->inited != 1) /* check handle initialization */
1478 {
1479 return 3; /* return error */
1480 }
1481
1482 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_WRITE_LUT_REGISTER, reg, len); /* write byte */
1483 if (res != 0) /* check the result */
1484 {
1485 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1486
1487 return 1; /* return error */
1488 }
1489
1490 return 0; /* success return 0 */
1491}
1492
1504{
1505 uint8_t res;
1506
1507 if (handle == NULL) /* check handle */
1508 {
1509 return 2; /* return error */
1510 }
1511 if (handle->inited != 1) /* check handle initialization */
1512 {
1513 return 3; /* return error */
1514 }
1515
1516 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_CRC_CALCULATION, NULL, 0); /* write byte */
1517 if (res != 0) /* check the result */
1518 {
1519 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1520
1521 return 1; /* return error */
1522 }
1523
1524 return 0; /* success return 0 */
1525}
1526
1538uint8_t ssd1681_get_crc_status(ssd1681_handle_t *handle, uint16_t *status)
1539{
1540 uint8_t res;
1541 uint8_t buf[2];
1542
1543 if (handle == NULL) /* check handle */
1544 {
1545 return 2; /* return error */
1546 }
1547 if (handle->inited != 1) /* check handle initialization */
1548 {
1549 return 3; /* return error */
1550 }
1551
1552 res = a_ssd1681_multiple_read_byte(handle, SSD1681_CMD_CRC_STATUS_READ, buf, 2); /* read byte */
1553 if (res != 0) /* check the result */
1554 {
1555 handle->debug_print("ssd1681: multiple read byte failed.\n"); /* multiple read byte failed */
1556
1557 return 1; /* return error */
1558 }
1559 *status = (uint16_t)(buf[0] << 0) | buf[1]; /* set the status */
1560
1561 return 0; /* success return 0 */
1562}
1563
1575{
1576 uint8_t res;
1577
1578 if (handle == NULL) /* check handle */
1579 {
1580 return 2; /* return error */
1581 }
1582 if (handle->inited != 1) /* check handle initialization */
1583 {
1584 return 3; /* return error */
1585 }
1586
1587 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_PROGRAM_OTP_SELECTION, NULL, 0); /* write byte */
1588 if (res != 0) /* check the result */
1589 {
1590 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1591
1592 return 1; /* return error */
1593 }
1594
1595 return 0; /* success return 0 */
1596}
1597
1609uint8_t ssd1681_otp_write_register(ssd1681_handle_t *handle, uint8_t param[11])
1610{
1611 uint8_t res;
1612
1613 if (handle == NULL) /* check handle */
1614 {
1615 return 2; /* return error */
1616 }
1617 if (handle->inited != 1) /* check handle initialization */
1618 {
1619 return 3; /* return error */
1620 }
1621
1622 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_WRITE_REGISTER_FOR_DISPLAY_OPTION, param, 11); /* write byte */
1623 if (res != 0) /* check the result */
1624 {
1625 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1626
1627 return 1; /* return error */
1628 }
1629
1630 return 0; /* success return 0 */
1631}
1632
1644uint8_t ssd1681_set_user_id(ssd1681_handle_t *handle, uint8_t id[10])
1645{
1646 uint8_t res;
1647
1648 if (handle == NULL) /* check handle */
1649 {
1650 return 2; /* return error */
1651 }
1652 if (handle->inited != 1) /* check handle initialization */
1653 {
1654 return 3; /* return error */
1655 }
1656
1657 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_WRITE_REGISTER_FOR_USER_ID, id, 10); /* write byte */
1658 if (res != 0) /* check the result */
1659 {
1660 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1661
1662 return 1; /* return error */
1663 }
1664
1665 return 0; /* success return 0 */
1666}
1667
1680{
1681 uint8_t res;
1682 uint8_t buf[1];
1683
1684 if (handle == NULL) /* check handle */
1685 {
1686 return 2; /* return error */
1687 }
1688 if (handle->inited != 1) /* check handle initialization */
1689 {
1690 return 3; /* return error */
1691 }
1692
1693 buf[0] = mode; /* set the mode */
1694 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_OTP_PROGRAM_MODE, buf, 1); /* write byte */
1695 if (res != 0) /* check the result */
1696 {
1697 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1698
1699 return 1; /* return error */
1700 }
1701
1702 return 0; /* success return 0 */
1703}
1704
1721{
1722 uint8_t res;
1723 uint8_t buf[1];
1724
1725 if (handle == NULL) /* check handle */
1726 {
1727 return 2; /* return error */
1728 }
1729 if (handle->inited != 1) /* check handle initialization */
1730 {
1731 return 3; /* return error */
1732 }
1733
1734 buf[0] = (uint8_t)((vbd << 6) | (level << 4) | (gs_tran << 2) | (vbd_tran << 0)); /* set the mode */
1735 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_BORDER_WAVEFORM_CONTROL, buf, 1); /* write byte */
1736 if (res != 0) /* check the result */
1737 {
1738 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1739
1740 return 1; /* return error */
1741 }
1742
1743 return 0; /* success return 0 */
1744}
1745
1758{
1759 uint8_t res;
1760 uint8_t buf[1];
1761
1762 if (handle == NULL) /* check handle */
1763 {
1764 return 2; /* return error */
1765 }
1766 if (handle->inited != 1) /* check handle initialization */
1767 {
1768 return 3; /* return error */
1769 }
1770
1771 buf[0] = opt; /* set the mode */
1772 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_END_OPTION, buf, 1); /* write byte */
1773 if (res != 0) /* check the result */
1774 {
1775 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1776
1777 return 1; /* return error */
1778 }
1779
1780 return 0; /* success return 0 */
1781}
1782
1795{
1796 uint8_t res;
1797 uint8_t buf[1];
1798
1799 if (handle == NULL) /* check handle */
1800 {
1801 return 2; /* return error */
1802 }
1803 if (handle->inited != 1) /* check handle initialization */
1804 {
1805 return 3; /* return error */
1806 }
1807
1808 buf[0] = ram; /* set the mode */
1809 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_READ_RAM_OPTION, buf, 1); /* write byte */
1810 if (res != 0) /* check the result */
1811 {
1812 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1813
1814 return 1; /* return error */
1815 }
1816
1817 return 0; /* success return 0 */
1818}
1819
1834uint8_t ssd1681_set_ram_x(ssd1681_handle_t *handle, uint8_t start, uint8_t end)
1835{
1836 uint8_t res;
1837 uint8_t buf[2];
1838
1839 if (handle == NULL) /* check handle */
1840 {
1841 return 2; /* return error */
1842 }
1843 if (handle->inited != 1) /* check handle initialization */
1844 {
1845 return 3; /* return error */
1846 }
1847 if (start > 0x3F) /* check the start */
1848 {
1849 handle->debug_print("ssd1681: start > 0x3F.\n"); /* start > 0x3F */
1850
1851 return 4; /* return error */
1852 }
1853 if (end > 0x3F) /* check the end */
1854 {
1855 handle->debug_print("ssd1681: end > 0x3F.\n"); /* end > 0x3F */
1856
1857 return 5; /* return error */
1858 }
1859
1860 buf[0] = start; /* set the start address */
1861 buf[1] = end; /* set the end address */
1862 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_SET_RAM_X, buf, 2); /* write byte */
1863 if (res != 0) /* check the result */
1864 {
1865 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1866
1867 return 1; /* return error */
1868 }
1869
1870 return 0; /* success return 0 */
1871}
1872
1885uint8_t ssd1681_set_ram_y(ssd1681_handle_t *handle, uint16_t start, uint16_t end)
1886{
1887 uint8_t res;
1888 uint8_t buf[4];
1889
1890 if (handle == NULL) /* check handle */
1891 {
1892 return 2; /* return error */
1893 }
1894 if (handle->inited != 1) /* check handle initialization */
1895 {
1896 return 3; /* return error */
1897 }
1898
1899 buf[0] = start & 0xFF; /* set the start address */
1900 buf[1] = (start >> 8) & 0x1; /* set the start address */
1901 buf[2] = end & 0xFF; /* set the end address */
1902 buf[3] = (end >> 8) & 0x01; /* set the end address */
1903 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_SET_RAM_Y, buf, 4); /* write byte */
1904 if (res != 0) /* check the result */
1905 {
1906 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1907
1908 return 1; /* return error */
1909 }
1910
1911 return 0; /* success return 0 */
1912}
1913
1927{
1928 uint8_t res;
1929 uint8_t buf[1];
1930
1931 if (handle == NULL) /* check handle */
1932 {
1933 return 2; /* return error */
1934 }
1935 if (handle->inited != 1) /* check handle initialization */
1936 {
1937 return 3; /* return error */
1938 }
1939
1940 buf[0] = (uint8_t)((height << 4) | (width << 0)); /* set the param */
1941 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_AUTO_WRITE_RED_RAM_FOR_REGULAR_PATTERN, buf, 1); /* write byte */
1942 if (res != 0) /* check the result */
1943 {
1944 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1945
1946 return 1; /* return error */
1947 }
1948
1949 return 0; /* success return 0 */
1950}
1951
1965{
1966 uint8_t res;
1967 uint8_t buf[1];
1968
1969 if (handle == NULL) /* check handle */
1970 {
1971 return 2; /* return error */
1972 }
1973 if (handle->inited != 1) /* check handle initialization */
1974 {
1975 return 3; /* return error */
1976 }
1977
1978 buf[0] = (uint8_t)((height << 4) | (width << 0)); /* set the param */
1979 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_AUTO_WRITE_BW_RAM_FOR_REGULAR_PATTERN, buf, 1); /* write byte */
1980 if (res != 0) /* check the result */
1981 {
1982 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
1983
1984 return 1; /* return error */
1985 }
1986
1987 return 0; /* success return 0 */
1988}
1989
2003{
2004 uint8_t res;
2005 uint8_t buf[1];
2006
2007 if (handle == NULL) /* check handle */
2008 {
2009 return 2; /* return error */
2010 }
2011 if (handle->inited != 1) /* check handle initialization */
2012 {
2013 return 3; /* return error */
2014 }
2015 if (cnt > 0x3F) /* check the result */
2016 {
2017 handle->debug_print("ssd1681: cnt > 0x3F.\n"); /* cnt > 0x3F */
2018
2019 return 4; /* return error */
2020 }
2021
2022 buf[0] = cnt; /* set the counter */
2023 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_SET_RAM_X_ADDRESS_COUNTER, buf, 1); /* write byte */
2024 if (res != 0) /* check the result */
2025 {
2026 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
2027
2028 return 1; /* return error */
2029 }
2030
2031 return 0; /* success return 0 */
2032}
2033
2047{
2048 uint8_t res;
2049 uint8_t buf[2];
2050
2051 if (handle == NULL) /* check handle */
2052 {
2053 return 2; /* return error */
2054 }
2055 if (handle->inited != 1) /* check handle initialization */
2056 {
2057 return 3; /* return error */
2058 }
2059 if (cnt > 0x1FF) /* check the result */
2060 {
2061 handle->debug_print("ssd1681: cnt > 0x1FF.\n"); /* cnt > 0x1FF */
2062
2063 return 4; /* return error */
2064 }
2065
2066 buf[0] = cnt & 0xFF; /* set the counter low */
2067 buf[1] = (cnt >> 8)& 0x01; /* set the counter high */
2068 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_SET_RAM_Y_ADDRESS_COUNTER, buf, 2); /* write byte */
2069 if (res != 0) /* check the result */
2070 {
2071 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
2072
2073 return 1; /* return error */
2074 }
2075
2076 return 0; /* success return 0 */
2077}
2078
2090{
2091 uint8_t res;
2092
2093 if (handle == NULL) /* check handle */
2094 {
2095 return 2; /* return error */
2096 }
2097 if (handle->inited != 1) /* check handle initialization */
2098 {
2099 return 3; /* return error */
2100 }
2101
2102 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_NOP, NULL, 0); /* write byte */
2103 if (res != 0) /* check the result */
2104 {
2105 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
2106
2107 return 1; /* return error */
2108 }
2109
2110 return 0; /* success return 0 */
2111}
2112
2125static uint8_t a_ssd1681_gram_draw_point(ssd1681_handle_t *handle, ssd1681_color_t color, uint8_t x, uint8_t y, uint8_t data)
2126{
2127 uint8_t pos;
2128 uint8_t bx;
2129 uint8_t temp = 0;
2130
2131 pos = y / 8; /* get y page */
2132 bx = y % 8; /* get y point */
2133 temp = 1 << (7 - bx); /* set data */
2134 if (color == SSD1681_COLOR_BLACK) /* if black */
2135 {
2136 if (data == 0) /* if 0 */
2137 {
2138 handle->black_gram[x][pos] |= temp; /* set 1 */
2139 }
2140 else
2141 {
2142 handle->black_gram[x][pos] &= ~temp; /* set 0 */
2143 }
2144 }
2145 else /* if red */
2146 {
2147 if (data != 0) /* if 1 */
2148 {
2149 handle->red_gram[x][pos] |= temp; /* set 1 */
2150 }
2151 else
2152 {
2153 handle->red_gram[x][pos] &= ~temp; /* set 0 */
2154 }
2155 }
2156
2157 return 0; /* success return 0 */
2158}
2159
2174static uint8_t a_ssd1681_gram_show_char(ssd1681_handle_t *handle, ssd1681_color_t color, uint8_t x, uint8_t y, uint8_t chr, uint8_t size, uint8_t mode)
2175{
2176 uint8_t temp, t, t1;
2177 uint8_t y0 = y;
2178 uint8_t csize = (size / 8 + ((size % 8) ? 1 : 0)) * (size / 2); /* get size */
2179
2180 chr = chr - ' '; /* get index */
2181 for (t = 0; t < csize; t++) /* write size */
2182 {
2183 if (size == 12) /* if size 12 */
2184 {
2185 temp = gsc_ssd1681_ascii_1206[chr][t]; /* get ascii 1206 */
2186 }
2187 else if (size == 16) /* if size 16 */
2188 {
2189 temp = gsc_ssd1681_ascii_1608[chr][t]; /* get ascii 1608 */
2190 }
2191 else if(size == 24) /* if size 24 */
2192 {
2193 temp = gsc_ssd1681_ascii_2412[chr][t]; /* get ascii 2412 */
2194 }
2195 else
2196 {
2197 return 1; /* return error */
2198 }
2199 for (t1 = 0; t1 < 8; t1++) /* write one line */
2200 {
2201 if ((temp & 0x80) != 0) /* if 1 */
2202 {
2203 if (a_ssd1681_gram_draw_point(handle, color, x, y, mode) != 0) /* draw point */
2204 {
2205 return 1; /* return error */
2206 }
2207 }
2208 else
2209 {
2210 if (a_ssd1681_gram_draw_point(handle, color, x, y, !mode) != 0) /* draw point */
2211 {
2212 return 1; /* return error */
2213 }
2214 }
2215 temp <<= 1; /* left shift 1 */
2216 y++;
2217 if ((y - y0) == size) /* reset size */
2218 {
2219 y = y0; /* set y */
2220 x++; /* x++ */
2221
2222 break; /* break */
2223 }
2224 }
2225 }
2226
2227 return 0; /* success return 0 */
2228}
2229
2242{
2243 uint8_t i;
2244 uint8_t j;
2245 uint8_t res;
2246 uint8_t buf[2];
2247
2248 if (handle == NULL) /* check handle */
2249 {
2250 return 2; /* return error */
2251 }
2252 if (handle->inited != 1) /* check handle initialization */
2253 {
2254 return 3; /* return error */
2255 }
2256
2257 buf[0] = 0x00; /* set 0x00 */
2258 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_SET_RAM_X_ADDRESS_COUNTER, buf, 1); /* write byte */
2259 if (res != 0) /* check the result */
2260 {
2261 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
2262
2263 return 1; /* return error */
2264 }
2265 buf[0] = 0xC7; /* set 0xC7 */
2266 buf[1] = 0x00; /* set 0x00 */
2267 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_SET_RAM_Y_ADDRESS_COUNTER, buf, 2); /* write byte */
2268 if (res != 0) /* check the result */
2269 {
2270 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
2271
2272 return 1; /* return error */
2273 }
2274 if (color == SSD1681_COLOR_BLACK) /* if black */
2275 {
2276 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_WRITE_RAM_BLACK, NULL, 0); /* write byte */
2277 if (res != 0) /* check the result */
2278 {
2279 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
2280
2281 return 1; /* return error */
2282 }
2283 res = handle->spi_cmd_data_gpio_write(SSD1681_DATA); /* write data */
2284 if (res != 0) /* check error */
2285 {
2286 handle->debug_print("ssd1681: spi cmd data gpio write failed.\n"); /* spi cmd data gpio write failed */
2287
2288 return 1; /* return error */
2289 }
2290 for (i = 0; i < 200; i++) /* x */
2291 {
2292 for (j = 0; j < 25; j++) /* y */
2293 {
2294 handle->black_gram[i][j] = 0xFF; /* set 0xFF */
2295 res = handle->spi_write_cmd(&handle->black_gram[i][j], 1); /* write gram */
2296 if (res != 0) /* check error */
2297 {
2298 handle->debug_print("ssd1681: spi write cmd failed.\n"); /* spi write cmd failed */
2299
2300 return 1; /* return error */
2301 }
2302 }
2303 }
2304 }
2305 else /* if red */
2306 {
2307 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_WRITE_RAM_RED, NULL, 0); /* write byte */
2308 if (res != 0) /* check the result */
2309 {
2310 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
2311
2312 return 1; /* return error */
2313 }
2314 res = handle->spi_cmd_data_gpio_write(SSD1681_DATA); /* write data */
2315 if (res != 0) /* check error */
2316 {
2317 handle->debug_print("ssd1681: spi cmd data gpio write failed.\n"); /* spi cmd data gpio write failed */
2318
2319 return 1; /* return error */
2320 }
2321 for (i = 0; i < 200; i++) /* x */
2322 {
2323 for (j = 0; j < 25; j++) /* y */
2324 {
2325 handle->red_gram[i][j] = 0x00; /* set 0x00 */
2326 res = handle->spi_write_cmd(&handle->red_gram[i][j], 1); /* write gram */
2327 if (res != 0) /* check error */
2328 {
2329 handle->debug_print("ssd1681: spi write cmd failed.\n"); /* spi write cmd failed */
2330
2331 return 1; /* return error */
2332 }
2333 }
2334 }
2335 }
2336
2337 buf[0] = 0xF7; /* set 0xF7 */
2338 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_DISPLAY_UPDATA_CONTROL_2, buf, 1); /* write byte */
2339 if (res != 0) /* check the result */
2340 {
2341 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
2342
2343 return 1; /* return error */
2344 }
2345 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_MASTER_ACTIVATION, NULL, 0); /* write byte */
2346 if (res != 0) /* check the result */
2347 {
2348 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
2349
2350 return 1; /* return error */
2351 }
2352
2353 return 0; /* success return 0 */
2354}
2355
2368{
2369 uint8_t i;
2370 uint8_t j;
2371 uint8_t res;
2372 uint8_t buf[2];
2373
2374 if (handle == NULL) /* check handle */
2375 {
2376 return 2; /* return error */
2377 }
2378 if (handle->inited != 1) /* check handle initialization */
2379 {
2380 return 3; /* return error */
2381 }
2382
2383 buf[0] = 0x00; /* set 0x00 */
2384 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_SET_RAM_X_ADDRESS_COUNTER, buf, 1); /* write byte */
2385 if (res != 0) /* check the result */
2386 {
2387 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
2388
2389 return 1; /* return error */
2390 }
2391 buf[0] = 0xC7; /* set 0xC7 */
2392 buf[1] = 0x00; /* set 0x00 */
2393 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_SET_RAM_Y_ADDRESS_COUNTER, buf, 2); /* write byte */
2394 if (res != 0) /* check the result */
2395 {
2396 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
2397
2398 return 1; /* return error */
2399 }
2400 if (color == SSD1681_COLOR_BLACK) /* if black */
2401 {
2402 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_WRITE_RAM_BLACK, NULL, 0); /* write byte */
2403 if (res != 0) /* check the result */
2404 {
2405 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
2406
2407 return 1; /* return error */
2408 }
2409 res = handle->spi_cmd_data_gpio_write(SSD1681_DATA); /* write data */
2410 if (res != 0) /* check error */
2411 {
2412 handle->debug_print("ssd1681: spi cmd data gpio write failed.\n"); /* spi cmd data gpio write failed */
2413
2414 return 1; /* return error */
2415 }
2416 for (i = 0; i < 200; i++) /* x */
2417 {
2418 for (j = 0; j < 25; j++) /* y */
2419 {
2420 res = handle->spi_write_cmd(&handle->black_gram[i][j], 1); /* write gram */
2421 if (res != 0) /* check error */
2422 {
2423 handle->debug_print("ssd1681: spi write cmd failed.\n"); /* spi write cmd failed */
2424
2425 return 1; /* return error */
2426 }
2427 }
2428 }
2429 }
2430 else /* if red */
2431 {
2432 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_WRITE_RAM_RED, NULL, 0); /* write byte */
2433 if (res != 0) /* check the result */
2434 {
2435 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
2436
2437 return 1; /* return error */
2438 }
2439 res = handle->spi_cmd_data_gpio_write(SSD1681_DATA); /* write data */
2440 if (res != 0) /* check error */
2441 {
2442 handle->debug_print("ssd1681: spi cmd data gpio write failed.\n"); /* spi cmd data gpio write failed */
2443
2444 return 1; /* return error */
2445 }
2446 for (i = 0; i < 200; i++) /* x */
2447 {
2448 for (j = 0; j < 25; j++) /* y */
2449 {
2450 res = handle->spi_write_cmd(&handle->red_gram[i][j], 1); /* write gram */
2451 if (res != 0) /* check error */
2452 {
2453 handle->debug_print("ssd1681: spi write cmd failed.\n"); /* spi write cmd failed */
2454
2455 return 1; /* return error */
2456 }
2457 }
2458 }
2459 }
2460
2461 buf[0] = 0xF7; /* set 0xF7 */
2462 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_DISPLAY_UPDATA_CONTROL_2, buf, 1); /* write byte */
2463 if (res != 0) /* check the result */
2464 {
2465 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
2466
2467 return 1; /* return error */
2468 }
2469 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_MASTER_ACTIVATION, NULL, 0); /* write byte */
2470 if (res != 0) /* check the result */
2471 {
2472 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
2473
2474 return 1; /* return error */
2475 }
2476
2477 return 0; /* success return 0 */
2478}
2479
2492{
2493 uint8_t i;
2494 uint8_t j;
2495
2496 if (handle == NULL) /* check handle */
2497 {
2498 return 2; /* return error */
2499 }
2500 if (handle->inited != 1) /* check handle initialization */
2501 {
2502 return 3; /* return error */
2503 }
2504
2505 if (color == SSD1681_COLOR_BLACK) /* if black */
2506 {
2507 for (i = 0; i < 200; i++) /* x */
2508 {
2509 for (j = 0; j < 25; j++) /* y */
2510 {
2511 handle->black_gram[i][j] = 0xFF; /* set 0xFF */
2512 }
2513 }
2514 }
2515 else /* if red */
2516 {
2517 for (i = 0; i < 200; i++) /* x */
2518 {
2519 for (j = 0; j < 25; j++) /* y */
2520 {
2521 handle->red_gram[i][j] = 0x00; /* set 0x00 */
2522 }
2523 }
2524 }
2525
2526 return 0; /* success return 0 */
2527}
2528
2544uint8_t ssd1681_gram_write_point(ssd1681_handle_t *handle, ssd1681_color_t color, uint8_t x, uint8_t y, uint8_t data)
2545{
2546 uint8_t pos;
2547 uint8_t bx;
2548 uint8_t temp = 0;
2549
2550 if (handle == NULL) /* check handle */
2551 {
2552 return 2; /* return error */
2553 }
2554 if (handle->inited != 1) /* check handle initialization */
2555 {
2556 return 3; /* return error */
2557 }
2558 if ((x > 200) || (y > 200)) /* check x, y */
2559 {
2560 handle->debug_print("ssd1681: x or y is invalid.\n"); /* x or y is invalid */
2561
2562 return 4; /* return error */
2563 }
2564
2565 pos = y / 8; /* get y page */
2566 bx = y % 8; /* get y point */
2567 temp = 1 << (7 - bx); /* set data */
2568 if (color == SSD1681_COLOR_BLACK) /* if black */
2569 {
2570 if (data == 0) /* if 0 */
2571 {
2572 handle->black_gram[x][pos] |= temp; /* set 1 */
2573 }
2574 else
2575 {
2576 handle->black_gram[x][pos] &= ~temp; /* set 0 */
2577 }
2578 }
2579 else /* if red */
2580 {
2581 if (data != 0) /* if 1 */
2582 {
2583 handle->red_gram[x][pos] |= temp; /* set 1 */
2584 }
2585 else
2586 {
2587 handle->red_gram[x][pos] &= ~temp; /* set 0 */
2588 }
2589 }
2590
2591 return 0; /* success return 0 */
2592}
2593
2609uint8_t ssd1681_gram_read_point(ssd1681_handle_t *handle, ssd1681_color_t color, uint8_t x, uint8_t y, uint8_t *data)
2610{
2611 uint8_t pos;
2612 uint8_t bx;
2613 uint8_t temp = 0;
2614
2615 if (handle == NULL) /* check handle */
2616 {
2617 return 2; /* return error */
2618 }
2619 if (handle->inited != 1) /* check handle initialization */
2620 {
2621 return 3; /* return error */
2622 }
2623 if ((x > 200) || (y > 200)) /* check x, y */
2624 {
2625 handle->debug_print("ssd1681: x or y is invalid.\n"); /* x or y is invalid */
2626
2627 return 4; /* return error */
2628 }
2629
2630 pos = y / 8; /* get y page */
2631 bx = y % 8; /* get y point */
2632 temp = 1 << (7 - bx); /* set data */
2633 if (color == SSD1681_COLOR_BLACK) /* if black */
2634 {
2635 if ((handle->black_gram[x][pos] & temp) != 0) /* get data */
2636 {
2637 *data = 0; /* set 0 */
2638 }
2639 else
2640 {
2641 *data = 1; /* set 1 */
2642 }
2643 }
2644 else /* if red */
2645 {
2646 if ((handle->red_gram[x][pos] & temp) != 0) /* get data */
2647 {
2648 *data = 1; /* set 1 */
2649 }
2650 else
2651 {
2652 *data = 0; /* set 0 */
2653 }
2654 }
2655
2656 return 0; /* success return 0 */
2657}
2658
2677uint8_t ssd1681_gram_write_string(ssd1681_handle_t *handle, ssd1681_color_t color, uint8_t x, uint8_t y, char *str, uint16_t len, uint8_t data, ssd1681_font_t font)
2678{
2679 if (handle == NULL) /* check handle */
2680 {
2681 return 2; /* return error */
2682 }
2683 if (handle->inited != 1) /* check handle initialization */
2684 {
2685 return 3; /* return error */
2686 }
2687 if((x > 199) || (y > 199)) /* check x, y */
2688 {
2689 handle->debug_print("ssd1681: x or y is invalid.\n"); /* x or y is invalid */
2690
2691 return 4; /* return error */
2692 }
2693
2694 while ((len != 0) && (*str <= '~') && (*str >= ' ')) /* write all string */
2695 {
2696 if (x > (199 - (font / 2))) /* check x point */
2697 {
2698 x = 0; /* set x */
2699 y += (uint8_t)font; /* set next row */
2700 }
2701 if (y > (199 - font)) /* check y pont */
2702 {
2703 y = x = 0; /* reset to 0,0 */
2704 }
2705 if (a_ssd1681_gram_show_char(handle, color, x, y, *str, font, data) != 0) /* show a char */
2706 {
2707 return 1; /* return error */
2708 }
2709 x += (uint8_t)(font / 2); /* x + font / 2 */
2710 str++; /* str address++ */
2711 len--; /* str length-- */
2712 }
2713
2714 return 0; /* success return 0 */
2715}
2716
2736uint8_t ssd1681_gram_fill_rect(ssd1681_handle_t *handle, ssd1681_color_t color, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t data)
2737{
2738 uint8_t x, y;
2739
2740 if (handle == NULL) /* check handle */
2741 {
2742 return 2; /* return error */
2743 }
2744 if (handle->inited != 1) /* check handle initialization */
2745 {
2746 return 3; /* return error */
2747 }
2748 if ((left > 199) || (top > 199)) /* check left top */
2749 {
2750 handle->debug_print("ssd1681: left or top is invalid.\n"); /* left or top is invalid */
2751
2752 return 4; /* return error */
2753 }
2754 if ((right > 199) || (bottom > 199)) /* check right bottom */
2755 {
2756 handle->debug_print("ssd1681: right or bottom is invalid.\n"); /* right or bottom is invalid */
2757
2758 return 5; /* return error */
2759 }
2760 if ((left > right) || (top > bottom)) /* check left right top bottom */
2761 {
2762 handle->debug_print("ssd1681: left > right or top > bottom.\n"); /* left > right or top > bottom */
2763
2764 return 6; /* return error */
2765 }
2766
2767 for (x = left; x <= right; x++) /* write x */
2768 {
2769 for (y = top; y <= bottom; y++) /* write y */
2770 {
2771 if (a_ssd1681_gram_draw_point(handle, color, x, y, data) != 0) /* draw point */
2772 {
2773 return 1; /* return error */
2774 }
2775 }
2776 }
2777
2778 return 0; /* return error */
2779}
2780
2800uint8_t ssd1681_gram_draw_picture(ssd1681_handle_t *handle, ssd1681_color_t color, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t *img)
2801{
2802 uint8_t x, y;
2803
2804 if (handle == NULL) /* check handle */
2805 {
2806 return 2; /* return error */
2807 }
2808 if (handle->inited != 1) /* check handle initialization */
2809 {
2810 return 3; /* return error */
2811 }
2812 if ((left > 199) || (top > 199)) /* check left top */
2813 {
2814 handle->debug_print("ssd1681: left or top is invalid.\n"); /* left or top is invalid */
2815
2816 return 4; /* return error */
2817 }
2818 if ((right > 199) || (bottom > 199)) /* check right bottom */
2819 {
2820 handle->debug_print("ssd1681: right or bottom is invalid.\n"); /* right or bottom is invalid */
2821
2822 return 5; /* return error */
2823 }
2824 if ((left > right) || (top > bottom)) /* check left right top bottom */
2825 {
2826 handle->debug_print("ssd1681: left > right or top > bottom.\n"); /* left > right or top > bottom */
2827
2828 return 6; /* return error */
2829 }
2830
2831 for (x = left; x <= right; x++) /* write x */
2832 {
2833 for (y = top; y <= bottom; y++) /* write y */
2834 {
2835 if (a_ssd1681_gram_draw_point(handle, color, x, y, *img) != 0) /* draw point */
2836 {
2837 return 1; /* return error */
2838 }
2839 img++; /* img++ */
2840 }
2841 }
2842
2843 return 0; /* succeed return 0 */
2844}
2845
2859{
2860 if (handle == NULL) /* check handle */
2861 {
2862 return 2; /* return error */
2863 }
2864 if (handle->debug_print == NULL) /* check debug_print */
2865 {
2866 return 3; /* return error */
2867 }
2868 if (handle->spi_init == NULL) /* check spi_init */
2869 {
2870 handle->debug_print("ssd1681: spi_init is null.\n"); /* spi_init is null */
2871
2872 return 3; /* return error */
2873 }
2874 if (handle->spi_deinit == NULL) /* check spi_deinit */
2875 {
2876 handle->debug_print("ssd1681: spi_deinit is null.\n"); /* spi_deinit is null */
2877
2878 return 3; /* return error */
2879 }
2880 if (handle->spi_write_cmd == NULL) /* check spi_write_cmd */
2881 {
2882 handle->debug_print("ssd1681: spi_write_cmd is null.\n"); /* spi_write_cmd is null */
2883
2884 return 3; /* return error */
2885 }
2886 if (handle->delay_ms == NULL) /* check delay_ms */
2887 {
2888 handle->debug_print("ssd1681: delay_ms is null.\n"); /* delay_ms is null */
2889
2890 return 3; /* return error */
2891 }
2892 if (handle->spi_cmd_data_gpio_init == NULL) /* check spi_cmd_data_gpio_init */
2893 {
2894 handle->debug_print("ssd1681: spi_cmd_data_gpio_init is null.\n"); /* spi_cmd_data_gpio_init is null */
2895
2896 return 3; /* return error */
2897 }
2898 if (handle->spi_cmd_data_gpio_deinit == NULL) /* check spi_cmd_data_gpio_deinit */
2899 {
2900 handle->debug_print("ssd1681: spi_cmd_data_gpio_deinit is null.\n"); /* spi_cmd_data_gpio_deinit is null */
2901
2902 return 3; /* return error */
2903 }
2904 if (handle->spi_cmd_data_gpio_write == NULL) /* check spi_cmd_data_gpio_write */
2905 {
2906 handle->debug_print("ssd1681: spi_cmd_data_gpio_write is null.\n"); /* spi_cmd_data_gpio_write is null */
2907
2908 return 3; /* return error */
2909 }
2910 if (handle->reset_gpio_init == NULL) /* check reset_gpio_init */
2911 {
2912 handle->debug_print("ssd1681: reset_gpio_init is null.\n"); /* reset_gpio_init is null */
2913
2914 return 3; /* return error */
2915 }
2916 if (handle->reset_gpio_deinit == NULL) /* check reset_gpio_deinit */
2917 {
2918 handle->debug_print("ssd1681: reset_gpio_deinit is null.\n"); /* reset_gpio_deinit is null */
2919
2920 return 3; /* return error */
2921 }
2922 if(handle->reset_gpio_write == NULL) /* check reset_gpio_write */
2923 {
2924 handle->debug_print("ssd1681: reset_gpio_write is null.\n"); /* reset_gpio_write is null */
2925
2926 return 3; /* return error */
2927 }
2928 if(handle->busy_gpio_init == NULL) /* check busy_gpio_init */
2929 {
2930 handle->debug_print("ssd1681: busy_gpio_init is null.\n"); /* busy_gpio_init is null */
2931
2932 return 3; /* return error */
2933 }
2934 if(handle->busy_gpio_deinit == NULL) /* check busy_gpio_deinit */
2935 {
2936 handle->debug_print("ssd1681: busy_gpio_deinit is null.\n"); /* busy_gpio_deinit is null */
2937
2938 return 3; /* return error */
2939 }
2940 if(handle->busy_gpio_read == NULL) /* check busy_gpio_read */
2941 {
2942 handle->debug_print("ssd1681: busy_gpio_read is null.\n"); /* busy_gpio_read is null */
2943
2944 return 3; /* return error */
2945 }
2946
2947 if (handle->spi_cmd_data_gpio_init() != 0) /* check spi_cmd_data_gpio_init */
2948 {
2949 handle->debug_print("ssd1681: spi cmd data gpio init failed.\n"); /* spi cmd data gpio init failed */
2950
2951 return 5; /* return error */
2952 }
2953 if (handle->reset_gpio_init() != 0) /* reset gpio init */
2954 {
2955 handle->debug_print("ssd1681: reset gpio init failed.\n"); /* reset gpio init failed */
2956 (void)handle->spi_cmd_data_gpio_deinit(); /* spi_cmd_data_gpio_deinit */
2957
2958 return 5; /* return error */
2959 }
2960 if (handle->busy_gpio_init() != 0) /* busy gpio init */
2961 {
2962 handle->debug_print("ssd1681: busy gpio init failed.\n"); /* busy gpio init failed */
2963 (void)handle->spi_cmd_data_gpio_deinit(); /* spi_cmd_data_gpio_deinit */
2964 (void)handle->reset_gpio_deinit(); /* reset_gpio_deinit */
2965
2966 return 5; /* return error */
2967 }
2968
2969 if (handle->reset_gpio_write(0) != 0) /* write 0 */
2970 {
2971 handle->debug_print("ssd1681: reset gpio write failed.\n"); /* reset gpio write failed */
2972 (void)handle->spi_cmd_data_gpio_deinit(); /* spi_cmd_data_gpio_deinit */
2973 (void)handle->reset_gpio_deinit(); /* reset_gpio_deinit */
2974 (void)handle->busy_gpio_deinit(); /* busy_gpio_deinit */
2975
2976 return 4; /* return error */
2977 }
2978 handle->delay_ms(10); /* delay 10 ms */
2979 if (handle->reset_gpio_write(1) != 0) /* write 1 */
2980 {
2981 handle->debug_print("ssd1681: reset gpio write failed.\n"); /* reset gpio write failed */
2982 (void)handle->spi_cmd_data_gpio_deinit(); /* spi_cmd_data_gpio_deinit */
2983 (void)handle->reset_gpio_deinit(); /* reset_gpio_deinit */
2984 (void)handle->busy_gpio_deinit(); /* busy_gpio_deinit */
2985
2986 return 4; /* return error */
2987 }
2988 handle->delay_ms(200); /* delay 200 ms */
2989
2990 if (handle->spi_init() != 0) /* spi init */
2991 {
2992 handle->debug_print("ssd1681: spi init failed.\n"); /* spi init failed */
2993 (void)handle->spi_cmd_data_gpio_deinit(); /* spi_cmd_data_gpio_deinit */
2994 (void)handle->reset_gpio_deinit(); /* reset_gpio_deinit */
2995 (void)handle->busy_gpio_deinit(); /* busy_gpio_deinit */
2996
2997 return 1; /* return error */
2998 }
2999
3000 handle->inited = 1; /* flag inited */
3001
3002 return 0; /* success return 0 */
3003}
3004
3020{
3021 uint8_t res;
3022 uint8_t buf[1];
3023
3024 if (handle == NULL) /* check handle */
3025 {
3026 return 2; /* return error */
3027 }
3028 if (handle->inited != 1) /* check handle initialization */
3029 {
3030 return 3; /* return error */
3031 }
3032
3033 buf[0] = 0x01; /* set 0x01 */
3034 res = a_ssd1681_multiple_write_byte(handle, SSD1681_CMD_DEEP_SLEEP_MODE, buf, 1); /* write byte */
3035 if (res != 0) /* check the result */
3036 {
3037 handle->debug_print("ssd1681: multiple write byte failed.\n"); /* multiple write byte failed */
3038
3039 return 4; /* return error */
3040 }
3041 handle->delay_ms(100); /* delay 100 ms */
3042
3043 if (handle->reset_gpio_deinit() != 0) /* reset gpio deinit */
3044 {
3045 handle->debug_print("ssd1681: reset gpio deinit failed.\n"); /* reset gpio deinit failed */
3046
3047 return 5; /* return error */
3048 }
3049 if (handle->spi_cmd_data_gpio_deinit() != 0) /* spi cmd data gpio deinit */
3050 {
3051 handle->debug_print("ssd1681: spi cmd data gpio deinit failed.\n"); /* spi cmd data gpio deinit failed */
3052
3053 return 6; /* return error */
3054 }
3055 if (handle->busy_gpio_deinit() != 0) /* busy gpio deinit */
3056 {
3057 handle->debug_print("ssd1681: busy gpio deinit failed.\n"); /* busy gpio deinit failed */
3058
3059 return 7; /* return error */
3060 }
3061
3062 if (handle->spi_deinit() != 0) /* spi deinit */
3063 {
3064 handle->debug_print("ssd1681: spi deinit failed.\n"); /* spi deinit failed */
3065
3066 return 1; /* return error */
3067 }
3068
3069 handle->inited = 0; /* flag close */
3070
3071 return 0; /* success return 0 */
3072}
3073
3086uint8_t ssd1681_write_cmd(ssd1681_handle_t *handle, uint8_t *buf, uint8_t len)
3087{
3088 uint8_t res;
3089 uint8_t i;
3090
3091 if (handle == NULL) /* check handle */
3092 {
3093 return 2; /* return error */
3094 }
3095 if (handle->inited != 1) /* check handle initialization */
3096 {
3097 return 3; /* return error */
3098 }
3099
3100 res = handle->spi_cmd_data_gpio_write(SSD1681_CMD); /* write command */
3101 if (res != 0) /* check error */
3102 {
3103 return 1; /* return error */
3104 }
3105 for (i = 0; i < len; i++) /* len times */
3106 {
3107 if (handle->spi_write_cmd(buf + i, 1) != 0) /* write command */
3108 {
3109 return 1; /* return error */
3110 }
3111 }
3112
3113 return 0; /* success return 0 */
3114}
3115
3128uint8_t ssd1681_write_data(ssd1681_handle_t *handle, uint8_t *buf, uint8_t len)
3129{
3130 uint8_t res;
3131 uint8_t i;
3132
3133 if (handle == NULL) /* check handle */
3134 {
3135 return 2; /* return error */
3136 }
3137 if (handle->inited != 1) /* check handle initialization */
3138 {
3139 return 3; /* return error */
3140 }
3141
3142 res = handle->spi_cmd_data_gpio_write(SSD1681_DATA); /* write data */
3143 if (res != 0) /* check error */
3144 {
3145 return 1; /* return error */
3146 }
3147 for (i = 0; i < len; i++) /* len times */
3148 {
3149 if (handle->spi_write_cmd(buf + i, 1) != 0) /* write command */
3150 {
3151 return 1; /* return error */
3152 }
3153 }
3154
3155 return 0; /* success return 0 */
3156}
3157
3170uint8_t ssd1681_read_data(ssd1681_handle_t *handle, uint8_t *buf, uint8_t len)
3171{
3172 uint8_t res;
3173 uint8_t i;
3174
3175 if (handle == NULL) /* check handle */
3176 {
3177 return 2; /* return error */
3178 }
3179 if (handle->inited != 1) /* check handle initialization */
3180 {
3181 return 3; /* return error */
3182 }
3183
3184 res = handle->spi_cmd_data_gpio_write(SSD1681_DATA); /* write data */
3185 if (res != 0) /* check error */
3186 {
3187 return 1; /* return error */
3188 }
3189 for (i = 0; i < len; i++) /* len times */
3190 {
3191 if (handle->spi_read_cmd(buf + i, 1) != 0) /* read command */
3192 {
3193 return 1; /* return error */
3194 }
3195 }
3196
3197 return 0; /* success return 0 */
3198}
3199
3209{
3210 if (info == NULL) /* check handle */
3211 {
3212 return 2; /* return error */
3213 }
3214
3215 memset(info, 0, sizeof(ssd1681_info_t)); /* initialize ssd1681 info structure */
3216 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
3217 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
3218 strncpy(info->interface, "SPI", 8); /* copy interface name */
3219 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
3220 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
3221 info->max_current_ma = MAX_CURRENT; /* set maximum current */
3222 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
3223 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
3224 info->driver_version = DRIVER_VERSION; /* set driver version */
3225
3226 return 0; /* success return 0 */
3227}
#define SSD1681_CMD_VCOM_SENSE
#define SSD1681_CMD_WRITE_REGISTER_FOR_VCOM_CONTROL
#define SSD1681_CMD_SOURCE_DRIVING_VOLTAGE_CONTROL
#define SSD1681_CMD_VCOM_SENSE_DURATION
#define SSD1681_CMD_LOAD_WS_OTP
#define SSD1681_CMD_MASTER_ACTIVATION
#define SSD1681_CMD_PROGRAM_WS_OTP
#define SSD1681_CMD_READ_REGISTER_FOR_INITIAL_CODE_SETTING
#define SSD1681_CMD_PROGRAM_VCOM_OTP
#define SSD1681_CMD_DATA_ENTRY_MODE_SETTING
#define SSD1681_CMD_NOP
#define SSD1681_CMD_READ_RAM
#define MAX_CURRENT
#define SSD1681_CMD_SW_RESET
#define SSD1681_CMD_PROGRAM_OTP_SELECTION
#define SSD1681_CMD_SET_RAM_X_ADDRESS_COUNTER
#define SSD1681_CMD_CRC_STATUS_READ
#define SSD1681_CMD_DEEP_SLEEP_MODE
#define SSD1681_CMD_SET_RAM_Y_ADDRESS_COUNTER
#define SSD1681_CMD_CRC_CALCULATION
#define SSD1681_CMD_WRITE_LUT_REGISTER
#define SSD1681_CMD_WRITE_RAM_BLACK
#define SSD1681_CMD_TEMPERATURE_SENSOR_CONTROL_WRITE_EXT
#define SSD1681_CMD_AUTO_WRITE_RED_RAM_FOR_REGULAR_PATTERN
#define SUPPLY_VOLTAGE_MAX
#define SSD1681_CMD_END_OPTION
#define SSD1681_CMD_OTP_PROGRAM_MODE
#define SSD1681_CMD_BOOSTER_SOFT_START_CONTROL
#define SSD1681_CMD_WRITE_REGISTER_FOR_INITIAL_CODE_SETTING
#define SSD1681_CMD_DISPLAY_UPDATA_CONTROL_1
#define SSD1681_CMD
chip command data definition
#define SSD1681_CMD_WRITE_RAM_RED
#define SSD1681_DATA
#define SSD1681_CMD_DISPLAY_UPDATA_CONTROL_2
#define TEMPERATURE_MAX
#define SSD1681_CMD_GATE_DRIVING_VOLTAGE_CONTROL
#define SSD1681_CMD_WRITE_REGISTER_FOR_DISPLAY_OPTION
#define SSD1681_CMD_OTP_REGISTER_READ_FOR_DISPLAY_OPTION
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define SSD1681_CMD_TEMPERATURE_SENSOR_CONTROL
#define SSD1681_CMD_READ_RAM_OPTION
#define SSD1681_CMD_USER_ID_READ
#define SSD1681_CMD_VCI_DETECTION
#define SSD1681_CMD_BORDER_WAVEFORM_CONTROL
#define SSD1681_CMD_AUTO_WRITE_BW_RAM_FOR_REGULAR_PATTERN
#define SSD1681_CMD_TEMPERATURE_SENSOR_CONTROL_WRITE
#define SSD1681_CMD_STATUS_BIT_READ
#define SSD1681_CMD_SET_RAM_Y
#define SSD1681_CMD_SET_RAM_X
#define CHIP_NAME
chip information definition
#define SSD1681_CMD_INITIAL_CODE_SETTING_OTP_PROGRAM
#define DRIVER_VERSION
#define SSD1681_CMD_HV_READY_DETECTION
#define SSD1681_CMD_TEMPERATURE_SENSOR_CONTROL_READ
#define SSD1681_CMD_WRITE_REGISTER_FOR_USER_ID
#define SSD1681_CMD_DRIVER_OUTPUT_CONTROL
chip command definition
#define SSD1681_CMD_WRITE_VCOM_REGISTER
driver ssd1681 header file
driver ssd1681 font header file
uint8_t ssd1681_otp_program_selection(ssd1681_handle_t *handle)
program otp selection
ssd1681_step_width_t
ssd1681 step width enumeration definition
uint8_t ssd1681_deinit(ssd1681_handle_t *handle)
close the chip
uint8_t ssd1681_set_display_sequence(ssd1681_handle_t *handle, ssd1681_display_sequence_t sequence)
set the display sequence
uint8_t ssd1681_write_temperature_sensor(ssd1681_handle_t *handle, uint16_t control)
write the temperature sensor
uint8_t ssd1681_init(ssd1681_handle_t *handle)
initialize the chip
uint8_t ssd1681_get_ram(ssd1681_handle_t *handle)
get the ram
struct ssd1681_info_s ssd1681_info_t
ssd1681 information structure definition
uint8_t ssd1681_set_ram_y_address_counter(ssd1681_handle_t *handle, uint16_t cnt)
set the ram y address counter
struct ssd1681_handle_s ssd1681_handle_t
ssd1681 handle structure definition
uint8_t ssd1681_set_lut_register(ssd1681_handle_t *handle, uint8_t *reg, uint16_t len)
set the lut register
uint8_t ssd1681_otp_initial_read(ssd1681_handle_t *handle)
read register for initial code setting
uint8_t ssd1681_set_user_id(ssd1681_handle_t *handle, uint8_t id[10])
set the user id
uint8_t ssd1681_set_red_ram(ssd1681_handle_t *handle)
set the red ram
ssd1681_step_height_t
ssd1681 step height enumeration definition
uint8_t ssd1681_set_vcom_sense_duration(ssd1681_handle_t *handle, uint8_t duration)
set the vcom sense duration
uint8_t ssd1681_otp_load_waveform(ssd1681_handle_t *handle)
load otp of waveform setting
uint8_t ssd1681_otp_read_register(ssd1681_handle_t *handle, uint8_t param[11])
otp register read for display option
ssd1681_otp_mode_t
ssd1681 otp mode enumeration definition
uint8_t ssd1681_get_user_id(ssd1681_handle_t *handle, uint8_t id[10])
get the user id
uint8_t ssd1681_read_temperature_sensor(ssd1681_handle_t *handle, uint16_t *control)
read the temperature sensor
uint8_t ssd1681_write_temperature_sensor_ext(ssd1681_handle_t *handle, uint8_t param[3])
write command to external temperature sensor
uint8_t ssd1681_set_vcom_control_reg(ssd1681_handle_t *handle)
write register for vcom control
ssd1681_end_opt_t
ssd1681 end opt enumeration definition
ssd1681_color_t
ssd1681 color enumeration definition
uint8_t ssd1681_set_master_activate(ssd1681_handle_t *handle)
master activate
ssd1681_vbd_fix_level_t
ssd1681 vbd fix level enumeration definition
uint8_t ssd1681_set_driver_output(ssd1681_handle_t *handle, uint16_t mux, ssd1681_bool_t gd, ssd1681_bool_t sm, ssd1681_bool_t tb)
set the driver output
uint8_t ssd1681_gram_draw_picture(ssd1681_handle_t *handle, ssd1681_color_t color, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t *img)
draw a picture in the gram
#define SSD1681_BUSY_MAX_DELAY_MS
ssd1681 busy max delay definition
uint8_t ssd1681_gram_write_string(ssd1681_handle_t *handle, ssd1681_color_t color, uint8_t x, uint8_t y, char *str, uint16_t len, uint8_t data, ssd1681_font_t font)
draw a string in the gram
uint8_t ssd1681_gram_clear(ssd1681_handle_t *handle, ssd1681_color_t color)
clear the screen in the gram
ssd1681_bool_t
ssd1681 bool enumeration definition
ssd1681_address_direction_t
ssd1681 address direction enumeration definition
uint8_t ssd1681_info(ssd1681_info_t *info)
get chip's information
ssd1681_mode_t
ssd1681 mode enumeration definition
uint8_t ssd1681_gram_fill_rect(ssd1681_handle_t *handle, ssd1681_color_t color, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t data)
fill a rectangle in the gram
uint8_t ssd1681_set_display_update_control(ssd1681_handle_t *handle, ssd1681_display_control_t red_control, ssd1681_display_control_t black_control)
set the display update control
uint8_t ssd1681_otp_program_mode(ssd1681_handle_t *handle, ssd1681_otp_mode_t mode)
set the otp program mode
uint8_t ssd1681_set_read_ram(ssd1681_handle_t *handle, ssd1681_read_ram_t ram)
set the read ram
uint8_t ssd1681_gram_read_point(ssd1681_handle_t *handle, ssd1681_color_t color, uint8_t x, uint8_t y, uint8_t *data)
read a point from the gram
uint8_t ssd1681_set_end_option(ssd1681_handle_t *handle, ssd1681_end_opt_t opt)
end option
uint8_t ssd1681_set_ram_y(ssd1681_handle_t *handle, uint16_t start, uint16_t end)
set the ram y range
ssd1681_temperature_sensor_t
ssd1681 temperature sensor enumeration definition
uint8_t ssd1681_software_reset(ssd1681_handle_t *handle)
software reset
ssd1681_display_sequence_t
ssd1681 display sequence enumeration definition
ssd1681_font_t
ssd1681 font enumeration definition
uint8_t ssd1681_set_mode(ssd1681_handle_t *handle, ssd1681_mode_t mode)
set the mode
uint8_t ssd1681_set_gate_driving_voltage(ssd1681_handle_t *handle, ssd1681_gate_driving_voltage_t voltage)
set the gate driving voltage
ssd1681_vci_level_t
ssd1681 vci level enumeration definition
uint8_t ssd1681_set_hv_ready_detection(ssd1681_handle_t *handle, uint8_t cool_down_duration, uint8_t cool_down_loop_num)
set the hv ready detection
uint8_t ssd1681_set_ram_x_address_counter(ssd1681_handle_t *handle, uint8_t cnt)
set the ram x address counter
ssd1681_vbd_transition_t
ssd1681 vbd transition enumeration definition
uint8_t ssd1681_otp_program_vcom(ssd1681_handle_t *handle)
program vcom otp
uint8_t ssd1681_set_auto_write_black_ram(ssd1681_handle_t *handle, ssd1681_step_height_t height, ssd1681_step_width_t width)
set the auto write black ram
uint8_t ssd1681_otp_initial(ssd1681_handle_t *handle)
initial code setting otp program
uint8_t ssd1681_otp_write_register(ssd1681_handle_t *handle, uint8_t param[11])
otp write register for display option
uint8_t ssd1681_set_auto_write_red_ram(ssd1681_handle_t *handle, ssd1681_step_height_t height, ssd1681_step_width_t width)
set the auto write red ram
uint8_t ssd1681_set_crc_calculation(ssd1681_handle_t *handle)
set the crc calculation
uint8_t ssd1681_otp_initial_write(ssd1681_handle_t *handle, uint8_t param[4])
write register for initial code setting
uint8_t ssd1681_gram_write_point(ssd1681_handle_t *handle, ssd1681_color_t color, uint8_t x, uint8_t y, uint8_t data)
write a point in the gram
uint8_t ssd1681_set_enter_vcom_sense(ssd1681_handle_t *handle)
set enter vcom sense
ssd1681_vsh_t
ssd1681 vsh enumeration definition
ssd1681_vcom_t
ssd1681 vcom enumeration definition
ssd1681_read_ram_t
ssd1681 read ram enumeration definition
uint8_t ssd1681_set_booster_soft_start(ssd1681_handle_t *handle, uint8_t phase1, uint8_t phase2, uint8_t phase3, uint8_t duration)
set the booster soft start
uint8_t ssd1681_set_source_driving_voltage(ssd1681_handle_t *handle, ssd1681_vsh_t vsh1, ssd1681_vsh_t vsh2, ssd1681_vsl_t vsl)
set the source driving voltage
ssd1681_gs_transition_t
ssd1681 gs transition enumeration definition
uint8_t ssd1681_set_temperature_sensor(ssd1681_handle_t *handle, ssd1681_temperature_sensor_t sensor)
set the temperature sensor
ssd1681_gate_driving_voltage_t
ssd1681 gate driving voltage enumeration definition
uint8_t ssd1681_set_vcom_register(ssd1681_handle_t *handle, ssd1681_vcom_t vcom)
write vcom register
uint8_t ssd1681_set_data_entry_mode(ssd1681_handle_t *handle, ssd1681_address_mode_t mode, ssd1681_address_direction_t direction)
set the data entry mode
uint8_t ssd1681_clear(ssd1681_handle_t *handle, ssd1681_color_t color)
clear the screen
uint8_t ssd1681_get_status(ssd1681_handle_t *handle, uint8_t *status)
get the status
uint8_t ssd1681_set_ram_x(ssd1681_handle_t *handle, uint8_t start, uint8_t end)
set the ram x range
ssd1681_vbd_t
ssd1681 vbd enumeration definition
uint8_t ssd1681_nop(ssd1681_handle_t *handle)
nop command
uint8_t ssd1681_set_border_waveform(ssd1681_handle_t *handle, ssd1681_vbd_t vbd, ssd1681_vbd_fix_level_t level, ssd1681_gs_transition_t gs_tran, ssd1681_vbd_transition_t vbd_tran)
set the border waveform
uint8_t ssd1681_set_vci_detection(ssd1681_handle_t *handle, ssd1681_vci_level_t level)
set the vci detection
uint8_t ssd1681_gram_update(ssd1681_handle_t *handle, ssd1681_color_t color)
update the gram data
#define SSD1681_BUSY_MAX_RETRY_TIMES
ssd1681 busy max retry times definition
uint8_t ssd1681_otp_program_waveform(ssd1681_handle_t *handle)
program otp of waveform setting
uint8_t ssd1681_set_black_ram(ssd1681_handle_t *handle)
set the black ram
ssd1681_address_mode_t
ssd1681 address mode enumeration definition
ssd1681_vsl_t
ssd1681 vsl enumeration definition
ssd1681_display_control_t
ssd1681 display control enumeration definition
uint8_t ssd1681_get_crc_status(ssd1681_handle_t *handle, uint16_t *status)
get the crc status
@ SSD1681_COLOR_BLACK
uint8_t ssd1681_read_data(ssd1681_handle_t *handle, uint8_t *buf, uint8_t len)
read the register data
uint8_t ssd1681_write_cmd(ssd1681_handle_t *handle, uint8_t *buf, uint8_t len)
write the register command
uint8_t ssd1681_write_data(ssd1681_handle_t *handle, uint8_t *buf, uint8_t len)
write the register data
uint8_t red_gram[200][25]
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* busy_gpio_init)(void)
uint8_t(* spi_read_cmd)(uint8_t *buf, uint16_t len)
uint8_t(* spi_cmd_data_gpio_deinit)(void)
uint8_t(* reset_gpio_deinit)(void)
void(* debug_print)(const char *const fmt,...)
uint8_t(* busy_gpio_deinit)(void)
uint8_t(* spi_deinit)(void)
uint8_t(* reset_gpio_init)(void)
uint8_t black_gram[200][25]
uint8_t(* spi_cmd_data_gpio_init)(void)
uint8_t(* busy_gpio_read)(uint8_t *value)
uint8_t(* spi_write_cmd)(uint8_t *buf, uint16_t len)
uint8_t(* spi_cmd_data_gpio_write)(uint8_t value)
uint8_t(* reset_gpio_write)(uint8_t value)
uint32_t driver_version
char manufacturer_name[32]