A TextDisplay driver that supports graphical displays using on of the SED133x conrtrolers. Allows stdout and stderr output to be redirected to the display.

Committer:
llagendijk
Date:
Sat Jan 29 21:28:42 2011 +0000
Revision:
9:68ad299df12b
Parent:
5:684f79f70ac9
First release of my version of TextDisPlay

Who changed what in which revision?

UserRevisionLine numberNew contents of line
llagendijk 0:9e72c57b16fd 1 /* mbed Terminal TextDisplay Library
llagendijk 0:9e72c57b16fd 2 * Copyright (c) 2007-2009 sford
llagendijk 0:9e72c57b16fd 3 * Released under the MIT License: http://mbed.org/license/mit
llagendijk 0:9e72c57b16fd 4 */
llagendijk 0:9e72c57b16fd 5
llagendijk 0:9e72c57b16fd 6 #include "Terminal.h"
llagendijk 0:9e72c57b16fd 7
llagendijk 0:9e72c57b16fd 8 #include "mbed.h"
llagendijk 0:9e72c57b16fd 9
llagendijk 1:18c56f038905 10 Terminal::Terminal(PinName tx, PinName rx, const char *name) : TextDisplay(name), _serial(tx, rx) {
llagendijk 0:9e72c57b16fd 11 cls();
llagendijk 0:9e72c57b16fd 12 }
llagendijk 5:684f79f70ac9 13 /** Create the TextDisplay interface
llagendijk 5:684f79f70ac9 14 *
llagendijk 5:684f79f70ac9 15 * reset PinName for reset
llagendijk 5:684f79f70ac9 16 * nRead PinName for /read
llagendijk 5:684f79f70ac9 17 * nWrite PinName for /write
llagendijk 5:684f79f70ac9 18 * nSelect PinName for /select
llagendijk 5:684f79f70ac9 19 * addr0 PinName for addr0
llagendijk 5:684f79f70ac9 20 * d0 - d7 PinName for D0 -D7
llagendijk 5:684f79f70ac9 21 * hor_dots horizontal resolution of display (in pixels), default: 256
llagendijk 5:684f79f70ac9 22 * vert_dots vertical resolution of display (in pixels), default: 128
llagendijk 5:684f79f70ac9 23 * char_width diaply width of character (in pixels), default: 6
llagendijk 5:684f79f70ac9 24 * char_height display height of character (in pixels), default: 10
llagendijk 5:684f79f70ac9 25 * name name to be used in pathname of the stream (defaults to "sed133x")
llagendijk 5:684f79f70ac9 26 * @param name The name used in the path to access the strean through the filesystem
llagendijk 5:684f79f70ac9 27 */
llagendijk 0:9e72c57b16fd 28 void Terminal::character(uint16_t column, uint16_t row, int c) {
llagendijk 0:9e72c57b16fd 29 // Cursor Home <ESC>[{ROW};{COLUMN}H
llagendijk 0:9e72c57b16fd 30 _serial.printf("\033[%u;%uH%c", row + 1, column + 1, c);
llagendijk 0:9e72c57b16fd 31 }
llagendijk 0:9e72c57b16fd 32
llagendijk 0:9e72c57b16fd 33 uint16_t Terminal::columns() {
llagendijk 0:9e72c57b16fd 34 return 80;
llagendijk 0:9e72c57b16fd 35 }
llagendijk 0:9e72c57b16fd 36
llagendijk 0:9e72c57b16fd 37 uint16_t Terminal::rows() {
llagendijk 0:9e72c57b16fd 38 return 35;
llagendijk 0:9e72c57b16fd 39 }
llagendijk 0:9e72c57b16fd 40
llagendijk 0:9e72c57b16fd 41 void Terminal::cls() {
llagendijk 0:9e72c57b16fd 42 _serial.printf("\033[2J");
llagendijk 0:9e72c57b16fd 43 }
llagendijk 0:9e72c57b16fd 44
llagendijk 0:9e72c57b16fd 45 void Terminal::foreground(uint32_t colour) {
llagendijk 0:9e72c57b16fd 46
llagendijk 0:9e72c57b16fd 47 /* Set Attribute Mode <ESC>[{n}m
llagendijk 0:9e72c57b16fd 48 * - Sets display attribute settings. The following lists standard attributes:
llagendijk 0:9e72c57b16fd 49 *
llagendijk 0:9e72c57b16fd 50 * Foreground Colours
llagendijk 0:9e72c57b16fd 51 * 30 Black
llagendijk 0:9e72c57b16fd 52 * 31 Red
llagendijk 0:9e72c57b16fd 53 * 32 Green
llagendijk 0:9e72c57b16fd 54 * 33 Yellow
llagendijk 0:9e72c57b16fd 55 * 34 Blue
llagendijk 0:9e72c57b16fd 56 * 35 Magenta
llagendijk 0:9e72c57b16fd 57 * 36 Cyan
llagendijk 0:9e72c57b16fd 58 * 37 White
llagendijk 0:9e72c57b16fd 59 */
llagendijk 0:9e72c57b16fd 60 uint32_t r = (colour >> 23) & 1;
llagendijk 0:9e72c57b16fd 61 uint32_t g = (colour >> 15) & 1;
llagendijk 0:9e72c57b16fd 62 uint32_t b = (colour >> 7) & 1;
llagendijk 0:9e72c57b16fd 63 uint32_t bgr = (b << 2) | (g << 1) | (r << 0);
llagendijk 0:9e72c57b16fd 64 uint32_t c = 30 + bgr;
llagendijk 0:9e72c57b16fd 65 _serial.printf("\033[%um", c);
llagendijk 0:9e72c57b16fd 66 }
llagendijk 0:9e72c57b16fd 67
llagendijk 0:9e72c57b16fd 68 void Terminal::background(uint32_t colour) {
llagendijk 0:9e72c57b16fd 69
llagendijk 0:9e72c57b16fd 70 /* Background Colours
llagendijk 0:9e72c57b16fd 71 * 40 Black
llagendijk 0:9e72c57b16fd 72 * 41 Red
llagendijk 0:9e72c57b16fd 73 * 42 Green
llagendijk 0:9e72c57b16fd 74 * 43 Yellow
llagendijk 0:9e72c57b16fd 75 * 44 Blue
llagendijk 0:9e72c57b16fd 76 * 45 Magenta
llagendijk 0:9e72c57b16fd 77 * 46 Cyan
llagendijk 0:9e72c57b16fd 78 * 47 White
llagendijk 0:9e72c57b16fd 79 */
llagendijk 0:9e72c57b16fd 80 uint32_t r = (colour >> 23) & 1;
llagendijk 0:9e72c57b16fd 81 uint32_t g = (colour >> 15) & 1;
llagendijk 0:9e72c57b16fd 82 uint32_t b = (colour >> 7) & 1;
llagendijk 0:9e72c57b16fd 83 uint32_t bgr = (b << 2) | (g << 1) | (r << 0);
llagendijk 0:9e72c57b16fd 84 uint32_t c = 40 + bgr;
llagendijk 0:9e72c57b16fd 85 _serial.printf("\033[%um", c);
llagendijk 0:9e72c57b16fd 86 }
llagendijk 0:9e72c57b16fd 87