AN1859 APPLICATION NOTE HOW TO MANAGE THE ST92195 OSD 1 INTRODUCTION The purpose of this application note is to provide the reader a help to design an OSD interface with the ST92195 micro-controller. To keep the information modular, each chapter of this application note deals with a feature of the OSD. Not all features of the OSD are covered. These chapters describe the initialisation, multi byte transfer, TDSRAM mapping, parallel attributes and box modes. Chapters will be added in the future. The serial mode linked to the Teletext function is not described. This document provides software examples to help you to get to know how to use this powerful OSD. Rev. 2 AN1859/0904 1/33 AN1859 - APPLICATION NOTE 2 ST92195 OSD 2.1 Features overview The OSD cell supports two display modes: SERIAL MODE DISPLAY provides the features required to support the Teletext standard and PARALLEL MODE DISPLAY with a wide range of powerful functions. The OSD is able to display 26 lines of 40 or 80 characters. A character is defined by a 10 by 10 dots matrix. The standard font character set contains 512 characters covering the eastern and western European languages. This set is stored in the Font ROM. Each character can be defined by the user with the OSD FONT EDITOR software. The OSD uses the data stored in the 8 Kbytes Teletext Data Storage RAM (TDSRAM). These data can come from user or from the Teletext data acquisition unit (Data Slicer). The OSD reads the character codes from the TDSRAM and from the Font ROM generates the RGB and Fast Blanking signals under control of the vertical (Vsync) and horizontal (Hsync) TV synchronisation signals. Now let's see a summary of the other features listed in the data sheet: 2.1.1 The global screen attributes First of all, you can enable/disable the display. You can select the serial or parallel mode. You have the choice between the 4/3 or 16/9 formats. The vertical and horizontal delays between the rising edge of Vsync and Hsync and the beginning of the display area can be adjusted. The horizontal blank length following the Hsync pulse can be also adjusted. You can choose your full screen color among 15 different colors. All the OSD screen can be in semi-transparent mode. All the characters can have a fringe or a rounding attribute. You can define your default background and foreground color for the characters. 2.1.2 The screen sizes The screen can be filled with 23 rows page plus one header row and two status rows or half screen with 12 rows and header and status rows, this is the line mode. You can display 80 characters per row in serial full page mode. 2.1.3 The box mode In addition to the solid or transparent background modes, you can have a box mode to create some windows with the following features: The inside text solid and the outside text blanked, the inside text solid and the outside text transparent, the outside text solid and the inside text blanked, the outside text solid and the inside text transparent. 2/33 AN1859 - APPLICATION NOTE 2.1.4 The character sizes The current size (simple height, simple width) can be modified in double height in serial mode and in double width, double height or double size (double width, double height) in parallel mode. But a global double height can be added (or not) to the previous size attributes, this function can be a zoom effect on the top or bottom half screen. 2.1.5 The cursor mode If you enable the cursor, you have the choice between a solid or flashing full cursor or an underlined solid cursor. You can move the cursor using cursor position registers (horizontally and vertically). 2.1.6 Scrolling mode You can scroll the screen vertically top/down and bottom/up. 2.1.7 Serial character attributes A serial attribute occupies a character space. It is inserted between characters. Serial attributes allow you to: ■ Choose 8 foreground colours, 8 background colours. ■ Validate/devalidate flashing. ■ Start a box and stop a box. ■ Use the double height size. ■ Conceal and reveal the display. ■ Fringe characters. ■ Use contiguous or separated mosaic characters. ■ Switch between 3 G0 fonts. 2.1.8 Parallel attributes A parallel attribute is not inserted within characters but it occupies an additional byte in RAM. Parallel attributes allow you to: ■ Choose 8 foreground colours, 15 background colours. ■ Underline a character. ■ Apply a smooth rounding effect to a character. ■ Select the G3 character font. ■ Create boxes. ■ Write characters in many sizes: double width, double height, double size. 3/33 AN1859 - APPLICATION NOTE 3 OSD EDIT SOFTWARE 3.1 Presentation The OSD screen editor was created to provide an easy way to create and modify entire 'On Screen' images like menus or user dialogues. This editor is available from STMicroelectronics, please contact the marketing department for details. 3.2 Output files & registers The OSD Edit software generates an ST9+ assembler file (osdfile.s for example) containing the characters and the attributes of the created screen. The format is the following: osdfile:: (the label is the file name) osdfile_Header_p:: .byte........ (the 40 header attributes) osdfile_Header_s:: .byte........ (the 40 header characters) osdfile_Row_1_p:: .byte........ (the first row 40 attributes) osdfile_Row_1_s:: .byte........ (the first row 40 characters) ...... osdfile_Row_23_p:: .byte........ osdfile_Row_23_s:: .byte........ osdfile_Status_0_p:: .byte........ osdfile_Status_0_s:: .byte........ osdfile_Status_1_p:: .byte........ osdfile_Status_1_s:: .byte........ (the last row 40 attributes) (the last row 40 characters) (the 40 status 0 attributes) (the 40 status 0 characters) (the 40 status 1 attributes) (the 40 status 1 characters) The C functions managing the OSD which will be described later use this format. These assembler files linked with the C code are tables of bytes representing OSD rows. 4/33 AN1859 - APPLICATION NOTE 4 ST92195 PROGRAMMING This chapter explains some important features of the OSD and refers to an example software managing the OSD. The structure of this software is based on an automaton calling up screen menus showing a particular feature. 4.1 Clocks and OSD initialisation To start the ST92195 you must initialize the PLLs correctly: You write the desired frequency value (multiplier frequency) of the main clock and of the pixel clock PLLs, then you start the main clock and pixel clock PLLs. After a 35 milliseconds delay you can enable the PLL clock as CPU clock, and the PLL pixel clock as slicer and OSD clock. The application software attached with this document provides the InitClocks() function which initialises clocks. The described delay is made up with a loop: for (i=9000 ; i!=0 ; i--); taking into account the CPU clock before the PLL clock enabling (crystal clock divided by 2). We provide the InitOSD() function as an initialisation example, the horizontal position adjustment (R241/F1h page 20h), the vertical position adjustment (R242/F2h page 20h) and the length of the horizontal blank which follows the horizontal sync pulse (R240/F0h page 20h), are parameters you can program (depending on the TV set used). 4.2 TDSRAM interface and multi-byte transfer In this document, we'll explain TDSRAM interface (TRI) without going into details. The TRI manages data flows between acquisition unit, OSD cell, TDSRAM and the multi-byte buffer (40 bytes). The multi-byte transfer brings an actual benefit when used in conjunction with the acquisition unit in Teletext mode because the fast DMA off loads the CPU. Concerning the OSD, the TRI and the OSD reading must be enabled, with the GEN and DON bits respectively of the CONFIG register (R252/FCh page 26h). This is done in the InitOSD() function. The multi-byte transfer consists of loading the 40 data characters or attributes of a row in the 40-byte buffer, then the DMA mechanism will load these data in the TDSRAM. The data are in a ROM table, the buffer is in register file: R240/255 page 24h; R240/255 page 25h; R240/247 page 26h. The destination address in the TDSRAM is written in two registers: MBTSA1R and MBTSA0R (R250/1 page 26h). The transfer starts when the BUSY bit of the BUFCR register (R248 page 26h) is set. Monitoring the BUSY bit allows you to access to the TDSRAM when it is ready. The function *write_MBT_BUFFER(*cha_pointer, *dest_address) allowing the mutli-byte transfer described above is attached with this document. The first pointer is the 40-character row pointer, the second one is the TDSRAM address to fill. 5/33 AN1859 - APPLICATION NOTE 4.3 Mapping and selection of the TDSRAM for display A screen is composed of a 23 rows page (1-23), a header row (0) and two status rows (24-25). The TDSRAM is a linear memory space but it can be seen as 8 blocks (0-7) of 1 Kbytes. 4.3.1 Page management: In full single page serial mode, a page needs a 1 Kbytes block. There are 8 pages (0-7). In full single page parallel mode, a page needs two 1 Kbytes blocks (one for the characters, one for the attributes). There are 4 pages (0-3). In 80 character full page serial mode, a page needs two 1 Kbytes blocks (one for the left side of the screen, the other for the right side). There are 4 pages (0-3). In these two last modes, the page begins with an even block (0,2...), thus in parallel mode the characters are in the even block and the attributes in the odd one. The base address of the TDSRAM is 8000h. To fill parallel page 1 (the second), the characters will be loaded in 8800h and the associated attributes in 8C00h (8800h+400h). Now, to select a page, you have to write into the 4 LSB of the TDPR location control register (R252/FCh, page 20h) the page number which depends on the mode. In fact, the value written in the register is the total number of 0.5 Kbytes blocks! Example: if you want to point (to select) the 3rd block (page 2 in serial mode, page 1 in parallel mode) you must write 6 in the TDPR control register. To avoid this calculation, the application software attached with this document provides functions which take into account only the "user" page number: FillFullSinglePageSerial(*FileAddress,PageNbr), and FillFullSinglePageParallel(*FileAddress,PageNbr). These functions wait for the address of the byte table taken from the OSD Edit file and the page number to fill. This number is from 0 to 7 for serial mode and from 0 to 3 for parallel mode. These functions use the multi-byte transfer. The function EnableDisplay(RowNumber, PageNbr, Mode) enables the page to display, with same comment for the page number. All the rows or a row number can be specified, as can the mode (serial, parallel, 80 characters). 6/33 AN1859 - APPLICATION NOTE 4.3.2 Header and status management: The header and the status rows are loaded in a 0.5 Kbytes block containing characters and attributes (if existing). To select a header and status block you have to write the 0.5 Kbytes block number into the 4 MSB of the TDPR location control register (R252/FCh, page 20h). If you want to point (to select) the 7th block, you must write 14 (decimal) in the TDPR control register. The application software attached with this document provides functions which take into account the 0.5 Kbytes block number: FillHeader(*FileAddress,HeaderStatusBlockNbr),FillStatus(*FileAddress,HeaderStatusBlockNbr). These functions wait for the address of the bytes table taken from the OSD Edit file and the block number to fill. This number is from 0 to 15. These functions use the multi-byte transfer. The function EnableHeaderStatus(BlockNbr, Mode) enables the header and the status to display. The block number is from 0 to 15, the mode is level 1 (no parallel attributes) or level 1+ (header and status with parallel attributes). Figure 1. Example of TDSRAM mapping and selection Address Block nbr. 1/2 Block nbr. 8000h 0 0 8400h 1 2 8800h 2 4 8C00h 3 6 9000h 4 8 9400h 5 0A 9800h 6 0C 9C00h 7 0E 1 3 5 7 9 0B 0D 0F Serial page 1 TDPR control register (R252/FCh) MSB: LSB: X 2 Characters Attributes Parallel page 2 MSB: LSB: X 8 Header & status block 0F MSB: LSB: F X The previous figure illustrates the page and the header/status management. In serial mode, to load page 1 (the second block) the address pointer is 8400h. To display this page the TDPR control register LSB are loaded with 2. In parallel mode, to load page 2 (the 4th and 5th blocks) the address pointer is 9000h for the characters and 9400h for the attributes. To display this page the TDPR control register LSB are loaded with 8. Loading the header and the status rows in the last block implies pointing to 9E00h and loading the TDPR control register MSB with Fh. The detailed routines for this management are available in the attached display.c file. 7/33 AN1859 - APPLICATION NOTE 4.4 Parallel mode (attributes management) An attribute is a byte associated to a character which modifies its color and shape aspect. As we saw in the TDSRAM mapping paragraph, these attribute bytes are located in a 1 Kbytes block following the 1 Kbytes characters block. Within parallel mode, two sub-modes exist, color mode and shape mode. They are selected by the PS bit of the attribute byte (Parallel attribute Selection, bit 7). We see below all the bits of the attribute byte. 4.4.1 Color mode In color mode (PS = 0), the character foreground can be chosen from 8 colors using the three bits FB, FG, FR (respectively bit 6,5 and 4). The character background can be from 15 colors using three bits BB, BG, BR (respectively bit 2,1 and 0) and the half intensity (HI) bit (bit 3). All colors are listed in the following table. Table 1. Table of the color attributes. Foreground colors FB FG FR Background colors HI BB BG BR Background colors HI BB BG BR Black 0 Black 0 Black 8 Red 1 Red 1 Dark red 9 Green 2 Green 2 Dark green a Yellow 3 Yellow 3 Dark yellow b Blue 4 Blue 4 Dark blue c Magenta 5 Magenta 5 Dark magenta d Cyan 6 Cyan 6 Dark cyan e White 7 White 7 Dark white f Note the color propagation: if you select a foreground and a background for a character of a row all the following characters of the row are in the same color till the end of row. A way to avoid this propagation is to select the same colors as those selected in the Default Color Register (R240/F0h page 21) and to write them in the following parallel attribute. 4.4.2 Shape mode In shape mode (PS = 1), the character size can be, in addition to normal size, double width, double height and double size when combining these two last sizes. The concerned bits are DH (bit 2), DW (bit 3) and UH (Upper Half, bit 4). We can display a character in the G3 font (or extended set) if bit CSS (Character Set Selection, bit 0) is set. The character can be underlined (US, bit 1) and smoothly rounded (SR, bit 6) independently of its size. BX (Box mode, bit 5) allows you to create boxes, this feature is described in a separate chapter. 8/33 AN1859 - APPLICATION NOTE ■ How to write a character in double height: Figure 2. The double height parallel attribute DH UH DH A A Attributes row n Attributes row n+1 Characters row n Characters row n+1 Screen The character must be written two times, on the current row and on the following row at the same column. The associated attributes are DH and UH for the first character, only DH for the second one. ■ How to write a character in double width: Figure 3. The double width parallel attribute DW DW A A B B Attributes row n Characters row n Advised Screen The character is written on the current row. The associated attribute is DW. The next character will not be displayed. The next attribute must not be DW. To write several characters in double width you have to skip an attribute each time. 9/33 AN1859 - APPLICATION NOTE ■ How to write double size: Figure 4. The double size parallel attribute DH UH DW DH UH DH DW DH Attributes row n Attributes row n+1 A A A A Characters row n Characters row n+1 Advised Screen This size being the combination of the two previous sizes, the character can be written two times like in double height but the attributes must be written four times. The associated attributes are DH, UH and DW for the first character, DH and DW for the second one. The next attributes of the first row are DH and UH, the next attribute of the second row is DH. ■ Shape propagation: Shape attributes are not propagated on a row except if the following character has a color attribute. The propagation lasts as long as a color attribute is applied to a character. This feature allows several colored characters with shapes in a same row, for example, a green double height underline A followed by a blue double height underline B.... Figure 5. A shape propagation example Shape attributes Colour attributes Attributes row n Attributes row n+1 Characters row n Characters row n+1 DH UH FR: FR: Blue Green DH FR: Red FR: Cyan A A A A A A Blue Green Red Cyan Screen Default colour 10/33 AN1859 - APPLICATION NOTE Note: – Underline is not taken into account on the upper half row in double height. – Underline is not taken into account with a G3 character. – In double width and double size the second character can be a space and the first character will be in double size. But if you want to underline this character the second half will not be underlined. To avoid that we advise writing the character twice. – The default colors for the character foreground and background are applied to the character if shape mode is selected (PS =1) and if there is no character with a color attribute before it. These colors are defined in the Default Color Register (R240/F0h page 21). In this case there are 15 foreground colors available. – The header and status rows accept the color and shape attributes except the size attributes (DH, DW, UH). – A parallel attribute in shape mode but without shape bits (PS = 1; 80h) is a "No effect attribute". To simplify the use of parallel attributes, the application software attached with this document provides functions which take into account the previous notes. The first one writes a character string in the TDSRAM with shape attributes: WriteStringParallelMode(*RAMpointer,*StringPointer,Size,Mode) where the size (normal, DW, DH, DS) and the mode (underline, G3, smooth rounding, box) can be specified. The second one writes the color attributes: WriteParallelColourAttribute(*RAMpointer, foreground, background). The WriteStringParallelModeHS(*RAMpointer,*StringPointer, Mode) writes a parallel string in the header or status rows (no size parameter). These functions write directly into the TDSRAM without multi-byte transfer. 11/33 AN1859 - APPLICATION NOTE 4.5 Box modes The OSD can display boxes. A box is a screen area which can take several aspects according to the 3 bits, Box Enable (BE), Text In Out (TIO), Mixed Mode (MM) of the Full Screen Control register (FSCR R243/F3h; page 20h): Table 2. Different aspects of the boxes BE TIO MM 1 0 0 1 0 1 1 1 0 1 1 1 Different aspects of the boxes The box(es) interior has a solid background (the character foreground and background are displayed) The box(es) area outside is blanked (no characters displayed) The box(es) interior has a solid background (the character foreground and background are displayed) The box(es) area outside has a transparent background (the only character foreground is displayed) The box(es) interior is blanked (no characters displayed) The box(es) area outside has a solid background (the character foreground and background are displayed) The box(es) interior has a transparent background (the only character foreground is displayed) The box(es) area outside has a solid background (the character foreground and background are displayed) Note: if BE is "0" no more boxes appear on the screen but the background is solid if MM is "0" or transparent if MM is "1". Solid means the character background is present and the TV image masked, transparent means the character background is not displayed, so the TV image appears. You can make boxes in serial and parallel mode. 12/33 AN1859 - APPLICATION NOTE 4.5.1 Box in serial mode In serial mode you must write the Box On attribute twice to begin the box and the Box Off attribute twice to end the box area. The box begins on the second Box On and finishes on the first Box Off. Figure 6. Box effect in serial mode Row n O U T BoxOn BoxOn B O X BoxOff BoxOff O U T Row n+1 O U T BoxOn BoxOn B O B X BoxOff BoxOff O U T B O X B O X TV image A Box inside : solid background. Box outside : blanked TV image O U T B O X O U T O U T B O X O U T Box inside : solid background. Box outside : transparent O U T O U T TV image TV image O U T O U T Box inside : blanked. Box outside : solid background O U T B O X O U T O U T B O X O U T Box inside : transparent. Box outside : solid background 13/33 AN1859 - APPLICATION NOTE 4.5.2 Box in parallel mode In parallel mode the BX bit of the parallel attribute (shape mode) can be applied to all characters of the box, but if a color attribute follows a Box attribute, this one is propagated (it is a shape attribute) till a "no effect attribute" (80h) is encountered. Figure 7. Box effect in parallel mode PS BX Attribute row n Character row n O U T TV image PS BX PS BX FR BG B O B X B O X FR BG PS O U T Box inside : solid background. Box outside : blanked TV image O U T B O X O U T Box inside : solid background. Box outside : transparent O U T TV image O U T Box inside : blanked. Box outside : solid background TV image O U T B O X O U Box inside : transparent. Box outside : solid background 14/33 T AN1859 - APPLICATION NOTE 5 SOFTWARE EXAMPLE 5.1 Display .c file /***************************STMICROELECTRONICS **************************** FILENAME : DISPLAY.C VERSION : V0.0 DATE : February 20, 1997 AUTHOR(s) : Robert Girard PROCESSOR : ST92195 DESCRIPTION : This file contains the source code for the On Screen Display Driver. MODIFICATIONS : ***************************************************************************/ #include "define.h" #include "display.h" #include "st92195.h" #include "st9macro.h" #include "osd_cons.h" const extern unsigned int menu0; /************************************************************************** INPUTS : none OUTPUTS : ST9 OSD registers DESCRIPTION : This function initializes the clock generator cell for CPU, peripherals,TV mode and Teletext mode. **************************************************************************/ void InitClocks(void) { unsigned int i; spp(CCR_PG);/* Select clock controller page */ /* main clock */ MCCR = 0x07; /* Set peripherals and CPU clock at 16MHz (Crystal Frequency: 4MHz) */ MCCR |= 0x80; /* Enable the frequency multiplier (main clock) */ /* pixel clock */ SKCCR = 0x09; /* Frequency dot clock = Crystal frequency * 5 = 20Mhz */ SKCCR |= 0x80; /* Enable the frequency multiplier (pixel clock) */ for (i=9000 ; i!=0 ; i--); /* 36 mS delay for PLL stabilization */ SLCCR = 0x80; PXCCR = 0x80; MCCR |= 0x40; /* Enable TXT slicer */ /* Enable pixel PLL */ /* Enable PLL as CPU clock */ /* synchro */ spp(SCCR_PG); /* Select synchro controller page */ CSYCTR = 0x00; /* Select VSYNC and HSYNC from VSYNC and HSYNC inputs (notfrom CVBS) */ CSYSUR = 0xc4; /* Select HSYNC and VSYNC polarity as well as the phase delay between HSYNC and VSYNC which is chassis hardware dependant */ } 15/33 AN1859 - APPLICATION NOTE /*************************************************************************** INPUTS : none OUTPUTS : ST9 OSD registers DESCRIPTION : This function initializes the display cell for both TV mode ( Menu, Stats...) and Teletext mode. ***************************************************************************/ void InitOSD(void) { spp(TDSRAMC2_PG); /* Select TDSRAM Interface page */ CONFIG = 0x03; /* Display ON (DON) RAM interface general enable ON (GEN)*/ spp(DCR1_PG); /* Select OSD page 1 */ HBLANKR = HORIZONTAL_DELAY; HPOSR = HORIZONTAL_POSITION; VPOSR = VERTICAL_POSITION; FSCCR = 0x20; /* Transparent background */ HSCR = 0x00; /* Header,status 1,2 disabled */ NCSR = 0x00; /* */ CHPOSR = 0x00; /* Cursor points the 1rst column */ CVPOSR = 0x00; /* Cursor points the header row. Cursor disabled */ SCLR = 0x00; /* Scrolling disabled */ SCHR = 0x2F; /* */ DCM0R = 0xbc; /* Display en,semitransparent des,fringe en,conceal en global fringe en,global rounding en,4/3 format, single page */ DCM1R = 0x04; /* Fast Blancking 1, full page mode, serial mode */ TDPR = 0xe0; /* Header and status in 1 kBytes block number 7, Page in block 0 */ DE0R = 0x00; /* Row 1 to 8 disabled*/ DE1R = 0x00; /* Row 9 to 16 disabled */ DE2R = 0x00; /* Row 17 to 23 disabled */ spp(DCR2_PG); /* Select OSD page 2 */ DCR = 0x7f; /* white foreground Pale Grey background,*/ } /*************************************************************************** **************************************************************************** TDSRAM management functions **************************************************************************** ***************************************************************************/ /*************************************************************************** INPUTS : Row number from 1 to 23 and page number (1kbyte) from 0 to 7 OUTPUTS : TDSRAM position DESCRIPTION : This function returns the TDSRAM location in a page ***************************************************************************/ tByte *get_TDSRAM_address(tByte PageNbr, tByte RowPosition) { return (tByte *)(cTDSRAM_BaseAddress + (PageNbr*cBlockLength) + ((RowPosition - 1) * 40)); } / **************************************************************************** INPUTS : Row number from 0 to 2 and block number (1/2kbyte) from 00 to 0F and selection (Characters or attributes). OUTPUTS : TDSRAM position 16/33 AN1859 - APPLICATION NOTE DESCRIPTION : This function returns the TDSRAM location in a header and status block ***************************************************************************/ tByte *get_TDSRAM_HS_address(tByte BlockNbr, tByte RowPosition, tByte Selection) { if (Selection == cCharacters) return (tByte *)(cTDSRAM_BaseAddress + (BlockNbr*cSemiBlockLength) + ((RowPosition - 1) * 40)); else return (tByte *)(cTDSRAM_BaseAddress + (BlockNbr*cSemiBlockLength) + ((RowPosition - 1) * 40) + 0x80); /* The header and status attributes are located at the block address plus 80h */ } /*************************************************************************** INPUTS : Character chain pointer Destination address in memory OUTPUTS : Destination address DESCRIPTION : This function copies the character chain into the Multi byte transfer buffer. ***************************************************************************/ tByte *write_MBT_BUFFER(const tByte *cha_pointer,tByte *dest_address) { tByte i; unsigned int j; spp(TDSRAMC0_PG); /* fill up first 16 registers of MBT buffer*/ asm volatile (" ld %0,#0xf0 repeat1: ld (%0)+,%1+ cp %0,#0 jxnz repeat1 " :"=r"(i) :"m"(*cha_pointer)); spp(TDSRAMC1_PG); /* fill up 2nd 16 registers of MBT buffer*/ asm volatile (" ld %0,#0xf0 repeat2: ld (%0)+,%1+ cp %0,#0 jxnz repeat2 " :"=r"(i) :"m"(*cha_pointer)); spp(TDSRAMC2_PG); /* fill up 3rd 8 registers of MBT buffer*/ asm volatile (" ld %0,#0xf0 repeat3: ld (%0)+,%1+ cp %0,#0xf8 jxnz repeat3 " :"=r"(i) :"m"(*cha_pointer)); /* set destination address */ j = (unsigned int) dest_address; MBTSA0 = (tByte) (j); MBTSA1 = (tByte) (j >> 8); BUFC = 0x01; /* starts transfer */ asm(" nop nop "); /* small delay before polling */ while(BUFC & 0x01) /* wait for end of transfer */ asm("nop"); 17/33 AN1859 - APPLICATION NOTE return (dest_address+40); } /************************************************************************ INPUTS : Address of the table corresponding to the .s file from OSD Edit. (refer to the format provided by OSD Edit) Page number to fill with the table. (Page=1Kb PageNbr from 0 to 7) OUTPUTS : none DESCRIPTION : This function fills a characters page in TDSRAM **************************************************************************/ void FillFullSinglePageSerial(const tByte *screen_line,tByte PageNbr) { tByte *i; tByte a; screen_line = screen_line + 80; /* skip the Header */ for (a = 1; a<=23; a++) /* 23 rows */ { i = get_TDSRAM_address(PageNbr,a); i = write_MBT_BUFFER(screen_line+40, i); /* write the character */ /* screen_line + 40 to skip the parallel attributes not used in serial mode but given by OSD Edit */ screen_line = screen_line + 80; /* skip one char. & one attr. line*/ } } /*************************************************************************** INPUTS : Address of the table corresponding to the .s file from OSD Edit. (refer to the format provided by OSD Edit) Page number to fill with the table.(Page=2Kb PageNbr from 0 to 3) OUTPUTS : none DESCRIPTION : This function fills a characters page and an attributes page in TDSRAM ***************************************************************************/ void FillFullSinglePageParallel(const tByte *screen_line,tByte PageNbr) { tByte *j; tByte *i; tByte a; screen_line = screen_line + 80; /* skip the Header */ for { j = i = j = i = (a = 1; a<=23; a++) get_TDSRAM_address((PageNbr*2)+1,a);/* get the attributes address */ get_TDSRAM_address((PageNbr*2),a); /* get the characters address */ write_MBT_BUFFER(screen_line, j); /* write the attributes */ write_MBT_BUFFER(screen_line+40, i);/* write the characters */ /* screen_line + 40 to skip the parallel attributes */ screen_line = screen_line + 80; /* skip one char. & one attr. line*/ } } /*************************************************************************** INPUTS : Address of the table corresponding to the .s file from OSD Edit. 18/33 AN1859 - APPLICATION NOTE Block number to fill with the table. (Block=1/2Kb ; HeaderStatusBlockNbr from 0x0e to 0x0f in this application) OUTPUTS : none DESCRIPTION : This function fills a header row in TDSRAM ***************************************************************************/ void FillHeader(const tByte *screen_line,tByte HeaderStatusBlockNbr) { tByte *j; tByte *i; j = get_TDSRAM_HS_address(HeaderStatusBlockNbr,1,cAttributes); i = get_TDSRAM_HS_address(HeaderStatusBlockNbr,1,cCharacters); j = write_MBT_BUFFER(screen_line, j); i = write_MBT_BUFFER(screen_line+40, i); } /*************************************************************************** INPUTS : Address of the table corresponding to the .s file from OSD Edit. Block number to fill with the table. (Block=1/2Kb ; HeaderStatusBlockNbr from 0x0e to 0x0f in this application)) OUTPUTS : none DESCRIPTION : This function fills status rows in TDSRAM ***************************************************************************/ void FillStatus(const tByte *screen_line,tByte HeaderStatusBlockNbr) { tByte a; tByte *i; tByte *j; screen_line = screen_line + (80*24); /* skip the Header and the page */ for (a = 1; a<=2; a++) { j = get_TDSRAM_HS_address(HeaderStatusBlockNbr,a,cAttributes); i = get_TDSRAM_HS_address(HeaderStatusBlockNbr,a,cCharacters); j = write_MBT_BUFFER(screen_line, j+40); i = write_MBT_BUFFER(screen_line+40, i+40); screen_line = screen_line + 80; /* skip one char. & attr. line*/ } } /*************************************************************************** INPUTS : Row number to display, page number and mode (serial, //, serial 80 col) ! The page number take into account the mode, i.e. 8 pages in serial mode ! and 4 in parallel mode (1K for characters 1K for attributes). ! and 4 in serial 80 characters mode (1K + 1K). OUTPUTS : ST9 OSD registers DESCRIPTION : This function displays a row. ***************************************************************************/ void EnableDisplay(tByte RowNumber, tByte PageNbr, tByte Mode) { tByte i, j; /* Temporary storage */ /* mode enabling & page number enabling */ spp(DCR1_PG); switch (Mode) 19/33 AN1859 - APPLICATION NOTE { case cSerial: DCM1R &= ~0x01; /* serial mode */ DCM0R &= ~0x01; /* single page */ TDPR &= 0xf0; TDPR |= PageNbr*2; /* page number in 1/2 Kbyte block */ break; case cParallel: DCM1R |= 0x01; /* parallel mode */ DCM0R &= ~0x01; /* single page */ TDPR &= 0xf0; TDPR |= PageNbr*4; /* page number in 1/2 Kbyte block */ break; case cSerial80: DCM1R &= ~0x01; /* serial mode */ DCM0R |= 0x01; /* double page */ TDPR &= 0xf0; TDPR |= PageNbr*4; /* page number in 1/2 Kbyte block */ break; } /* row enabling */ if (RowNumber == cRowAll) { DE0R = 0xff; DE1R = 0xff; DE2R = 0xff; return; } /* Set bit position according to the row number */ for (i=1, j=RowNumber; j>1; j--) asm ("rol %0" : :"r"(i)); /* Enable selected row */ if (RowNumber <= cRow8) { DE0R = DE0R | i; return; } if (RowNumber <= cRow16) { DE1R = DE1R | i; return; } if (RowNumber <= cRow23) { DE2R = DE2R | i; } } / **************************************************************************** INPUTS : Row number to cancel OUTPUTS : ST9 OSD registers DESCRIPTION : This function cancel a row. ***************************************************************************/ 20/33 AN1859 - APPLICATION NOTE void DisableDisplay(tByte RowNumber) { tByte i, j; /* Temporary storage */ spp(DCR1_PG); if (RowNumber == cRowAll) { DE0R = 0x00; DE1R = 0x00; DE2R = 0x00; return; } /* Set bit position according to the row number */ for (i=1, j=RowNumber; j>1; j--) asm ("rol %0" : :"r"(i)); /* Disable selected row */ if (RowNumber <= cRow8) { DE0R = DE0R & ~i; return; } if (RowNumber <= cRow16) { DE1R = DE1R & ~i; return; } if (RowNumber <= cRow23) { DE2R = DE2R & ~i; } } /*************************************************************************** INPUTS : Block number to display and mode (level 1 or level 1 plus) OUTPUTS : ST9 OSD registers DESCRIPTION : This function displays header and status. ***************************************************************************/ void EnableHeaderStatus(tByte BlockNbr, tByte Mode) { /* mode enabling & page number enabling */ spp(DCR1_PG); if (Mode == cLevelOne) { HSCR = 0x2a; /* Header,status 0,1 enabled and processed as level1 (serial attributes) */ TDPR &= 0x0f; TDPR |= (BlockNbr<<4); } else { HSCR = 0x3f; /* Header,status 0,1 enabled and processed as level1+ (// attributes) */ TDPR &= 0x0f; TDPR |= (BlockNbr<<4); } } 21/33 AN1859 - APPLICATION NOTE /*************************************************************************** INPUTS : OUTPUTS : ST9 OSD registers DESCRIPTION : This function disable header and status. ***************************************************************************/ void DisableHeaderStatus(void) { spp(DCR1_PG); HSCR = 0x00; /* Header,status 0,1 disabled */ } /*************************************************************************** INPUTS : OUTPUTS : ST9 OSD registers DESCRIPTION : This function disable header. ***************************************************************************/ void DisableHeader(void) { spp(DCR1_PG); HSCR &= ~0x01; /* Header disabled */ } /*************************************************************************** INPUTS : OUTPUTS : ST9 OSD registers DESCRIPTION : This function disable status. ***************************************************************************/ void DisableStatus(void) { spp(DCR1_PG); HSCR &= ~0x28; /* Header,status 0,1 disabled */ } /*************************************************************************** **************************************************************************** Parallel mode functions **************************************************************************** ***************************************************************************/ /*************************************************************************** INPUTS : DRAM pointer - Point the location to write the data (character or attribute) into the TDSRAM OUTPUTS : Return the next TDSRAM location DESCRIPTION : This function writes the given character. ***************************************************************************/ tByte *WriteData(tByte *Pointer,tByte Data) { *Pointer++ = Data; return Pointer; } /*************************************************************************** INPUTS : DRAM pointer - Point the location to "OR" the data (character or attribute) into the TDSRAM OUTPUTS : Return the next TDSRAM location DESCRIPTION : This function writes the given character. ***************************************************************************/ tByte *OrData(tByte *Pointer,tByte Data) { *Pointer++ |= Data; return Pointer; 22/33 AN1859 - APPLICATION NOTE } /*************************************************************************** INPUTS : The location to write. The attribute to write into the TDSRAM. The attributes number to write. OUTPUTS : DESCRIPTION : This function writes the given parallel attribute. ***************************************************************************/ void WriteParallelAttribute(tByte *Pointer,tByte Attribute,tByte Number) { while (Number != 0) { Pointer = WriteData(Pointer,Attribute); /* write the attribute */ Number--; } } /*************************************************************************** INPUTS : The location to write. The shape attribute to overwrite into the TDSRAM. The attributes number to write. OUTPUTS : DESCRIPTION : This function writes the given parallel attribute. ***************************************************************************/ void WriteParallelShapeAttribute(tByte *Pointer,tByte Attribute,tByte Number) { while (Number != 0) { Pointer = OrData(Pointer,Attribute); /* overwrite the attribute */ Number--; } } /*************************************************************************** INPUTS : The location to write. The colour attribute to write into the TDSRAM. The attributes number to write. OUTPUTS : DESCRIPTION : This function writes the given parallel attribute. ***************************************************************************/ void WriteParallelColourAttribute(tByte *Pointer,tByte Foreground, tByte Background) { Pointer = WriteData(Pointer,(Foreground<<4)| Background); /* write the attribute */ } /*************************************************************************** INPUTS : TDSRAM pointer - Point the location to start with String pointer - Point the first character to write into the TDSRAM Mode: Underline, Box mode, Smooth rounding, Character set selection OUTPUTS : DESCRIPTION : This function writes the given string. ***************************************************************************/ void WriteStringParallelModeHS(tByte *RAMPointer,const tByte *StringPointer,tByte Mode) { 23/33 AN1859 - APPLICATION NOTE while (*StringPointer != '\0') /*loop till the end of the string */ { *RAMPointer = *StringPointer++; /*points to the next string character*/ /* write the shape attribute :add 0x80 to the pointer to point the HS at tributes) */ *(RAMPointer++ + 0x80) = (cNormal|Mode); /*points to the next RAM byte*/ } } / **************************************************************************** INPUTS : TDSRAM pointer - Point the location to start with String pointer - Point the first character to write into the TDSRAM Size: Normal size, double width, double height, double size Mode: Underline, Box mode, Smooth rounding, Character set selection OUTPUTS : DESCRIPTION : This function writes the given string. ***************************************************************************/ void WriteStringParallelMode(tByte *RAMPointer,const tByte *StringPointer,tByte Size, tByte Mode) { while (*StringPointer != '\0') /*loop till the end of the string */ { switch (Size) { case cNormal: /*normal size */ /* write the character */ *RAMPointer = *StringPointer++; /*points to the next string character*/ /* write the size & shape attribute : add to the pointer the block lenght*/ *(RAMPointer++ + cBlockLength) = (cNormal|Mode); /*points to the next RAM byte*/ break; case cDoubleHeight: /*double height: 2 rows are used */ /* write the first character */ *RAMPointer = *StringPointer; /* write the first size & shape attribute: add to the pointer the block lenght*/ *(RAMPointer + cBlockLength) = (cDoubleHeight|cUpperHalf|Mode); /* write the 2nd character:add to the pointer the row length*/ *(RAMPointer + 40) = *StringPointer++; /*points to the next string character*/ /* write the 2nd size & shape attribute: add to the pointer the block lenght*/ *(RAMPointer++ + 40 + cBlockLength) = (cDoubleHeight|Mode); /*points to the next RAM byte*/ break; case cDoubleWidth: /*double widht: the characters are doubled */ /* write the first character */ *RAMPointer = *StringPointer; /* write the first size & shape attribute: add to the pointer the block lenght*/ 24/33 AN1859 - APPLICATION NOTE *(RAMPointer++ + cBlockLength) = (cDoubleWidth|Mode); /*points to the next RAM byte*/ /* write the 2nd character*/ *RAMPointer = *StringPointer++; /*points to the next string character*/ /* write the 2nd (only) shape attribute: add to the pointer the block lenght*/ *(RAMPointer++ + cBlockLength) = Mode;/*points to the next RAM byte*/ break; case cDoubleSize: /*double size: four characters are writen */ /* write the first character */ *RAMPointer = *StringPointer; /* write the first size & shape attribute: add to the pointer the block lenght*/ *(RAMPointer + cBlockLength) = (cDoubleHeight|cUpperHalf|cDoubleWidth|Mode); /* write the 2nd character:add to the pointer the row length*/ *(RAMPointer+40) = *StringPointer; /* write the 2nd size & shape attribute: add to the pointer the block and the row lenghts*/ *(RAMPointer++ + 40 + cBlockLength) = (cDoubleHeight|cDoubleWidth|Mode);/*points to the next RAM byte*/ /* write the 3rd character */ *RAMPointer = *StringPointer; /* write the 3rd size & shape attribute: add to the pointer the block lenght*/ *(RAMPointer + cBlockLength) = (cDoubleHeight|cUpperHalf|Mode); /* write the 4th character:add to the pointer the row length*/ *(RAMPointer + 40) = *StringPointer++; /*points to the next string character*/ /* write the 4th size & shape attribute: add to the pointer the block and the row lenghts*/ *(RAMPointer++ + 40 + cBlockLength) = (cDoubleHeight|Mode);/*points to the next RAM byte*/ break; } } } /*************************************************************************** INPUTS : TDSRAM pointer - Point the location to start The data to fill in (can be different in case of // attribute) OUTPUTS : DESCRIPTION : This function clears a row. ***************************************************************************/ void ClearRow(tByte *Pointer,tByte Data) { tByte i; for (i=0;i<40;i++) { Pointer = WriteData(Pointer,Data); 25/33 AN1859 - APPLICATION NOTE } }/************************************************************************** INPUTS : The national character set number (0-14) OUTPUTS : DESCRIPTION : This function selects the national character set. ***************************************************************************/ void SetNationalCharacter(tByte NationalSet) { spp(DCR1_PG); NCSR |= NationalSet; } /*************************************************************************** INPUTS : The foreground and the background colour OUTPUTS : DESCRIPTION : This function selects the colour. ***************************************************************************/ void SetDefaultColour(tByte Foreground,tByte Background) { spp(DCR2_PG); DCR = ((Foreground<<4)|Background); /* write foreground and background */ } /*************************************************************************** INPUTS : The mode for the boxes and the background The full screen colour OUTPUTS : DESCRIPTION : This function selects the background and the box mode ***************************************************************************/ void BoxMode(tByte BoxMode,tByte ScreenColour) { spp(DCR1_PG); FSCCR = (BoxMode|ScreenColour); /* write the mode and the colour */ } 26/33 AN1859 - APPLICATION NOTE 5.2 Display.h file /***************************STMICROELECTRONICS **************************** FILENAME : DISPLAY.H VERSION : V0.0 DATE : February 20, 1997 AUTHOR(s) : Robert Girard PROCESSOR : ST92195 DESCRIPTION : This module contains constant definitions and function prototypes. MODIFICATIONS : ***************************************************************************/ / **************************************************************************** Prototypes ***************************************************************************/ void WaitForSecond(tByte Number); void InitClocks(void); void InitOSD(void); tByte *get_TDSRAM_address(tByte PageNbr, tByte RowPosition); tByte *get_TDSRAM_HS_address(tByte BlockNbr, tByte RowPosition, tByte Selection); tByte *write_MBT_BUFFER(const tByte *cha_pointer,tByte *dest_address); void FillFullSinglePageSerial(const tByte *screen_line,tByte PageNbr); void FillFullSinglePageParallel(const tByte *screen_line,tByte PageNbr); void FillHeader(const tByte *screen_line,tByte HeaderStatusBlockNbr); void FillStatus(const tByte *screen_line,tByte HeaderStatusBlockNbr); void EnableDisplay(tByte RowNumber, tByte PageNbr, tByte Mode); void DisableDisplay(tByte RowNumber); void EnableHeaderStatus(tByte BlockNbr, tByte Mode); void DisableHeaderStatus(void); void DisableHeader(void); void DisableStatus(void); tByte *WriteData(tByte *Pointer,tByte Data); tByte *OrData(tByte *Pointer,tByte Data); void WriteParallelAttribute(tByte *Pointer,tByte Attribute,tByte Number); void WriteParallelColourAttribute(tByte *Pointer,tByte Foreground,tByte Background); void WriteParallelShapeAttribute(tByte *Pointer,tByte Attribute,tByte Number); void WriteStringParallelModeHS(tByte *Pointer,const tByte *StringPointer,tByte Mode); void WriteStringParallelMode(tByte *Pointer, const tByte *StringPointer,tByte Size, tByte Mode); void ClearRow(tByte *Pointer,tByte Data); void SetDefaultColour(tByte Foreground,tByte Background); void SetNationalCharacter(tByte NationalSet); void BoxMode(tByte BoxMode,tByte ScreenColour); /*************************************************************************** Definitions ***************************************************************************/ #define cTDSRAM_BaseAddress 0x8000 #define cBlockLength 0x400 #define cSemiBlockLength 0x200 27/33 AN1859 - APPLICATION NOTE #define #define #define #define #define #define #define #define #define #define #define #define #define #define cPage0 0x00 cPage1 0x01 cPage2 0x02 cPage3 0x03 cPage4 0x04 cPage5 0x05 cPage6 0x06 cPage7 0x07 cPageHeader0 0x0e cPageHeader1 0x0f cAttributePage0 cPage1 cAttributePage1 cPage3 cAttributePage2 cPage5 cAttributePage3 cPage7 /* Modes*/ #define cSerial 0x00 #define cParallel 0x01 #define cSerial80 0x02 #define cLevelOne 0x00 #define cLevelOnePlus 0x01 #define cCharacters 0x00 #define cAttributes 0xFF /*Rows*/ #define cHeaderRow 1 #define cStatusRow0 2 #define cStatusRow1 3 #define cRowAll 0xFF #define cRow1 1 #define cRow2 2 #define cRow3 3 #define cRow4 4 #define cRow5 5 #define cRow6 6 #define cRow7 7 #define cRow8 8 #define cRow9 9 #define cRow10 10 #define cRow11 11 #define cRow12 12 #define cRow13 13 #define cRow14 14 #define cRow15 15 #define cRow16 16 #define cRow17 17 #define cRow18 18 #define cRow19 19 #define cRow20 20 #define cRow21 21 #define cRow22 22 #define cRow23 23 /* Parallel shape attributes */ #define cNone 0x80 #define cNormal 0x80 28/33 AN1859 - APPLICATION NOTE #define #define #define #define #define #define #define #define cCharacterSelection 0x81 cUnderline 0x82 cDoubleHeight 0x84 cDoubleWidth 0x88 cDoubleSize 0x8c cUpperHalf 0x90 cBoxMode 0xa0 cSmoothRounding 0xc0 /* Parallel colour attributes */ #define cBlack 0x00 #define cRed 0x01 #define cGreen 0x02 #define cYellow 0x03 #define cBlue 0x04 #define cMagenta 0x05 #define cCyan 0x06 #define cWhite 0x07 #define #define #define #define #define #define #define cRedHI 0x09 cGreenHI 0x0A cYellowHI 0x0B cBlueHI 0x0C cMagentaHI 0x0D cCyanHI 0x0E cGrey 0x0F /* Default colour */ #define cDefaultBlack 0x00 #define cDefaultBlue 0x01 #define cDefaultGreen 0x02 #define cDefaultCyan 0x03 #define cDefaultRed 0x04 #define cDefaultMagenta 0x05 #define cDefaultYellow 0x06 #define cDefaultWhite 0x07 #define cDefaultBlueHI 0x09 #define cDefaultGreenHI 0x0a #define cDefaultCyanHI 0x0b #define cDefaultRedHI 0x0c #define cDefaultMagentaHI 0x0d #define cDefaultYellowHI 0x0e #define cDefaultGrey 0x0f /* Box mode */ #define cSolidBackground 0x00 #define cTransparentBackground 0x20 #define cInSolidOutBlanked 0x80 #define cInSolidOutTransparent 0xa0 #define cInBlankedOutSolid 0xc0 #define cInTransparentOutSolid 0xe0 #define cFullScreenBlack 0x00 #define cFullScreenBlue 0x01 #define cFullScreenGreen 0x02 #define cFullScreenCyan 0x03 #define cFullScreenRed 0x04 29/33 AN1859 - APPLICATION NOTE #define #define #define #define #define #define #define #define #define #define cFullScreenMagenta 0x05 cFullScreenYellow 0x06 cFullScreenWhite 0x07 cFullScreenBlueHI 0x09 cFullScreenGreenHI 0x0a cFullScreenCyanHI 0x0b cFullScreenRedHI 0x0c cFullScreenMagentaHI 0x0d cFullScreenYellowHI 0x0e cFullScreenGrey 0x0f /* TV dependent */ #define HORIZONTAL_DELAY 0x30 #define HORIZONTAL_POSITION 0x45 #define VERTICAL_POSITION 0x0E 30/33 AN1859 - APPLICATION NOTE 5.3 Examples of use of the previous routines /*************************************************************************** INPUTS : none OUTPUTS : none DESCRIPTION : This function displays a simple menu ***************************************************************************/ void ShowMenu0() { SetDefaultColour(cDefaultBlue,cDefaultCyan); BoxMode(cTransparentBackground,cFullScreenCyanHI); /*select a transparent background*/ /* The main menu is a serial screen, located in block 6 */ FillFullSinglePageSerial((const unsigned char *) &menu0,cPage6); /* The header and status rows are located in the lower part of block 7 */ FillHeader((const unsigned char *) &menu0,cPageHeader0); FillStatus((const unsigned char *) &menu0,cPageHeader0); EnableDisplay(cRowAll,cPage6,cSerial); /* All the rows are enable in serial mode */ EnableHeaderStatus(cPageHeader0,cLevelOne); /* H&S enable in level one mode (serial) */ } /*double size in parallel mode */ .... const unsigned char sString[] = "STMICROELECTRONICS"; tByte * j; j = get_TDSRAM_address(cPage0,cRow15); WriteStringParallelMode(j+9,sString,cDoubleSize,cNone); /* write the string in row 15 column 9 page 0 */ .... 31/33 AN1859 - APPLICATION NOTE 6 REVISION HISTORY Table 3. Revision History 32/33 Date Revision Description of Changes April-1999 1 First Issue 14-Sep-2004 2 Stylesheet update. No content change. AN1859 - APPLICATION NOTE The present note which is for guidance only, aims at providing customers with information regarding their products in order for them to save time. As a result, STMicroelectronics shall not be held liable for any direct, indirect or consequential damages with respect to any claims arising from the content of such a note and/or the use made by customers of the information contained herein in connection with their products. Information furnished is believed to be accurate and reliable. However, STMicroelectronics assumes no responsibility for the consequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. No license is granted by implication or otherwise under any patent or patent rights of STMicroelectronics. Specifications mentioned in this publication are subject to change without notice. This publication supersedes and replaces all information previously supplied. STMicroelectronics products are not authorized for use as critical components in life support devices or systems without express written approval of STMicroelectronics. The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners © 2004 STMicroelectronics - All rights reserved STMicroelectronics group of companies Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan Malaysia - Malta - Morocco - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America www.st.com 33/33
© Copyright 2024