28 #ifdef TEXTDISPLAY_FONT_8x8
30 #define FONT_ASCII_START (' ')
31 #define FONT_CHARACTERS (100)
32 #define FONT_BITS_MASK (0x7)
33 #define FONT_BITS_LOG2 (3)
34 #define fontBits chars_8x8_bits
37 #ifdef TEXTDISPLAY_FONT_6x8
39 #define FONT_ASCII_START (' ')
40 #define FONT_CHARACTERS (100)
41 #define FONT_BITS_MASK (0x7)
42 #define FONT_BITS_LOG2 (3)
43 #define fontBits chars_6x8_bits
46 #ifdef TEXTDISPLAY_NUMBER_FONT_16x20
48 #define FONT_ASCII_START ('0')
49 #define FONT_CHARACTERS (12)
50 #define FONT_BITS_MASK (0xF)
51 #define FONT_BITS_LOG2 (4)
52 #define fontBits numbers_16x20_bits
62 typedef enum TEXTDISPLAY_UpdateMode_t
64 TEXTDISPLAY_UPDATE_MODE_FULL,
65 TEXTDISPLAY_UPDATE_MODE_LINE,
66 TEXTDISPLAY_UPDATE_MODE_CHAR,
67 TEXTDISPLAY_UPDATE_MODE_NONE
68 } TEXTDISPLAY_UpdateMode_t;
71 typedef struct TEXTDISPLAY_Device_t
100 TEXTDISPLAY_UpdateMode_t updateMode;
104 } TEXTDISPLAY_Device_t;
107 typedef struct TEXTDISPLAY_CharBuffers_t
110 unsigned int columns;
114 } TEXTDISPLAY_CharBuffers_t;
122 static TEXTDISPLAY_Device_t textdisplayTbl[TEXTDISPLAY_DEVICES_MAX];
126 char charBufferDevice0[TEXTDISPLAY_DEVICE_0_LINES * TEXTDISPLAY_DEVICE_0_COLUMNS];
127 char* charArrayDevice0[TEXTDISPLAY_DEVICE_0_LINES];
129 #if (TEXTDISPLAY_DEVICES_MAX == 2)
130 char charBufferDevice1[TEXTDISPLAY_DEVICE_1_LINES * TEXTDISPLAY_DEVICE_1_COLUMNS];
131 char* charArrayDevice1[TEXTDISPLAY_DEVICE_1_LINES];
134 #if (TEXTDISPLAY_DEVICES_MAX == 3)
135 char charBufferDevice2[TEXTDISPLAY_DEVICE_2_LINES * TEXTDISPLAY_DEVICE_2_COLUMNS];
136 char* charArrayDevice2[TEXTDISPLAY_DEVICE_2_LINES];
139 #if (TEXTDISPLAY_DEVICES_MAX == 4)
140 char charBufferDevice3[TEXTDISPLAY_DEVICE_3_LINES * TEXTDISPLAY_DEVICE_3_COLUMNS];
141 char* charArrayDevice3[TEXTDISPLAY_DEVICE_3_LINES];
145 static TEXTDISPLAY_CharBuffers_t charBufferTbl[TEXTDISPLAY_DEVICES_MAX] =
148 TEXTDISPLAY_DEVICE_0_LINES,
149 TEXTDISPLAY_DEVICE_0_COLUMNS,
153 #if (TEXTDISPLAY_DEVICES_MAX == 2)
155 TEXTDISPLAY_DEVICE_1_LINES,
156 TEXTDISPLAY_DEVICE_1_COLUMNS,
161 #if (TEXTDISPLAY_DEVICES_MAX == 3)
163 TEXTDISPLAY_DEVICE_2_LINES,
164 TEXTDISPLAY_DEVICE_2_COLUMNS,
169 #if (TEXTDISPLAY_DEVICES_MAX == 4)
171 TEXTDISPLAY_DEVICE_3_LINES,
172 TEXTDISPLAY_DEVICE_3_COLUMNS,
185 static void TextdisplayClear (TEXTDISPLAY_Device_t* textdisplay);
186 static void TextdisplayScrollUp (TEXTDISPLAY_Device_t* textdisplay);
187 static void TextdisplayCharAdd (TEXTDISPLAY_Device_t* textdisplay,
189 static EMSTATUS TextdisplayLineDraw (TEXTDISPLAY_Device_t* textdisplay,
191 static EMSTATUS TextdisplayUpdate (TEXTDISPLAY_Device_t* textdisplay);
213 TEXTDISPLAY_Device_t* textdisplay;
219 for (textdisplay=NULL,
220 deviceNo=0; deviceNo<TEXTDISPLAY_DEVICES_MAX; deviceNo++)
224 textdisplay = &textdisplayTbl[deviceNo];
228 if (NULL == textdisplay)
244 textdisplay->displayDevice.
245 pPixelMatrixAllocate (&textdisplay->displayDevice,
246 textdisplay->displayDevice.geometry.width,
247 #ifdef EMWIN_WORKAROUND
248 textdisplay->displayDevice.geometry.width,
251 &textdisplay->lineBuffer);
256 textdisplay->displayDevice.
257 pPixelMatrixClear (&textdisplay->displayDevice,
258 textdisplay->lineBuffer,
259 textdisplay->displayDevice.geometry.width,
267 textdisplay->lineBuffer = NULL;
272 if (charBufferTbl[deviceNo].lines >
273 textdisplay->displayDevice.geometry.height / FONT_HEIGHT)
275 if (charBufferTbl[deviceNo].columns >
276 textdisplay->displayDevice.geometry.width / FONT_WIDTH)
280 textdisplay->lines = charBufferTbl[deviceNo].lines;
281 textdisplay->columns = charBufferTbl[deviceNo].columns;
282 textdisplay->charBuffer = charBufferTbl[deviceNo].charBuffer;
283 textdisplay->charArray = charBufferTbl[deviceNo].charArray;
288 textdisplay->lfToCrLf = config->
lfToCrLf;
291 for (i=0; i<textdisplay->lines; i++)
292 textdisplay->charArray[i] =
293 textdisplay->charBuffer + textdisplay->columns * i;
297 textdisplay->rgbColor[0] = 0xff;
298 textdisplay->rgbColor[1] = 0xff;
299 textdisplay->rgbColor[2] = 0xff;
302 TextdisplayClear(textdisplay);
304 textdisplay->initialized =
true;
324 TEXTDISPLAY_Device_t* textdisplay = (TEXTDISPLAY_Device_t*) handle;
326 if (textdisplay->initialized)
328 textdisplay->charBuffer = NULL;
329 textdisplay->charArray = NULL;
331 if (textdisplay->lineBuffer)
333 textdisplay->displayDevice.pPixelMatrixFree (&textdisplay->displayDevice,
334 textdisplay->lineBuffer);
335 textdisplay->lineBuffer = NULL;
339 textdisplay->displayDeviceNo = -1;
341 textdisplay->initialized =
false;
364 TEXTDISPLAY_Device_t* textdisplay = (TEXTDISPLAY_Device_t*) handle;
366 textdisplay->lfToCrLf = on;
384 TEXTDISPLAY_Device_t* textdisplay = (TEXTDISPLAY_Device_t*) handle;
387 if (
false == textdisplay->initialized)
395 textdisplay->updateMode = TEXTDISPLAY_UPDATE_MODE_LINE;
399 textdisplay->updateMode = TEXTDISPLAY_UPDATE_MODE_CHAR;
402 if (textdisplay->scrollEnable)
406 if ((0==textdisplay->xpos) && (textdisplay->ypos == textdisplay->lines-1))
408 textdisplay->updateMode = TEXTDISPLAY_UPDATE_MODE_FULL;
415 if ((0==textdisplay->xpos) && (0==textdisplay->ypos))
417 textdisplay->updateMode = TEXTDISPLAY_UPDATE_MODE_FULL;
424 TextdisplayClear(textdisplay);
426 textdisplay->updateMode = TEXTDISPLAY_UPDATE_MODE_FULL;
427 return TextdisplayUpdate(textdisplay);
431 if (textdisplay->lfToCrLf && (c ==
'\n'))
433 TextdisplayCharAdd(textdisplay,
'\r');
435 TextdisplayCharAdd(textdisplay, c);
437 if (TEXTDISPLAY_UPDATE_MODE_NONE != textdisplay->updateMode)
439 return TextdisplayUpdate(textdisplay);
457 TEXTDISPLAY_Device_t* textdisplay = (TEXTDISPLAY_Device_t*) handle;
460 bool displayUpdated=
false;
463 if (
false == textdisplay->initialized)
471 textdisplay->updateMode = TEXTDISPLAY_UPDATE_MODE_LINE;
475 textdisplay->updateMode = TEXTDISPLAY_UPDATE_MODE_CHAR;
481 displayUpdated =
false;
485 if ((0==textdisplay->xpos) && (0==textdisplay->ypos) &&
486 (
false == textdisplay->scrollEnable))
488 TextdisplayClear(textdisplay);
489 textdisplay->updateMode = TEXTDISPLAY_UPDATE_MODE_FULL;
498 TextdisplayClear(textdisplay);
499 textdisplay->updateMode = TEXTDISPLAY_UPDATE_MODE_FULL;
504 status = TextdisplayUpdate(textdisplay);
508 displayUpdated =
true;
511 if (textdisplay->lfToCrLf)
513 TextdisplayCharAdd(textdisplay,
'\r');
516 TextdisplayCharAdd(textdisplay, c);
520 TextdisplayCharAdd(textdisplay, c);
526 if ((textdisplay->xpos >= textdisplay->columns) ||
527 (textdisplay->updateMode == TEXTDISPLAY_UPDATE_MODE_FULL))
529 status = TextdisplayUpdate(textdisplay);
532 displayUpdated =
true;
540 return TextdisplayUpdate(textdisplay);
557 static void TextdisplayClear(TEXTDISPLAY_Device_t* textdisplay)
559 if (textdisplay->charArray)
562 #if (FONT_ASCII_START>' ') || (FONT_ASCII_START+FONT_CHARACTERS<' ')
566 memset(textdisplay->charBuffer, FONT_CHARACTERS - 1,
567 textdisplay->lines * textdisplay->columns);
569 memset(textdisplay->charBuffer, 0,
570 textdisplay->lines * textdisplay->columns);
574 textdisplay->xpos = 0;
575 textdisplay->ypos = 0;
577 textdisplay->updateMode = TEXTDISPLAY_UPDATE_MODE_FULL;
587 static void TextdisplayScrollUp(TEXTDISPLAY_Device_t* textdisplay)
592 for (y = 0; y < (textdisplay->lines - 1); y++)
594 memcpy(textdisplay->charArray[y],
595 textdisplay->charArray[y + 1],
596 textdisplay->columns);
600 memset(&textdisplay->charArray[textdisplay->lines - 1][0],
602 textdisplay->columns);
604 textdisplay->xpos = 0;
605 textdisplay->ypos = textdisplay->lines - 1;
606 textdisplay->updateMode = TEXTDISPLAY_UPDATE_MODE_FULL;
610 #ifdef INCLUDE_VIDEO_TERMINAL_ESCAPE_SEQUENCE_SUPPORT
622 static bool TextdisplayEscapeSequence(TEXTDISPLAY_Device_t* textdisplay,
625 #define ASCII_ESC (27)
626 #define ESC_SEQ_SIZE_MAX (4)
627 #define ESC_SEQ_MAX (6)
628 static char escapeSequence[ESC_SEQ_SIZE_MAX]= {0,0,0,0};
629 static const char escapeSequences[ESC_SEQ_MAX][ESC_SEQ_SIZE_MAX] =
634 TEXTDISPLAY_ESC_SEQ_CURSOR_HOME_VT100,
635 TEXTDISPLAY_ESC_SEQ_CURSOR_HOME_VT52,
636 TEXTDISPLAY_ESC_SEQ_CURSOR_UP_ONE_LINE,
637 TEXTDISPLAY_ESC_SEQ_CURSOR_DOWN_ONE_LINE,
638 TEXTDISPLAY_ESC_SEQ_CURSOR_RIGHT_ONE_CHAR,
639 TEXTDISPLAY_ESC_SEQ_CURSOR_LEFT_ONE_CHAR
641 #define TEXTDISPLAY_ESC_SEQNO_CURSOR_HOME_VT100 (0)
642 #define TEXTDISPLAY_ESC_SEQNO_CURSOR_HOME_VT52 (1)
643 #define TEXTDISPLAY_ESC_SEQNO_CURSOR_UP_ONE_LINE (2)
644 #define TEXTDISPLAY_ESC_SEQNO_CURSOR_DOWN_ONE_LINE (3)
645 #define TEXTDISPLAY_ESC_SEQNO_CURSOR_RIGHT_ONE_CHAR (4)
646 #define TEXTDISPLAY_ESC_SEQNO_CURSOR_LEFT_ONE_CHAR (5)
650 bool anyMatch =
false;
657 memset(escapeSequence, 0, ESC_SEQ_SIZE_MAX);
659 textdisplay->updateMode = TEXTDISPLAY_UPDATE_MODE_NONE;
663 if (ASCII_ESC != escapeSequence[0])
676 pChar = escapeSequence;
680 len = strlen(escapeSequence);
682 for (seqNo=0; seqNo<ESC_SEQ_MAX; seqNo++)
685 if (0 == strncmp(escapeSequence, escapeSequences[seqNo], len))
690 textdisplay->updateMode = TEXTDISPLAY_UPDATE_MODE_NONE;
693 if (len == strlen(escapeSequences[seqNo]))
697 case TEXTDISPLAY_ESC_SEQNO_CURSOR_HOME_VT100:
698 case TEXTDISPLAY_ESC_SEQNO_CURSOR_HOME_VT52:
700 textdisplay->ypos = 0;
701 textdisplay->xpos = 0;
703 case TEXTDISPLAY_ESC_SEQNO_CURSOR_UP_ONE_LINE:
705 if (textdisplay->ypos)
708 case TEXTDISPLAY_ESC_SEQNO_CURSOR_DOWN_ONE_LINE:
710 if (textdisplay->ypos < textdisplay->lines-1)
713 case TEXTDISPLAY_ESC_SEQNO_CURSOR_RIGHT_ONE_CHAR:
715 if (textdisplay->xpos < textdisplay->columns-1)
718 case TEXTDISPLAY_ESC_SEQNO_CURSOR_LEFT_ONE_CHAR:
720 if (textdisplay->xpos)
726 memset(escapeSequence, 0, ESC_SEQ_SIZE_MAX);
727 textdisplay->updateMode = TEXTDISPLAY_UPDATE_MODE_NONE;
737 if (
false == anyMatch)
740 memset(escapeSequence, 0, ESC_SEQ_SIZE_MAX);
744 if (ESC_SEQ_SIZE_MAX-1 == len)
748 memset(escapeSequence, 0, ESC_SEQ_SIZE_MAX);
749 textdisplay->updateMode = TEXTDISPLAY_UPDATE_MODE_NONE;
773 static void TextdisplayCharAdd(TEXTDISPLAY_Device_t* textdisplay,
779 textdisplay->xpos = 0;
783 textdisplay->ypos = textdisplay->ypos + 1;
784 textdisplay->xpos = 0;
785 if (textdisplay->ypos >= textdisplay->lines)
787 if (textdisplay->scrollEnable)
790 TextdisplayScrollUp(textdisplay);
791 textdisplay->ypos = (textdisplay->lines - 1);
795 TextdisplayClear(textdisplay);
802 textdisplay->displayDevice.colourMode) &&
804 textdisplay->displayDevice.colourMode) )
806 if (textdisplay->rgbColor[1] == 0xff)
808 textdisplay->rgbColor[1] = 0x00;
809 textdisplay->rgbColor[2] = 0x00;
813 textdisplay->rgbColor[1] = 0xff;
814 textdisplay->rgbColor[2] = 0xff;
821 #ifdef INCLUDE_VIDEO_TERMINAL_ESCAPE_SEQUENCE_SUPPORT
822 if (TextdisplayEscapeSequence(textdisplay, c))
835 #if 100 > FONT_CHARACTERS
838 if ( (FONT_ASCII_START>c) || (FONT_ASCII_START+FONT_CHARACTERS<=c) )
840 #if (FONT_ASCII_START>' ') || (FONT_ASCII_START+FONT_CHARACTERS<' ')
843 c = FONT_ASCII_START + FONT_CHARACTERS - 1;
850 if (textdisplay->xpos >= textdisplay->columns)
852 textdisplay->xpos = 0;
853 textdisplay->ypos = textdisplay->ypos + 1;
855 if (textdisplay->ypos >= textdisplay->lines)
857 if (textdisplay->scrollEnable)
859 TextdisplayScrollUp(textdisplay);
860 textdisplay->ypos = textdisplay->lines - 1;
864 TextdisplayClear(textdisplay);
867 textdisplay->charArray[textdisplay->ypos][textdisplay->xpos] =
868 c - FONT_ASCII_START;
870 textdisplay->xpos = textdisplay->xpos + 1;
884 static EMSTATUS TextdisplayLineDraw(TEXTDISPLAY_Device_t* textdisplay,
889 FontBits_t* rowPtr = (FontBits_t*) textdisplay->lineBuffer;
890 FontBits_t pixelBits;
892 for (i = 0; i < FONT_HEIGHT; i++)
894 for (x = 0; x < textdisplay->columns; x++)
896 c = textdisplay->charArray[y][x];
898 pixelBits =
fontBits[c + FONT_CHARACTERS * i];
900 switch (textdisplay->displayDevice.colourMode)
902 #if (8 == FONT_WIDTH) || (16 == FONT_WIDTH)
904 rowPtr[x] = pixelBits;
908 rowPtr[x] = ~pixelBits;
910 #elif (8 > FONT_WIDTH) || (16 > FONT_WIDTH)
912 pixelBits = ~pixelBits;
915 int startPixel = x * FONT_WIDTH;
916 int pixelNo = startPixel;
917 for (; pixelNo<startPixel+FONT_WIDTH; pixelBits>>=1, pixelNo++)
921 rowPtr[pixelNo>>FONT_BITS_LOG2] |= 1 << (pixelNo&FONT_BITS_MASK);
925 rowPtr[pixelNo>>FONT_BITS_LOG2] &= ~(1 << (pixelNo&FONT_BITS_MASK));
934 #if (8 != FONT_WIDTH) || (16 != FONT_WIDTH)
936 if (textdisplay->displayDevice.colourMode ==
940 int startPixel = x * FONT_WIDTH;
943 usedBits = startPixel & FONT_BITS_MASK;
947 rowPtr[startPixel>>FONT_BITS_LOG2] &= (1<<usedBits)-1;
949 startPixel += (
sizeof(FontBits_t)*8) - usedBits;
951 memset (&rowPtr[startPixel>>FONT_BITS_LOG2], 0xff,
952 (textdisplay->displayDevice.geometry.width - startPixel)/8);
957 textdisplay->displayDevice.geometry.stride / (
sizeof(FontBits_t) * 8) ;
961 textdisplay->displayDevice.pPixelMatrixDraw(&textdisplay->displayDevice,
962 textdisplay->lineBuffer,
964 textdisplay->columns*FONT_WIDTH,
965 #ifdef EMWIN_WORKAROUND
966 textdisplay->columns*FONT_WIDTH,
980 static EMSTATUS TextdisplayUpdate(TEXTDISPLAY_Device_t* textdisplay)
985 switch (textdisplay->updateMode)
987 case TEXTDISPLAY_UPDATE_MODE_NONE:
991 case TEXTDISPLAY_UPDATE_MODE_FULL:
995 switch (textdisplay->displayDevice.addressMode)
1000 for (i=0; i<textdisplay->lines; i++)
1002 TextdisplayLineDraw(textdisplay, i);
1005 if (textdisplay->lines * FONT_HEIGHT <
1006 textdisplay->displayDevice.geometry.height)
1008 switch (textdisplay->displayDevice.colourMode)
1011 memset (textdisplay->lineBuffer, 0x00,
1012 textdisplay->displayDevice.geometry.width/8);
1015 memset (textdisplay->lineBuffer, 0xff,
1016 textdisplay->displayDevice.geometry.width/8);
1022 for (i = textdisplay->lines * FONT_HEIGHT;
1023 i < textdisplay->displayDevice.geometry.height;
1027 textdisplay->displayDevice.pPixelMatrixDraw(&textdisplay->displayDevice,
1028 textdisplay->lineBuffer,
1030 textdisplay->displayDevice.geometry.width,
1031 #ifdef EMWIN_WORKAROUND
1032 textdisplay->displayDevice.geometry.width,
1046 case TEXTDISPLAY_UPDATE_MODE_LINE:
1048 switch (textdisplay->displayDevice.addressMode)
1053 return TextdisplayLineDraw(textdisplay, textdisplay->ypos);
1059 case TEXTDISPLAY_UPDATE_MODE_CHAR:
#define TEXTDISPLAY_EMSTATUS_NOT_ENOUGH_MEMORY
#define TEXTDISPLAY_EMSTATUS_OK
EMSTATUS TEXTDISPLAY_New(TEXTDISPLAY_Config_t *config, TEXTDISPLAY_Handle_t *handle)
Create a new text display device.
static uint8_t charBuffer[LINES][CHARS]
8x8 font with all characters
EMSTATUS TEXTDISPLAY_WriteString(TEXTDISPLAY_Handle_t handle, const char *str)
Write a string of characters to a text display.
#define TEXTDISPLAY_EMSTATUS_NOT_SUPPORTED
16x20 font with only number characters and the colon':' and space ' ' signs.
6x8 font with all characters
static uint8_t rgbColor[3]
Display device interface.
#define TEXTDISPLAY_EMSTATUS_INVALID_PARAM
#define DISPLAY_EMSTATUS_OK
Main configuration file for the DISPLAY driver software stack.
#define TEXTDISPLAY_EMSTATUS_NOT_INITIALIZED
#define TEXTDISPLAY_EMSTATUS_OUT_OF_RANGE
EMSTATUS TEXTDISPLAY_LfToCrLf(TEXTDISPLAY_Handle_t handle, bool on)
Enable or disable LF to CR+LF conversion.
void * TEXTDISPLAY_Handle_t
EMSTATUS TEXTDISPLAY_WriteChar(TEXTDISPLAY_Handle_t handle, char c)
Write a single character to a text display.
EMSTATUS DISPLAY_DeviceGet(int displayDeviceNo, DISPLAY_Device_t *device)
Get the display device data structure corresponding to the device number.
EMSTATUS TEXTDISPLAY_Delete(TEXTDISPLAY_Handle_t handle)
Delete a text display device.
void * DISPLAY_PixelMatrix_t