Crate vga_framebuffer

Source
Expand description

VGA Frame Buffer for Embedded Microcontrollers

Generates an 800 x 600 @ 60 Hz SVGA signal from a 48 column x 36 row monochrome text buffer. The image has a border.

TODO: Implement smooth scrolling in the vertical direction with an extra text row.

Width = 400 double width pixels => 400 = 8 + (48 x 8) + 8

Height = 600 pixels => 600 = 12 + (36 x 16) + 12

<-------------- 400 px, pixel doubled to 800 px ------------->
+------------------------------------------------------------+
|<--> 8 pixel border     ^                8 pixel border <-->|
|                        | 12 px border                      |
|                        v                                   |
|    +--------------------------------------------------+    |
|    | <--^------ 48 chars x 8 px = 384  px ----------->|    |
|    |    |                                             |    |
|    |    |                                             |    |
|    |    | 36 rows x 16 px = 576 px                    |    |
|    |    |                                             |    |
|    |    |                                             |    |
|    |    v                                             |    |
|    +--------------------------------------------------+    |
|                          ^                                 |
|                          | 12 px border                    |
|                          v                                 |
+------------------------------------------------------------+

Requires pixels to be emitted with a 20 MHz pixel clock (against a nominal 40 MHz pixel clock, in order to acheive the horizontal doubling).

In order to maintain performance, only one font size is supported: 8x16 pixels. But you can substitute your own font if required (e.g. for Teletext support).

There is optional cursor support. Rather than try and check each text cell at render time to see if it is in the cursor position, we swap chars in and out of the text buffer as the cursor moves. It’s a little more expensive, but the cost is at text write time, not at render time (and so it won’t break sync).

See https://github.com/thejpster/monotron for an example.

Modules§

freebsd_cp850
freebsd_teletext

Structs§

Attr
This structure describes the attributes for a Char. They’re all packed into 8 bits to save RAM.
Col
Describes a vertical column on the screen. Zero is on the left.
FrameBuffer
This structure represents the framebuffer - a 2D array of monochome pixels.
Mode0TextRow
Mode2
Represents Mode2 1-bpp graphics
ModeInfo
Describes a video mode.
Point
A point on the screen. The arguments are X (column), Y (row)
Position
Describes a place on the screen. (0, 0) is the top left.
Row
Identifies a horizontal row on the screen. Zero is at the top.
XRGBColour
Represents 8 pixels, each of which can be any 3-bit RGB colour

Enums§

Char
This MS-DOS CodePage 850. It offers a compromise between the box characters of CodePage 437 and the accents of ISO 8859-1 / Latin-1.
Colour
ControlCharMode
How to handle Control Characters
DoubleHeightMode
You can set this on a row to make the text double-height. This was common on the BBC Micro in Mode 7/Teletext mode.
EscapeCharMode
SpecialChar
Special types of character we need to interpret

Constants§

MODE0_HORIZONTAL_OCTETS
How many words in a line (including the border)
MODE0_TEXT_MAX_COL
Highest X co-ord for text
MODE0_TEXT_MAX_ROW
Highest Y co-ord for text
MODE0_TEXT_NUM_COLS
How many characters in a row
MODE0_TEXT_NUM_ROWS
How many rows of characters on the screen
MODE0_USABLE_COLS
Number of columns in frame buffer
MODE0_USABLE_HORIZONTAL_OCTETS
How many words in a line (excluding the border)
MODE0_USABLE_LINES
Number of lines in frame buffer
MODE2_USABLE_LINES
Number of scan-lines in an image in Mode 2. Note, we print each one twice.
MODE2_WIDTH_PIXELS
Number of pixels in a scan-line in Mode 2

Traits§

AsciiConsole
Refinement of BaseConsole which supports 8-bit characters. Use this is you are implementing an old-fashioned ASCII console (including extended ASCII, like Code Page 850, or ISO 8859-1).
BaseConsole
Abstraction for our console. We can move the cursor around and write text to it. You should use either UnicodeConsole or AsciiConsole depending on whether you want full Unicode support (&str, char, etc), or just 8-bit characters (&[u8] and u8).
Hardware
Implement this on your microcontroller’s timer object.
UnicodeConsole
Refinement of BaseConsole which supports Unicode characters. Use this is you are implementing a modern console with Unicode support.