39#define LOG_DOMAIN "display"
44#define M_PI 3.14159265358979323846
47static 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);
308 pynq_error(
"display_destroy: display has not been initialized\n");
320 pynq_error(
"displayDrawPixel: display has not been initialized\n");
323 pynq_error(
"displayDrawPixel: x=%d y=%d outside screen boundaries\n", x, y);
325 uint16_t _x = x + display->
_offsetx;
326 uint16_t _y = y + display->
_offsety;
337 uint16_t size, uint16_t *
colors) {
339 pynq_error(
"displayDrawMultiPixels: display has not been initialized\n");
341 if (x > display->
_width || x + size > display->
_width ||
344 "displayDrawMultiPixels: x=%d y=%d size=%d outside screen boundaries\n",
348 uint16_t _x1 = x + display->
_offsetx;
349 uint16_t _x2 = _x1 + size;
350 uint16_t _y1 = y + display->
_offsety;
362 uint16_t x2, uint16_t y2, uint16_t color) {
364 pynq_error(
"displayDrawPixel: display has not been initialized\n");
368 pynq_error(
"displayDrawFillRect: x1=%d y1=%d x2=%d y2=%d outside screen "
374 uint16_t x1_temp = x1, x2_temp = x2;
375 uint16_t y1_temp = y1, y2_temp = y2;
387 uint16_t _x1 = x1 + display->
_offsetx;
388 uint16_t _x2 = x2 + display->
_offsetx;
389 uint16_t _y1 = y1 + display->
_offsety;
390 uint16_t _y2 = y2 + display->
_offsety;
397 for (
int i = _x1; i <= _x2; i++) {
398 uint16_t size = _y2 - _y1 + 1;
405 pynq_error(
"displayDisplayOff: display has not been initialized\n");
412 pynq_error(
"displayDisplayOn: display has not been initialized\n");
419 pynq_error(
"displayFillScreen: display has not been initialized\n");
426 uint16_t y2, uint16_t color) {
428 pynq_error(
"displayDrawLine: display has not been initialized\n");
431 pynq_error(
"displayDrawLine: x1=%d y1=%d outside screen boundaries\n", x1,
433 }
else if (x2 >= display->
_width || y2 >= display->
_height) {
434 pynq_error(
"displayDrawLine: x2=%d y2=%d outside screen boundaries\n", x2,
443 dx = (x2 > x1) ? x2 - x1 : x1 - x2;
444 dy = (y2 > y1) ? y2 - y1 : y1 - y2;
447 sx = (x2 > x1) ? 1 : -1;
448 sy = (y2 > y1) ? 1 : -1;
453 for (i = 0; i <= dx; i++) {
466 for (i = 0; i <= dy; i++) {
479 uint16_t y2, uint16_t color) {
481 pynq_error(
"displayDrawRect: display has not been initialized\n");
484 pynq_error(
"displayDrawRect: x1=%d y1=%d outside screen boundaries\n", x1,
486 }
else if (x2 >= display->
_width || y2 >= display->
_height) {
487 pynq_error(
"displayDrawRect: x2=%d y2=%d outside screen boundaries\n", x2,
497 uint16_t w, uint16_t h, uint16_t angle,
504 rd = -angle *
M_PI / 180.0;
507 x1 = (int)(xd * cos(rd) - yd * sin(rd) + xc);
508 y1 = (int)(xd * sin(rd) + yd * cos(rd) + yc);
511 x2 = (int)(xd * cos(rd) - yd * sin(rd) + xc);
512 y2 = (int)(xd * sin(rd) + yd * cos(rd) + yc);
516 x3 = (int)(xd * cos(rd) - yd * sin(rd) + xc);
517 y3 = (int)(xd * sin(rd) + yd * cos(rd) + yc);
520 x4 = (int)(xd * cos(rd) - yd * sin(rd) + xc);
521 y4 = (int)(xd * sin(rd) + yd * cos(rd) + yc);
524 pynq_error(
"displayDrawRectAngle: display has not been initialized\n");
527 pynq_error(
"displayDrawRectAngle: x1=%d y1=%d outside screen boundaries\n",
529 }
else if (x2 >= display->
_width || y2 >= display->
_height) {
530 pynq_error(
"displayDrawRectAngle: x2=%d y2=%d outside screen boundaries\n",
532 }
else if (x3 >= display->
_width || y3 >= display->
_height) {
533 pynq_error(
"displayDrawRectAngle: x3=%d y3=%d outside screen boundaries\n",
535 }
else if (x4 >= display->
_width || y4 >= display->
_height) {
536 pynq_error(
"displayDrawRectAngle: x4=%d y4=%d outside screen boundaries\n",
554 uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3,
557 pynq_error(
"displayDrawTriangle: display has not been initialized\n");
560 pynq_error(
"displayDrawRectAngle: x1=%d y1=%d outside screen boundaries\n",
562 }
else if (x2 >= display->
_width || y2 >= display->
_height) {
563 pynq_error(
"displayDrawRectAngle: x2=%d y2=%d outside screen boundaries\n",
565 }
else if (x3 >= display->
_width || y3 >= display->
_height) {
566 pynq_error(
"displayDrawRectAngle: x3=%d y3=%d outside screen boundaries\n",
581 uint16_t w, uint16_t h, uint16_t angle,
587 rd = -angle *
M_PI / 180.0;
590 x1 = (int)(xd * cos(rd) - yd * sin(rd) + xc);
591 y1 = (int)(xd * sin(rd) + yd * cos(rd) + yc);
595 x2 = (int)(xd * cos(rd) - yd * sin(rd) + xc);
596 y2 = (int)(xd * sin(rd) + yd * cos(rd) + yc);
599 x3 = (int)(xd * cos(rd) - yd * sin(rd) + xc);
600 y3 = (int)(xd * sin(rd) + yd * cos(rd) + yc);
603 pynq_error(
"displayDrawTriangleCenter: display has not been initialized\n");
606 pynq_error(
"displayDrawRectAngle: x1=%d y1=%d outside screen boundaries\n",
608 }
else if (x2 >= display->
_width || y2 >= display->
_height) {
609 pynq_error(
"displayDrawRectAngle: x2=%d y2=%d outside screen boundaries\n",
611 }
else if (x3 >= display->
_width || y3 >= display->
_height) {
612 pynq_error(
"displayDrawRectAngle: x3=%d y3=%d outside screen boundaries\n",
622 uint16_t r, uint16_t color) {
624 pynq_error(
"displayDrawCircle: display has not been initialized\n");
628 "displayDrawCircle: x_center=%d y_center=%d r=%d r cannot be 0\n",
629 x_center, y_center, r);
632 int x_max = x_center + r, x_min = x_center - r, y_max = y_center + r,
633 y_min = y_center - r;
635 if (x_max >= display->
_width || x_min < 0 || y_max >= display->
_height ||
637 pynq_error(
"displayDrawCircle: x_center=%d y_center=%d r=%d outside screen "
639 x_center, y_center, r);
655 if ((old_err = err) <= x)
657 if (old_err > y || err > x)
663 uint16_t y_center, uint16_t r, uint16_t color) {
665 pynq_error(
"displayDrawFillCircle: display has not been initialized\n");
669 "displayDrawFillCircle: x_center=%d y_center=%d r=%d r cannot be 0\n",
670 x_center, y_center, r);
673 int x_max = x_center + r, x_min = x_center - r, y_max = y_center + r,
674 y_min = y_center - r;
676 if (x_max >= display->
_width || x_min < 0 || y_max >= display->
_height ||
678 pynq_error(
"displayDrawFillCircle: x_center=%d y_center=%d r=%d outside "
679 "screen boundaries\n",
680 x_center, y_center, r);
696 y_center + y, color);
698 y_center + y, color);
700 ChangeX = (old_err = err) <= x;
703 if (old_err > y || err > x)
709 uint16_t x2, uint16_t y2, uint16_t r,
712 pynq_error(
"displayDrawRoundRect: display has not been initialized\n");
715 pynq_error(
"displayDrawRoundRect: x_center=%d x1=%d y1=%d r cannot be 0\n",
717 }
else if (x1 >= display->
_width || y1 >= display->
_height) {
718 pynq_error(
"displayDrawRoundRect: x1=%d y1=%d outside screen boundaries\n",
720 }
else if (x2 >= display->
_width || y2 >= display->
_height) {
721 pynq_error(
"displayDrawRoundRect: x2=%d y2=%d outside screen boundaries\n",
743 printf(
"x1=%d x2=%d delta=%d r=%d", x1, x2, x2 - x1, r);
745 printf(
"y1=%d y2=%d delta=%d r=%d", y1, y2, y2 - y1, r);
762 if ((old_err = err) <= x)
764 if (old_err > y || err > x)
769 printf(
"x1+r=%d x2-r=%d", x1 + r, x2 - r);
773 printf(
"y1+r=%d y2-r=%d", y1 + r, y2 - r);
778uint16_t
rgb_conv(uint16_t r, uint16_t g, uint16_t b) {
779 return (((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3));
783 uint8_t ascii, uint16_t color) {
784 uint16_t xx, yy, bit, ofs;
785 unsigned char fonts[128];
786 unsigned char pw, ph;
789 bool rc =
GetFontx(fxs, ascii, fonts, &pw, &ph);
792 pynq_error(
"displayDrawChar: display has not been initialized\n");
796 printf(
"GetFontx rc=%d pw=%d ph=%d\n", rc, pw, ph);
800 pynq_error(
"displayDrawChar: cannot get font from font file\n");
805 if (x + pw >= display->
_width || y + ph >= display->
_height) {
806 pynq_error(
"displayDrawChar: x=%d y=%d for font height=%d width=%d and "
807 "direction=%d outside screen boundaries\n",
812 if (x + ph >= display->
_height || y + pw >= display->
_width) {
813 pynq_error(
"displayDrawChar: x=%d y=%d for font height=%d width=%d and "
814 "direction=%d outside screen boundaries\n",
819 if (x - pw <= 0 || y - ph <= 0) {
820 pynq_error(
"displayDrawChar: x=%d y=%d for font height=%d width=%d and "
821 "direction=%d outside screen boundaries\n",
826 if (x - ph <= 0 || y - pw <= 0) {
827 pynq_error(
"displayDrawChar: x=%d y=%d for font height=%d width=%d and "
828 "direction=%d outside screen boundaries\n",
834 int16_t xd1 = 0, yd1 = 0, xd2 = 0, yd2 = 0;
835 uint16_t xss = 0, yss = 0;
836 int16_t xsd = 0, ysd = 0, next = 0;
837 uint16_t x0 = 0, x1 = 0, y0 = 0, y1 = 0;
908 printf(
"xss=%d yss=%d\n", xss, yss);
912 for (h = 0; h < ph; h++) {
918 for (w = 0; w < ((pw + 4) / 8); w++) {
920 for (bit = 0; bit < 8; bit++) {
952 uint8_t *ascii, uint16_t color) {
953 int length = strlen((
char *)ascii);
955 pynq_error(
"displayDrawString: display has not been initialized\n");
958 printf(
"displayDrawString length=%d\n", length);
959 for (
int i = 0; i < length; i++) {
961 printf(
"ascii[%d]=%x x=%d y=%d\n", i, ascii[i], x, y);
984 pynq_error(
"displaySetFontDirection: display has not been initialized\n");
991 pynq_error(
"displaySetFontFill: display has not been initialized\n");
1001 pynq_error(
"displaySetFontUnderLine: display has not been initialized\n");
1009 pynq_error(
"displayUnsetFontUnderLine: display has not been initialized\n");
1016 pynq_error(
"displayBacklightOff: display has not been initialized\n");
1018 if (display->
_bl >= 0) {
1025 pynq_error(
"displayBacklightOn: display has not been initialized\n");
1027 if (display->
_bl >= 0) {
1034 pynq_error(
"displayInversionOff: display has not been initialized\n");
1041 pynq_error(
"displayInversionOn: display has not been initialized\n");
void displayInit(display_t *display, int width, int height, int offsetx, int offsety)
void spi_master_init(display_t *display)
void display_destroy(display_t *display __attribute__((unused)))
gpio_level_t spi_to_gpio(spi_mode_t mode)
bool spi_master_write_command(display_t *display, uint8_t cmd)
bool spi_master_write_addr(display_t *display, uint16_t addr1, uint16_t addr2)
bool spi_master_write_color(display_t *display, uint16_t color, uint16_t size)
bool spi_master_write_data_word(display_t *display, uint16_t data)
bool spi_master_write_data_byte(display_t *display, uint8_t data)
bool spi_master_write_colors(display_t *display, uint16_t *colors, uint16_t size)
void displayDrawMultiPixels(display_t *display, uint16_t x, uint16_t y, uint16_t size, uint16_t *colors)
void arm_shared_close(arm_shared *handle)
void * arm_shared_init(arm_shared *handle, const uint32_t address, const uint32_t length)
int displayDrawString(display_t *display, FontxFile *fx, uint16_t x, uint16_t y, uint8_t *ascii, uint16_t color)
Function to draw a string on the display.
void display_set_flip(display_t *display, bool xflip, bool yflip)
Flip the drawing off the screen.
void displayDrawFillRect(display_t *display, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Draw a filled rectangle to the display.
void displaySetFontUnderLine(display_t *display, uint16_t color)
Turns on _font_underline in the display handle and sets the _font_underline_color to the specified co...
void displaySetFontDirection(display_t *display, uint16_t dir)
Changes the direction the characters will be printed.
void displayDrawTriangle(display_t *display, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, uint16_t color)
Draw a triangle without infill between the three given points in the given color.
void displaySetFontFill(display_t *display, uint16_t color)
Enables the _font_fill and sets the _font_fill_color in the display handle.
void displayDrawRect(display_t *display, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Draw a filled rectangle.
void displayUnsetFontFill(display_t *display)
Sets the _font_fill parameter to false in the display handle, turns off the font fill.
void display_init(display_t *display)
Initialize the display display.
uint16_t rgb_conv(uint16_t r, uint16_t g, uint16_t b)
RGB conversion for generating a color.
void displayDisplayOff(display_t *display)
Turn off the display.
void displayDrawLine(display_t *display, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Draw a line from two coordinates.
void displayInversionOff(display_t *display)
Turn off inversion of the colors.
void displayDrawRoundRect(display_t *display, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t r, uint16_t color)
Draw a rectangle with rounded angles.
void displayInversionOn(display_t *display)
Turn on inversion of the colors.
int displayDrawChar(display_t *display, FontxFile *fxs, uint16_t x, uint16_t y, uint8_t ascii, uint16_t color)
Draws a character on the given coordinates of the display.
void displayBacklightOn(display_t *display)
Turn on the display backlight.
void displayDrawCircle(display_t *display, uint16_t x_center, uint16_t y_center, uint16_t r, uint16_t color)
Draw a circle without infill on the display.
void displayFillScreen(display_t *display, uint16_t color)
Fill entire display with a single color using the ldcDrawFillRect function.
void displayBacklightOff(display_t *display)
Turn off the display backlight.
void displayDisplayOn(display_t *display)
Initialize DISPLAY screen.
void displayUnsetFontUnderLine(display_t *display)
Turns off _font_underline in the display handle.
void displayDrawPixel(display_t *display, uint16_t x, uint16_t y, uint16_t color)
Draw a single pixel to the display.
colors
Colors that can be used with the display.
void displayDrawRectAngle(display_t *display, uint16_t xc, uint16_t yc, uint16_t w, uint16_t h, uint16_t angle, uint16_t color)
Draws a rectangle with rounded corners at a specified angle on the display.
void displayDrawFillCircle(display_t *display, uint16_t x_center, uint16_t y_center, uint16_t r, uint16_t color)
Draw a circle with infill on the display.
void displayDrawTriangleCenter(display_t *display, uint16_t xc, uint16_t yc, uint16_t w, uint16_t h, uint16_t angle, uint16_t color)
Draws a triangle at a specified angle on the display.
bool GetFontx(FontxFile *fxs, uint8_t ascii, uint8_t *pGlyph, uint8_t *pw, uint8_t *ph)
Gets the glyph data for the specified ASCII character.
void gpio_set_direction(const io_t pin, const gpio_direction_t dir)
Set the IO pin as in input or output.
void gpio_set_level(const io_t pin, const gpio_level_t level)
Set the level of the output IO pin. If the pin is configured as input, this function does nothing.
void gpio_reset_pin(const io_t pin)
Function is currently a no-op placeholder for arduino compatibility.
void switchbox_set_pin(const io_t pin_number, const io_configuration_t io_type)
Set the type of a switch pin.
void sleep_msec(int msec)
Wait for msec milliseconds.
Struct representing a font file.
Internal type, do not use. Type of display that stores parameters for usage in different functions.
uint16_t _font_fill_color
uint16_t _font_underline_color