29 #include <lcdconfig.h>
39 #define LOG_DOMAIN "display"
44 #define M_PI 3.14159265358979323846
47 static volatile uint32_t *spi0 = NULL;
52 #define GPIO_MODE_OUTPUT 1
68 while (((spi0[0x64 / 4]) & 4) == 0) {
77 spi0[0x68 / 4] = data;
78 while (((spi0[0x64 / 4]) & 4) == 0) {
84 static uint8_t Byte[2];
85 Byte[0] = (data >> 8) & 0xFF;
86 Byte[1] = data & 0xFF;
88 spi0[0x68 / 4] = Byte[0];
89 spi0[0x68 / 4] = Byte[1];
91 while (((spi0[0x64 / 4]) & 4) == 0) {
97 static uint8_t Byte[4];
98 Byte[0] = (addr1 >> 8) & 0xFF;
99 Byte[1] = addr1 & 0xFF;
100 Byte[2] = (addr2 >> 8) & 0xFF;
101 Byte[3] = addr2 & 0xFF;
105 spi0[0x68 / 4] = Byte[0];
106 spi0[0x68 / 4] = Byte[1];
107 spi0[0x68 / 4] = Byte[2];
108 spi0[0x68 / 4] = Byte[3];
110 while (((spi0[0x64 / 4]) & 4) == 0) {
117 for (
int i = 0; i < size; i++) {
118 while (((spi0[0x64 / 4]) & 8) == 8) {
120 spi0[0x68 / 4] = (color >> 8) & 0xFF;
121 while (((spi0[0x64 / 4]) & 8) == 8) {
123 spi0[0x68 / 4] = (color) & 0xFF;
125 while (((spi0[0x64 / 4]) & 4) == 0) {
133 for (
int i = 0; i < size; i++) {
134 while (((spi0[0x64 / 4]) & 8) == 8) {
136 spi0[0x68 / 4] = (
colors[i] >> 8) & 0xFF;
137 while (((spi0[0x64 / 4]) & 8) == 8) {
139 spi0[0x68 / 4] = (
colors[i]) & 0xFF;
143 while (((spi0[0x64 / 4]) & 4) == 0) {
169 printf(
"spi reset: %08X\n", spi0[0x40 / 4]);
170 spi0[0x40 / 4] = 0x0000000a;
172 printf(
"spi control: %08X\n", spi0[0x60 / 4]);
173 spi0[0x60 / 4] = (1 << 4) | (1 << 3) | (1 << 2) | (1 << 1);
175 printf(
"spi control: %08X\n", spi0[0x60 / 4]);
177 printf(
"spi status: %08X\n", spi0[0x64 / 4]);
182 printf(
"spi control: %08X\n", spi0[0x60 / 4]);
184 printf(
"testing DISPLAY\n");
186 printf(
"LCD_CS=%d\n", LCD_CS);
194 printf(
"LCD_DC=%d", LCD_DC);
199 printf(
"LCD_RESET=%d", LCD_RESET);
201 if (LCD_RESET >= 0) {
213 printf(
"LCD_BL=%d", LCD_BL);
221 printf(
"LCD_MOSI=%d", LCD_MOSI);
223 printf(
"LCD_SCLK=%d\n", LCD_SCLK);
225 display->
_dc = LCD_DC;
226 display->
_bl = LCD_BL;
274 if (display->
_bl >= 0) {
280 if (display == NULL) {
281 pynq_error(
"display_destroy: display has not been initialized\n");
284 pynq_error(
"display_destroy: internal error (wrong display hardware)\n");
287 uint8_t set = (yflip << 7) | (xflip << 6);
302 if (display == NULL) {
303 pynq_error(
"display_init: display is NULL\n");
311 pynq_error(
"display_destroy: display has not been initialized\n");
323 pynq_error(
"displayDrawPixel: display has not been initialized\n");
326 pynq_error(
"displayDrawPixel: x=%d y=%d outside screen boundaries\n", x, y);
328 uint16_t _x = x + display->
_offsetx;
329 uint16_t _y = y + display->
_offsety;
340 uint16_t size, uint16_t *
colors) {
342 pynq_error(
"displayDrawMultiPixels: display has not been initialized\n");
344 if (x > display->
_width || x + size > display->
_width ||
347 "displayDrawMultiPixels: x=%d y=%d size=%d outside screen boundaries\n",
351 uint16_t _x1 = x + display->
_offsetx;
352 uint16_t _x2 = _x1 + size;
353 uint16_t _y1 = y + display->
_offsety;
365 uint16_t x2, uint16_t y2, uint16_t color) {
367 pynq_error(
"displayDrawPixel: display has not been initialized\n");
371 pynq_error(
"displayDrawFillRect: x1=%d y1=%d x2=%d y2=%d outside screen "
377 uint16_t x1_temp = x1, x2_temp = x2;
378 uint16_t y1_temp = y1, y2_temp = y2;
390 uint16_t _x1 = x1 + display->
_offsetx;
391 uint16_t _x2 = x2 + display->
_offsetx;
392 uint16_t _y1 = y1 + display->
_offsety;
393 uint16_t _y2 = y2 + display->
_offsety;
400 for (
int i = _x1; i <= _x2; i++) {
401 uint16_t size = _y2 - _y1 + 1;
408 pynq_error(
"displayDisplayOff: display has not been initialized\n");
415 pynq_error(
"displayDisplayOn: display has not been initialized\n");
422 pynq_error(
"displayFillScreen: display has not been initialized\n");
429 uint16_t y2, uint16_t color) {
431 pynq_error(
"displayDrawLine: display has not been initialized\n");
434 pynq_error(
"displayDrawLine: x1=%d y1=%d outside screen boundaries\n", x1,
436 }
else if (x2 >= display->
_width || y2 >= display->
_height) {
437 pynq_error(
"displayDrawLine: x2=%d y2=%d outside screen boundaries\n", x2,
446 dx = (x2 > x1) ? x2 - x1 : x1 - x2;
447 dy = (y2 > y1) ? y2 - y1 : y1 - y2;
450 sx = (x2 > x1) ? 1 : -1;
451 sy = (y2 > y1) ? 1 : -1;
456 for (i = 0; i <= dx; i++) {
469 for (i = 0; i <= dy; i++) {
482 uint16_t y2, uint16_t color) {
484 pynq_error(
"displayDrawRect: display has not been initialized\n");
487 pynq_error(
"displayDrawRect: x1=%d y1=%d outside screen boundaries\n", x1,
489 }
else if (x2 >= display->
_width || y2 >= display->
_height) {
490 pynq_error(
"displayDrawRect: x2=%d y2=%d outside screen boundaries\n", x2,
500 uint16_t w, uint16_t h, uint16_t angle,
507 rd = -angle *
M_PI / 180.0;
510 x1 = (int)(xd * cos(rd) - yd * sin(rd) + xc);
511 y1 = (int)(xd * sin(rd) + yd * cos(rd) + yc);
514 x2 = (int)(xd * cos(rd) - yd * sin(rd) + xc);
515 y2 = (int)(xd * sin(rd) + yd * cos(rd) + yc);
519 x3 = (int)(xd * cos(rd) - yd * sin(rd) + xc);
520 y3 = (int)(xd * sin(rd) + yd * cos(rd) + yc);
523 x4 = (int)(xd * cos(rd) - yd * sin(rd) + xc);
524 y4 = (int)(xd * sin(rd) + yd * cos(rd) + yc);
527 pynq_error(
"displayDrawRectAngle: display has not been initialized\n");
530 pynq_error(
"displayDrawRectAngle: x1=%d y1=%d outside screen boundaries\n",
532 }
else if (x2 >= display->
_width || y2 >= display->
_height) {
533 pynq_error(
"displayDrawRectAngle: x2=%d y2=%d outside screen boundaries\n",
535 }
else if (x3 >= display->
_width || y3 >= display->
_height) {
536 pynq_error(
"displayDrawRectAngle: x3=%d y3=%d outside screen boundaries\n",
538 }
else if (x4 >= display->
_width || y4 >= display->
_height) {
539 pynq_error(
"displayDrawRectAngle: x4=%d y4=%d outside screen boundaries\n",
557 uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3,
560 pynq_error(
"displayDrawTriangle: display has not been initialized\n");
563 pynq_error(
"displayDrawRectAngle: x1=%d y1=%d outside screen boundaries\n",
565 }
else if (x2 >= display->
_width || y2 >= display->
_height) {
566 pynq_error(
"displayDrawRectAngle: x2=%d y2=%d outside screen boundaries\n",
568 }
else if (x3 >= display->
_width || y3 >= display->
_height) {
569 pynq_error(
"displayDrawRectAngle: x3=%d y3=%d outside screen boundaries\n",
584 uint16_t w, uint16_t h, uint16_t angle,
590 rd = -angle *
M_PI / 180.0;
593 x1 = (int)(xd * cos(rd) - yd * sin(rd) + xc);
594 y1 = (int)(xd * sin(rd) + yd * cos(rd) + yc);
598 x2 = (int)(xd * cos(rd) - yd * sin(rd) + xc);
599 y2 = (int)(xd * sin(rd) + yd * cos(rd) + yc);
602 x3 = (int)(xd * cos(rd) - yd * sin(rd) + xc);
603 y3 = (int)(xd * sin(rd) + yd * cos(rd) + yc);
606 pynq_error(
"displayDrawTriangleCenter: display has not been initialized\n");
609 pynq_error(
"displayDrawRectAngle: x1=%d y1=%d outside screen boundaries\n",
611 }
else if (x2 >= display->
_width || y2 >= display->
_height) {
612 pynq_error(
"displayDrawRectAngle: x2=%d y2=%d outside screen boundaries\n",
614 }
else if (x3 >= display->
_width || y3 >= display->
_height) {
615 pynq_error(
"displayDrawRectAngle: x3=%d y3=%d outside screen boundaries\n",
625 uint16_t r, uint16_t color) {
627 pynq_error(
"displayDrawCircle: display has not been initialized\n");
631 "displayDrawCircle: x_center=%d y_center=%d r=%d r cannot be 0\n",
632 x_center, y_center, r);
635 int x_max = x_center + r, x_min = x_center - r, y_max = y_center + r,
636 y_min = y_center - r;
638 if (x_max >= display->
_width || x_min < 0 || y_max >= display->
_height ||
640 pynq_error(
"displayDrawCircle: x_center=%d y_center=%d r=%d outside screen "
642 x_center, y_center, r);
658 if ((old_err = err) <= x)
660 if (old_err > y || err > x)
666 uint16_t y_center, uint16_t r, uint16_t color) {
668 pynq_error(
"displayDrawFillCircle: display has not been initialized\n");
672 "displayDrawFillCircle: x_center=%d y_center=%d r=%d r cannot be 0\n",
673 x_center, y_center, r);
676 int x_max = x_center + r, x_min = x_center - r, y_max = y_center + r,
677 y_min = y_center - r;
679 if (x_max >= display->
_width || x_min < 0 || y_max >= display->
_height ||
681 pynq_error(
"displayDrawFillCircle: x_center=%d y_center=%d r=%d outside "
682 "screen boundaries\n",
683 x_center, y_center, r);
699 y_center + y, color);
701 y_center + y, color);
703 ChangeX = (old_err = err) <= x;
706 if (old_err > y || err > x)
712 uint16_t x2, uint16_t y2, uint16_t r,
715 pynq_error(
"displayDrawRoundRect: display has not been initialized\n");
718 pynq_error(
"displayDrawRoundRect: x_center=%d x1=%d y1=%d r cannot be 0\n",
720 }
else if (x1 >= display->
_width || y1 >= display->
_height) {
721 pynq_error(
"displayDrawRoundRect: x1=%d y1=%d outside screen boundaries\n",
723 }
else if (x2 >= display->
_width || y2 >= display->
_height) {
724 pynq_error(
"displayDrawRoundRect: x2=%d y2=%d outside screen boundaries\n",
746 printf(
"x1=%d x2=%d delta=%d r=%d", x1, x2, x2 - x1, r);
748 printf(
"y1=%d y2=%d delta=%d r=%d", y1, y2, y2 - y1, r);
765 if ((old_err = err) <= x)
767 if (old_err > y || err > x)
772 printf(
"x1+r=%d x2-r=%d", x1 + r, x2 - r);
776 printf(
"y1+r=%d y2-r=%d", y1 + r, y2 - r);
781 uint16_t
rgb_conv(uint16_t r, uint16_t g, uint16_t b) {
782 return (((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3));
786 uint8_t ascii, uint16_t color) {
787 uint16_t xx, yy, bit, ofs;
788 unsigned char fonts[128];
789 unsigned char pw, ph;
792 bool rc =
GetFontx(fxs, ascii, fonts, &pw, &ph);
795 pynq_error(
"displayDrawChar: display has not been initialized\n");
799 printf(
"GetFontx rc=%d pw=%d ph=%d\n", rc, pw, ph);
803 pynq_error(
"displayDrawChar: cannot get font from font file\n");
808 if (x + pw >= display->
_width || y + ph >= display->
_height) {
809 pynq_error(
"displayDrawChar: x=%d y=%d for font height=%d width=%d and "
810 "direction=%d outside screen boundaries\n",
815 if (x + ph >= display->
_height || y + pw >= display->
_width) {
816 pynq_error(
"displayDrawChar: x=%d y=%d for font height=%d width=%d and "
817 "direction=%d outside screen boundaries\n",
822 if (x - pw <= 0 || y - ph <= 0) {
823 pynq_error(
"displayDrawChar: x=%d y=%d for font height=%d width=%d and "
824 "direction=%d outside screen boundaries\n",
829 if (x - ph <= 0 || y - pw <= 0) {
830 pynq_error(
"displayDrawChar: x=%d y=%d for font height=%d width=%d and "
831 "direction=%d outside screen boundaries\n",
837 int16_t xd1 = 0, yd1 = 0, xd2 = 0, yd2 = 0;
838 uint16_t xss = 0, yss = 0;
839 int16_t xsd = 0, ysd = 0, next = 0;
840 uint16_t x0 = 0, x1 = 0, y0 = 0, y1 = 0;
911 printf(
"xss=%d yss=%d\n", xss, yss);
915 for (h = 0; h < ph; h++) {
921 for (w = 0; w < ((pw + 4) / 8); w++) {
923 for (bit = 0; bit < 8; bit++) {
955 uint8_t *ascii, uint16_t color) {
956 int length = strlen((
char *)ascii);
958 pynq_error(
"displayDrawString: display has not been initialized\n");
961 printf(
"displayDrawString length=%d\n", length);
962 for (
int i = 0; i < length; i++) {
964 printf(
"ascii[%d]=%x x=%d y=%d\n", i, ascii[i], x, y);
987 pynq_error(
"displaySetFontDirection: display has not been initialized\n");
994 pynq_error(
"displaySetFontFill: display has not been initialized\n");
1004 pynq_error(
"displaySetFontUnderLine: display has not been initialized\n");
1012 pynq_error(
"displayUnsetFontUnderLine: display has not been initialized\n");
1019 pynq_error(
"displayBacklightOff: display has not been initialized\n");
1021 if (display->
_bl >= 0) {
1028 pynq_error(
"displayBacklightOn: display has not been initialized\n");
1030 if (display->
_bl >= 0) {
1037 pynq_error(
"displayInversionOff: display has not been initialized\n");
1044 pynq_error(
"displayInversionOn: display has not been initialized\n");